blob: 7c178a6baae34470774c7d944b4e5e7d0066f899 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_CPUMASK_H
2#define __LINUX_CPUMASK_H
3
4/*
5 * Cpumasks provide a bitmap suitable for representing the
6 * set of CPU's in a system, one bit position per CPU number.
7 *
Rusty Russell2d3854a2008-11-05 13:39:10 +11008 * The new cpumask_ ops take a "struct cpumask *"; the old ones
9 * use cpumask_t.
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * See detailed comments in the file linux/bitmap.h describing the
12 * data type on which these cpumasks are based.
13 *
Reinette Chatre01a3ee22006-10-11 01:21:55 -070014 * For details of cpumask_scnprintf() and cpumask_parse_user(),
15 * see bitmap_scnprintf() and bitmap_parse_user() in lib/bitmap.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * For details of cpulist_scnprintf() and cpulist_parse(), see
17 * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c.
Paul Jacksonfb5eeee2005-10-30 15:02:33 -080018 * For details of cpu_remap(), see bitmap_bitremap in lib/bitmap.c
19 * For details of cpus_remap(), see bitmap_remap in lib/bitmap.c.
Paul Jackson7ea931c2008-04-28 02:12:29 -070020 * For details of cpus_onto(), see bitmap_onto in lib/bitmap.c.
21 * For details of cpus_fold(), see bitmap_fold in lib/bitmap.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
Mike Travis41df0d612008-05-12 21:21:13 +020023 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24 * Note: The alternate operations with the suffix "_nr" are used
25 * to limit the range of the loop to nr_cpu_ids instead of
26 * NR_CPUS when NR_CPUS > 64 for performance reasons.
27 * If NR_CPUS is <= 64 then most assembler bitmask
28 * operators execute faster with a constant range, so
29 * the operator will continue to use NR_CPUS.
30 *
31 * Another consideration is that nr_cpu_ids is initialized
32 * to NR_CPUS and isn't lowered until the possible cpus are
33 * discovered (including any disabled cpus). So early uses
34 * will span the entire range of NR_CPUS.
35 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36 *
Rusty Russell2d3854a2008-11-05 13:39:10 +110037 * The obsolescent cpumask operations are:
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 *
39 * void cpu_set(cpu, mask) turn on bit 'cpu' in mask
40 * void cpu_clear(cpu, mask) turn off bit 'cpu' in mask
41 * void cpus_setall(mask) set all bits
42 * void cpus_clear(mask) clear all bits
43 * int cpu_isset(cpu, mask) true iff bit 'cpu' set in mask
44 * int cpu_test_and_set(cpu, mask) test and set bit 'cpu' in mask
45 *
46 * void cpus_and(dst, src1, src2) dst = src1 & src2 [intersection]
47 * void cpus_or(dst, src1, src2) dst = src1 | src2 [union]
48 * void cpus_xor(dst, src1, src2) dst = src1 ^ src2
49 * void cpus_andnot(dst, src1, src2) dst = src1 & ~src2
50 * void cpus_complement(dst, src) dst = ~src
51 *
52 * int cpus_equal(mask1, mask2) Does mask1 == mask2?
53 * int cpus_intersects(mask1, mask2) Do mask1 and mask2 intersect?
54 * int cpus_subset(mask1, mask2) Is mask1 a subset of mask2?
55 * int cpus_empty(mask) Is mask empty (no bits sets)?
56 * int cpus_full(mask) Is mask full (all bits sets)?
57 * int cpus_weight(mask) Hamming weigh - number of set bits
Mike Travis41df0d612008-05-12 21:21:13 +020058 * int cpus_weight_nr(mask) Same using nr_cpu_ids instead of NR_CPUS
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 *
60 * void cpus_shift_right(dst, src, n) Shift right
61 * void cpus_shift_left(dst, src, n) Shift left
62 *
63 * int first_cpu(mask) Number lowest set bit, or NR_CPUS
64 * int next_cpu(cpu, mask) Next cpu past 'cpu', or NR_CPUS
Mike Travis41df0d612008-05-12 21:21:13 +020065 * int next_cpu_nr(cpu, mask) Next cpu past 'cpu', or nr_cpu_ids
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 *
67 * cpumask_t cpumask_of_cpu(cpu) Return cpumask with bit 'cpu' set
Mike Travisb8d317d2008-07-24 18:21:29 -070068 * (can be used as an lvalue)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * CPU_MASK_ALL Initializer - all bits set
70 * CPU_MASK_NONE Initializer - no bits set
71 * unsigned long *cpus_addr(mask) Array of unsigned long's in mask
72 *
Mike Travis80422d32008-07-18 18:11:33 -070073 * CPUMASK_ALLOC kmalloc's a structure that is a composite of many cpumask_t
74 * variables, and CPUMASK_PTR provides pointers to each field.
75 *
76 * The structure should be defined something like this:
77 * struct my_cpumasks {
78 * cpumask_t mask1;
79 * cpumask_t mask2;
80 * };
81 *
82 * Usage is then:
83 * CPUMASK_ALLOC(my_cpumasks);
84 * CPUMASK_PTR(mask1, my_cpumasks);
85 * CPUMASK_PTR(mask2, my_cpumasks);
86 *
87 * --- DO NOT reference cpumask_t pointers until this check ---
88 * if (my_cpumasks == NULL)
89 * "kmalloc failed"...
90 *
91 * References are now pointers to the cpumask_t variables (*mask1, ...)
92 *
Mike Travis77586c22008-07-15 14:14:36 -070093 *if NR_CPUS > BITS_PER_LONG
94 * CPUMASK_ALLOC(m) Declares and allocates struct m *m =
Mike Travis80422d32008-07-18 18:11:33 -070095 * kmalloc(sizeof(*m), GFP_KERNEL)
96 * CPUMASK_FREE(m) Macro for kfree(m)
Mike Travis77586c22008-07-15 14:14:36 -070097 *else
98 * CPUMASK_ALLOC(m) Declares struct m _m, *m = &_m
99 * CPUMASK_FREE(m) Nop
100 *endif
Mike Travis80422d32008-07-18 18:11:33 -0700101 * CPUMASK_PTR(v, m) Declares cpumask_t *v = &(m->v)
102 * ------------------------------------------------------------------------
Mike Travis77586c22008-07-15 14:14:36 -0700103 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 * int cpumask_scnprintf(buf, len, mask) Format cpumask for printing
Reinette Chatre01a3ee22006-10-11 01:21:55 -0700105 * int cpumask_parse_user(ubuf, ulen, mask) Parse ascii string as cpumask
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 * int cpulist_scnprintf(buf, len, mask) Format cpumask as list for printing
107 * int cpulist_parse(buf, map) Parse ascii string as cpulist
Paul Jacksonfb5eeee2005-10-30 15:02:33 -0800108 * int cpu_remap(oldbit, old, new) newbit = map(old, new)(oldbit)
Paul Jackson7ea931c2008-04-28 02:12:29 -0700109 * void cpus_remap(dst, src, old, new) *dst = map(old, new)(src)
110 * void cpus_onto(dst, orig, relmap) *dst = orig relative to relmap
111 * void cpus_fold(dst, orig, sz) dst bits = orig bits mod sz
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 *
Mike Travis41df0d612008-05-12 21:21:13 +0200113 * for_each_cpu_mask(cpu, mask) for-loop cpu over mask using NR_CPUS
114 * for_each_cpu_mask_nr(cpu, mask) for-loop cpu over mask using nr_cpu_ids
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * int num_online_cpus() Number of online CPUs
117 * int num_possible_cpus() Number of all possible CPUs
118 * int num_present_cpus() Number of present CPUs
119 *
120 * int cpu_online(cpu) Is some cpu online?
121 * int cpu_possible(cpu) Is some cpu possible?
122 * int cpu_present(cpu) Is some cpu present (can schedule)?
123 *
124 * int any_online_cpu(mask) First online cpu in mask
125 *
KAMEZAWA Hiroyuki631d6742006-03-28 01:56:36 -0800126 * for_each_possible_cpu(cpu) for-loop cpu over cpu_possible_map
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 * for_each_online_cpu(cpu) for-loop cpu over cpu_online_map
128 * for_each_present_cpu(cpu) for-loop cpu over cpu_present_map
129 *
130 * Subtlety:
131 * 1) The 'type-checked' form of cpu_isset() causes gcc (3.3.2, anyway)
132 * to generate slightly worse code. Note for example the additional
133 * 40 lines of assembly code compiling the "for each possible cpu"
134 * loops buried in the disk_stat_read() macros calls when compiling
135 * drivers/block/genhd.c (arch i386, CONFIG_SMP=y). So use a simple
136 * one-line #define for cpu_isset(), instead of wrapping an inline
137 * inside a macro, the way we do the other calls.
138 */
139
140#include <linux/kernel.h>
141#include <linux/threads.h>
142#include <linux/bitmap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Rusty Russell2d3854a2008-11-05 13:39:10 +1100144typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145extern cpumask_t _unused_cpumask_arg_;
146
147#define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
148static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
149{
150 set_bit(cpu, dstp->bits);
151}
152
153#define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
154static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
155{
156 clear_bit(cpu, dstp->bits);
157}
158
159#define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
160static inline void __cpus_setall(cpumask_t *dstp, int nbits)
161{
162 bitmap_fill(dstp->bits, nbits);
163}
164
165#define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
166static inline void __cpus_clear(cpumask_t *dstp, int nbits)
167{
168 bitmap_zero(dstp->bits, nbits);
169}
170
171/* No static inline type checking - see Subtlety (1) above. */
172#define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
173
174#define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
175static inline int __cpu_test_and_set(int cpu, cpumask_t *addr)
176{
177 return test_and_set_bit(cpu, addr->bits);
178}
179
180#define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
181static inline void __cpus_and(cpumask_t *dstp, const cpumask_t *src1p,
182 const cpumask_t *src2p, int nbits)
183{
184 bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
185}
186
187#define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
188static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p,
189 const cpumask_t *src2p, int nbits)
190{
191 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
192}
193
194#define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
195static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p,
196 const cpumask_t *src2p, int nbits)
197{
198 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
199}
200
201#define cpus_andnot(dst, src1, src2) \
202 __cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
203static inline void __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p,
204 const cpumask_t *src2p, int nbits)
205{
206 bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
207}
208
209#define cpus_complement(dst, src) __cpus_complement(&(dst), &(src), NR_CPUS)
210static inline void __cpus_complement(cpumask_t *dstp,
211 const cpumask_t *srcp, int nbits)
212{
213 bitmap_complement(dstp->bits, srcp->bits, nbits);
214}
215
216#define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
217static inline int __cpus_equal(const cpumask_t *src1p,
218 const cpumask_t *src2p, int nbits)
219{
220 return bitmap_equal(src1p->bits, src2p->bits, nbits);
221}
222
223#define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
224static inline int __cpus_intersects(const cpumask_t *src1p,
225 const cpumask_t *src2p, int nbits)
226{
227 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
228}
229
230#define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
231static inline int __cpus_subset(const cpumask_t *src1p,
232 const cpumask_t *src2p, int nbits)
233{
234 return bitmap_subset(src1p->bits, src2p->bits, nbits);
235}
236
237#define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
238static inline int __cpus_empty(const cpumask_t *srcp, int nbits)
239{
240 return bitmap_empty(srcp->bits, nbits);
241}
242
243#define cpus_full(cpumask) __cpus_full(&(cpumask), NR_CPUS)
244static inline int __cpus_full(const cpumask_t *srcp, int nbits)
245{
246 return bitmap_full(srcp->bits, nbits);
247}
248
249#define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
250static inline int __cpus_weight(const cpumask_t *srcp, int nbits)
251{
252 return bitmap_weight(srcp->bits, nbits);
253}
254
255#define cpus_shift_right(dst, src, n) \
256 __cpus_shift_right(&(dst), &(src), (n), NR_CPUS)
257static inline void __cpus_shift_right(cpumask_t *dstp,
258 const cpumask_t *srcp, int n, int nbits)
259{
260 bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
261}
262
263#define cpus_shift_left(dst, src, n) \
264 __cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
265static inline void __cpus_shift_left(cpumask_t *dstp,
266 const cpumask_t *srcp, int n, int nbits)
267{
268 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
269}
270
Rusty Russellae7a47e2008-12-30 09:05:15 +1030271/**
272 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
273 * @bitmap: the bitmap
274 *
275 * There are a few places where cpumask_var_t isn't appropriate and
276 * static cpumasks must be used (eg. very early boot), yet we don't
277 * expose the definition of 'struct cpumask'.
278 *
279 * This does the conversion, and can be used as a constant initializer.
280 */
281#define to_cpumask(bitmap) \
282 ((struct cpumask *)(1 ? (bitmap) \
283 : (void *)sizeof(__check_is_bitmap(bitmap))))
284
285static inline int __check_is_bitmap(const unsigned long *bitmap)
286{
287 return 1;
288}
289
Linus Torvaldse56b3bc2008-07-28 11:32:33 -0700290/*
291 * Special-case data structure for "single bit set only" constant CPU masks.
292 *
293 * We pre-generate all the 64 (or 32) possible bit positions, with enough
294 * padding to the left and the right, and return the constant pointer
295 * appropriately offset.
296 */
297extern const unsigned long
298 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Rusty Russellae7a47e2008-12-30 09:05:15 +1030300static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
Linus Torvaldse56b3bc2008-07-28 11:32:33 -0700301{
302 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
303 p -= cpu / BITS_PER_LONG;
Rusty Russellae7a47e2008-12-30 09:05:15 +1030304 return to_cpumask(p);
Linus Torvaldse56b3bc2008-07-28 11:32:33 -0700305}
306
307/*
308 * In cases where we take the address of the cpumask immediately,
309 * gcc optimizes it out (it's a constant) and there's no huge stack
310 * variable created:
311 */
Stephen Rothwell3dd730f2008-07-29 16:07:37 +1000312#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
Linus Torvaldse56b3bc2008-07-28 11:32:33 -0700313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
316
317#if NR_CPUS <= BITS_PER_LONG
318
319#define CPU_MASK_ALL \
320(cpumask_t) { { \
321 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
322} }
323
Mike Travis321a8e92008-04-04 18:11:02 -0700324#define CPU_MASK_ALL_PTR (&CPU_MASK_ALL)
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#else
327
328#define CPU_MASK_ALL \
329(cpumask_t) { { \
330 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
331 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
332} }
333
Mike Travis321a8e92008-04-04 18:11:02 -0700334/* cpu_mask_all is in init/main.c */
335extern cpumask_t cpu_mask_all;
336#define CPU_MASK_ALL_PTR (&cpu_mask_all)
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#endif
339
340#define CPU_MASK_NONE \
341(cpumask_t) { { \
342 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
343} }
344
345#define CPU_MASK_CPU0 \
346(cpumask_t) { { \
347 [0] = 1UL \
348} }
349
350#define cpus_addr(src) ((src).bits)
351
Mike Travis77586c22008-07-15 14:14:36 -0700352#if NR_CPUS > BITS_PER_LONG
353#define CPUMASK_ALLOC(m) struct m *m = kmalloc(sizeof(*m), GFP_KERNEL)
354#define CPUMASK_FREE(m) kfree(m)
355#else
Mike Travis80422d32008-07-18 18:11:33 -0700356#define CPUMASK_ALLOC(m) struct m _m, *m = &_m
Mike Travis77586c22008-07-15 14:14:36 -0700357#define CPUMASK_FREE(m)
358#endif
Mike Travis80422d32008-07-18 18:11:33 -0700359#define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v)
Mike Travis77586c22008-07-15 14:14:36 -0700360
Paul Jacksonfb5eeee2005-10-30 15:02:33 -0800361#define cpu_remap(oldbit, old, new) \
362 __cpu_remap((oldbit), &(old), &(new), NR_CPUS)
363static inline int __cpu_remap(int oldbit,
364 const cpumask_t *oldp, const cpumask_t *newp, int nbits)
365{
366 return bitmap_bitremap(oldbit, oldp->bits, newp->bits, nbits);
367}
368
369#define cpus_remap(dst, src, old, new) \
370 __cpus_remap(&(dst), &(src), &(old), &(new), NR_CPUS)
371static inline void __cpus_remap(cpumask_t *dstp, const cpumask_t *srcp,
372 const cpumask_t *oldp, const cpumask_t *newp, int nbits)
373{
374 bitmap_remap(dstp->bits, srcp->bits, oldp->bits, newp->bits, nbits);
375}
376
Paul Jackson7ea931c2008-04-28 02:12:29 -0700377#define cpus_onto(dst, orig, relmap) \
378 __cpus_onto(&(dst), &(orig), &(relmap), NR_CPUS)
379static inline void __cpus_onto(cpumask_t *dstp, const cpumask_t *origp,
380 const cpumask_t *relmapp, int nbits)
381{
382 bitmap_onto(dstp->bits, origp->bits, relmapp->bits, nbits);
383}
384
385#define cpus_fold(dst, orig, sz) \
386 __cpus_fold(&(dst), &(orig), sz, NR_CPUS)
387static inline void __cpus_fold(cpumask_t *dstp, const cpumask_t *origp,
388 int sz, int nbits)
389{
390 bitmap_fold(dstp->bits, origp->bits, sz, nbits);
391}
392
Mike Travis41df0d612008-05-12 21:21:13 +0200393#if NR_CPUS == 1
394
395#define nr_cpu_ids 1
396#define first_cpu(src) ({ (void)(src); 0; })
397#define next_cpu(n, src) ({ (void)(src); 1; })
398#define any_online_cpu(mask) 0
399#define for_each_cpu_mask(cpu, mask) \
400 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
401
402#else /* NR_CPUS > 1 */
403
404extern int nr_cpu_ids;
405int __first_cpu(const cpumask_t *srcp);
406int __next_cpu(int n, const cpumask_t *srcp);
407int __any_online_cpu(const cpumask_t *mask);
408
409#define first_cpu(src) __first_cpu(&(src))
410#define next_cpu(n, src) __next_cpu((n), &(src))
411#define any_online_cpu(mask) __any_online_cpu(&(mask))
Alexander van Heukelum7baac8b2008-05-13 11:28:21 +0200412#define for_each_cpu_mask(cpu, mask) \
413 for ((cpu) = -1; \
414 (cpu) = next_cpu((cpu), (mask)), \
415 (cpu) < NR_CPUS; )
Mike Travis41df0d612008-05-12 21:21:13 +0200416#endif
417
418#if NR_CPUS <= 64
419
420#define next_cpu_nr(n, src) next_cpu(n, src)
421#define cpus_weight_nr(cpumask) cpus_weight(cpumask)
422#define for_each_cpu_mask_nr(cpu, mask) for_each_cpu_mask(cpu, mask)
423
424#else /* NR_CPUS > 64 */
425
426int __next_cpu_nr(int n, const cpumask_t *srcp);
427#define next_cpu_nr(n, src) __next_cpu_nr((n), &(src))
428#define cpus_weight_nr(cpumask) __cpus_weight(&(cpumask), nr_cpu_ids)
Alexander van Heukelum7baac8b2008-05-13 11:28:21 +0200429#define for_each_cpu_mask_nr(cpu, mask) \
430 for ((cpu) = -1; \
431 (cpu) = next_cpu_nr((cpu), (mask)), \
432 (cpu) < nr_cpu_ids; )
Mike Travis41df0d612008-05-12 21:21:13 +0200433
434#endif /* NR_CPUS > 64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436/*
437 * The following particular system cpumasks and operations manage
Rusty Russellb3199c02008-12-30 09:05:14 +1030438 * possible, present, active and online cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 *
Rusty Russellb3199c02008-12-30 09:05:14 +1030440 * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
441 * cpu_present_mask - has bit 'cpu' set iff cpu is populated
442 * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
443 * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 *
Rusty Russellb3199c02008-12-30 09:05:14 +1030445 * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *
Rusty Russellb3199c02008-12-30 09:05:14 +1030447 * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
448 * that it is possible might ever be plugged in at anytime during the
449 * life of that system boot. The cpu_present_mask is dynamic(*),
450 * representing which CPUs are currently plugged in. And
451 * cpu_online_mask is the dynamic subset of cpu_present_mask,
452 * indicating those CPUs available for scheduling.
453 *
454 * If HOTPLUG is enabled, then cpu_possible_mask is forced to have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 * all NR_CPUS bits set, otherwise it is just the set of CPUs that
456 * ACPI reports present at boot.
457 *
Rusty Russellb3199c02008-12-30 09:05:14 +1030458 * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 * depending on what ACPI reports as currently plugged in, otherwise
Rusty Russellb3199c02008-12-30 09:05:14 +1030460 * cpu_present_mask is just a copy of cpu_possible_mask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 *
Rusty Russellb3199c02008-12-30 09:05:14 +1030462 * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
463 * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 *
465 * Subtleties:
466 * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
467 * assumption that their single CPU is online. The UP
Rusty Russellb3199c02008-12-30 09:05:14 +1030468 * cpu_{online,possible,present}_masks are placebos. Changing them
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 * will have no useful affect on the following num_*_cpus()
470 * and cpu_*() macros in the UP case. This ugliness is a UP
471 * optimization - don't waste any instructions or memory references
472 * asking if you're online or how many CPUs there are if there is
473 * only one CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 */
475
Rusty Russellb3199c02008-12-30 09:05:14 +1030476extern const struct cpumask *const cpu_possible_mask;
477extern const struct cpumask *const cpu_online_mask;
478extern const struct cpumask *const cpu_present_mask;
479extern const struct cpumask *const cpu_active_mask;
480
481/* These strip const, as traditionally they weren't const. */
482#define cpu_possible_map (*(cpumask_t *)cpu_possible_mask)
483#define cpu_online_map (*(cpumask_t *)cpu_online_mask)
484#define cpu_present_map (*(cpumask_t *)cpu_present_mask)
485#define cpu_active_map (*(cpumask_t *)cpu_active_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487#if NR_CPUS > 1
Rusty Russellae7a47e2008-12-30 09:05:15 +1030488#define num_online_cpus() cpumask_weight(cpu_online_mask)
489#define num_possible_cpus() cpumask_weight(cpu_possible_mask)
490#define num_present_cpus() cpumask_weight(cpu_present_mask)
491#define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
492#define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
493#define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
494#define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#else
496#define num_online_cpus() 1
497#define num_possible_cpus() 1
498#define num_present_cpus() 1
499#define cpu_online(cpu) ((cpu) == 0)
500#define cpu_possible(cpu) ((cpu) == 0)
501#define cpu_present(cpu) ((cpu) == 0)
Max Krasnyanskye761b772008-07-15 04:43:49 -0700502#define cpu_active(cpu) ((cpu) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#endif
504
Ingo Molnara2638982007-12-30 11:58:17 +0100505#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
506
Rusty Russell2d3854a2008-11-05 13:39:10 +1100507/* These are the new versions of the cpumask operators: passed by pointer.
508 * The older versions will be implemented in terms of these, then deleted. */
509#define cpumask_bits(maskp) ((maskp)->bits)
510
511#if NR_CPUS <= BITS_PER_LONG
512#define CPU_BITS_ALL \
513{ \
514 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
515}
516
Rusty Russell2d3854a2008-11-05 13:39:10 +1100517#else /* NR_CPUS > BITS_PER_LONG */
518
519#define CPU_BITS_ALL \
520{ \
521 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
522 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
523}
Rusty Russell2d3854a2008-11-05 13:39:10 +1100524#endif /* NR_CPUS > BITS_PER_LONG */
525
Rusty Russell7be75852008-12-13 21:20:28 +1030526#ifdef CONFIG_CPUMASK_OFFSTACK
527/* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
528 * not all bits may be allocated. */
529#define nr_cpumask_bits nr_cpu_ids
530#else
531#define nr_cpumask_bits NR_CPUS
532#endif
533
Rusty Russell2d3854a2008-11-05 13:39:10 +1100534/* verify cpu argument to cpumask_* operators */
535static inline unsigned int cpumask_check(unsigned int cpu)
536{
537#ifdef CONFIG_DEBUG_PER_CPU_MAPS
538 WARN_ON_ONCE(cpu >= nr_cpumask_bits);
539#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
540 return cpu;
541}
542
543#if NR_CPUS == 1
Rusty Russell984f2f32008-11-08 20:24:19 +1100544/* Uniprocessor. Assume all masks are "1". */
545static inline unsigned int cpumask_first(const struct cpumask *srcp)
546{
547 return 0;
548}
549
550/* Valid inputs for n are -1 and 0. */
551static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
552{
553 return n+1;
554}
555
556static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
557{
558 return n+1;
559}
560
561static inline unsigned int cpumask_next_and(int n,
562 const struct cpumask *srcp,
563 const struct cpumask *andp)
564{
565 return n+1;
566}
567
568/* cpu must be a valid cpu, ie 0, so there's no other choice. */
569static inline unsigned int cpumask_any_but(const struct cpumask *mask,
570 unsigned int cpu)
571{
572 return 1;
573}
Rusty Russell2d3854a2008-11-05 13:39:10 +1100574
575#define for_each_cpu(cpu, mask) \
576 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
577#define for_each_cpu_and(cpu, mask, and) \
578 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
579#else
580/**
581 * cpumask_first - get the first cpu in a cpumask
582 * @srcp: the cpumask pointer
583 *
584 * Returns >= nr_cpu_ids if no cpus set.
585 */
586static inline unsigned int cpumask_first(const struct cpumask *srcp)
587{
588 return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
589}
590
591/**
592 * cpumask_next - get the next cpu in a cpumask
593 * @n: the cpu prior to the place to search (ie. return will be > @n)
594 * @srcp: the cpumask pointer
595 *
596 * Returns >= nr_cpu_ids if no further cpus set.
597 */
598static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
599{
600 /* -1 is a legal arg here. */
601 if (n != -1)
602 cpumask_check(n);
603 return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
604}
605
606/**
607 * cpumask_next_zero - get the next unset cpu in a cpumask
608 * @n: the cpu prior to the place to search (ie. return will be > @n)
609 * @srcp: the cpumask pointer
610 *
611 * Returns >= nr_cpu_ids if no further cpus unset.
612 */
613static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
614{
615 /* -1 is a legal arg here. */
616 if (n != -1)
617 cpumask_check(n);
618 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
619}
620
621int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
622int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
623
Rusty Russell984f2f32008-11-08 20:24:19 +1100624/**
625 * for_each_cpu - iterate over every cpu in a mask
626 * @cpu: the (optionally unsigned) integer iterator
627 * @mask: the cpumask pointer
628 *
629 * After the loop, cpu is >= nr_cpu_ids.
630 */
Rusty Russell2d3854a2008-11-05 13:39:10 +1100631#define for_each_cpu(cpu, mask) \
632 for ((cpu) = -1; \
633 (cpu) = cpumask_next((cpu), (mask)), \
634 (cpu) < nr_cpu_ids;)
Rusty Russell984f2f32008-11-08 20:24:19 +1100635
636/**
637 * for_each_cpu_and - iterate over every cpu in both masks
638 * @cpu: the (optionally unsigned) integer iterator
639 * @mask: the first cpumask pointer
640 * @and: the second cpumask pointer
641 *
642 * This saves a temporary CPU mask in many places. It is equivalent to:
643 * struct cpumask tmp;
644 * cpumask_and(&tmp, &mask, &and);
645 * for_each_cpu(cpu, &tmp)
646 * ...
647 *
648 * After the loop, cpu is >= nr_cpu_ids.
649 */
Rusty Russell2d3854a2008-11-05 13:39:10 +1100650#define for_each_cpu_and(cpu, mask, and) \
651 for ((cpu) = -1; \
652 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
653 (cpu) < nr_cpu_ids;)
654#endif /* SMP */
655
656#define CPU_BITS_NONE \
657{ \
658 [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
659}
660
661#define CPU_BITS_CPU0 \
662{ \
663 [0] = 1UL \
664}
665
666/**
667 * cpumask_set_cpu - set a cpu in a cpumask
668 * @cpu: cpu number (< nr_cpu_ids)
669 * @dstp: the cpumask pointer
670 */
671static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
672{
673 set_bit(cpumask_check(cpu), cpumask_bits(dstp));
674}
675
676/**
677 * cpumask_clear_cpu - clear a cpu in a cpumask
678 * @cpu: cpu number (< nr_cpu_ids)
679 * @dstp: the cpumask pointer
680 */
681static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
682{
683 clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
684}
685
686/**
687 * cpumask_test_cpu - test for a cpu in a cpumask
688 * @cpu: cpu number (< nr_cpu_ids)
689 * @cpumask: the cpumask pointer
690 *
691 * No static inline type checking - see Subtlety (1) above.
692 */
693#define cpumask_test_cpu(cpu, cpumask) \
Rusty Russellae7a47e2008-12-30 09:05:15 +1030694 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
Rusty Russell2d3854a2008-11-05 13:39:10 +1100695
696/**
697 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
698 * @cpu: cpu number (< nr_cpu_ids)
699 * @cpumask: the cpumask pointer
700 *
701 * test_and_set_bit wrapper for cpumasks.
702 */
703static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
704{
705 return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
706}
707
708/**
709 * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
710 * @dstp: the cpumask pointer
711 */
712static inline void cpumask_setall(struct cpumask *dstp)
713{
714 bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
715}
716
717/**
718 * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
719 * @dstp: the cpumask pointer
720 */
721static inline void cpumask_clear(struct cpumask *dstp)
722{
723 bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
724}
725
726/**
727 * cpumask_and - *dstp = *src1p & *src2p
728 * @dstp: the cpumask result
729 * @src1p: the first input
730 * @src2p: the second input
731 */
732static inline void cpumask_and(struct cpumask *dstp,
733 const struct cpumask *src1p,
734 const struct cpumask *src2p)
735{
736 bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
737 cpumask_bits(src2p), nr_cpumask_bits);
738}
739
740/**
741 * cpumask_or - *dstp = *src1p | *src2p
742 * @dstp: the cpumask result
743 * @src1p: the first input
744 * @src2p: the second input
745 */
746static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
747 const struct cpumask *src2p)
748{
749 bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
750 cpumask_bits(src2p), nr_cpumask_bits);
751}
752
753/**
754 * cpumask_xor - *dstp = *src1p ^ *src2p
755 * @dstp: the cpumask result
756 * @src1p: the first input
757 * @src2p: the second input
758 */
759static inline void cpumask_xor(struct cpumask *dstp,
760 const struct cpumask *src1p,
761 const struct cpumask *src2p)
762{
763 bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
764 cpumask_bits(src2p), nr_cpumask_bits);
765}
766
767/**
768 * cpumask_andnot - *dstp = *src1p & ~*src2p
769 * @dstp: the cpumask result
770 * @src1p: the first input
771 * @src2p: the second input
772 */
773static inline void cpumask_andnot(struct cpumask *dstp,
774 const struct cpumask *src1p,
775 const struct cpumask *src2p)
776{
777 bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
778 cpumask_bits(src2p), nr_cpumask_bits);
779}
780
781/**
782 * cpumask_complement - *dstp = ~*srcp
783 * @dstp: the cpumask result
784 * @srcp: the input to invert
785 */
786static inline void cpumask_complement(struct cpumask *dstp,
787 const struct cpumask *srcp)
788{
789 bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
790 nr_cpumask_bits);
791}
792
793/**
794 * cpumask_equal - *src1p == *src2p
795 * @src1p: the first input
796 * @src2p: the second input
797 */
798static inline bool cpumask_equal(const struct cpumask *src1p,
799 const struct cpumask *src2p)
800{
801 return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
802 nr_cpumask_bits);
803}
804
805/**
806 * cpumask_intersects - (*src1p & *src2p) != 0
807 * @src1p: the first input
808 * @src2p: the second input
809 */
810static inline bool cpumask_intersects(const struct cpumask *src1p,
811 const struct cpumask *src2p)
812{
813 return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
814 nr_cpumask_bits);
815}
816
817/**
818 * cpumask_subset - (*src1p & ~*src2p) == 0
819 * @src1p: the first input
820 * @src2p: the second input
821 */
822static inline int cpumask_subset(const struct cpumask *src1p,
823 const struct cpumask *src2p)
824{
825 return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
826 nr_cpumask_bits);
827}
828
829/**
830 * cpumask_empty - *srcp == 0
831 * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
832 */
833static inline bool cpumask_empty(const struct cpumask *srcp)
834{
835 return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
836}
837
838/**
839 * cpumask_full - *srcp == 0xFFFFFFFF...
840 * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
841 */
842static inline bool cpumask_full(const struct cpumask *srcp)
843{
844 return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
845}
846
847/**
848 * cpumask_weight - Count of bits in *srcp
849 * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
850 */
851static inline unsigned int cpumask_weight(const struct cpumask *srcp)
852{
853 return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
854}
855
856/**
857 * cpumask_shift_right - *dstp = *srcp >> n
858 * @dstp: the cpumask result
859 * @srcp: the input to shift
860 * @n: the number of bits to shift by
861 */
862static inline void cpumask_shift_right(struct cpumask *dstp,
863 const struct cpumask *srcp, int n)
864{
865 bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
866 nr_cpumask_bits);
867}
868
869/**
870 * cpumask_shift_left - *dstp = *srcp << n
871 * @dstp: the cpumask result
872 * @srcp: the input to shift
873 * @n: the number of bits to shift by
874 */
875static inline void cpumask_shift_left(struct cpumask *dstp,
876 const struct cpumask *srcp, int n)
877{
878 bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
879 nr_cpumask_bits);
880}
881
882/**
883 * cpumask_copy - *dstp = *srcp
884 * @dstp: the result
885 * @srcp: the input cpumask
886 */
887static inline void cpumask_copy(struct cpumask *dstp,
888 const struct cpumask *srcp)
889{
890 bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
891}
892
893/**
894 * cpumask_any - pick a "random" cpu from *srcp
895 * @srcp: the input cpumask
896 *
897 * Returns >= nr_cpu_ids if no cpus set.
898 */
899#define cpumask_any(srcp) cpumask_first(srcp)
900
901/**
902 * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
903 * @src1p: the first input
904 * @src2p: the second input
905 *
906 * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
907 */
908#define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
909
910/**
911 * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
912 * @mask1: the first input cpumask
913 * @mask2: the second input cpumask
914 *
915 * Returns >= nr_cpu_ids if no cpus set.
916 */
917#define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
918
919/**
Rusty Russellcd83e422008-11-07 11:12:29 +1100920 * cpumask_of - the cpumask containing just a given cpu
921 * @cpu: the cpu (<= nr_cpu_ids)
922 */
923#define cpumask_of(cpu) (get_cpu_mask(cpu))
924
925/**
Rusty Russell29c01772008-12-13 21:20:25 +1030926 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
927 * @buf: the buffer to sprintf into
928 * @len: the length of the buffer
929 * @srcp: the cpumask to print
930 *
931 * If len is zero, returns zero. Otherwise returns the length of the
932 * (nul-terminated) @buf string.
933 */
934static inline int cpumask_scnprintf(char *buf, int len,
935 const struct cpumask *srcp)
936{
Rusty Russellae7a47e2008-12-30 09:05:15 +1030937 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
Rusty Russell29c01772008-12-13 21:20:25 +1030938}
939
940/**
941 * cpumask_parse_user - extract a cpumask from a user string
942 * @buf: the buffer to extract from
943 * @len: the length of the buffer
944 * @dstp: the cpumask to set.
945 *
946 * Returns -errno, or 0 for success.
947 */
948static inline int cpumask_parse_user(const char __user *buf, int len,
949 struct cpumask *dstp)
950{
Rusty Russellae7a47e2008-12-30 09:05:15 +1030951 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
Rusty Russell29c01772008-12-13 21:20:25 +1030952}
953
954/**
955 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
956 * @buf: the buffer to sprintf into
957 * @len: the length of the buffer
958 * @srcp: the cpumask to print
959 *
960 * If len is zero, returns zero. Otherwise returns the length of the
961 * (nul-terminated) @buf string.
962 */
963static inline int cpulist_scnprintf(char *buf, int len,
964 const struct cpumask *srcp)
965{
Rusty Russellae7a47e2008-12-30 09:05:15 +1030966 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
967 nr_cpumask_bits);
Rusty Russell29c01772008-12-13 21:20:25 +1030968}
969
970/**
971 * cpulist_parse_user - extract a cpumask from a user string of ranges
972 * @buf: the buffer to extract from
973 * @len: the length of the buffer
974 * @dstp: the cpumask to set.
975 *
976 * Returns -errno, or 0 for success.
977 */
978static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
979{
Rusty Russellae7a47e2008-12-30 09:05:15 +1030980 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
Rusty Russell2d3854a2008-11-05 13:39:10 +1100981}
982
983/**
984 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
985 *
986 * This will eventually be a runtime variable, depending on nr_cpu_ids.
987 */
988static inline size_t cpumask_size(void)
989{
990 /* FIXME: Once all cpumask assignments are eliminated, this
991 * can be nr_cpumask_bits */
992 return BITS_TO_LONGS(NR_CPUS) * sizeof(long);
993}
994
995/*
996 * cpumask_var_t: struct cpumask for stack usage.
997 *
998 * Oh, the wicked games we play! In order to make kernel coding a
999 * little more difficult, we typedef cpumask_var_t to an array or a
1000 * pointer: doing &mask on an array is a noop, so it still works.
1001 *
1002 * ie.
1003 * cpumask_var_t tmpmask;
1004 * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
1005 * return -ENOMEM;
1006 *
1007 * ... use 'tmpmask' like a normal struct cpumask * ...
1008 *
1009 * free_cpumask_var(tmpmask);
1010 */
1011#ifdef CONFIG_CPUMASK_OFFSTACK
1012typedef struct cpumask *cpumask_var_t;
1013
Mike Travis7b4967c2008-12-19 16:56:37 +10301014bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
Rusty Russell2d3854a2008-11-05 13:39:10 +11001015bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
1016void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
1017void free_cpumask_var(cpumask_var_t mask);
Rusty Russellcd83e422008-11-07 11:12:29 +11001018void free_bootmem_cpumask_var(cpumask_var_t mask);
Rusty Russell2d3854a2008-11-05 13:39:10 +11001019
1020#else
1021typedef struct cpumask cpumask_var_t[1];
1022
1023static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
1024{
1025 return true;
1026}
1027
Mike Travis7b4967c2008-12-19 16:56:37 +10301028static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
1029 int node)
1030{
1031 return true;
1032}
1033
Rusty Russell2d3854a2008-11-05 13:39:10 +11001034static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
1035{
1036}
1037
1038static inline void free_cpumask_var(cpumask_var_t mask)
1039{
1040}
Rusty Russellcd83e422008-11-07 11:12:29 +11001041
1042static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
1043{
1044}
Rusty Russell2d3854a2008-11-05 13:39:10 +11001045#endif /* CONFIG_CPUMASK_OFFSTACK */
1046
Rusty Russell2d3854a2008-11-05 13:39:10 +11001047/* It's common to want to use cpu_all_mask in struct member initializers,
1048 * so it has to refer to an address rather than a pointer. */
1049extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
1050#define cpu_all_mask to_cpumask(cpu_all_bits)
1051
1052/* First bits of cpu_bit_bitmap are in fact unset. */
1053#define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
1054
Rusty Russellae7a47e2008-12-30 09:05:15 +10301055#define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
1056#define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
1057#define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
1058
Rusty Russell2d3854a2008-11-05 13:39:10 +11001059/* Wrappers for arch boot code to manipulate normally-constant masks */
Rusty Russell3fa41522008-12-30 09:05:16 +10301060void set_cpu_possible(unsigned int cpu, bool possible);
1061void set_cpu_present(unsigned int cpu, bool present);
1062void set_cpu_online(unsigned int cpu, bool online);
1063void set_cpu_active(unsigned int cpu, bool active);
1064void init_cpu_present(const struct cpumask *src);
1065void init_cpu_possible(const struct cpumask *src);
1066void init_cpu_online(const struct cpumask *src);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067#endif /* __LINUX_CPUMASK_H */