1 #ifndef __LINUX_CPUMASK_H
2 #define __LINUX_CPUMASK_H
9 #include <linux/kernel.h>
11 #include <linux/bitmap.h>
23 #define cpumask_bits(maskp) ((maskp)->bits)
31 #ifdef CONFIG_CPUMASK_OFFSTACK
34 #define nr_cpumask_bits nr_cpu_ids
36 #define nr_cpumask_bits NR_CPUS
85 #define num_online_cpus() cpumask_weight(cpu_online_mask)
86 #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
87 #define num_present_cpus() cpumask_weight(cpu_present_mask)
88 #define num_active_cpus() cpumask_weight(cpu_active_mask)
89 #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
90 #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
91 #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
92 #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
94 #define num_online_cpus() 1U
95 #define num_possible_cpus() 1U
96 #define num_present_cpus() 1U
97 #define num_active_cpus() 1U
98 #define cpu_online(cpu) ((cpu) == 0)
99 #define cpu_possible(cpu) ((cpu) == 0)
100 #define cpu_present(cpu) ((cpu) == 0)
101 #define cpu_active(cpu) ((cpu) == 0)
105 static inline unsigned int cpumask_check(
unsigned int cpu)
107 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
115 static inline unsigned int cpumask_first(
const struct cpumask *srcp)
121 static inline unsigned int cpumask_next(
int n,
const struct cpumask *srcp)
126 static inline unsigned int cpumask_next_zero(
int n,
const struct cpumask *srcp)
145 #define for_each_cpu(cpu, mask) \
146 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
147 #define for_each_cpu_not(cpu, mask) \
148 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
149 #define for_each_cpu_and(cpu, mask, and) \
150 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
158 static inline unsigned int cpumask_first(
const struct cpumask *srcp)
170 static inline unsigned int cpumask_next(
int n,
const struct cpumask *srcp)
185 static inline unsigned int cpumask_next_zero(
int n,
const struct cpumask *srcp)
203 #define for_each_cpu(cpu, mask) \
205 (cpu) = cpumask_next((cpu), (mask)), \
215 #define for_each_cpu_not(cpu, mask) \
217 (cpu) = cpumask_next_zero((cpu), (mask)), \
234 #define for_each_cpu_and(cpu, mask, and) \
236 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
240 #define CPU_BITS_NONE \
242 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
245 #define CPU_BITS_CPU0 \
255 static inline void cpumask_set_cpu(
unsigned int cpu,
struct cpumask *dstp)
265 static inline void cpumask_clear_cpu(
int cpu,
struct cpumask *dstp)
279 #define cpumask_test_cpu(cpu, cpumask) \
280 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
291 static inline int cpumask_test_and_set_cpu(
int cpu,
struct cpumask *
cpumask)
305 static inline int cpumask_test_and_clear_cpu(
int cpu,
struct cpumask *
cpumask)
314 static inline void cpumask_setall(
struct cpumask *dstp)
323 static inline void cpumask_clear(
struct cpumask *dstp)
336 static inline int cpumask_and(
struct cpumask *dstp,
337 const struct cpumask *src1p,
338 const struct cpumask *src2p)
350 static inline void cpumask_or(
struct cpumask *dstp,
const struct cpumask *src1p,
351 const struct cpumask *src2p)
363 static inline void cpumask_xor(
struct cpumask *dstp,
364 const struct cpumask *src1p,
365 const struct cpumask *src2p)
379 static inline int cpumask_andnot(
struct cpumask *dstp,
380 const struct cpumask *src1p,
381 const struct cpumask *src2p)
392 static inline void cpumask_complement(
struct cpumask *dstp,
393 const struct cpumask *srcp)
404 static inline bool cpumask_equal(
const struct cpumask *src1p,
405 const struct cpumask *src2p)
416 static inline bool cpumask_intersects(
const struct cpumask *src1p,
417 const struct cpumask *src2p)
430 static inline int cpumask_subset(
const struct cpumask *src1p,
431 const struct cpumask *src2p)
441 static inline bool cpumask_empty(
const struct cpumask *srcp)
450 static inline bool cpumask_full(
const struct cpumask *srcp)
459 static inline unsigned int cpumask_weight(
const struct cpumask *srcp)
470 static inline void cpumask_shift_right(
struct cpumask *dstp,
471 const struct cpumask *srcp,
int n)
483 static inline void cpumask_shift_left(
struct cpumask *dstp,
484 const struct cpumask *srcp,
int n)
495 static inline void cpumask_copy(
struct cpumask *dstp,
496 const struct cpumask *srcp)
507 #define cpumask_any(srcp) cpumask_first(srcp)
516 #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
525 #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
531 #define cpumask_of(cpu) (get_cpu_mask(cpu))
542 static inline int cpumask_scnprintf(
char *
buf,
int len,
543 const struct cpumask *srcp)
556 static inline int cpumask_parse_user(
const char __user *
buf,
int len,
557 struct cpumask *dstp)
570 static inline int cpumask_parselist_user(
const char __user *buf,
int len,
571 struct cpumask *dstp)
586 static inline int cpulist_scnprintf(
char *buf,
int len,
587 const struct cpumask *srcp)
600 static inline int cpulist_parse(
const char *buf,
struct cpumask *dstp)
610 static inline size_t cpumask_size(
void)
647 #ifdef CONFIG_CPUMASK_OFFSTACK
654 void alloc_bootmem_cpumask_var(cpumask_var_t *
mask);
655 void free_cpumask_var(cpumask_var_t
mask);
656 void free_bootmem_cpumask_var(cpumask_var_t
mask);
659 typedef struct cpumask cpumask_var_t[1];
661 static inline bool alloc_cpumask_var(cpumask_var_t *
mask,
gfp_t flags)
666 static inline bool alloc_cpumask_var_node(cpumask_var_t *
mask,
gfp_t flags,
672 static inline bool zalloc_cpumask_var(cpumask_var_t *
mask,
gfp_t flags)
674 cpumask_clear(*mask);
678 static inline bool zalloc_cpumask_var_node(cpumask_var_t *
mask,
gfp_t flags,
681 cpumask_clear(*mask);
685 static inline void alloc_bootmem_cpumask_var(cpumask_var_t *
mask)
689 static inline void free_cpumask_var(cpumask_var_t
mask)
693 static inline void free_bootmem_cpumask_var(cpumask_var_t
mask)
701 #define cpu_all_mask to_cpumask(cpu_all_bits)
704 #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
706 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
707 #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
708 #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
729 #define to_cpumask(bitmap) \
730 ((struct cpumask *)(1 ? (bitmap) \
731 : (void *)sizeof(__check_is_bitmap(bitmap))))
733 static inline int __check_is_bitmap(
const unsigned long *
bitmap)
745 extern const unsigned long
748 static inline const struct cpumask *get_cpu_mask(
unsigned int cpu)
755 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
757 #if NR_CPUS <= BITS_PER_LONG
758 #define CPU_BITS_ALL \
760 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
765 #define CPU_BITS_ALL \
767 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
768 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
777 #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
778 #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
780 #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
782 #if NR_CPUS <= BITS_PER_LONG
784 #define CPU_MASK_ALL \
786 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
791 #define CPU_MASK_ALL \
793 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
794 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
799 #define CPU_MASK_NONE \
801 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
804 #define CPU_MASK_CPU0 \
810 #define first_cpu(src) ({ (void)(src); 0; })
811 #define next_cpu(n, src) ({ (void)(src); 1; })
812 #define any_online_cpu(mask) 0
813 #define for_each_cpu_mask(cpu, mask) \
814 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
819 #define first_cpu(src) __first_cpu(&(src))
820 #define next_cpu(n, src) __next_cpu((n), &(src))
821 #define any_online_cpu(mask) cpumask_any_and(&mask, cpu_online_mask)
822 #define for_each_cpu_mask(cpu, mask) \
824 (cpu) = next_cpu((cpu), (mask)), \
830 #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
834 int __next_cpu_nr(
int n,
const cpumask_t *srcp);
835 #define for_each_cpu_mask_nr(cpu, mask) \
837 (cpu) = __next_cpu_nr((cpu), &(mask)), \
838 (cpu) < nr_cpu_ids; )
842 #define cpus_addr(src) ((src).bits)
844 #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
845 static inline void __cpu_set(
int cpu,
volatile cpumask_t *dstp)
850 #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
851 static inline void __cpu_clear(
int cpu,
volatile cpumask_t *dstp)
856 #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
857 static inline void __cpus_setall(
cpumask_t *dstp,
int nbits)
859 bitmap_fill(dstp->bits, nbits);
862 #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
863 static inline void __cpus_clear(
cpumask_t *dstp,
int nbits)
865 bitmap_zero(dstp->bits, nbits);
869 #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
871 #define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
872 static inline int __cpu_test_and_set(
int cpu,
cpumask_t *
addr)
877 #define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
881 return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
884 #define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
888 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
891 #define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
895 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
898 #define cpus_andnot(dst, src1, src2) \
899 __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
903 return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
906 #define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
907 static inline int __cpus_equal(
const cpumask_t *src1p,
910 return bitmap_equal(src1p->bits, src2p->bits, nbits);
913 #define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
914 static inline int __cpus_intersects(
const cpumask_t *src1p,
917 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
920 #define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
921 static inline int __cpus_subset(
const cpumask_t *src1p,
924 return bitmap_subset(src1p->bits, src2p->bits, nbits);
927 #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
928 static inline int __cpus_empty(
const cpumask_t *srcp,
int nbits)
930 return bitmap_empty(srcp->bits, nbits);
933 #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
934 static inline int __cpus_weight(
const cpumask_t *srcp,
int nbits)
936 return bitmap_weight(srcp->bits, nbits);
939 #define cpus_shift_left(dst, src, n) \
940 __cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
941 static inline void __cpus_shift_left(
cpumask_t *dstp,
944 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);