This source file includes following definitions.
- num_online_cpus
- cpu_max_bits_warn
- cpumask_check
- cpumask_first
- cpumask_last
- cpumask_next
- cpumask_next_zero
- cpumask_next_and
- cpumask_next_wrap
- cpumask_any_but
- cpumask_local_spread
- cpumask_first
- cpumask_last
- cpumask_next_zero
- cpumask_set_cpu
- __cpumask_set_cpu
- cpumask_clear_cpu
- __cpumask_clear_cpu
- cpumask_test_cpu
- cpumask_test_and_set_cpu
- cpumask_test_and_clear_cpu
- cpumask_setall
- cpumask_clear
- cpumask_and
- cpumask_or
- cpumask_xor
- cpumask_andnot
- cpumask_complement
- cpumask_equal
- cpumask_or_equal
- cpumask_intersects
- cpumask_subset
- cpumask_empty
- cpumask_full
- cpumask_weight
- cpumask_shift_right
- cpumask_shift_left
- cpumask_copy
- cpumask_parse_user
- cpumask_parselist_user
- cpumask_parse
- cpulist_parse
- cpumask_size
- cpumask_available
- alloc_cpumask_var
- alloc_cpumask_var_node
- zalloc_cpumask_var
- zalloc_cpumask_var_node
- alloc_bootmem_cpumask_var
- free_cpumask_var
- free_bootmem_cpumask_var
- cpumask_available
- reset_cpu_possible_mask
- set_cpu_possible
- set_cpu_present
- set_cpu_active
- __check_is_bitmap
- get_cpu_mask
- cpumap_print_to_pagebuf
1
2 #ifndef __LINUX_CPUMASK_H
3 #define __LINUX_CPUMASK_H
4
5
6
7
8
9
10 #include <linux/kernel.h>
11 #include <linux/threads.h>
12 #include <linux/bitmap.h>
13 #include <linux/atomic.h>
14 #include <linux/bug.h>
15
16
17 typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
18
19
20
21
22
23
24
25
26 #define cpumask_bits(maskp) ((maskp)->bits)
27
28
29
30
31
32
33
34 #define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp)
35
36 #if NR_CPUS == 1
37 #define nr_cpu_ids 1U
38 #else
39 extern unsigned int nr_cpu_ids;
40 #endif
41
42 #ifdef CONFIG_CPUMASK_OFFSTACK
43
44
45 #define nr_cpumask_bits nr_cpu_ids
46 #else
47 #define nr_cpumask_bits ((unsigned int)NR_CPUS)
48 #endif
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 extern struct cpumask __cpu_possible_mask;
91 extern struct cpumask __cpu_online_mask;
92 extern struct cpumask __cpu_present_mask;
93 extern struct cpumask __cpu_active_mask;
94 #define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
95 #define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask)
96 #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask)
97 #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask)
98
99 extern atomic_t __num_online_cpus;
100
101 #if NR_CPUS > 1
102
103
104
105
106
107
108
109
110 static inline unsigned int num_online_cpus(void)
111 {
112 return atomic_read(&__num_online_cpus);
113 }
114 #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
115 #define num_present_cpus() cpumask_weight(cpu_present_mask)
116 #define num_active_cpus() cpumask_weight(cpu_active_mask)
117 #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
118 #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
119 #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
120 #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
121 #else
122 #define num_online_cpus() 1U
123 #define num_possible_cpus() 1U
124 #define num_present_cpus() 1U
125 #define num_active_cpus() 1U
126 #define cpu_online(cpu) ((cpu) == 0)
127 #define cpu_possible(cpu) ((cpu) == 0)
128 #define cpu_present(cpu) ((cpu) == 0)
129 #define cpu_active(cpu) ((cpu) == 0)
130 #endif
131
132 extern cpumask_t cpus_booted_once_mask;
133
134 static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
135 {
136 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
137 WARN_ON_ONCE(cpu >= bits);
138 #endif
139 }
140
141
142 static inline unsigned int cpumask_check(unsigned int cpu)
143 {
144 cpu_max_bits_warn(cpu, nr_cpumask_bits);
145 return cpu;
146 }
147
148 #if NR_CPUS == 1
149
150 static inline unsigned int cpumask_first(const struct cpumask *srcp)
151 {
152 return 0;
153 }
154
155 static inline unsigned int cpumask_last(const struct cpumask *srcp)
156 {
157 return 0;
158 }
159
160
161 static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
162 {
163 return n+1;
164 }
165
166 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
167 {
168 return n+1;
169 }
170
171 static inline unsigned int cpumask_next_and(int n,
172 const struct cpumask *srcp,
173 const struct cpumask *andp)
174 {
175 return n+1;
176 }
177
178 static inline unsigned int cpumask_next_wrap(int n, const struct cpumask *mask,
179 int start, bool wrap)
180 {
181
182 return (wrap && n == 0);
183 }
184
185
186 static inline unsigned int cpumask_any_but(const struct cpumask *mask,
187 unsigned int cpu)
188 {
189 return 1;
190 }
191
192 static inline unsigned int cpumask_local_spread(unsigned int i, int node)
193 {
194 return 0;
195 }
196
197 #define for_each_cpu(cpu, mask) \
198 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
199 #define for_each_cpu_not(cpu, mask) \
200 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
201 #define for_each_cpu_wrap(cpu, mask, start) \
202 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start))
203 #define for_each_cpu_and(cpu, mask1, mask2) \
204 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2)
205 #else
206
207
208
209
210
211
212 static inline unsigned int cpumask_first(const struct cpumask *srcp)
213 {
214 return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
215 }
216
217
218
219
220
221
222
223 static inline unsigned int cpumask_last(const struct cpumask *srcp)
224 {
225 return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits);
226 }
227
228 unsigned int cpumask_next(int n, const struct cpumask *srcp);
229
230
231
232
233
234
235
236
237 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
238 {
239
240 if (n != -1)
241 cpumask_check(n);
242 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
243 }
244
245 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
246 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
247 unsigned int cpumask_local_spread(unsigned int i, int node);
248
249
250
251
252
253
254
255
256 #define for_each_cpu(cpu, mask) \
257 for ((cpu) = -1; \
258 (cpu) = cpumask_next((cpu), (mask)), \
259 (cpu) < nr_cpu_ids;)
260
261
262
263
264
265
266
267
268 #define for_each_cpu_not(cpu, mask) \
269 for ((cpu) = -1; \
270 (cpu) = cpumask_next_zero((cpu), (mask)), \
271 (cpu) < nr_cpu_ids;)
272
273 extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
274
275
276
277
278
279
280
281
282
283
284
285 #define for_each_cpu_wrap(cpu, mask, start) \
286 for ((cpu) = cpumask_next_wrap((start)-1, (mask), (start), false); \
287 (cpu) < nr_cpumask_bits; \
288 (cpu) = cpumask_next_wrap((cpu), (mask), (start), true))
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304 #define for_each_cpu_and(cpu, mask1, mask2) \
305 for ((cpu) = -1; \
306 (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \
307 (cpu) < nr_cpu_ids;)
308 #endif
309
310 #define CPU_BITS_NONE \
311 { \
312 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
313 }
314
315 #define CPU_BITS_CPU0 \
316 { \
317 [0] = 1UL \
318 }
319
320
321
322
323
324
325 static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
326 {
327 set_bit(cpumask_check(cpu), cpumask_bits(dstp));
328 }
329
330 static inline void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
331 {
332 __set_bit(cpumask_check(cpu), cpumask_bits(dstp));
333 }
334
335
336
337
338
339
340
341 static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
342 {
343 clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
344 }
345
346 static inline void __cpumask_clear_cpu(int cpu, struct cpumask *dstp)
347 {
348 __clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
349 }
350
351
352
353
354
355
356
357
358 static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
359 {
360 return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
361 }
362
363
364
365
366
367
368
369
370
371
372 static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
373 {
374 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
375 }
376
377
378
379
380
381
382
383
384
385
386 static inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
387 {
388 return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
389 }
390
391
392
393
394
395 static inline void cpumask_setall(struct cpumask *dstp)
396 {
397 bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
398 }
399
400
401
402
403
404 static inline void cpumask_clear(struct cpumask *dstp)
405 {
406 bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
407 }
408
409
410
411
412
413
414
415
416
417 static inline int cpumask_and(struct cpumask *dstp,
418 const struct cpumask *src1p,
419 const struct cpumask *src2p)
420 {
421 return bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
422 cpumask_bits(src2p), nr_cpumask_bits);
423 }
424
425
426
427
428
429
430
431 static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
432 const struct cpumask *src2p)
433 {
434 bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
435 cpumask_bits(src2p), nr_cpumask_bits);
436 }
437
438
439
440
441
442
443
444 static inline void cpumask_xor(struct cpumask *dstp,
445 const struct cpumask *src1p,
446 const struct cpumask *src2p)
447 {
448 bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
449 cpumask_bits(src2p), nr_cpumask_bits);
450 }
451
452
453
454
455
456
457
458
459
460 static inline int cpumask_andnot(struct cpumask *dstp,
461 const struct cpumask *src1p,
462 const struct cpumask *src2p)
463 {
464 return bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
465 cpumask_bits(src2p), nr_cpumask_bits);
466 }
467
468
469
470
471
472
473 static inline void cpumask_complement(struct cpumask *dstp,
474 const struct cpumask *srcp)
475 {
476 bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
477 nr_cpumask_bits);
478 }
479
480
481
482
483
484
485 static inline bool cpumask_equal(const struct cpumask *src1p,
486 const struct cpumask *src2p)
487 {
488 return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
489 nr_cpumask_bits);
490 }
491
492
493
494
495
496
497
498 static inline bool cpumask_or_equal(const struct cpumask *src1p,
499 const struct cpumask *src2p,
500 const struct cpumask *src3p)
501 {
502 return bitmap_or_equal(cpumask_bits(src1p), cpumask_bits(src2p),
503 cpumask_bits(src3p), nr_cpumask_bits);
504 }
505
506
507
508
509
510
511 static inline bool cpumask_intersects(const struct cpumask *src1p,
512 const struct cpumask *src2p)
513 {
514 return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
515 nr_cpumask_bits);
516 }
517
518
519
520
521
522
523
524
525 static inline int cpumask_subset(const struct cpumask *src1p,
526 const struct cpumask *src2p)
527 {
528 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
529 nr_cpumask_bits);
530 }
531
532
533
534
535
536 static inline bool cpumask_empty(const struct cpumask *srcp)
537 {
538 return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
539 }
540
541
542
543
544
545 static inline bool cpumask_full(const struct cpumask *srcp)
546 {
547 return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
548 }
549
550
551
552
553
554 static inline unsigned int cpumask_weight(const struct cpumask *srcp)
555 {
556 return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
557 }
558
559
560
561
562
563
564
565 static inline void cpumask_shift_right(struct cpumask *dstp,
566 const struct cpumask *srcp, int n)
567 {
568 bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
569 nr_cpumask_bits);
570 }
571
572
573
574
575
576
577
578 static inline void cpumask_shift_left(struct cpumask *dstp,
579 const struct cpumask *srcp, int n)
580 {
581 bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
582 nr_cpumask_bits);
583 }
584
585
586
587
588
589
590 static inline void cpumask_copy(struct cpumask *dstp,
591 const struct cpumask *srcp)
592 {
593 bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
594 }
595
596
597
598
599
600
601
602 #define cpumask_any(srcp) cpumask_first(srcp)
603
604
605
606
607
608
609
610
611 #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
612
613
614
615
616
617
618
619
620 #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
621
622
623
624
625
626 #define cpumask_of(cpu) (get_cpu_mask(cpu))
627
628
629
630
631
632
633
634
635
636 static inline int cpumask_parse_user(const char __user *buf, int len,
637 struct cpumask *dstp)
638 {
639 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
640 }
641
642
643
644
645
646
647
648
649
650 static inline int cpumask_parselist_user(const char __user *buf, int len,
651 struct cpumask *dstp)
652 {
653 return bitmap_parselist_user(buf, len, cpumask_bits(dstp),
654 nr_cpumask_bits);
655 }
656
657
658
659
660
661
662
663
664 static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
665 {
666 unsigned int len = strchrnul(buf, '\n') - buf;
667
668 return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
669 }
670
671
672
673
674
675
676
677
678 static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
679 {
680 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
681 }
682
683
684
685
686 static inline unsigned int cpumask_size(void)
687 {
688 return BITS_TO_LONGS(nr_cpumask_bits) * sizeof(long);
689 }
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731 #ifdef CONFIG_CPUMASK_OFFSTACK
732 typedef struct cpumask *cpumask_var_t;
733
734 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x)
735 #define __cpumask_var_read_mostly __read_mostly
736
737 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
738 bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
739 bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
740 bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
741 void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
742 void free_cpumask_var(cpumask_var_t mask);
743 void free_bootmem_cpumask_var(cpumask_var_t mask);
744
745 static inline bool cpumask_available(cpumask_var_t mask)
746 {
747 return mask != NULL;
748 }
749
750 #else
751 typedef struct cpumask cpumask_var_t[1];
752
753 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x)
754 #define __cpumask_var_read_mostly
755
756 static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
757 {
758 return true;
759 }
760
761 static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
762 int node)
763 {
764 return true;
765 }
766
767 static inline bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
768 {
769 cpumask_clear(*mask);
770 return true;
771 }
772
773 static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
774 int node)
775 {
776 cpumask_clear(*mask);
777 return true;
778 }
779
780 static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
781 {
782 }
783
784 static inline void free_cpumask_var(cpumask_var_t mask)
785 {
786 }
787
788 static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
789 {
790 }
791
792 static inline bool cpumask_available(cpumask_var_t mask)
793 {
794 return true;
795 }
796 #endif
797
798
799
800 extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
801 #define cpu_all_mask to_cpumask(cpu_all_bits)
802
803
804 #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
805
806 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
807 #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
808 #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
809
810
811 void init_cpu_present(const struct cpumask *src);
812 void init_cpu_possible(const struct cpumask *src);
813 void init_cpu_online(const struct cpumask *src);
814
815 static inline void reset_cpu_possible_mask(void)
816 {
817 bitmap_zero(cpumask_bits(&__cpu_possible_mask), NR_CPUS);
818 }
819
820 static inline void
821 set_cpu_possible(unsigned int cpu, bool possible)
822 {
823 if (possible)
824 cpumask_set_cpu(cpu, &__cpu_possible_mask);
825 else
826 cpumask_clear_cpu(cpu, &__cpu_possible_mask);
827 }
828
829 static inline void
830 set_cpu_present(unsigned int cpu, bool present)
831 {
832 if (present)
833 cpumask_set_cpu(cpu, &__cpu_present_mask);
834 else
835 cpumask_clear_cpu(cpu, &__cpu_present_mask);
836 }
837
838 void set_cpu_online(unsigned int cpu, bool online);
839
840 static inline void
841 set_cpu_active(unsigned int cpu, bool active)
842 {
843 if (active)
844 cpumask_set_cpu(cpu, &__cpu_active_mask);
845 else
846 cpumask_clear_cpu(cpu, &__cpu_active_mask);
847 }
848
849
850
851
852
853
854
855
856
857
858
859
860 #define to_cpumask(bitmap) \
861 ((struct cpumask *)(1 ? (bitmap) \
862 : (void *)sizeof(__check_is_bitmap(bitmap))))
863
864 static inline int __check_is_bitmap(const unsigned long *bitmap)
865 {
866 return 1;
867 }
868
869
870
871
872
873
874
875
876 extern const unsigned long
877 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
878
879 static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
880 {
881 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
882 p -= cpu / BITS_PER_LONG;
883 return to_cpumask(p);
884 }
885
886 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
887
888 #if NR_CPUS <= BITS_PER_LONG
889 #define CPU_BITS_ALL \
890 { \
891 [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
892 }
893
894 #else
895
896 #define CPU_BITS_ALL \
897 { \
898 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
899 [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
900 }
901 #endif
902
903
904
905
906
907
908
909
910
911
912
913 static inline ssize_t
914 cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
915 {
916 return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
917 nr_cpu_ids);
918 }
919
920 #if NR_CPUS <= BITS_PER_LONG
921 #define CPU_MASK_ALL \
922 (cpumask_t) { { \
923 [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
924 } }
925 #else
926 #define CPU_MASK_ALL \
927 (cpumask_t) { { \
928 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
929 [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
930 } }
931 #endif
932
933 #define CPU_MASK_NONE \
934 (cpumask_t) { { \
935 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
936 } }
937
938 #define CPU_MASK_CPU0 \
939 (cpumask_t) { { \
940 [0] = 1UL \
941 } }
942
943 #endif