Merge branch 'cfq-2.6.33' into for-2.6.33
[linux-2.6/next.git] / include / linux / cpumask.h
blob789cf5f920ce80e697ca05a9a7fde743cdde9e1a
1 #ifndef __LINUX_CPUMASK_H
2 #define __LINUX_CPUMASK_H
4 /*
5 * Cpumasks provide a bitmap suitable for representing the
6 * set of CPU's in a system, one bit position per CPU number. In general,
7 * only nr_cpu_ids (<= NR_CPUS) bits are valid.
8 */
9 #include <linux/kernel.h>
10 #include <linux/threads.h>
11 #include <linux/bitmap.h>
13 typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
15 /**
16 * cpumask_bits - get the bits in a cpumask
17 * @maskp: the struct cpumask *
19 * You should only assume nr_cpu_ids bits of this mask are valid. This is
20 * a macro so it's const-correct.
22 #define cpumask_bits(maskp) ((maskp)->bits)
24 #if NR_CPUS == 1
25 #define nr_cpu_ids 1
26 #else
27 extern int nr_cpu_ids;
28 #endif
30 #ifdef CONFIG_CPUMASK_OFFSTACK
31 /* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
32 * not all bits may be allocated. */
33 #define nr_cpumask_bits nr_cpu_ids
34 #else
35 #define nr_cpumask_bits NR_CPUS
36 #endif
39 * The following particular system cpumasks and operations manage
40 * possible, present, active and online cpus.
42 * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
43 * cpu_present_mask - has bit 'cpu' set iff cpu is populated
44 * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
45 * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
47 * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
49 * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
50 * that it is possible might ever be plugged in at anytime during the
51 * life of that system boot. The cpu_present_mask is dynamic(*),
52 * representing which CPUs are currently plugged in. And
53 * cpu_online_mask is the dynamic subset of cpu_present_mask,
54 * indicating those CPUs available for scheduling.
56 * If HOTPLUG is enabled, then cpu_possible_mask is forced to have
57 * all NR_CPUS bits set, otherwise it is just the set of CPUs that
58 * ACPI reports present at boot.
60 * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
61 * depending on what ACPI reports as currently plugged in, otherwise
62 * cpu_present_mask is just a copy of cpu_possible_mask.
64 * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
65 * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
67 * Subtleties:
68 * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
69 * assumption that their single CPU is online. The UP
70 * cpu_{online,possible,present}_masks are placebos. Changing them
71 * will have no useful affect on the following num_*_cpus()
72 * and cpu_*() macros in the UP case. This ugliness is a UP
73 * optimization - don't waste any instructions or memory references
74 * asking if you're online or how many CPUs there are if there is
75 * only one CPU.
78 extern const struct cpumask *const cpu_possible_mask;
79 extern const struct cpumask *const cpu_online_mask;
80 extern const struct cpumask *const cpu_present_mask;
81 extern const struct cpumask *const cpu_active_mask;
83 #if NR_CPUS > 1
84 #define num_online_cpus() cpumask_weight(cpu_online_mask)
85 #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
86 #define num_present_cpus() cpumask_weight(cpu_present_mask)
87 #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
88 #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
89 #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
90 #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
91 #else
92 #define num_online_cpus() 1
93 #define num_possible_cpus() 1
94 #define num_present_cpus() 1
95 #define cpu_online(cpu) ((cpu) == 0)
96 #define cpu_possible(cpu) ((cpu) == 0)
97 #define cpu_present(cpu) ((cpu) == 0)
98 #define cpu_active(cpu) ((cpu) == 0)
99 #endif
101 /* verify cpu argument to cpumask_* operators */
102 static inline unsigned int cpumask_check(unsigned int cpu)
104 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
105 WARN_ON_ONCE(cpu >= nr_cpumask_bits);
106 #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
107 return cpu;
110 #if NR_CPUS == 1
111 /* Uniprocessor. Assume all masks are "1". */
112 static inline unsigned int cpumask_first(const struct cpumask *srcp)
114 return 0;
117 /* Valid inputs for n are -1 and 0. */
118 static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
120 return n+1;
123 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
125 return n+1;
128 static inline unsigned int cpumask_next_and(int n,
129 const struct cpumask *srcp,
130 const struct cpumask *andp)
132 return n+1;
135 /* cpu must be a valid cpu, ie 0, so there's no other choice. */
136 static inline unsigned int cpumask_any_but(const struct cpumask *mask,
137 unsigned int cpu)
139 return 1;
142 #define for_each_cpu(cpu, mask) \
143 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
144 #define for_each_cpu_and(cpu, mask, and) \
145 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
146 #else
148 * cpumask_first - get the first cpu in a cpumask
149 * @srcp: the cpumask pointer
151 * Returns >= nr_cpu_ids if no cpus set.
153 static inline unsigned int cpumask_first(const struct cpumask *srcp)
155 return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
159 * cpumask_next - get the next cpu in a cpumask
160 * @n: the cpu prior to the place to search (ie. return will be > @n)
161 * @srcp: the cpumask pointer
163 * Returns >= nr_cpu_ids if no further cpus set.
165 static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
167 /* -1 is a legal arg here. */
168 if (n != -1)
169 cpumask_check(n);
170 return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
174 * cpumask_next_zero - get the next unset cpu in a cpumask
175 * @n: the cpu prior to the place to search (ie. return will be > @n)
176 * @srcp: the cpumask pointer
178 * Returns >= nr_cpu_ids if no further cpus unset.
180 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
182 /* -1 is a legal arg here. */
183 if (n != -1)
184 cpumask_check(n);
185 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
188 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
189 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
192 * for_each_cpu - iterate over every cpu in a mask
193 * @cpu: the (optionally unsigned) integer iterator
194 * @mask: the cpumask pointer
196 * After the loop, cpu is >= nr_cpu_ids.
198 #define for_each_cpu(cpu, mask) \
199 for ((cpu) = -1; \
200 (cpu) = cpumask_next((cpu), (mask)), \
201 (cpu) < nr_cpu_ids;)
204 * for_each_cpu_and - iterate over every cpu in both masks
205 * @cpu: the (optionally unsigned) integer iterator
206 * @mask: the first cpumask pointer
207 * @and: the second cpumask pointer
209 * This saves a temporary CPU mask in many places. It is equivalent to:
210 * struct cpumask tmp;
211 * cpumask_and(&tmp, &mask, &and);
212 * for_each_cpu(cpu, &tmp)
213 * ...
215 * After the loop, cpu is >= nr_cpu_ids.
217 #define for_each_cpu_and(cpu, mask, and) \
218 for ((cpu) = -1; \
219 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
220 (cpu) < nr_cpu_ids;)
221 #endif /* SMP */
223 #define CPU_BITS_NONE \
225 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
228 #define CPU_BITS_CPU0 \
230 [0] = 1UL \
234 * cpumask_set_cpu - set a cpu in a cpumask
235 * @cpu: cpu number (< nr_cpu_ids)
236 * @dstp: the cpumask pointer
238 static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
240 set_bit(cpumask_check(cpu), cpumask_bits(dstp));
244 * cpumask_clear_cpu - clear a cpu in a cpumask
245 * @cpu: cpu number (< nr_cpu_ids)
246 * @dstp: the cpumask pointer
248 static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
250 clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
254 * cpumask_test_cpu - test for a cpu in a cpumask
255 * @cpu: cpu number (< nr_cpu_ids)
256 * @cpumask: the cpumask pointer
258 * No static inline type checking - see Subtlety (1) above.
260 #define cpumask_test_cpu(cpu, cpumask) \
261 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
264 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
265 * @cpu: cpu number (< nr_cpu_ids)
266 * @cpumask: the cpumask pointer
268 * test_and_set_bit wrapper for cpumasks.
270 static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
272 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
276 * cpumask_test_and_clear_cpu - atomically test and clear a cpu in a cpumask
277 * @cpu: cpu number (< nr_cpu_ids)
278 * @cpumask: the cpumask pointer
280 * test_and_clear_bit wrapper for cpumasks.
282 static inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
284 return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
288 * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
289 * @dstp: the cpumask pointer
291 static inline void cpumask_setall(struct cpumask *dstp)
293 bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
297 * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
298 * @dstp: the cpumask pointer
300 static inline void cpumask_clear(struct cpumask *dstp)
302 bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
306 * cpumask_and - *dstp = *src1p & *src2p
307 * @dstp: the cpumask result
308 * @src1p: the first input
309 * @src2p: the second input
311 static inline int cpumask_and(struct cpumask *dstp,
312 const struct cpumask *src1p,
313 const struct cpumask *src2p)
315 return bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
316 cpumask_bits(src2p), nr_cpumask_bits);
320 * cpumask_or - *dstp = *src1p | *src2p
321 * @dstp: the cpumask result
322 * @src1p: the first input
323 * @src2p: the second input
325 static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
326 const struct cpumask *src2p)
328 bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
329 cpumask_bits(src2p), nr_cpumask_bits);
333 * cpumask_xor - *dstp = *src1p ^ *src2p
334 * @dstp: the cpumask result
335 * @src1p: the first input
336 * @src2p: the second input
338 static inline void cpumask_xor(struct cpumask *dstp,
339 const struct cpumask *src1p,
340 const struct cpumask *src2p)
342 bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
343 cpumask_bits(src2p), nr_cpumask_bits);
347 * cpumask_andnot - *dstp = *src1p & ~*src2p
348 * @dstp: the cpumask result
349 * @src1p: the first input
350 * @src2p: the second input
352 static inline int cpumask_andnot(struct cpumask *dstp,
353 const struct cpumask *src1p,
354 const struct cpumask *src2p)
356 return bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
357 cpumask_bits(src2p), nr_cpumask_bits);
361 * cpumask_complement - *dstp = ~*srcp
362 * @dstp: the cpumask result
363 * @srcp: the input to invert
365 static inline void cpumask_complement(struct cpumask *dstp,
366 const struct cpumask *srcp)
368 bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
369 nr_cpumask_bits);
373 * cpumask_equal - *src1p == *src2p
374 * @src1p: the first input
375 * @src2p: the second input
377 static inline bool cpumask_equal(const struct cpumask *src1p,
378 const struct cpumask *src2p)
380 return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
381 nr_cpumask_bits);
385 * cpumask_intersects - (*src1p & *src2p) != 0
386 * @src1p: the first input
387 * @src2p: the second input
389 static inline bool cpumask_intersects(const struct cpumask *src1p,
390 const struct cpumask *src2p)
392 return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
393 nr_cpumask_bits);
397 * cpumask_subset - (*src1p & ~*src2p) == 0
398 * @src1p: the first input
399 * @src2p: the second input
401 static inline int cpumask_subset(const struct cpumask *src1p,
402 const struct cpumask *src2p)
404 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
405 nr_cpumask_bits);
409 * cpumask_empty - *srcp == 0
410 * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
412 static inline bool cpumask_empty(const struct cpumask *srcp)
414 return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
418 * cpumask_full - *srcp == 0xFFFFFFFF...
419 * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
421 static inline bool cpumask_full(const struct cpumask *srcp)
423 return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
427 * cpumask_weight - Count of bits in *srcp
428 * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
430 static inline unsigned int cpumask_weight(const struct cpumask *srcp)
432 return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
436 * cpumask_shift_right - *dstp = *srcp >> n
437 * @dstp: the cpumask result
438 * @srcp: the input to shift
439 * @n: the number of bits to shift by
441 static inline void cpumask_shift_right(struct cpumask *dstp,
442 const struct cpumask *srcp, int n)
444 bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
445 nr_cpumask_bits);
449 * cpumask_shift_left - *dstp = *srcp << n
450 * @dstp: the cpumask result
451 * @srcp: the input to shift
452 * @n: the number of bits to shift by
454 static inline void cpumask_shift_left(struct cpumask *dstp,
455 const struct cpumask *srcp, int n)
457 bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
458 nr_cpumask_bits);
462 * cpumask_copy - *dstp = *srcp
463 * @dstp: the result
464 * @srcp: the input cpumask
466 static inline void cpumask_copy(struct cpumask *dstp,
467 const struct cpumask *srcp)
469 bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
473 * cpumask_any - pick a "random" cpu from *srcp
474 * @srcp: the input cpumask
476 * Returns >= nr_cpu_ids if no cpus set.
478 #define cpumask_any(srcp) cpumask_first(srcp)
481 * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
482 * @src1p: the first input
483 * @src2p: the second input
485 * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
487 #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
490 * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
491 * @mask1: the first input cpumask
492 * @mask2: the second input cpumask
494 * Returns >= nr_cpu_ids if no cpus set.
496 #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
499 * cpumask_of - the cpumask containing just a given cpu
500 * @cpu: the cpu (<= nr_cpu_ids)
502 #define cpumask_of(cpu) (get_cpu_mask(cpu))
505 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
506 * @buf: the buffer to sprintf into
507 * @len: the length of the buffer
508 * @srcp: the cpumask to print
510 * If len is zero, returns zero. Otherwise returns the length of the
511 * (nul-terminated) @buf string.
513 static inline int cpumask_scnprintf(char *buf, int len,
514 const struct cpumask *srcp)
516 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
520 * cpumask_parse_user - extract a cpumask from a user string
521 * @buf: the buffer to extract from
522 * @len: the length of the buffer
523 * @dstp: the cpumask to set.
525 * Returns -errno, or 0 for success.
527 static inline int cpumask_parse_user(const char __user *buf, int len,
528 struct cpumask *dstp)
530 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
534 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
535 * @buf: the buffer to sprintf into
536 * @len: the length of the buffer
537 * @srcp: the cpumask to print
539 * If len is zero, returns zero. Otherwise returns the length of the
540 * (nul-terminated) @buf string.
542 static inline int cpulist_scnprintf(char *buf, int len,
543 const struct cpumask *srcp)
545 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
546 nr_cpumask_bits);
550 * cpulist_parse_user - extract a cpumask from a user string of ranges
551 * @buf: the buffer to extract from
552 * @len: the length of the buffer
553 * @dstp: the cpumask to set.
555 * Returns -errno, or 0 for success.
557 static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
559 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
563 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
565 * This will eventually be a runtime variable, depending on nr_cpu_ids.
567 static inline size_t cpumask_size(void)
569 /* FIXME: Once all cpumask assignments are eliminated, this
570 * can be nr_cpumask_bits */
571 return BITS_TO_LONGS(NR_CPUS) * sizeof(long);
575 * cpumask_var_t: struct cpumask for stack usage.
577 * Oh, the wicked games we play! In order to make kernel coding a
578 * little more difficult, we typedef cpumask_var_t to an array or a
579 * pointer: doing &mask on an array is a noop, so it still works.
581 * ie.
582 * cpumask_var_t tmpmask;
583 * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
584 * return -ENOMEM;
586 * ... use 'tmpmask' like a normal struct cpumask * ...
588 * free_cpumask_var(tmpmask);
590 #ifdef CONFIG_CPUMASK_OFFSTACK
591 typedef struct cpumask *cpumask_var_t;
593 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
594 bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
595 bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
596 bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
597 void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
598 void free_cpumask_var(cpumask_var_t mask);
599 void free_bootmem_cpumask_var(cpumask_var_t mask);
601 #else
602 typedef struct cpumask cpumask_var_t[1];
604 static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
606 return true;
609 static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
610 int node)
612 return true;
615 static inline bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
617 cpumask_clear(*mask);
618 return true;
621 static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
622 int node)
624 cpumask_clear(*mask);
625 return true;
628 static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
632 static inline void free_cpumask_var(cpumask_var_t mask)
636 static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
639 #endif /* CONFIG_CPUMASK_OFFSTACK */
641 /* It's common to want to use cpu_all_mask in struct member initializers,
642 * so it has to refer to an address rather than a pointer. */
643 extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
644 #define cpu_all_mask to_cpumask(cpu_all_bits)
646 /* First bits of cpu_bit_bitmap are in fact unset. */
647 #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
649 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
650 #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
651 #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
653 /* Wrappers for arch boot code to manipulate normally-constant masks */
654 void set_cpu_possible(unsigned int cpu, bool possible);
655 void set_cpu_present(unsigned int cpu, bool present);
656 void set_cpu_online(unsigned int cpu, bool online);
657 void set_cpu_active(unsigned int cpu, bool active);
658 void init_cpu_present(const struct cpumask *src);
659 void init_cpu_possible(const struct cpumask *src);
660 void init_cpu_online(const struct cpumask *src);
663 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
664 * @bitmap: the bitmap
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'.
670 * This does the conversion, and can be used as a constant initializer.
672 #define to_cpumask(bitmap) \
673 ((struct cpumask *)(1 ? (bitmap) \
674 : (void *)sizeof(__check_is_bitmap(bitmap))))
676 static inline int __check_is_bitmap(const unsigned long *bitmap)
678 return 1;
682 * Special-case data structure for "single bit set only" constant CPU masks.
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.
688 extern const unsigned long
689 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
691 static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
693 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
694 p -= cpu / BITS_PER_LONG;
695 return to_cpumask(p);
698 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
700 #if NR_CPUS <= BITS_PER_LONG
701 #define CPU_BITS_ALL \
703 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
706 #else /* NR_CPUS > BITS_PER_LONG */
708 #define CPU_BITS_ALL \
710 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
711 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
713 #endif /* NR_CPUS > BITS_PER_LONG */
717 * From here down, all obsolete. Use cpumask_ variants!
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)
727 #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
729 #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
731 #if NR_CPUS <= BITS_PER_LONG
733 #define CPU_MASK_ALL \
734 (cpumask_t) { { \
735 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
738 #else
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 \
746 #endif
748 #define CPU_MASK_NONE \
749 (cpumask_t) { { \
750 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
753 #define CPU_MASK_CPU0 \
754 (cpumask_t) { { \
755 [0] = 1UL \
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);
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 */
778 #if NR_CPUS <= 64
780 #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
782 #else /* NR_CPUS > 64 */
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; )
790 #endif /* NR_CPUS > 64 */
792 #define cpus_addr(src) ((src).bits)
794 #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
795 static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
797 set_bit(cpu, dstp->bits);
800 #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
801 static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
803 clear_bit(cpu, dstp->bits);
806 #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
807 static inline void __cpus_setall(cpumask_t *dstp, int nbits)
809 bitmap_fill(dstp->bits, nbits);
812 #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
813 static inline void __cpus_clear(cpumask_t *dstp, int nbits)
815 bitmap_zero(dstp->bits, nbits);
818 /* No static inline type checking - see Subtlety (1) above. */
819 #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
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)
824 return test_and_set_bit(cpu, addr->bits);
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)
831 return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
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)
838 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
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)
845 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
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)
853 return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
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)
860 return bitmap_equal(src1p->bits, src2p->bits, nbits);
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)
867 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
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)
874 return bitmap_subset(src1p->bits, src2p->bits, nbits);
877 #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
878 static inline int __cpus_empty(const cpumask_t *srcp, int nbits)
880 return bitmap_empty(srcp->bits, nbits);
883 #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
884 static inline int __cpus_weight(const cpumask_t *srcp, int nbits)
886 return bitmap_weight(srcp->bits, nbits);
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)
894 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
896 #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */
898 #endif /* __LINUX_CPUMASK_H */