Linux 2.6.33-rc2
[pohmelfs.git] / include / linux / cpumask.h
blobd77b54733c5b63980c51fe354ee91de1a41ce81a
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 num_active_cpus() cpumask_weight(cpu_active_mask)
88 #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
89 #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
90 #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
91 #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
92 #else
93 #define num_online_cpus() 1
94 #define num_possible_cpus() 1
95 #define num_present_cpus() 1
96 #define num_active_cpus() 1
97 #define cpu_online(cpu) ((cpu) == 0)
98 #define cpu_possible(cpu) ((cpu) == 0)
99 #define cpu_present(cpu) ((cpu) == 0)
100 #define cpu_active(cpu) ((cpu) == 0)
101 #endif
103 /* verify cpu argument to cpumask_* operators */
104 static inline unsigned int cpumask_check(unsigned int cpu)
106 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
107 WARN_ON_ONCE(cpu >= nr_cpumask_bits);
108 #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
109 return cpu;
112 #if NR_CPUS == 1
113 /* Uniprocessor. Assume all masks are "1". */
114 static inline unsigned int cpumask_first(const struct cpumask *srcp)
116 return 0;
119 /* Valid inputs for n are -1 and 0. */
120 static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
122 return n+1;
125 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
127 return n+1;
130 static inline unsigned int cpumask_next_and(int n,
131 const struct cpumask *srcp,
132 const struct cpumask *andp)
134 return n+1;
137 /* cpu must be a valid cpu, ie 0, so there's no other choice. */
138 static inline unsigned int cpumask_any_but(const struct cpumask *mask,
139 unsigned int cpu)
141 return 1;
144 #define for_each_cpu(cpu, mask) \
145 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
146 #define for_each_cpu_and(cpu, mask, and) \
147 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
148 #else
150 * cpumask_first - get the first cpu in a cpumask
151 * @srcp: the cpumask pointer
153 * Returns >= nr_cpu_ids if no cpus set.
155 static inline unsigned int cpumask_first(const struct cpumask *srcp)
157 return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
161 * cpumask_next - get the next cpu in a cpumask
162 * @n: the cpu prior to the place to search (ie. return will be > @n)
163 * @srcp: the cpumask pointer
165 * Returns >= nr_cpu_ids if no further cpus set.
167 static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
169 /* -1 is a legal arg here. */
170 if (n != -1)
171 cpumask_check(n);
172 return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
176 * cpumask_next_zero - get the next unset cpu in a cpumask
177 * @n: the cpu prior to the place to search (ie. return will be > @n)
178 * @srcp: the cpumask pointer
180 * Returns >= nr_cpu_ids if no further cpus unset.
182 static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
184 /* -1 is a legal arg here. */
185 if (n != -1)
186 cpumask_check(n);
187 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
190 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
191 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
194 * for_each_cpu - iterate over every cpu in a mask
195 * @cpu: the (optionally unsigned) integer iterator
196 * @mask: the cpumask pointer
198 * After the loop, cpu is >= nr_cpu_ids.
200 #define for_each_cpu(cpu, mask) \
201 for ((cpu) = -1; \
202 (cpu) = cpumask_next((cpu), (mask)), \
203 (cpu) < nr_cpu_ids;)
206 * for_each_cpu_and - iterate over every cpu in both masks
207 * @cpu: the (optionally unsigned) integer iterator
208 * @mask: the first cpumask pointer
209 * @and: the second cpumask pointer
211 * This saves a temporary CPU mask in many places. It is equivalent to:
212 * struct cpumask tmp;
213 * cpumask_and(&tmp, &mask, &and);
214 * for_each_cpu(cpu, &tmp)
215 * ...
217 * After the loop, cpu is >= nr_cpu_ids.
219 #define for_each_cpu_and(cpu, mask, and) \
220 for ((cpu) = -1; \
221 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
222 (cpu) < nr_cpu_ids;)
223 #endif /* SMP */
225 #define CPU_BITS_NONE \
227 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
230 #define CPU_BITS_CPU0 \
232 [0] = 1UL \
236 * cpumask_set_cpu - set a cpu in a cpumask
237 * @cpu: cpu number (< nr_cpu_ids)
238 * @dstp: the cpumask pointer
240 static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
242 set_bit(cpumask_check(cpu), cpumask_bits(dstp));
246 * cpumask_clear_cpu - clear a cpu in a cpumask
247 * @cpu: cpu number (< nr_cpu_ids)
248 * @dstp: the cpumask pointer
250 static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
252 clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
256 * cpumask_test_cpu - test for a cpu in a cpumask
257 * @cpu: cpu number (< nr_cpu_ids)
258 * @cpumask: the cpumask pointer
260 * No static inline type checking - see Subtlety (1) above.
262 #define cpumask_test_cpu(cpu, cpumask) \
263 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
266 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
267 * @cpu: cpu number (< nr_cpu_ids)
268 * @cpumask: the cpumask pointer
270 * test_and_set_bit wrapper for cpumasks.
272 static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
274 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
278 * cpumask_test_and_clear_cpu - atomically test and clear a cpu in a cpumask
279 * @cpu: cpu number (< nr_cpu_ids)
280 * @cpumask: the cpumask pointer
282 * test_and_clear_bit wrapper for cpumasks.
284 static inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
286 return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
290 * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
291 * @dstp: the cpumask pointer
293 static inline void cpumask_setall(struct cpumask *dstp)
295 bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
299 * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
300 * @dstp: the cpumask pointer
302 static inline void cpumask_clear(struct cpumask *dstp)
304 bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
308 * cpumask_and - *dstp = *src1p & *src2p
309 * @dstp: the cpumask result
310 * @src1p: the first input
311 * @src2p: the second input
313 static inline int cpumask_and(struct cpumask *dstp,
314 const struct cpumask *src1p,
315 const struct cpumask *src2p)
317 return bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
318 cpumask_bits(src2p), nr_cpumask_bits);
322 * cpumask_or - *dstp = *src1p | *src2p
323 * @dstp: the cpumask result
324 * @src1p: the first input
325 * @src2p: the second input
327 static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
328 const struct cpumask *src2p)
330 bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
331 cpumask_bits(src2p), nr_cpumask_bits);
335 * cpumask_xor - *dstp = *src1p ^ *src2p
336 * @dstp: the cpumask result
337 * @src1p: the first input
338 * @src2p: the second input
340 static inline void cpumask_xor(struct cpumask *dstp,
341 const struct cpumask *src1p,
342 const struct cpumask *src2p)
344 bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
345 cpumask_bits(src2p), nr_cpumask_bits);
349 * cpumask_andnot - *dstp = *src1p & ~*src2p
350 * @dstp: the cpumask result
351 * @src1p: the first input
352 * @src2p: the second input
354 static inline int cpumask_andnot(struct cpumask *dstp,
355 const struct cpumask *src1p,
356 const struct cpumask *src2p)
358 return bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
359 cpumask_bits(src2p), nr_cpumask_bits);
363 * cpumask_complement - *dstp = ~*srcp
364 * @dstp: the cpumask result
365 * @srcp: the input to invert
367 static inline void cpumask_complement(struct cpumask *dstp,
368 const struct cpumask *srcp)
370 bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
371 nr_cpumask_bits);
375 * cpumask_equal - *src1p == *src2p
376 * @src1p: the first input
377 * @src2p: the second input
379 static inline bool cpumask_equal(const struct cpumask *src1p,
380 const struct cpumask *src2p)
382 return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
383 nr_cpumask_bits);
387 * cpumask_intersects - (*src1p & *src2p) != 0
388 * @src1p: the first input
389 * @src2p: the second input
391 static inline bool cpumask_intersects(const struct cpumask *src1p,
392 const struct cpumask *src2p)
394 return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
395 nr_cpumask_bits);
399 * cpumask_subset - (*src1p & ~*src2p) == 0
400 * @src1p: the first input
401 * @src2p: the second input
403 static inline int cpumask_subset(const struct cpumask *src1p,
404 const struct cpumask *src2p)
406 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
407 nr_cpumask_bits);
411 * cpumask_empty - *srcp == 0
412 * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
414 static inline bool cpumask_empty(const struct cpumask *srcp)
416 return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
420 * cpumask_full - *srcp == 0xFFFFFFFF...
421 * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
423 static inline bool cpumask_full(const struct cpumask *srcp)
425 return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
429 * cpumask_weight - Count of bits in *srcp
430 * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
432 static inline unsigned int cpumask_weight(const struct cpumask *srcp)
434 return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
438 * cpumask_shift_right - *dstp = *srcp >> n
439 * @dstp: the cpumask result
440 * @srcp: the input to shift
441 * @n: the number of bits to shift by
443 static inline void cpumask_shift_right(struct cpumask *dstp,
444 const struct cpumask *srcp, int n)
446 bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
447 nr_cpumask_bits);
451 * cpumask_shift_left - *dstp = *srcp << n
452 * @dstp: the cpumask result
453 * @srcp: the input to shift
454 * @n: the number of bits to shift by
456 static inline void cpumask_shift_left(struct cpumask *dstp,
457 const struct cpumask *srcp, int n)
459 bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
460 nr_cpumask_bits);
464 * cpumask_copy - *dstp = *srcp
465 * @dstp: the result
466 * @srcp: the input cpumask
468 static inline void cpumask_copy(struct cpumask *dstp,
469 const struct cpumask *srcp)
471 bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
475 * cpumask_any - pick a "random" cpu from *srcp
476 * @srcp: the input cpumask
478 * Returns >= nr_cpu_ids if no cpus set.
480 #define cpumask_any(srcp) cpumask_first(srcp)
483 * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
484 * @src1p: the first input
485 * @src2p: the second input
487 * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
489 #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
492 * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
493 * @mask1: the first input cpumask
494 * @mask2: the second input cpumask
496 * Returns >= nr_cpu_ids if no cpus set.
498 #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
501 * cpumask_of - the cpumask containing just a given cpu
502 * @cpu: the cpu (<= nr_cpu_ids)
504 #define cpumask_of(cpu) (get_cpu_mask(cpu))
507 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
508 * @buf: the buffer to sprintf into
509 * @len: the length of the buffer
510 * @srcp: the cpumask to print
512 * If len is zero, returns zero. Otherwise returns the length of the
513 * (nul-terminated) @buf string.
515 static inline int cpumask_scnprintf(char *buf, int len,
516 const struct cpumask *srcp)
518 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
522 * cpumask_parse_user - extract a cpumask from a user string
523 * @buf: the buffer to extract from
524 * @len: the length of the buffer
525 * @dstp: the cpumask to set.
527 * Returns -errno, or 0 for success.
529 static inline int cpumask_parse_user(const char __user *buf, int len,
530 struct cpumask *dstp)
532 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
536 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
537 * @buf: the buffer to sprintf into
538 * @len: the length of the buffer
539 * @srcp: the cpumask to print
541 * If len is zero, returns zero. Otherwise returns the length of the
542 * (nul-terminated) @buf string.
544 static inline int cpulist_scnprintf(char *buf, int len,
545 const struct cpumask *srcp)
547 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
548 nr_cpumask_bits);
552 * cpulist_parse_user - extract a cpumask from a user string of ranges
553 * @buf: the buffer to extract from
554 * @len: the length of the buffer
555 * @dstp: the cpumask to set.
557 * Returns -errno, or 0 for success.
559 static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
561 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
565 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
567 * This will eventually be a runtime variable, depending on nr_cpu_ids.
569 static inline size_t cpumask_size(void)
571 /* FIXME: Once all cpumask assignments are eliminated, this
572 * can be nr_cpumask_bits */
573 return BITS_TO_LONGS(NR_CPUS) * sizeof(long);
577 * cpumask_var_t: struct cpumask for stack usage.
579 * Oh, the wicked games we play! In order to make kernel coding a
580 * little more difficult, we typedef cpumask_var_t to an array or a
581 * pointer: doing &mask on an array is a noop, so it still works.
583 * ie.
584 * cpumask_var_t tmpmask;
585 * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
586 * return -ENOMEM;
588 * ... use 'tmpmask' like a normal struct cpumask * ...
590 * free_cpumask_var(tmpmask);
592 #ifdef CONFIG_CPUMASK_OFFSTACK
593 typedef struct cpumask *cpumask_var_t;
595 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
596 bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
597 bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
598 bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
599 void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
600 void free_cpumask_var(cpumask_var_t mask);
601 void free_bootmem_cpumask_var(cpumask_var_t mask);
603 #else
604 typedef struct cpumask cpumask_var_t[1];
606 static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
608 return true;
611 static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
612 int node)
614 return true;
617 static inline bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
619 cpumask_clear(*mask);
620 return true;
623 static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
624 int node)
626 cpumask_clear(*mask);
627 return true;
630 static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
634 static inline void free_cpumask_var(cpumask_var_t mask)
638 static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
641 #endif /* CONFIG_CPUMASK_OFFSTACK */
643 /* It's common to want to use cpu_all_mask in struct member initializers,
644 * so it has to refer to an address rather than a pointer. */
645 extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
646 #define cpu_all_mask to_cpumask(cpu_all_bits)
648 /* First bits of cpu_bit_bitmap are in fact unset. */
649 #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
651 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
652 #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
653 #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
655 /* Wrappers for arch boot code to manipulate normally-constant masks */
656 void set_cpu_possible(unsigned int cpu, bool possible);
657 void set_cpu_present(unsigned int cpu, bool present);
658 void set_cpu_online(unsigned int cpu, bool online);
659 void set_cpu_active(unsigned int cpu, bool active);
660 void init_cpu_present(const struct cpumask *src);
661 void init_cpu_possible(const struct cpumask *src);
662 void init_cpu_online(const struct cpumask *src);
665 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
666 * @bitmap: the bitmap
668 * There are a few places where cpumask_var_t isn't appropriate and
669 * static cpumasks must be used (eg. very early boot), yet we don't
670 * expose the definition of 'struct cpumask'.
672 * This does the conversion, and can be used as a constant initializer.
674 #define to_cpumask(bitmap) \
675 ((struct cpumask *)(1 ? (bitmap) \
676 : (void *)sizeof(__check_is_bitmap(bitmap))))
678 static inline int __check_is_bitmap(const unsigned long *bitmap)
680 return 1;
684 * Special-case data structure for "single bit set only" constant CPU masks.
686 * We pre-generate all the 64 (or 32) possible bit positions, with enough
687 * padding to the left and the right, and return the constant pointer
688 * appropriately offset.
690 extern const unsigned long
691 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
693 static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
695 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
696 p -= cpu / BITS_PER_LONG;
697 return to_cpumask(p);
700 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
702 #if NR_CPUS <= BITS_PER_LONG
703 #define CPU_BITS_ALL \
705 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
708 #else /* NR_CPUS > BITS_PER_LONG */
710 #define CPU_BITS_ALL \
712 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
713 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
715 #endif /* NR_CPUS > BITS_PER_LONG */
719 * From here down, all obsolete. Use cpumask_ variants!
722 #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
723 /* These strip const, as traditionally they weren't const. */
724 #define cpu_possible_map (*(cpumask_t *)cpu_possible_mask)
725 #define cpu_online_map (*(cpumask_t *)cpu_online_mask)
726 #define cpu_present_map (*(cpumask_t *)cpu_present_mask)
727 #define cpu_active_map (*(cpumask_t *)cpu_active_mask)
729 #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
731 #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
733 #if NR_CPUS <= BITS_PER_LONG
735 #define CPU_MASK_ALL \
736 (cpumask_t) { { \
737 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
740 #else
742 #define CPU_MASK_ALL \
743 (cpumask_t) { { \
744 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
745 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
748 #endif
750 #define CPU_MASK_NONE \
751 (cpumask_t) { { \
752 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
755 #define CPU_MASK_CPU0 \
756 (cpumask_t) { { \
757 [0] = 1UL \
760 #if NR_CPUS == 1
761 #define first_cpu(src) ({ (void)(src); 0; })
762 #define next_cpu(n, src) ({ (void)(src); 1; })
763 #define any_online_cpu(mask) 0
764 #define for_each_cpu_mask(cpu, mask) \
765 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
766 #else /* NR_CPUS > 1 */
767 int __first_cpu(const cpumask_t *srcp);
768 int __next_cpu(int n, const cpumask_t *srcp);
769 int __any_online_cpu(const cpumask_t *mask);
771 #define first_cpu(src) __first_cpu(&(src))
772 #define next_cpu(n, src) __next_cpu((n), &(src))
773 #define any_online_cpu(mask) __any_online_cpu(&(mask))
774 #define for_each_cpu_mask(cpu, mask) \
775 for ((cpu) = -1; \
776 (cpu) = next_cpu((cpu), (mask)), \
777 (cpu) < NR_CPUS; )
778 #endif /* SMP */
780 #if NR_CPUS <= 64
782 #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
784 #else /* NR_CPUS > 64 */
786 int __next_cpu_nr(int n, const cpumask_t *srcp);
787 #define for_each_cpu_mask_nr(cpu, mask) \
788 for ((cpu) = -1; \
789 (cpu) = __next_cpu_nr((cpu), &(mask)), \
790 (cpu) < nr_cpu_ids; )
792 #endif /* NR_CPUS > 64 */
794 #define cpus_addr(src) ((src).bits)
796 #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
797 static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
799 set_bit(cpu, dstp->bits);
802 #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
803 static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
805 clear_bit(cpu, dstp->bits);
808 #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
809 static inline void __cpus_setall(cpumask_t *dstp, int nbits)
811 bitmap_fill(dstp->bits, nbits);
814 #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
815 static inline void __cpus_clear(cpumask_t *dstp, int nbits)
817 bitmap_zero(dstp->bits, nbits);
820 /* No static inline type checking - see Subtlety (1) above. */
821 #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
823 #define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
824 static inline int __cpu_test_and_set(int cpu, cpumask_t *addr)
826 return test_and_set_bit(cpu, addr->bits);
829 #define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
830 static inline int __cpus_and(cpumask_t *dstp, const cpumask_t *src1p,
831 const cpumask_t *src2p, int nbits)
833 return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
836 #define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
837 static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p,
838 const cpumask_t *src2p, int nbits)
840 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
843 #define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
844 static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p,
845 const cpumask_t *src2p, int nbits)
847 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
850 #define cpus_andnot(dst, src1, src2) \
851 __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
852 static inline int __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p,
853 const cpumask_t *src2p, int nbits)
855 return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
858 #define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
859 static inline int __cpus_equal(const cpumask_t *src1p,
860 const cpumask_t *src2p, int nbits)
862 return bitmap_equal(src1p->bits, src2p->bits, nbits);
865 #define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
866 static inline int __cpus_intersects(const cpumask_t *src1p,
867 const cpumask_t *src2p, int nbits)
869 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
872 #define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
873 static inline int __cpus_subset(const cpumask_t *src1p,
874 const cpumask_t *src2p, int nbits)
876 return bitmap_subset(src1p->bits, src2p->bits, nbits);
879 #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
880 static inline int __cpus_empty(const cpumask_t *srcp, int nbits)
882 return bitmap_empty(srcp->bits, nbits);
885 #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
886 static inline int __cpus_weight(const cpumask_t *srcp, int nbits)
888 return bitmap_weight(srcp->bits, nbits);
891 #define cpus_shift_left(dst, src, n) \
892 __cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
893 static inline void __cpus_shift_left(cpumask_t *dstp,
894 const cpumask_t *srcp, int n, int nbits)
896 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
898 #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */
900 #endif /* __LINUX_CPUMASK_H */