1 #ifndef __LINUX_CPUMASK_H
2 #define __LINUX_CPUMASK_H
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.
9 #include <linux/kernel.h>
10 #include <linux/threads.h>
11 #include <linux/bitmap.h>
12 #include <linux/bug.h>
14 typedef struct cpumask
{ DECLARE_BITMAP(bits
, NR_CPUS
); } cpumask_t
;
17 * cpumask_bits - get the bits in a cpumask
18 * @maskp: the struct cpumask *
20 * You should only assume nr_cpu_ids bits of this mask are valid. This is
21 * a macro so it's const-correct.
23 #define cpumask_bits(maskp) ((maskp)->bits)
26 * cpumask_pr_args - printf args to output a cpumask
27 * @maskp: cpumask to be printed
29 * Can be used to provide arguments for '%*pb[l]' when printing a cpumask.
31 #define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp)
36 extern int nr_cpu_ids
;
39 #ifdef CONFIG_CPUMASK_OFFSTACK
40 /* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
41 * not all bits may be allocated. */
42 #define nr_cpumask_bits nr_cpu_ids
44 #define nr_cpumask_bits NR_CPUS
48 * The following particular system cpumasks and operations manage
49 * possible, present, active and online cpus.
51 * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
52 * cpu_present_mask - has bit 'cpu' set iff cpu is populated
53 * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
54 * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
56 * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
58 * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
59 * that it is possible might ever be plugged in at anytime during the
60 * life of that system boot. The cpu_present_mask is dynamic(*),
61 * representing which CPUs are currently plugged in. And
62 * cpu_online_mask is the dynamic subset of cpu_present_mask,
63 * indicating those CPUs available for scheduling.
65 * If HOTPLUG is enabled, then cpu_possible_mask is forced to have
66 * all NR_CPUS bits set, otherwise it is just the set of CPUs that
67 * ACPI reports present at boot.
69 * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
70 * depending on what ACPI reports as currently plugged in, otherwise
71 * cpu_present_mask is just a copy of cpu_possible_mask.
73 * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
74 * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
77 * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
78 * assumption that their single CPU is online. The UP
79 * cpu_{online,possible,present}_masks are placebos. Changing them
80 * will have no useful affect on the following num_*_cpus()
81 * and cpu_*() macros in the UP case. This ugliness is a UP
82 * optimization - don't waste any instructions or memory references
83 * asking if you're online or how many CPUs there are if there is
87 extern const struct cpumask
*const cpu_possible_mask
;
88 extern const struct cpumask
*const cpu_online_mask
;
89 extern const struct cpumask
*const cpu_present_mask
;
90 extern const struct cpumask
*const cpu_active_mask
;
93 #define num_online_cpus() cpumask_weight(cpu_online_mask)
94 #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
95 #define num_present_cpus() cpumask_weight(cpu_present_mask)
96 #define num_active_cpus() cpumask_weight(cpu_active_mask)
97 #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
98 #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
99 #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
100 #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
102 #define num_online_cpus() 1U
103 #define num_possible_cpus() 1U
104 #define num_present_cpus() 1U
105 #define num_active_cpus() 1U
106 #define cpu_online(cpu) ((cpu) == 0)
107 #define cpu_possible(cpu) ((cpu) == 0)
108 #define cpu_present(cpu) ((cpu) == 0)
109 #define cpu_active(cpu) ((cpu) == 0)
112 /* verify cpu argument to cpumask_* operators */
113 static inline unsigned int cpumask_check(unsigned int cpu
)
115 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
116 WARN_ON_ONCE(cpu
>= nr_cpumask_bits
);
117 #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
122 /* Uniprocessor. Assume all masks are "1". */
123 static inline unsigned int cpumask_first(const struct cpumask
*srcp
)
128 /* Valid inputs for n are -1 and 0. */
129 static inline unsigned int cpumask_next(int n
, const struct cpumask
*srcp
)
134 static inline unsigned int cpumask_next_zero(int n
, const struct cpumask
*srcp
)
139 static inline unsigned int cpumask_next_and(int n
,
140 const struct cpumask
*srcp
,
141 const struct cpumask
*andp
)
146 /* cpu must be a valid cpu, ie 0, so there's no other choice. */
147 static inline unsigned int cpumask_any_but(const struct cpumask
*mask
,
153 static inline int cpumask_set_cpu_local_first(int i
, int numa_node
, cpumask_t
*dstp
)
155 set_bit(0, cpumask_bits(dstp
));
160 #define for_each_cpu(cpu, mask) \
161 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
162 #define for_each_cpu_not(cpu, mask) \
163 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
164 #define for_each_cpu_and(cpu, mask, and) \
165 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
168 * cpumask_first - get the first cpu in a cpumask
169 * @srcp: the cpumask pointer
171 * Returns >= nr_cpu_ids if no cpus set.
173 static inline unsigned int cpumask_first(const struct cpumask
*srcp
)
175 return find_first_bit(cpumask_bits(srcp
), nr_cpumask_bits
);
179 * cpumask_next - get the next cpu in a cpumask
180 * @n: the cpu prior to the place to search (ie. return will be > @n)
181 * @srcp: the cpumask pointer
183 * Returns >= nr_cpu_ids if no further cpus set.
185 static inline unsigned int cpumask_next(int n
, const struct cpumask
*srcp
)
187 /* -1 is a legal arg here. */
190 return find_next_bit(cpumask_bits(srcp
), nr_cpumask_bits
, n
+1);
194 * cpumask_next_zero - get the next unset cpu in a cpumask
195 * @n: the cpu prior to the place to search (ie. return will be > @n)
196 * @srcp: the cpumask pointer
198 * Returns >= nr_cpu_ids if no further cpus unset.
200 static inline unsigned int cpumask_next_zero(int n
, const struct cpumask
*srcp
)
202 /* -1 is a legal arg here. */
205 return find_next_zero_bit(cpumask_bits(srcp
), nr_cpumask_bits
, n
+1);
208 int cpumask_next_and(int n
, const struct cpumask
*, const struct cpumask
*);
209 int cpumask_any_but(const struct cpumask
*mask
, unsigned int cpu
);
210 int cpumask_set_cpu_local_first(int i
, int numa_node
, cpumask_t
*dstp
);
213 * for_each_cpu - iterate over every cpu in a mask
214 * @cpu: the (optionally unsigned) integer iterator
215 * @mask: the cpumask pointer
217 * After the loop, cpu is >= nr_cpu_ids.
219 #define for_each_cpu(cpu, mask) \
221 (cpu) = cpumask_next((cpu), (mask)), \
225 * for_each_cpu_not - iterate over every cpu in a complemented mask
226 * @cpu: the (optionally unsigned) integer iterator
227 * @mask: the cpumask pointer
229 * After the loop, cpu is >= nr_cpu_ids.
231 #define for_each_cpu_not(cpu, mask) \
233 (cpu) = cpumask_next_zero((cpu), (mask)), \
237 * for_each_cpu_and - iterate over every cpu in both masks
238 * @cpu: the (optionally unsigned) integer iterator
239 * @mask: the first cpumask pointer
240 * @and: the second cpumask pointer
242 * This saves a temporary CPU mask in many places. It is equivalent to:
243 * struct cpumask tmp;
244 * cpumask_and(&tmp, &mask, &and);
245 * for_each_cpu(cpu, &tmp)
248 * After the loop, cpu is >= nr_cpu_ids.
250 #define for_each_cpu_and(cpu, mask, and) \
252 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
256 #define CPU_BITS_NONE \
258 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
261 #define CPU_BITS_CPU0 \
267 * cpumask_set_cpu - set a cpu in a cpumask
268 * @cpu: cpu number (< nr_cpu_ids)
269 * @dstp: the cpumask pointer
271 static inline void cpumask_set_cpu(unsigned int cpu
, struct cpumask
*dstp
)
273 set_bit(cpumask_check(cpu
), cpumask_bits(dstp
));
277 * cpumask_clear_cpu - clear a cpu in a cpumask
278 * @cpu: cpu number (< nr_cpu_ids)
279 * @dstp: the cpumask pointer
281 static inline void cpumask_clear_cpu(int cpu
, struct cpumask
*dstp
)
283 clear_bit(cpumask_check(cpu
), cpumask_bits(dstp
));
287 * cpumask_test_cpu - test for a cpu in a cpumask
288 * @cpu: cpu number (< nr_cpu_ids)
289 * @cpumask: the cpumask pointer
291 * Returns 1 if @cpu is set in @cpumask, else returns 0
293 * No static inline type checking - see Subtlety (1) above.
295 #define cpumask_test_cpu(cpu, cpumask) \
296 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
299 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
300 * @cpu: cpu number (< nr_cpu_ids)
301 * @cpumask: the cpumask pointer
303 * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
305 * test_and_set_bit wrapper for cpumasks.
307 static inline int cpumask_test_and_set_cpu(int cpu
, struct cpumask
*cpumask
)
309 return test_and_set_bit(cpumask_check(cpu
), cpumask_bits(cpumask
));
313 * cpumask_test_and_clear_cpu - atomically test and clear a cpu in a cpumask
314 * @cpu: cpu number (< nr_cpu_ids)
315 * @cpumask: the cpumask pointer
317 * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
319 * test_and_clear_bit wrapper for cpumasks.
321 static inline int cpumask_test_and_clear_cpu(int cpu
, struct cpumask
*cpumask
)
323 return test_and_clear_bit(cpumask_check(cpu
), cpumask_bits(cpumask
));
327 * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
328 * @dstp: the cpumask pointer
330 static inline void cpumask_setall(struct cpumask
*dstp
)
332 bitmap_fill(cpumask_bits(dstp
), nr_cpumask_bits
);
336 * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
337 * @dstp: the cpumask pointer
339 static inline void cpumask_clear(struct cpumask
*dstp
)
341 bitmap_zero(cpumask_bits(dstp
), nr_cpumask_bits
);
345 * cpumask_and - *dstp = *src1p & *src2p
346 * @dstp: the cpumask result
347 * @src1p: the first input
348 * @src2p: the second input
350 * If *@dstp is empty, returns 0, else returns 1
352 static inline int cpumask_and(struct cpumask
*dstp
,
353 const struct cpumask
*src1p
,
354 const struct cpumask
*src2p
)
356 return bitmap_and(cpumask_bits(dstp
), cpumask_bits(src1p
),
357 cpumask_bits(src2p
), nr_cpumask_bits
);
361 * cpumask_or - *dstp = *src1p | *src2p
362 * @dstp: the cpumask result
363 * @src1p: the first input
364 * @src2p: the second input
366 static inline void cpumask_or(struct cpumask
*dstp
, const struct cpumask
*src1p
,
367 const struct cpumask
*src2p
)
369 bitmap_or(cpumask_bits(dstp
), cpumask_bits(src1p
),
370 cpumask_bits(src2p
), nr_cpumask_bits
);
374 * cpumask_xor - *dstp = *src1p ^ *src2p
375 * @dstp: the cpumask result
376 * @src1p: the first input
377 * @src2p: the second input
379 static inline void cpumask_xor(struct cpumask
*dstp
,
380 const struct cpumask
*src1p
,
381 const struct cpumask
*src2p
)
383 bitmap_xor(cpumask_bits(dstp
), cpumask_bits(src1p
),
384 cpumask_bits(src2p
), nr_cpumask_bits
);
388 * cpumask_andnot - *dstp = *src1p & ~*src2p
389 * @dstp: the cpumask result
390 * @src1p: the first input
391 * @src2p: the second input
393 * If *@dstp is empty, returns 0, else returns 1
395 static inline int cpumask_andnot(struct cpumask
*dstp
,
396 const struct cpumask
*src1p
,
397 const struct cpumask
*src2p
)
399 return bitmap_andnot(cpumask_bits(dstp
), cpumask_bits(src1p
),
400 cpumask_bits(src2p
), nr_cpumask_bits
);
404 * cpumask_complement - *dstp = ~*srcp
405 * @dstp: the cpumask result
406 * @srcp: the input to invert
408 static inline void cpumask_complement(struct cpumask
*dstp
,
409 const struct cpumask
*srcp
)
411 bitmap_complement(cpumask_bits(dstp
), cpumask_bits(srcp
),
416 * cpumask_equal - *src1p == *src2p
417 * @src1p: the first input
418 * @src2p: the second input
420 static inline bool cpumask_equal(const struct cpumask
*src1p
,
421 const struct cpumask
*src2p
)
423 return bitmap_equal(cpumask_bits(src1p
), cpumask_bits(src2p
),
428 * cpumask_intersects - (*src1p & *src2p) != 0
429 * @src1p: the first input
430 * @src2p: the second input
432 static inline bool cpumask_intersects(const struct cpumask
*src1p
,
433 const struct cpumask
*src2p
)
435 return bitmap_intersects(cpumask_bits(src1p
), cpumask_bits(src2p
),
440 * cpumask_subset - (*src1p & ~*src2p) == 0
441 * @src1p: the first input
442 * @src2p: the second input
444 * Returns 1 if *@src1p is a subset of *@src2p, else returns 0
446 static inline int cpumask_subset(const struct cpumask
*src1p
,
447 const struct cpumask
*src2p
)
449 return bitmap_subset(cpumask_bits(src1p
), cpumask_bits(src2p
),
454 * cpumask_empty - *srcp == 0
455 * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
457 static inline bool cpumask_empty(const struct cpumask
*srcp
)
459 return bitmap_empty(cpumask_bits(srcp
), nr_cpumask_bits
);
463 * cpumask_full - *srcp == 0xFFFFFFFF...
464 * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
466 static inline bool cpumask_full(const struct cpumask
*srcp
)
468 return bitmap_full(cpumask_bits(srcp
), nr_cpumask_bits
);
472 * cpumask_weight - Count of bits in *srcp
473 * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
475 static inline unsigned int cpumask_weight(const struct cpumask
*srcp
)
477 return bitmap_weight(cpumask_bits(srcp
), nr_cpumask_bits
);
481 * cpumask_shift_right - *dstp = *srcp >> n
482 * @dstp: the cpumask result
483 * @srcp: the input to shift
484 * @n: the number of bits to shift by
486 static inline void cpumask_shift_right(struct cpumask
*dstp
,
487 const struct cpumask
*srcp
, int n
)
489 bitmap_shift_right(cpumask_bits(dstp
), cpumask_bits(srcp
), n
,
494 * cpumask_shift_left - *dstp = *srcp << n
495 * @dstp: the cpumask result
496 * @srcp: the input to shift
497 * @n: the number of bits to shift by
499 static inline void cpumask_shift_left(struct cpumask
*dstp
,
500 const struct cpumask
*srcp
, int n
)
502 bitmap_shift_left(cpumask_bits(dstp
), cpumask_bits(srcp
), n
,
507 * cpumask_copy - *dstp = *srcp
509 * @srcp: the input cpumask
511 static inline void cpumask_copy(struct cpumask
*dstp
,
512 const struct cpumask
*srcp
)
514 bitmap_copy(cpumask_bits(dstp
), cpumask_bits(srcp
), nr_cpumask_bits
);
518 * cpumask_any - pick a "random" cpu from *srcp
519 * @srcp: the input cpumask
521 * Returns >= nr_cpu_ids if no cpus set.
523 #define cpumask_any(srcp) cpumask_first(srcp)
526 * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
527 * @src1p: the first input
528 * @src2p: the second input
530 * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
532 #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
535 * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
536 * @mask1: the first input cpumask
537 * @mask2: the second input cpumask
539 * Returns >= nr_cpu_ids if no cpus set.
541 #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
544 * cpumask_of - the cpumask containing just a given cpu
545 * @cpu: the cpu (<= nr_cpu_ids)
547 #define cpumask_of(cpu) (get_cpu_mask(cpu))
550 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
551 * @buf: the buffer to sprintf into
552 * @len: the length of the buffer
553 * @srcp: the cpumask to print
555 * If len is zero, returns zero. Otherwise returns the length of the
556 * (nul-terminated) @buf string.
558 static inline int cpumask_scnprintf(char *buf
, int len
,
559 const struct cpumask
*srcp
)
561 return bitmap_scnprintf(buf
, len
, cpumask_bits(srcp
), nr_cpu_ids
);
565 * cpumask_parse_user - extract a cpumask from a user string
566 * @buf: the buffer to extract from
567 * @len: the length of the buffer
568 * @dstp: the cpumask to set.
570 * Returns -errno, or 0 for success.
572 static inline int cpumask_parse_user(const char __user
*buf
, int len
,
573 struct cpumask
*dstp
)
575 return bitmap_parse_user(buf
, len
, cpumask_bits(dstp
), nr_cpu_ids
);
579 * cpumask_parselist_user - extract a cpumask from a user string
580 * @buf: the buffer to extract from
581 * @len: the length of the buffer
582 * @dstp: the cpumask to set.
584 * Returns -errno, or 0 for success.
586 static inline int cpumask_parselist_user(const char __user
*buf
, int len
,
587 struct cpumask
*dstp
)
589 return bitmap_parselist_user(buf
, len
, cpumask_bits(dstp
),
594 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
595 * @buf: the buffer to sprintf into
596 * @len: the length of the buffer
597 * @srcp: the cpumask to print
599 * If len is zero, returns zero. Otherwise returns the length of the
600 * (nul-terminated) @buf string.
602 static inline int cpulist_scnprintf(char *buf
, int len
,
603 const struct cpumask
*srcp
)
605 return bitmap_scnlistprintf(buf
, len
, cpumask_bits(srcp
),
610 * cpumask_parse - extract a cpumask from from a string
611 * @buf: the buffer to extract from
612 * @dstp: the cpumask to set.
614 * Returns -errno, or 0 for success.
616 static inline int cpumask_parse(const char *buf
, struct cpumask
*dstp
)
618 char *nl
= strchr(buf
, '\n');
619 unsigned int len
= nl
? (unsigned int)(nl
- buf
) : strlen(buf
);
621 return bitmap_parse(buf
, len
, cpumask_bits(dstp
), nr_cpu_ids
);
625 * cpulist_parse - extract a cpumask from a user string of ranges
626 * @buf: the buffer to extract from
627 * @dstp: the cpumask to set.
629 * Returns -errno, or 0 for success.
631 static inline int cpulist_parse(const char *buf
, struct cpumask
*dstp
)
633 return bitmap_parselist(buf
, cpumask_bits(dstp
), nr_cpu_ids
);
637 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
639 * This will eventually be a runtime variable, depending on nr_cpu_ids.
641 static inline size_t cpumask_size(void)
643 /* FIXME: Once all cpumask assignments are eliminated, this
644 * can be nr_cpumask_bits */
645 return BITS_TO_LONGS(NR_CPUS
) * sizeof(long);
649 * cpumask_var_t: struct cpumask for stack usage.
651 * Oh, the wicked games we play! In order to make kernel coding a
652 * little more difficult, we typedef cpumask_var_t to an array or a
653 * pointer: doing &mask on an array is a noop, so it still works.
656 * cpumask_var_t tmpmask;
657 * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
660 * ... use 'tmpmask' like a normal struct cpumask * ...
662 * free_cpumask_var(tmpmask);
665 * However, one notable exception is there. alloc_cpumask_var() allocates
666 * only nr_cpumask_bits bits (in the other hand, real cpumask_t always has
667 * NR_CPUS bits). Therefore you don't have to dereference cpumask_var_t.
669 * cpumask_var_t tmpmask;
670 * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
675 * This code makes NR_CPUS length memcopy and brings to a memory corruption.
676 * cpumask_copy() provide safe copy functionality.
678 * Note that there is another evil here: If you define a cpumask_var_t
679 * as a percpu variable then the way to obtain the address of the cpumask
680 * structure differently influences what this_cpu_* operation needs to be
681 * used. Please use this_cpu_cpumask_var_t in those cases. The direct use
682 * of this_cpu_ptr() or this_cpu_read() will lead to failures when the
683 * other type of cpumask_var_t implementation is configured.
685 #ifdef CONFIG_CPUMASK_OFFSTACK
686 typedef struct cpumask
*cpumask_var_t
;
688 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x)
690 bool alloc_cpumask_var_node(cpumask_var_t
*mask
, gfp_t flags
, int node
);
691 bool alloc_cpumask_var(cpumask_var_t
*mask
, gfp_t flags
);
692 bool zalloc_cpumask_var_node(cpumask_var_t
*mask
, gfp_t flags
, int node
);
693 bool zalloc_cpumask_var(cpumask_var_t
*mask
, gfp_t flags
);
694 void alloc_bootmem_cpumask_var(cpumask_var_t
*mask
);
695 void free_cpumask_var(cpumask_var_t mask
);
696 void free_bootmem_cpumask_var(cpumask_var_t mask
);
699 typedef struct cpumask cpumask_var_t
[1];
701 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x)
703 static inline bool alloc_cpumask_var(cpumask_var_t
*mask
, gfp_t flags
)
708 static inline bool alloc_cpumask_var_node(cpumask_var_t
*mask
, gfp_t flags
,
714 static inline bool zalloc_cpumask_var(cpumask_var_t
*mask
, gfp_t flags
)
716 cpumask_clear(*mask
);
720 static inline bool zalloc_cpumask_var_node(cpumask_var_t
*mask
, gfp_t flags
,
723 cpumask_clear(*mask
);
727 static inline void alloc_bootmem_cpumask_var(cpumask_var_t
*mask
)
731 static inline void free_cpumask_var(cpumask_var_t mask
)
735 static inline void free_bootmem_cpumask_var(cpumask_var_t mask
)
738 #endif /* CONFIG_CPUMASK_OFFSTACK */
740 /* It's common to want to use cpu_all_mask in struct member initializers,
741 * so it has to refer to an address rather than a pointer. */
742 extern const DECLARE_BITMAP(cpu_all_bits
, NR_CPUS
);
743 #define cpu_all_mask to_cpumask(cpu_all_bits)
745 /* First bits of cpu_bit_bitmap are in fact unset. */
746 #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
748 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
749 #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
750 #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
752 /* Wrappers for arch boot code to manipulate normally-constant masks */
753 void set_cpu_possible(unsigned int cpu
, bool possible
);
754 void set_cpu_present(unsigned int cpu
, bool present
);
755 void set_cpu_online(unsigned int cpu
, bool online
);
756 void set_cpu_active(unsigned int cpu
, bool active
);
757 void init_cpu_present(const struct cpumask
*src
);
758 void init_cpu_possible(const struct cpumask
*src
);
759 void init_cpu_online(const struct cpumask
*src
);
762 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
763 * @bitmap: the bitmap
765 * There are a few places where cpumask_var_t isn't appropriate and
766 * static cpumasks must be used (eg. very early boot), yet we don't
767 * expose the definition of 'struct cpumask'.
769 * This does the conversion, and can be used as a constant initializer.
771 #define to_cpumask(bitmap) \
772 ((struct cpumask *)(1 ? (bitmap) \
773 : (void *)sizeof(__check_is_bitmap(bitmap))))
775 static inline int __check_is_bitmap(const unsigned long *bitmap
)
781 * Special-case data structure for "single bit set only" constant CPU masks.
783 * We pre-generate all the 64 (or 32) possible bit positions, with enough
784 * padding to the left and the right, and return the constant pointer
785 * appropriately offset.
787 extern const unsigned long
788 cpu_bit_bitmap
[BITS_PER_LONG
+1][BITS_TO_LONGS(NR_CPUS
)];
790 static inline const struct cpumask
*get_cpu_mask(unsigned int cpu
)
792 const unsigned long *p
= cpu_bit_bitmap
[1 + cpu
% BITS_PER_LONG
];
793 p
-= cpu
/ BITS_PER_LONG
;
794 return to_cpumask(p
);
797 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
799 #if NR_CPUS <= BITS_PER_LONG
800 #define CPU_BITS_ALL \
802 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
805 #else /* NR_CPUS > BITS_PER_LONG */
807 #define CPU_BITS_ALL \
809 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
810 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
812 #endif /* NR_CPUS > BITS_PER_LONG */
815 * cpumap_print_to_pagebuf - copies the cpumask into the buffer either
816 * as comma-separated list of cpus or hex values of cpumask
817 * @list: indicates whether the cpumap must be list
818 * @mask: the cpumask to copy
819 * @buf: the buffer to copy into
821 * Returns the length of the (null-terminated) @buf string, zero if
824 static inline ssize_t
825 cpumap_print_to_pagebuf(bool list
, char *buf
, const struct cpumask
*mask
)
827 return bitmap_print_to_pagebuf(list
, buf
, cpumask_bits(mask
),
833 * From here down, all obsolete. Use cpumask_ variants!
836 #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
837 #define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
839 #define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
841 #if NR_CPUS <= BITS_PER_LONG
843 #define CPU_MASK_ALL \
845 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
850 #define CPU_MASK_ALL \
852 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
853 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
858 #define CPU_MASK_NONE \
860 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
863 #define CPU_MASK_CPU0 \
869 #define first_cpu(src) ({ (void)(src); 0; })
870 #define next_cpu(n, src) ({ (void)(src); 1; })
871 #define any_online_cpu(mask) 0
872 #define for_each_cpu_mask(cpu, mask) \
873 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
874 #else /* NR_CPUS > 1 */
875 int __first_cpu(const cpumask_t
*srcp
);
876 int __next_cpu(int n
, const cpumask_t
*srcp
);
878 #define first_cpu(src) __first_cpu(&(src))
879 #define next_cpu(n, src) __next_cpu((n), &(src))
880 #define any_online_cpu(mask) cpumask_any_and(&mask, cpu_online_mask)
881 #define for_each_cpu_mask(cpu, mask) \
883 (cpu) = next_cpu((cpu), (mask)), \
889 #define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
891 #else /* NR_CPUS > 64 */
893 int __next_cpu_nr(int n
, const cpumask_t
*srcp
);
894 #define for_each_cpu_mask_nr(cpu, mask) \
896 (cpu) = __next_cpu_nr((cpu), &(mask)), \
897 (cpu) < nr_cpu_ids; )
899 #endif /* NR_CPUS > 64 */
901 #define cpus_addr(src) ((src).bits)
903 #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
904 static inline void __cpu_set(int cpu
, volatile cpumask_t
*dstp
)
906 set_bit(cpu
, dstp
->bits
);
909 #define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
910 static inline void __cpu_clear(int cpu
, volatile cpumask_t
*dstp
)
912 clear_bit(cpu
, dstp
->bits
);
915 #define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
916 static inline void __cpus_setall(cpumask_t
*dstp
, unsigned int nbits
)
918 bitmap_fill(dstp
->bits
, nbits
);
921 #define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
922 static inline void __cpus_clear(cpumask_t
*dstp
, unsigned int nbits
)
924 bitmap_zero(dstp
->bits
, nbits
);
927 /* No static inline type checking - see Subtlety (1) above. */
928 #define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
930 #define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
931 static inline int __cpu_test_and_set(int cpu
, cpumask_t
*addr
)
933 return test_and_set_bit(cpu
, addr
->bits
);
936 #define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
937 static inline int __cpus_and(cpumask_t
*dstp
, const cpumask_t
*src1p
,
938 const cpumask_t
*src2p
, unsigned int nbits
)
940 return bitmap_and(dstp
->bits
, src1p
->bits
, src2p
->bits
, nbits
);
943 #define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
944 static inline void __cpus_or(cpumask_t
*dstp
, const cpumask_t
*src1p
,
945 const cpumask_t
*src2p
, unsigned int nbits
)
947 bitmap_or(dstp
->bits
, src1p
->bits
, src2p
->bits
, nbits
);
950 #define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
951 static inline void __cpus_xor(cpumask_t
*dstp
, const cpumask_t
*src1p
,
952 const cpumask_t
*src2p
, unsigned int nbits
)
954 bitmap_xor(dstp
->bits
, src1p
->bits
, src2p
->bits
, nbits
);
957 #define cpus_andnot(dst, src1, src2) \
958 __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
959 static inline int __cpus_andnot(cpumask_t
*dstp
, const cpumask_t
*src1p
,
960 const cpumask_t
*src2p
, unsigned int nbits
)
962 return bitmap_andnot(dstp
->bits
, src1p
->bits
, src2p
->bits
, nbits
);
965 #define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
966 static inline int __cpus_equal(const cpumask_t
*src1p
,
967 const cpumask_t
*src2p
, unsigned int nbits
)
969 return bitmap_equal(src1p
->bits
, src2p
->bits
, nbits
);
972 #define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
973 static inline int __cpus_intersects(const cpumask_t
*src1p
,
974 const cpumask_t
*src2p
, unsigned int nbits
)
976 return bitmap_intersects(src1p
->bits
, src2p
->bits
, nbits
);
979 #define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
980 static inline int __cpus_subset(const cpumask_t
*src1p
,
981 const cpumask_t
*src2p
, unsigned int nbits
)
983 return bitmap_subset(src1p
->bits
, src2p
->bits
, nbits
);
986 #define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
987 static inline int __cpus_empty(const cpumask_t
*srcp
, unsigned int nbits
)
989 return bitmap_empty(srcp
->bits
, nbits
);
992 #define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
993 static inline int __cpus_weight(const cpumask_t
*srcp
, unsigned int nbits
)
995 return bitmap_weight(srcp
->bits
, nbits
);
998 #define cpus_shift_left(dst, src, n) \
999 __cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
1000 static inline void __cpus_shift_left(cpumask_t
*dstp
,
1001 const cpumask_t
*srcp
, int n
, int nbits
)
1003 bitmap_shift_left(dstp
->bits
, srcp
->bits
, n
, nbits
);
1005 #endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */
1007 #endif /* __LINUX_CPUMASK_H */
This page took 0.052108 seconds and 5 git commands to generate.