diff options
| -rw-r--r-- | include/linux/cpumask.h | 593 |
1 files changed, 252 insertions, 341 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index e162d13c65ab..789cf5f920ce 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h | |||
| @@ -3,328 +3,37 @@ | |||
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| 5 | * Cpumasks provide a bitmap suitable for representing the | 5 | * Cpumasks provide a bitmap suitable for representing the |
| 6 | * set of CPU's in a system, one bit position per CPU number. | 6 | * set of CPU's in a system, one bit position per CPU number. In general, |
| 7 | * | 7 | * only nr_cpu_ids (<= NR_CPUS) bits are valid. |
| 8 | * The new cpumask_ ops take a "struct cpumask *"; the old ones | ||
| 9 | * use cpumask_t. | ||
| 10 | * | ||
| 11 | * See detailed comments in the file linux/bitmap.h describing the | ||
| 12 | * data type on which these cpumasks are based. | ||
| 13 | * | ||
| 14 | * For details of cpumask_scnprintf() and cpumask_parse_user(), | ||
| 15 | * see bitmap_scnprintf() and bitmap_parse_user() in lib/bitmap.c. | ||
| 16 | * For details of cpulist_scnprintf() and cpulist_parse(), see | ||
| 17 | * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c. | ||
| 18 | * | ||
| 19 | * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | ||
| 20 | * Note: The alternate operations with the suffix "_nr" are used | ||
| 21 | * to limit the range of the loop to nr_cpu_ids instead of | ||
| 22 | * NR_CPUS when NR_CPUS > 64 for performance reasons. | ||
| 23 | * If NR_CPUS is <= 64 then most assembler bitmask | ||
| 24 | * operators execute faster with a constant range, so | ||
| 25 | * the operator will continue to use NR_CPUS. | ||
| 26 | * | ||
| 27 | * Another consideration is that nr_cpu_ids is initialized | ||
| 28 | * to NR_CPUS and isn't lowered until the possible cpus are | ||
| 29 | * discovered (including any disabled cpus). So early uses | ||
| 30 | * will span the entire range of NR_CPUS. | ||
| 31 | * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | ||
| 32 | * | ||
| 33 | * The obsolescent cpumask operations are: | ||
| 34 | * | ||
| 35 | * void cpu_set(cpu, mask) turn on bit 'cpu' in mask | ||
| 36 | * void cpu_clear(cpu, mask) turn off bit 'cpu' in mask | ||
| 37 | * void cpus_setall(mask) set all bits | ||
| 38 | * void cpus_clear(mask) clear all bits | ||
| 39 | * int cpu_isset(cpu, mask) true iff bit 'cpu' set in mask | ||
| 40 | * int cpu_test_and_set(cpu, mask) test and set bit 'cpu' in mask | ||
| 41 | * | ||
| 42 | * int cpus_and(dst, src1, src2) dst = src1 & src2 [intersection] | ||
| 43 | * void cpus_or(dst, src1, src2) dst = src1 | src2 [union] | ||
| 44 | * void cpus_xor(dst, src1, src2) dst = src1 ^ src2 | ||
| 45 | * int cpus_andnot(dst, src1, src2) dst = src1 & ~src2 | ||
| 46 | * | ||
| 47 | * int cpus_equal(mask1, mask2) Does mask1 == mask2? | ||
| 48 | * int cpus_intersects(mask1, mask2) Do mask1 and mask2 intersect? | ||
| 49 | * int cpus_subset(mask1, mask2) Is mask1 a subset of mask2? | ||
| 50 | * int cpus_empty(mask) Is mask empty (no bits sets)? | ||
| 51 | * int cpus_weight(mask) Hamming weigh - number of set bits | ||
| 52 | * | ||
| 53 | * void cpus_shift_left(dst, src, n) Shift left | ||
| 54 | * | ||
| 55 | * int first_cpu(mask) Number lowest set bit, or NR_CPUS | ||
| 56 | * int next_cpu(cpu, mask) Next cpu past 'cpu', or NR_CPUS | ||
| 57 | * | ||
| 58 | * cpumask_t cpumask_of_cpu(cpu) Return cpumask with bit 'cpu' set | ||
| 59 | * (can be used as an lvalue) | ||
| 60 | * CPU_MASK_ALL Initializer - all bits set | ||
| 61 | * CPU_MASK_NONE Initializer - no bits set | ||
| 62 | * unsigned long *cpus_addr(mask) Array of unsigned long's in mask | ||
| 63 | * | ||
| 64 | * int cpumask_scnprintf(buf, len, mask) Format cpumask for printing | ||
| 65 | * int cpumask_parse_user(ubuf, ulen, mask) Parse ascii string as cpumask | ||
| 66 | * int cpulist_scnprintf(buf, len, mask) Format cpumask as list for printing | ||
| 67 | * int cpulist_parse(buf, map) Parse ascii string as cpulist | ||
| 68 | * | ||
| 69 | * for_each_cpu_mask(cpu, mask) for-loop cpu over mask using NR_CPUS | ||
| 70 | * for_each_cpu_mask_nr(cpu, mask) for-loop cpu over mask using nr_cpu_ids | ||
| 71 | * | ||
| 72 | * int num_online_cpus() Number of online CPUs | ||
| 73 | * int num_possible_cpus() Number of all possible CPUs | ||
| 74 | * int num_present_cpus() Number of present CPUs | ||
| 75 | * | ||
| 76 | * int cpu_online(cpu) Is some cpu online? | ||
| 77 | * int cpu_possible(cpu) Is some cpu possible? | ||
| 78 | * int cpu_present(cpu) Is some cpu present (can schedule)? | ||
| 79 | * | ||
| 80 | * int any_online_cpu(mask) First online cpu in mask | ||
| 81 | * | ||
| 82 | * for_each_possible_cpu(cpu) for-loop cpu over cpu_possible_map | ||
| 83 | * for_each_online_cpu(cpu) for-loop cpu over cpu_online_map | ||
| 84 | * for_each_present_cpu(cpu) for-loop cpu over cpu_present_map | ||
| 85 | * | ||
| 86 | * Subtlety: | ||
| 87 | * 1) The 'type-checked' form of cpu_isset() causes gcc (3.3.2, anyway) | ||
| 88 | * to generate slightly worse code. Note for example the additional | ||
| 89 | * 40 lines of assembly code compiling the "for each possible cpu" | ||
| 90 | * loops buried in the disk_stat_read() macros calls when compiling | ||
| 91 | * drivers/block/genhd.c (arch i386, CONFIG_SMP=y). So use a simple | ||
| 92 | * one-line #define for cpu_isset(), instead of wrapping an inline | ||
| 93 | * inside a macro, the way we do the other calls. | ||
| 94 | */ | 8 | */ |
| 95 | |||
| 96 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
| 97 | #include <linux/threads.h> | 10 | #include <linux/threads.h> |
| 98 | #include <linux/bitmap.h> | 11 | #include <linux/bitmap.h> |
| 99 | 12 | ||
| 100 | typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; | 13 | typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; |
| 101 | 14 | ||
| 102 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | ||
| 103 | #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst)) | ||
| 104 | static inline void __cpu_set(int cpu, volatile cpumask_t *dstp) | ||
| 105 | { | ||
| 106 | set_bit(cpu, dstp->bits); | ||
| 107 | } | ||
| 108 | |||
| 109 | #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst)) | ||
| 110 | static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp) | ||
| 111 | { | ||
| 112 | clear_bit(cpu, dstp->bits); | ||
| 113 | } | ||
| 114 | |||
| 115 | #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS) | ||
| 116 | static inline void __cpus_setall(cpumask_t *dstp, int nbits) | ||
| 117 | { | ||
| 118 | bitmap_fill(dstp->bits, nbits); | ||
| 119 | } | ||
| 120 | |||
| 121 | #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS) | ||
| 122 | static inline void __cpus_clear(cpumask_t *dstp, int nbits) | ||
| 123 | { | ||
| 124 | bitmap_zero(dstp->bits, nbits); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* No static inline type checking - see Subtlety (1) above. */ | ||
| 128 | #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits) | ||
| 129 | |||
| 130 | #define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask)) | ||
| 131 | static inline int __cpu_test_and_set(int cpu, cpumask_t *addr) | ||
| 132 | { | ||
| 133 | return test_and_set_bit(cpu, addr->bits); | ||
| 134 | } | ||
| 135 | |||
| 136 | #define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 137 | static inline int __cpus_and(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 138 | const cpumask_t *src2p, int nbits) | ||
| 139 | { | ||
| 140 | return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 141 | } | ||
| 142 | |||
| 143 | #define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 144 | static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 145 | const cpumask_t *src2p, int nbits) | ||
| 146 | { | ||
| 147 | bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 148 | } | ||
| 149 | |||
| 150 | #define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 151 | static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 152 | const cpumask_t *src2p, int nbits) | ||
| 153 | { | ||
| 154 | bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 155 | } | ||
| 156 | |||
| 157 | #define cpus_andnot(dst, src1, src2) \ | ||
| 158 | __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 159 | static inline int __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 160 | const cpumask_t *src2p, int nbits) | ||
| 161 | { | ||
| 162 | return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 163 | } | ||
| 164 | |||
| 165 | #define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS) | ||
| 166 | static inline int __cpus_equal(const cpumask_t *src1p, | ||
| 167 | const cpumask_t *src2p, int nbits) | ||
| 168 | { | ||
| 169 | return bitmap_equal(src1p->bits, src2p->bits, nbits); | ||
| 170 | } | ||
| 171 | |||
| 172 | #define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS) | ||
| 173 | static inline int __cpus_intersects(const cpumask_t *src1p, | ||
| 174 | const cpumask_t *src2p, int nbits) | ||
| 175 | { | ||
| 176 | return bitmap_intersects(src1p->bits, src2p->bits, nbits); | ||
| 177 | } | ||
| 178 | |||
| 179 | #define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS) | ||
| 180 | static inline int __cpus_subset(const cpumask_t *src1p, | ||
| 181 | const cpumask_t *src2p, int nbits) | ||
| 182 | { | ||
| 183 | return bitmap_subset(src1p->bits, src2p->bits, nbits); | ||
| 184 | } | ||
| 185 | |||
| 186 | #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS) | ||
| 187 | static inline int __cpus_empty(const cpumask_t *srcp, int nbits) | ||
| 188 | { | ||
| 189 | return bitmap_empty(srcp->bits, nbits); | ||
| 190 | } | ||
| 191 | |||
| 192 | #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS) | ||
| 193 | static inline int __cpus_weight(const cpumask_t *srcp, int nbits) | ||
| 194 | { | ||
| 195 | return bitmap_weight(srcp->bits, nbits); | ||
| 196 | } | ||
| 197 | |||
| 198 | #define cpus_shift_left(dst, src, n) \ | ||
| 199 | __cpus_shift_left(&(dst), &(src), (n), NR_CPUS) | ||
| 200 | static inline void __cpus_shift_left(cpumask_t *dstp, | ||
| 201 | const cpumask_t *srcp, int n, int nbits) | ||
| 202 | { | ||
| 203 | bitmap_shift_left(dstp->bits, srcp->bits, n, nbits); | ||
| 204 | } | ||
| 205 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 206 | |||
| 207 | /** | 15 | /** |
| 208 | * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * | 16 | * cpumask_bits - get the bits in a cpumask |
| 209 | * @bitmap: the bitmap | 17 | * @maskp: the struct cpumask * |
| 210 | * | 18 | * |
| 211 | * There are a few places where cpumask_var_t isn't appropriate and | 19 | * You should only assume nr_cpu_ids bits of this mask are valid. This is |
| 212 | * static cpumasks must be used (eg. very early boot), yet we don't | 20 | * a macro so it's const-correct. |
| 213 | * expose the definition of 'struct cpumask'. | ||
| 214 | * | ||
| 215 | * This does the conversion, and can be used as a constant initializer. | ||
| 216 | */ | 21 | */ |
| 217 | #define to_cpumask(bitmap) \ | 22 | #define cpumask_bits(maskp) ((maskp)->bits) |
| 218 | ((struct cpumask *)(1 ? (bitmap) \ | ||
| 219 | : (void *)sizeof(__check_is_bitmap(bitmap)))) | ||
| 220 | |||
| 221 | static inline int __check_is_bitmap(const unsigned long *bitmap) | ||
| 222 | { | ||
| 223 | return 1; | ||
| 224 | } | ||
| 225 | |||
| 226 | /* | ||
| 227 | * Special-case data structure for "single bit set only" constant CPU masks. | ||
| 228 | * | ||
| 229 | * We pre-generate all the 64 (or 32) possible bit positions, with enough | ||
| 230 | * padding to the left and the right, and return the constant pointer | ||
| 231 | * appropriately offset. | ||
| 232 | */ | ||
| 233 | extern const unsigned long | ||
| 234 | cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)]; | ||
| 235 | |||
| 236 | static inline const struct cpumask *get_cpu_mask(unsigned int cpu) | ||
| 237 | { | ||
| 238 | const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG]; | ||
| 239 | p -= cpu / BITS_PER_LONG; | ||
| 240 | return to_cpumask(p); | ||
| 241 | } | ||
| 242 | |||
| 243 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | ||
| 244 | /* | ||
| 245 | * In cases where we take the address of the cpumask immediately, | ||
| 246 | * gcc optimizes it out (it's a constant) and there's no huge stack | ||
| 247 | * variable created: | ||
| 248 | */ | ||
| 249 | #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu)) | ||
| 250 | |||
| 251 | |||
| 252 | #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS) | ||
| 253 | |||
| 254 | #if NR_CPUS <= BITS_PER_LONG | ||
| 255 | |||
| 256 | #define CPU_MASK_ALL \ | ||
| 257 | (cpumask_t) { { \ | ||
| 258 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 259 | } } | ||
| 260 | |||
| 261 | #else | ||
| 262 | |||
| 263 | #define CPU_MASK_ALL \ | ||
| 264 | (cpumask_t) { { \ | ||
| 265 | [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ | ||
| 266 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 267 | } } | ||
| 268 | |||
| 269 | #endif | ||
| 270 | |||
| 271 | #define CPU_MASK_NONE \ | ||
| 272 | (cpumask_t) { { \ | ||
| 273 | [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \ | ||
| 274 | } } | ||
| 275 | |||
| 276 | #define CPU_MASK_CPU0 \ | ||
| 277 | (cpumask_t) { { \ | ||
| 278 | [0] = 1UL \ | ||
| 279 | } } | ||
| 280 | |||
| 281 | #define cpus_addr(src) ((src).bits) | ||
| 282 | |||
| 283 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 284 | 23 | ||
| 285 | #if NR_CPUS == 1 | 24 | #if NR_CPUS == 1 |
| 286 | |||
| 287 | #define nr_cpu_ids 1 | 25 | #define nr_cpu_ids 1 |
| 288 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | 26 | #else |
| 289 | #define first_cpu(src) ({ (void)(src); 0; }) | ||
| 290 | #define next_cpu(n, src) ({ (void)(src); 1; }) | ||
| 291 | #define any_online_cpu(mask) 0 | ||
| 292 | #define for_each_cpu_mask(cpu, mask) \ | ||
| 293 | for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) | ||
| 294 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 295 | #else /* NR_CPUS > 1 */ | ||
| 296 | |||
| 297 | extern int nr_cpu_ids; | 27 | extern int nr_cpu_ids; |
| 298 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | ||
| 299 | int __first_cpu(const cpumask_t *srcp); | ||
| 300 | int __next_cpu(int n, const cpumask_t *srcp); | ||
| 301 | int __any_online_cpu(const cpumask_t *mask); | ||
| 302 | |||
| 303 | #define first_cpu(src) __first_cpu(&(src)) | ||
| 304 | #define next_cpu(n, src) __next_cpu((n), &(src)) | ||
| 305 | #define any_online_cpu(mask) __any_online_cpu(&(mask)) | ||
| 306 | #define for_each_cpu_mask(cpu, mask) \ | ||
| 307 | for ((cpu) = -1; \ | ||
| 308 | (cpu) = next_cpu((cpu), (mask)), \ | ||
| 309 | (cpu) < NR_CPUS; ) | ||
| 310 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 311 | #endif | 28 | #endif |
| 312 | 29 | ||
| 313 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | 30 | #ifdef CONFIG_CPUMASK_OFFSTACK |
| 314 | #if NR_CPUS <= 64 | 31 | /* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also, |
| 315 | 32 | * not all bits may be allocated. */ | |
| 316 | #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask) | 33 | #define nr_cpumask_bits nr_cpu_ids |
| 317 | 34 | #else | |
| 318 | #else /* NR_CPUS > 64 */ | 35 | #define nr_cpumask_bits NR_CPUS |
| 319 | 36 | #endif | |
| 320 | int __next_cpu_nr(int n, const cpumask_t *srcp); | ||
| 321 | #define for_each_cpu_mask_nr(cpu, mask) \ | ||
| 322 | for ((cpu) = -1; \ | ||
| 323 | (cpu) = __next_cpu_nr((cpu), &(mask)), \ | ||
| 324 | (cpu) < nr_cpu_ids; ) | ||
| 325 | |||
| 326 | #endif /* NR_CPUS > 64 */ | ||
| 327 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 328 | 37 | ||
| 329 | /* | 38 | /* |
| 330 | * The following particular system cpumasks and operations manage | 39 | * The following particular system cpumasks and operations manage |
| @@ -371,12 +80,6 @@ extern const struct cpumask *const cpu_online_mask; | |||
| 371 | extern const struct cpumask *const cpu_present_mask; | 80 | extern const struct cpumask *const cpu_present_mask; |
| 372 | extern const struct cpumask *const cpu_active_mask; | 81 | extern const struct cpumask *const cpu_active_mask; |
| 373 | 82 | ||
| 374 | /* These strip const, as traditionally they weren't const. */ | ||
| 375 | #define cpu_possible_map (*(cpumask_t *)cpu_possible_mask) | ||
| 376 | #define cpu_online_map (*(cpumask_t *)cpu_online_mask) | ||
| 377 | #define cpu_present_map (*(cpumask_t *)cpu_present_mask) | ||
| 378 | #define cpu_active_map (*(cpumask_t *)cpu_active_mask) | ||
| 379 | |||
| 380 | #if NR_CPUS > 1 | 83 | #if NR_CPUS > 1 |
| 381 | #define num_online_cpus() cpumask_weight(cpu_online_mask) | 84 | #define num_online_cpus() cpumask_weight(cpu_online_mask) |
| 382 | #define num_possible_cpus() cpumask_weight(cpu_possible_mask) | 85 | #define num_possible_cpus() cpumask_weight(cpu_possible_mask) |
| @@ -395,35 +98,6 @@ extern const struct cpumask *const cpu_active_mask; | |||
| 395 | #define cpu_active(cpu) ((cpu) == 0) | 98 | #define cpu_active(cpu) ((cpu) == 0) |
| 396 | #endif | 99 | #endif |
| 397 | 100 | ||
| 398 | #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) | ||
| 399 | |||
| 400 | /* These are the new versions of the cpumask operators: passed by pointer. | ||
| 401 | * The older versions will be implemented in terms of these, then deleted. */ | ||
| 402 | #define cpumask_bits(maskp) ((maskp)->bits) | ||
| 403 | |||
| 404 | #if NR_CPUS <= BITS_PER_LONG | ||
| 405 | #define CPU_BITS_ALL \ | ||
| 406 | { \ | ||
| 407 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 408 | } | ||
| 409 | |||
| 410 | #else /* NR_CPUS > BITS_PER_LONG */ | ||
| 411 | |||
| 412 | #define CPU_BITS_ALL \ | ||
| 413 | { \ | ||
| 414 | [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ | ||
| 415 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 416 | } | ||
| 417 | #endif /* NR_CPUS > BITS_PER_LONG */ | ||
| 418 | |||
| 419 | #ifdef CONFIG_CPUMASK_OFFSTACK | ||
| 420 | /* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also, | ||
| 421 | * not all bits may be allocated. */ | ||
| 422 | #define nr_cpumask_bits nr_cpu_ids | ||
| 423 | #else | ||
| 424 | #define nr_cpumask_bits NR_CPUS | ||
| 425 | #endif | ||
| 426 | |||
| 427 | /* verify cpu argument to cpumask_* operators */ | 101 | /* verify cpu argument to cpumask_* operators */ |
| 428 | static inline unsigned int cpumask_check(unsigned int cpu) | 102 | static inline unsigned int cpumask_check(unsigned int cpu) |
| 429 | { | 103 | { |
| @@ -984,4 +658,241 @@ void set_cpu_active(unsigned int cpu, bool active); | |||
| 984 | void init_cpu_present(const struct cpumask *src); | 658 | void init_cpu_present(const struct cpumask *src); |
| 985 | void init_cpu_possible(const struct cpumask *src); | 659 | void init_cpu_possible(const struct cpumask *src); |
| 986 | void init_cpu_online(const struct cpumask *src); | 660 | void init_cpu_online(const struct cpumask *src); |
| 661 | |||
| 662 | /** | ||
| 663 | * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * | ||
| 664 | * @bitmap: the bitmap | ||
| 665 | * | ||
| 666 | * There are a few places where cpumask_var_t isn't appropriate and | ||
| 667 | * static cpumasks must be used (eg. very early boot), yet we don't | ||
| 668 | * expose the definition of 'struct cpumask'. | ||
| 669 | * | ||
| 670 | * This does the conversion, and can be used as a constant initializer. | ||
| 671 | */ | ||
| 672 | #define to_cpumask(bitmap) \ | ||
| 673 | ((struct cpumask *)(1 ? (bitmap) \ | ||
| 674 | : (void *)sizeof(__check_is_bitmap(bitmap)))) | ||
| 675 | |||
| 676 | static inline int __check_is_bitmap(const unsigned long *bitmap) | ||
| 677 | { | ||
| 678 | return 1; | ||
| 679 | } | ||
| 680 | |||
| 681 | /* | ||
| 682 | * Special-case data structure for "single bit set only" constant CPU masks. | ||
| 683 | * | ||
| 684 | * We pre-generate all the 64 (or 32) possible bit positions, with enough | ||
| 685 | * padding to the left and the right, and return the constant pointer | ||
| 686 | * appropriately offset. | ||
| 687 | */ | ||
| 688 | extern const unsigned long | ||
| 689 | cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)]; | ||
| 690 | |||
| 691 | static inline const struct cpumask *get_cpu_mask(unsigned int cpu) | ||
| 692 | { | ||
| 693 | const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG]; | ||
| 694 | p -= cpu / BITS_PER_LONG; | ||
| 695 | return to_cpumask(p); | ||
| 696 | } | ||
| 697 | |||
| 698 | #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) | ||
| 699 | |||
| 700 | #if NR_CPUS <= BITS_PER_LONG | ||
| 701 | #define CPU_BITS_ALL \ | ||
| 702 | { \ | ||
| 703 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 704 | } | ||
| 705 | |||
| 706 | #else /* NR_CPUS > BITS_PER_LONG */ | ||
| 707 | |||
| 708 | #define CPU_BITS_ALL \ | ||
| 709 | { \ | ||
| 710 | [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ | ||
| 711 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 712 | } | ||
| 713 | #endif /* NR_CPUS > BITS_PER_LONG */ | ||
| 714 | |||
| 715 | /* | ||
| 716 | * | ||
| 717 | * From here down, all obsolete. Use cpumask_ variants! | ||
| 718 | * | ||
| 719 | */ | ||
| 720 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | ||
| 721 | /* These strip const, as traditionally they weren't const. */ | ||
| 722 | #define cpu_possible_map (*(cpumask_t *)cpu_possible_mask) | ||
| 723 | #define cpu_online_map (*(cpumask_t *)cpu_online_mask) | ||
| 724 | #define cpu_present_map (*(cpumask_t *)cpu_present_mask) | ||
| 725 | #define cpu_active_map (*(cpumask_t *)cpu_active_mask) | ||
| 726 | |||
| 727 | #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu)) | ||
| 728 | |||
| 729 | #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS) | ||
| 730 | |||
| 731 | #if NR_CPUS <= BITS_PER_LONG | ||
| 732 | |||
| 733 | #define CPU_MASK_ALL \ | ||
| 734 | (cpumask_t) { { \ | ||
| 735 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 736 | } } | ||
| 737 | |||
| 738 | #else | ||
| 739 | |||
| 740 | #define CPU_MASK_ALL \ | ||
| 741 | (cpumask_t) { { \ | ||
| 742 | [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ | ||
| 743 | [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ | ||
| 744 | } } | ||
| 745 | |||
| 746 | #endif | ||
| 747 | |||
| 748 | #define CPU_MASK_NONE \ | ||
| 749 | (cpumask_t) { { \ | ||
| 750 | [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \ | ||
| 751 | } } | ||
| 752 | |||
| 753 | #define CPU_MASK_CPU0 \ | ||
| 754 | (cpumask_t) { { \ | ||
| 755 | [0] = 1UL \ | ||
| 756 | } } | ||
| 757 | |||
| 758 | #if NR_CPUS == 1 | ||
| 759 | #define first_cpu(src) ({ (void)(src); 0; }) | ||
| 760 | #define next_cpu(n, src) ({ (void)(src); 1; }) | ||
| 761 | #define any_online_cpu(mask) 0 | ||
| 762 | #define for_each_cpu_mask(cpu, mask) \ | ||
| 763 | for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) | ||
| 764 | #else /* NR_CPUS > 1 */ | ||
| 765 | int __first_cpu(const cpumask_t *srcp); | ||
| 766 | int __next_cpu(int n, const cpumask_t *srcp); | ||
| 767 | int __any_online_cpu(const cpumask_t *mask); | ||
| 768 | |||
| 769 | #define first_cpu(src) __first_cpu(&(src)) | ||
| 770 | #define next_cpu(n, src) __next_cpu((n), &(src)) | ||
| 771 | #define any_online_cpu(mask) __any_online_cpu(&(mask)) | ||
| 772 | #define for_each_cpu_mask(cpu, mask) \ | ||
| 773 | for ((cpu) = -1; \ | ||
| 774 | (cpu) = next_cpu((cpu), (mask)), \ | ||
| 775 | (cpu) < NR_CPUS; ) | ||
| 776 | #endif /* SMP */ | ||
| 777 | |||
| 778 | #if NR_CPUS <= 64 | ||
| 779 | |||
| 780 | #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask) | ||
| 781 | |||
| 782 | #else /* NR_CPUS > 64 */ | ||
| 783 | |||
| 784 | int __next_cpu_nr(int n, const cpumask_t *srcp); | ||
| 785 | #define for_each_cpu_mask_nr(cpu, mask) \ | ||
| 786 | for ((cpu) = -1; \ | ||
| 787 | (cpu) = __next_cpu_nr((cpu), &(mask)), \ | ||
| 788 | (cpu) < nr_cpu_ids; ) | ||
| 789 | |||
| 790 | #endif /* NR_CPUS > 64 */ | ||
| 791 | |||
| 792 | #define cpus_addr(src) ((src).bits) | ||
| 793 | |||
| 794 | #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst)) | ||
| 795 | static inline void __cpu_set(int cpu, volatile cpumask_t *dstp) | ||
| 796 | { | ||
| 797 | set_bit(cpu, dstp->bits); | ||
| 798 | } | ||
| 799 | |||
| 800 | #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst)) | ||
| 801 | static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp) | ||
| 802 | { | ||
| 803 | clear_bit(cpu, dstp->bits); | ||
| 804 | } | ||
| 805 | |||
| 806 | #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS) | ||
| 807 | static inline void __cpus_setall(cpumask_t *dstp, int nbits) | ||
| 808 | { | ||
| 809 | bitmap_fill(dstp->bits, nbits); | ||
| 810 | } | ||
| 811 | |||
| 812 | #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS) | ||
| 813 | static inline void __cpus_clear(cpumask_t *dstp, int nbits) | ||
| 814 | { | ||
| 815 | bitmap_zero(dstp->bits, nbits); | ||
| 816 | } | ||
| 817 | |||
| 818 | /* No static inline type checking - see Subtlety (1) above. */ | ||
| 819 | #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits) | ||
| 820 | |||
| 821 | #define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask)) | ||
| 822 | static inline int __cpu_test_and_set(int cpu, cpumask_t *addr) | ||
| 823 | { | ||
| 824 | return test_and_set_bit(cpu, addr->bits); | ||
| 825 | } | ||
| 826 | |||
| 827 | #define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 828 | static inline int __cpus_and(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 829 | const cpumask_t *src2p, int nbits) | ||
| 830 | { | ||
| 831 | return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 832 | } | ||
| 833 | |||
| 834 | #define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 835 | static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 836 | const cpumask_t *src2p, int nbits) | ||
| 837 | { | ||
| 838 | bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 839 | } | ||
| 840 | |||
| 841 | #define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 842 | static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 843 | const cpumask_t *src2p, int nbits) | ||
| 844 | { | ||
| 845 | bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 846 | } | ||
| 847 | |||
| 848 | #define cpus_andnot(dst, src1, src2) \ | ||
| 849 | __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS) | ||
| 850 | static inline int __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p, | ||
| 851 | const cpumask_t *src2p, int nbits) | ||
| 852 | { | ||
| 853 | return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits); | ||
| 854 | } | ||
| 855 | |||
| 856 | #define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS) | ||
| 857 | static inline int __cpus_equal(const cpumask_t *src1p, | ||
| 858 | const cpumask_t *src2p, int nbits) | ||
| 859 | { | ||
| 860 | return bitmap_equal(src1p->bits, src2p->bits, nbits); | ||
| 861 | } | ||
| 862 | |||
| 863 | #define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS) | ||
| 864 | static inline int __cpus_intersects(const cpumask_t *src1p, | ||
| 865 | const cpumask_t *src2p, int nbits) | ||
| 866 | { | ||
| 867 | return bitmap_intersects(src1p->bits, src2p->bits, nbits); | ||
| 868 | } | ||
| 869 | |||
| 870 | #define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS) | ||
| 871 | static inline int __cpus_subset(const cpumask_t *src1p, | ||
| 872 | const cpumask_t *src2p, int nbits) | ||
| 873 | { | ||
| 874 | return bitmap_subset(src1p->bits, src2p->bits, nbits); | ||
| 875 | } | ||
| 876 | |||
| 877 | #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS) | ||
| 878 | static inline int __cpus_empty(const cpumask_t *srcp, int nbits) | ||
| 879 | { | ||
| 880 | return bitmap_empty(srcp->bits, nbits); | ||
| 881 | } | ||
| 882 | |||
| 883 | #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS) | ||
| 884 | static inline int __cpus_weight(const cpumask_t *srcp, int nbits) | ||
| 885 | { | ||
| 886 | return bitmap_weight(srcp->bits, nbits); | ||
| 887 | } | ||
| 888 | |||
| 889 | #define cpus_shift_left(dst, src, n) \ | ||
| 890 | __cpus_shift_left(&(dst), &(src), (n), NR_CPUS) | ||
| 891 | static inline void __cpus_shift_left(cpumask_t *dstp, | ||
| 892 | const cpumask_t *srcp, int n, int nbits) | ||
| 893 | { | ||
| 894 | bitmap_shift_left(dstp->bits, srcp->bits, n, nbits); | ||
| 895 | } | ||
| 896 | #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */ | ||
| 897 | |||
| 987 | #endif /* __LINUX_CPUMASK_H */ | 898 | #endif /* __LINUX_CPUMASK_H */ |
