@@ -50,8 +50,41 @@ static inline void set_nr_cpu_ids(unsigned int nr)
50
50
#endif
51
51
}
52
52
53
- /* Deprecated. Always use nr_cpu_ids. */
54
- #define nr_cpumask_bits nr_cpu_ids
53
+ /*
54
+ * We have several different "preferred sizes" for the cpumask
55
+ * operations, depending on operation.
56
+ *
57
+ * For example, the bitmap scanning and operating operations have
58
+ * optimized routines that work for the single-word case, but only when
59
+ * the size is constant. So if NR_CPUS fits in one single word, we are
60
+ * better off using that small constant, in order to trigger the
61
+ * optimized bit finding. That is 'small_cpumask_size'.
62
+ *
63
+ * The clearing and copying operations will similarly perform better
64
+ * with a constant size, but we limit that size arbitrarily to four
65
+ * words. We call this 'large_cpumask_size'.
66
+ *
67
+ * Finally, some operations just want the exact limit, either because
68
+ * they set bits or just don't have any faster fixed-sized versions. We
69
+ * call this just 'nr_cpumask_size'.
70
+ *
71
+ * Note that these optional constants are always guaranteed to be at
72
+ * least as big as 'nr_cpu_ids' itself is, and all our cpumask
73
+ * allocations are at least that size (see cpumask_size()). The
74
+ * optimization comes from being able to potentially use a compile-time
75
+ * constant instead of a run-time generated exact number of CPUs.
76
+ */
77
+ #if NR_CPUS <= BITS_PER_LONG
78
+ #define small_cpumask_bits ((unsigned int)NR_CPUS)
79
+ #define large_cpumask_bits ((unsigned int)NR_CPUS)
80
+ #elif NR_CPUS <= 4 * BITS_PER_LONG
81
+ #define small_cpumask_bits nr_cpu_ids
82
+ #define large_cpumask_bits ((unsigned int)NR_CPUS)
83
+ #else
84
+ #define small_cpumask_bits nr_cpu_ids
85
+ #define large_cpumask_bits nr_cpu_ids
86
+ #endif
87
+ #define nr_cpumask_bits nr_cpu_ids
55
88
56
89
/*
57
90
* The following particular system cpumasks and operations manage
@@ -126,7 +159,7 @@ static __always_inline unsigned int cpumask_check(unsigned int cpu)
126
159
*/
127
160
static inline unsigned int cpumask_first (const struct cpumask * srcp )
128
161
{
129
- return find_first_bit (cpumask_bits (srcp ), nr_cpumask_bits );
162
+ return find_first_bit (cpumask_bits (srcp ), small_cpumask_bits );
130
163
}
131
164
132
165
/**
@@ -137,7 +170,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
137
170
*/
138
171
static inline unsigned int cpumask_first_zero (const struct cpumask * srcp )
139
172
{
140
- return find_first_zero_bit (cpumask_bits (srcp ), nr_cpumask_bits );
173
+ return find_first_zero_bit (cpumask_bits (srcp ), small_cpumask_bits );
141
174
}
142
175
143
176
/**
@@ -150,7 +183,7 @@ static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
150
183
static inline
151
184
unsigned int cpumask_first_and (const struct cpumask * srcp1 , const struct cpumask * srcp2 )
152
185
{
153
- return find_first_and_bit (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ), nr_cpumask_bits );
186
+ return find_first_and_bit (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ), small_cpumask_bits );
154
187
}
155
188
156
189
/**
@@ -161,7 +194,7 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask
161
194
*/
162
195
static inline unsigned int cpumask_last (const struct cpumask * srcp )
163
196
{
164
- return find_last_bit (cpumask_bits (srcp ), nr_cpumask_bits );
197
+ return find_last_bit (cpumask_bits (srcp ), small_cpumask_bits );
165
198
}
166
199
167
200
/**
@@ -177,7 +210,7 @@ unsigned int cpumask_next(int n, const struct cpumask *srcp)
177
210
/* -1 is a legal arg here. */
178
211
if (n != -1 )
179
212
cpumask_check (n );
180
- return find_next_bit (cpumask_bits (srcp ), nr_cpumask_bits , n + 1 );
213
+ return find_next_bit (cpumask_bits (srcp ), small_cpumask_bits , n + 1 );
181
214
}
182
215
183
216
/**
@@ -192,7 +225,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
192
225
/* -1 is a legal arg here. */
193
226
if (n != -1 )
194
227
cpumask_check (n );
195
- return find_next_zero_bit (cpumask_bits (srcp ), nr_cpumask_bits , n + 1 );
228
+ return find_next_zero_bit (cpumask_bits (srcp ), small_cpumask_bits , n + 1 );
196
229
}
197
230
198
231
#if NR_CPUS == 1
@@ -235,7 +268,7 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
235
268
if (n != -1 )
236
269
cpumask_check (n );
237
270
return find_next_and_bit (cpumask_bits (src1p ), cpumask_bits (src2p ),
238
- nr_cpumask_bits , n + 1 );
271
+ small_cpumask_bits , n + 1 );
239
272
}
240
273
241
274
/**
@@ -246,17 +279,7 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
246
279
* After the loop, cpu is >= nr_cpu_ids.
247
280
*/
248
281
#define for_each_cpu (cpu , mask ) \
249
- for_each_set_bit(cpu, cpumask_bits(mask), nr_cpumask_bits)
250
-
251
- /**
252
- * for_each_cpu_not - iterate over every cpu in a complemented mask
253
- * @cpu: the (optionally unsigned) integer iterator
254
- * @mask: the cpumask pointer
255
- *
256
- * After the loop, cpu is >= nr_cpu_ids.
257
- */
258
- #define for_each_cpu_not (cpu , mask ) \
259
- for_each_clear_bit(cpu, cpumask_bits(mask), nr_cpumask_bits)
282
+ for_each_set_bit(cpu, cpumask_bits(mask), small_cpumask_bits)
260
283
261
284
#if NR_CPUS == 1
262
285
static inline
@@ -290,7 +313,7 @@ unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int sta
290
313
* After the loop, cpu is >= nr_cpu_ids.
291
314
*/
292
315
#define for_each_cpu_wrap (cpu , mask , start ) \
293
- for_each_set_bit_wrap(cpu, cpumask_bits(mask), nr_cpumask_bits , start)
316
+ for_each_set_bit_wrap(cpu, cpumask_bits(mask), small_cpumask_bits , start)
294
317
295
318
/**
296
319
* for_each_cpu_and - iterate over every cpu in both masks
@@ -307,7 +330,7 @@ unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int sta
307
330
* After the loop, cpu is >= nr_cpu_ids.
308
331
*/
309
332
#define for_each_cpu_and (cpu , mask1 , mask2 ) \
310
- for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits )
333
+ for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), small_cpumask_bits )
311
334
312
335
/**
313
336
* for_each_cpu_andnot - iterate over every cpu present in one mask, excluding
@@ -325,7 +348,7 @@ unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int sta
325
348
* After the loop, cpu is >= nr_cpu_ids.
326
349
*/
327
350
#define for_each_cpu_andnot (cpu , mask1 , mask2 ) \
328
- for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits )
351
+ for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), small_cpumask_bits )
329
352
330
353
/**
331
354
* cpumask_any_but - return a "random" in a cpumask, but not this one.
@@ -356,7 +379,7 @@ unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
356
379
*/
357
380
static inline unsigned int cpumask_nth (unsigned int cpu , const struct cpumask * srcp )
358
381
{
359
- return find_nth_bit (cpumask_bits (srcp ), nr_cpumask_bits , cpumask_check (cpu ));
382
+ return find_nth_bit (cpumask_bits (srcp ), small_cpumask_bits , cpumask_check (cpu ));
360
383
}
361
384
362
385
/**
@@ -372,7 +395,7 @@ unsigned int cpumask_nth_and(unsigned int cpu, const struct cpumask *srcp1,
372
395
const struct cpumask * srcp2 )
373
396
{
374
397
return find_nth_and_bit (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ),
375
- nr_cpumask_bits , cpumask_check (cpu ));
398
+ small_cpumask_bits , cpumask_check (cpu ));
376
399
}
377
400
378
401
/**
@@ -388,7 +411,7 @@ unsigned int cpumask_nth_andnot(unsigned int cpu, const struct cpumask *srcp1,
388
411
const struct cpumask * srcp2 )
389
412
{
390
413
return find_nth_andnot_bit (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ),
391
- nr_cpumask_bits , cpumask_check (cpu ));
414
+ small_cpumask_bits , cpumask_check (cpu ));
392
415
}
393
416
394
417
/**
@@ -408,7 +431,7 @@ unsigned int cpumask_nth_and_andnot(unsigned int cpu, const struct cpumask *srcp
408
431
return find_nth_and_andnot_bit (cpumask_bits (srcp1 ),
409
432
cpumask_bits (srcp2 ),
410
433
cpumask_bits (srcp3 ),
411
- nr_cpumask_bits , cpumask_check (cpu ));
434
+ small_cpumask_bits , cpumask_check (cpu ));
412
435
}
413
436
414
437
#define CPU_BITS_NONE \
@@ -495,10 +518,14 @@ static __always_inline bool cpumask_test_and_clear_cpu(int cpu, struct cpumask *
495
518
/**
496
519
* cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
497
520
* @dstp: the cpumask pointer
521
+ *
522
+ * Note: since we set bits, we should use the tighter 'bitmap_set()' with
523
+ * the eact number of bits, not 'bitmap_fill()' that will fill past the
524
+ * end.
498
525
*/
499
526
static inline void cpumask_setall (struct cpumask * dstp )
500
527
{
501
- bitmap_fill (cpumask_bits (dstp ), nr_cpumask_bits );
528
+ bitmap_set (cpumask_bits (dstp ), 0 , nr_cpumask_bits );
502
529
}
503
530
504
531
/**
@@ -507,7 +534,7 @@ static inline void cpumask_setall(struct cpumask *dstp)
507
534
*/
508
535
static inline void cpumask_clear (struct cpumask * dstp )
509
536
{
510
- bitmap_zero (cpumask_bits (dstp ), nr_cpumask_bits );
537
+ bitmap_zero (cpumask_bits (dstp ), large_cpumask_bits );
511
538
}
512
539
513
540
/**
@@ -523,7 +550,7 @@ static inline bool cpumask_and(struct cpumask *dstp,
523
550
const struct cpumask * src2p )
524
551
{
525
552
return bitmap_and (cpumask_bits (dstp ), cpumask_bits (src1p ),
526
- cpumask_bits (src2p ), nr_cpumask_bits );
553
+ cpumask_bits (src2p ), small_cpumask_bits );
527
554
}
528
555
529
556
/**
@@ -536,7 +563,7 @@ static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
536
563
const struct cpumask * src2p )
537
564
{
538
565
bitmap_or (cpumask_bits (dstp ), cpumask_bits (src1p ),
539
- cpumask_bits (src2p ), nr_cpumask_bits );
566
+ cpumask_bits (src2p ), small_cpumask_bits );
540
567
}
541
568
542
569
/**
@@ -550,7 +577,7 @@ static inline void cpumask_xor(struct cpumask *dstp,
550
577
const struct cpumask * src2p )
551
578
{
552
579
bitmap_xor (cpumask_bits (dstp ), cpumask_bits (src1p ),
553
- cpumask_bits (src2p ), nr_cpumask_bits );
580
+ cpumask_bits (src2p ), small_cpumask_bits );
554
581
}
555
582
556
583
/**
@@ -566,19 +593,7 @@ static inline bool cpumask_andnot(struct cpumask *dstp,
566
593
const struct cpumask * src2p )
567
594
{
568
595
return bitmap_andnot (cpumask_bits (dstp ), cpumask_bits (src1p ),
569
- cpumask_bits (src2p ), nr_cpumask_bits );
570
- }
571
-
572
- /**
573
- * cpumask_complement - *dstp = ~*srcp
574
- * @dstp: the cpumask result
575
- * @srcp: the input to invert
576
- */
577
- static inline void cpumask_complement (struct cpumask * dstp ,
578
- const struct cpumask * srcp )
579
- {
580
- bitmap_complement (cpumask_bits (dstp ), cpumask_bits (srcp ),
581
- nr_cpumask_bits );
596
+ cpumask_bits (src2p ), small_cpumask_bits );
582
597
}
583
598
584
599
/**
@@ -590,7 +605,7 @@ static inline bool cpumask_equal(const struct cpumask *src1p,
590
605
const struct cpumask * src2p )
591
606
{
592
607
return bitmap_equal (cpumask_bits (src1p ), cpumask_bits (src2p ),
593
- nr_cpumask_bits );
608
+ small_cpumask_bits );
594
609
}
595
610
596
611
/**
@@ -604,7 +619,7 @@ static inline bool cpumask_or_equal(const struct cpumask *src1p,
604
619
const struct cpumask * src3p )
605
620
{
606
621
return bitmap_or_equal (cpumask_bits (src1p ), cpumask_bits (src2p ),
607
- cpumask_bits (src3p ), nr_cpumask_bits );
622
+ cpumask_bits (src3p ), small_cpumask_bits );
608
623
}
609
624
610
625
/**
@@ -616,7 +631,7 @@ static inline bool cpumask_intersects(const struct cpumask *src1p,
616
631
const struct cpumask * src2p )
617
632
{
618
633
return bitmap_intersects (cpumask_bits (src1p ), cpumask_bits (src2p ),
619
- nr_cpumask_bits );
634
+ small_cpumask_bits );
620
635
}
621
636
622
637
/**
@@ -630,7 +645,7 @@ static inline bool cpumask_subset(const struct cpumask *src1p,
630
645
const struct cpumask * src2p )
631
646
{
632
647
return bitmap_subset (cpumask_bits (src1p ), cpumask_bits (src2p ),
633
- nr_cpumask_bits );
648
+ small_cpumask_bits );
634
649
}
635
650
636
651
/**
@@ -639,7 +654,7 @@ static inline bool cpumask_subset(const struct cpumask *src1p,
639
654
*/
640
655
static inline bool cpumask_empty (const struct cpumask * srcp )
641
656
{
642
- return bitmap_empty (cpumask_bits (srcp ), nr_cpumask_bits );
657
+ return bitmap_empty (cpumask_bits (srcp ), small_cpumask_bits );
643
658
}
644
659
645
660
/**
@@ -657,7 +672,7 @@ static inline bool cpumask_full(const struct cpumask *srcp)
657
672
*/
658
673
static inline unsigned int cpumask_weight (const struct cpumask * srcp )
659
674
{
660
- return bitmap_weight (cpumask_bits (srcp ), nr_cpumask_bits );
675
+ return bitmap_weight (cpumask_bits (srcp ), small_cpumask_bits );
661
676
}
662
677
663
678
/**
@@ -668,7 +683,7 @@ static inline unsigned int cpumask_weight(const struct cpumask *srcp)
668
683
static inline unsigned int cpumask_weight_and (const struct cpumask * srcp1 ,
669
684
const struct cpumask * srcp2 )
670
685
{
671
- return bitmap_weight_and (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ), nr_cpumask_bits );
686
+ return bitmap_weight_and (cpumask_bits (srcp1 ), cpumask_bits (srcp2 ), small_cpumask_bits );
672
687
}
673
688
674
689
/**
@@ -681,7 +696,7 @@ static inline void cpumask_shift_right(struct cpumask *dstp,
681
696
const struct cpumask * srcp , int n )
682
697
{
683
698
bitmap_shift_right (cpumask_bits (dstp ), cpumask_bits (srcp ), n ,
684
- nr_cpumask_bits );
699
+ small_cpumask_bits );
685
700
}
686
701
687
702
/**
@@ -705,7 +720,7 @@ static inline void cpumask_shift_left(struct cpumask *dstp,
705
720
static inline void cpumask_copy (struct cpumask * dstp ,
706
721
const struct cpumask * srcp )
707
722
{
708
- bitmap_copy (cpumask_bits (dstp ), cpumask_bits (srcp ), nr_cpumask_bits );
723
+ bitmap_copy (cpumask_bits (dstp ), cpumask_bits (srcp ), large_cpumask_bits );
709
724
}
710
725
711
726
/**
@@ -789,7 +804,7 @@ static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
789
804
*/
790
805
static inline unsigned int cpumask_size (void )
791
806
{
792
- return BITS_TO_LONGS (nr_cpumask_bits ) * sizeof (long );
807
+ return BITS_TO_LONGS (large_cpumask_bits ) * sizeof (long );
793
808
}
794
809
795
810
/*
0 commit comments