cpumask.h 34 KB

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