cpumask.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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.
  367. *
  368. * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
  369. * cpu_present_mask - has bit 'cpu' set iff cpu is populated
  370. * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
  371. * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
  372. *
  373. * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
  374. *
  375. * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
  376. * that it is possible might ever be plugged in at anytime during the
  377. * life of that system boot. The cpu_present_mask is dynamic(*),
  378. * representing which CPUs are currently plugged in. And
  379. * cpu_online_mask is the dynamic subset of cpu_present_mask,
  380. * indicating those CPUs available for scheduling.
  381. *
  382. * If HOTPLUG is enabled, then cpu_possible_mask is forced to have
  383. * all NR_CPUS bits set, otherwise it is just the set of CPUs that
  384. * ACPI reports present at boot.
  385. *
  386. * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
  387. * depending on what ACPI reports as currently plugged in, otherwise
  388. * cpu_present_mask is just a copy of cpu_possible_mask.
  389. *
  390. * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
  391. * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
  392. *
  393. * Subtleties:
  394. * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
  395. * assumption that their single CPU is online. The UP
  396. * cpu_{online,possible,present}_masks are placebos. Changing them
  397. * will have no useful affect on the following num_*_cpus()
  398. * and cpu_*() macros in the UP case. This ugliness is a UP
  399. * optimization - don't waste any instructions or memory references
  400. * asking if you're online or how many CPUs there are if there is
  401. * only one CPU.
  402. */
  403. extern const struct cpumask *const cpu_possible_mask;
  404. extern const struct cpumask *const cpu_online_mask;
  405. extern const struct cpumask *const cpu_present_mask;
  406. extern const struct cpumask *const cpu_active_mask;
  407. /* These strip const, as traditionally they weren't const. */
  408. #define cpu_possible_map (*(cpumask_t *)cpu_possible_mask)
  409. #define cpu_online_map (*(cpumask_t *)cpu_online_mask)
  410. #define cpu_present_map (*(cpumask_t *)cpu_present_mask)
  411. #define cpu_active_map (*(cpumask_t *)cpu_active_mask)
  412. #if NR_CPUS > 1
  413. #define num_online_cpus() cpus_weight_nr(cpu_online_map)
  414. #define num_possible_cpus() cpus_weight_nr(cpu_possible_map)
  415. #define num_present_cpus() cpus_weight_nr(cpu_present_map)
  416. #define cpu_online(cpu) cpu_isset((cpu), cpu_online_map)
  417. #define cpu_possible(cpu) cpu_isset((cpu), cpu_possible_map)
  418. #define cpu_present(cpu) cpu_isset((cpu), cpu_present_map)
  419. #define cpu_active(cpu) cpu_isset((cpu), cpu_active_map)
  420. #else
  421. #define num_online_cpus() 1
  422. #define num_possible_cpus() 1
  423. #define num_present_cpus() 1
  424. #define cpu_online(cpu) ((cpu) == 0)
  425. #define cpu_possible(cpu) ((cpu) == 0)
  426. #define cpu_present(cpu) ((cpu) == 0)
  427. #define cpu_active(cpu) ((cpu) == 0)
  428. #endif
  429. #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
  430. #define for_each_possible_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_possible_map)
  431. #define for_each_online_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_online_map)
  432. #define for_each_present_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_present_map)
  433. /* These are the new versions of the cpumask operators: passed by pointer.
  434. * The older versions will be implemented in terms of these, then deleted. */
  435. #define cpumask_bits(maskp) ((maskp)->bits)
  436. #if NR_CPUS <= BITS_PER_LONG
  437. #define CPU_BITS_ALL \
  438. { \
  439. [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
  440. }
  441. #else /* NR_CPUS > BITS_PER_LONG */
  442. #define CPU_BITS_ALL \
  443. { \
  444. [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
  445. [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
  446. }
  447. #endif /* NR_CPUS > BITS_PER_LONG */
  448. #ifdef CONFIG_CPUMASK_OFFSTACK
  449. /* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
  450. * not all bits may be allocated. */
  451. #define nr_cpumask_bits nr_cpu_ids
  452. #else
  453. #define nr_cpumask_bits NR_CPUS
  454. #endif
  455. /* verify cpu argument to cpumask_* operators */
  456. static inline unsigned int cpumask_check(unsigned int cpu)
  457. {
  458. #ifdef CONFIG_DEBUG_PER_CPU_MAPS
  459. WARN_ON_ONCE(cpu >= nr_cpumask_bits);
  460. #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
  461. return cpu;
  462. }
  463. #if NR_CPUS == 1
  464. /* Uniprocessor. Assume all masks are "1". */
  465. static inline unsigned int cpumask_first(const struct cpumask *srcp)
  466. {
  467. return 0;
  468. }
  469. /* Valid inputs for n are -1 and 0. */
  470. static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
  471. {
  472. return n+1;
  473. }
  474. static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  475. {
  476. return n+1;
  477. }
  478. static inline unsigned int cpumask_next_and(int n,
  479. const struct cpumask *srcp,
  480. const struct cpumask *andp)
  481. {
  482. return n+1;
  483. }
  484. /* cpu must be a valid cpu, ie 0, so there's no other choice. */
  485. static inline unsigned int cpumask_any_but(const struct cpumask *mask,
  486. unsigned int cpu)
  487. {
  488. return 1;
  489. }
  490. #define for_each_cpu(cpu, mask) \
  491. for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
  492. #define for_each_cpu_and(cpu, mask, and) \
  493. for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
  494. #else
  495. /**
  496. * cpumask_first - get the first cpu in a cpumask
  497. * @srcp: the cpumask pointer
  498. *
  499. * Returns >= nr_cpu_ids if no cpus set.
  500. */
  501. static inline unsigned int cpumask_first(const struct cpumask *srcp)
  502. {
  503. return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
  504. }
  505. /**
  506. * cpumask_next - get the next cpu in a cpumask
  507. * @n: the cpu prior to the place to search (ie. return will be > @n)
  508. * @srcp: the cpumask pointer
  509. *
  510. * Returns >= nr_cpu_ids if no further cpus set.
  511. */
  512. static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
  513. {
  514. /* -1 is a legal arg here. */
  515. if (n != -1)
  516. cpumask_check(n);
  517. return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
  518. }
  519. /**
  520. * cpumask_next_zero - get the next unset cpu in a cpumask
  521. * @n: the cpu prior to the place to search (ie. return will be > @n)
  522. * @srcp: the cpumask pointer
  523. *
  524. * Returns >= nr_cpu_ids if no further cpus unset.
  525. */
  526. static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  527. {
  528. /* -1 is a legal arg here. */
  529. if (n != -1)
  530. cpumask_check(n);
  531. return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
  532. }
  533. int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
  534. int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
  535. /**
  536. * for_each_cpu - iterate over every cpu in a mask
  537. * @cpu: the (optionally unsigned) integer iterator
  538. * @mask: the cpumask pointer
  539. *
  540. * After the loop, cpu is >= nr_cpu_ids.
  541. */
  542. #define for_each_cpu(cpu, mask) \
  543. for ((cpu) = -1; \
  544. (cpu) = cpumask_next((cpu), (mask)), \
  545. (cpu) < nr_cpu_ids;)
  546. /**
  547. * for_each_cpu_and - iterate over every cpu in both masks
  548. * @cpu: the (optionally unsigned) integer iterator
  549. * @mask: the first cpumask pointer
  550. * @and: the second cpumask pointer
  551. *
  552. * This saves a temporary CPU mask in many places. It is equivalent to:
  553. * struct cpumask tmp;
  554. * cpumask_and(&tmp, &mask, &and);
  555. * for_each_cpu(cpu, &tmp)
  556. * ...
  557. *
  558. * After the loop, cpu is >= nr_cpu_ids.
  559. */
  560. #define for_each_cpu_and(cpu, mask, and) \
  561. for ((cpu) = -1; \
  562. (cpu) = cpumask_next_and((cpu), (mask), (and)), \
  563. (cpu) < nr_cpu_ids;)
  564. #endif /* SMP */
  565. #define CPU_BITS_NONE \
  566. { \
  567. [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
  568. }
  569. #define CPU_BITS_CPU0 \
  570. { \
  571. [0] = 1UL \
  572. }
  573. /**
  574. * cpumask_set_cpu - set a cpu in a cpumask
  575. * @cpu: cpu number (< nr_cpu_ids)
  576. * @dstp: the cpumask pointer
  577. */
  578. static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
  579. {
  580. set_bit(cpumask_check(cpu), cpumask_bits(dstp));
  581. }
  582. /**
  583. * cpumask_clear_cpu - clear a cpu in a cpumask
  584. * @cpu: cpu number (< nr_cpu_ids)
  585. * @dstp: the cpumask pointer
  586. */
  587. static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
  588. {
  589. clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
  590. }
  591. /**
  592. * cpumask_test_cpu - test for a cpu in a cpumask
  593. * @cpu: cpu number (< nr_cpu_ids)
  594. * @cpumask: the cpumask pointer
  595. *
  596. * No static inline type checking - see Subtlety (1) above.
  597. */
  598. #define cpumask_test_cpu(cpu, cpumask) \
  599. test_bit(cpumask_check(cpu), (cpumask)->bits)
  600. /**
  601. * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
  602. * @cpu: cpu number (< nr_cpu_ids)
  603. * @cpumask: the cpumask pointer
  604. *
  605. * test_and_set_bit wrapper for cpumasks.
  606. */
  607. static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
  608. {
  609. return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
  610. }
  611. /**
  612. * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
  613. * @dstp: the cpumask pointer
  614. */
  615. static inline void cpumask_setall(struct cpumask *dstp)
  616. {
  617. bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
  618. }
  619. /**
  620. * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
  621. * @dstp: the cpumask pointer
  622. */
  623. static inline void cpumask_clear(struct cpumask *dstp)
  624. {
  625. bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
  626. }
  627. /**
  628. * cpumask_and - *dstp = *src1p & *src2p
  629. * @dstp: the cpumask result
  630. * @src1p: the first input
  631. * @src2p: the second input
  632. */
  633. static inline void cpumask_and(struct cpumask *dstp,
  634. const struct cpumask *src1p,
  635. const struct cpumask *src2p)
  636. {
  637. bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
  638. cpumask_bits(src2p), nr_cpumask_bits);
  639. }
  640. /**
  641. * cpumask_or - *dstp = *src1p | *src2p
  642. * @dstp: the cpumask result
  643. * @src1p: the first input
  644. * @src2p: the second input
  645. */
  646. static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
  647. const struct cpumask *src2p)
  648. {
  649. bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
  650. cpumask_bits(src2p), nr_cpumask_bits);
  651. }
  652. /**
  653. * cpumask_xor - *dstp = *src1p ^ *src2p
  654. * @dstp: the cpumask result
  655. * @src1p: the first input
  656. * @src2p: the second input
  657. */
  658. static inline void cpumask_xor(struct cpumask *dstp,
  659. const struct cpumask *src1p,
  660. const struct cpumask *src2p)
  661. {
  662. bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
  663. cpumask_bits(src2p), nr_cpumask_bits);
  664. }
  665. /**
  666. * cpumask_andnot - *dstp = *src1p & ~*src2p
  667. * @dstp: the cpumask result
  668. * @src1p: the first input
  669. * @src2p: the second input
  670. */
  671. static inline void cpumask_andnot(struct cpumask *dstp,
  672. const struct cpumask *src1p,
  673. const struct cpumask *src2p)
  674. {
  675. bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
  676. cpumask_bits(src2p), nr_cpumask_bits);
  677. }
  678. /**
  679. * cpumask_complement - *dstp = ~*srcp
  680. * @dstp: the cpumask result
  681. * @srcp: the input to invert
  682. */
  683. static inline void cpumask_complement(struct cpumask *dstp,
  684. const struct cpumask *srcp)
  685. {
  686. bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
  687. nr_cpumask_bits);
  688. }
  689. /**
  690. * cpumask_equal - *src1p == *src2p
  691. * @src1p: the first input
  692. * @src2p: the second input
  693. */
  694. static inline bool cpumask_equal(const struct cpumask *src1p,
  695. const struct cpumask *src2p)
  696. {
  697. return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
  698. nr_cpumask_bits);
  699. }
  700. /**
  701. * cpumask_intersects - (*src1p & *src2p) != 0
  702. * @src1p: the first input
  703. * @src2p: the second input
  704. */
  705. static inline bool cpumask_intersects(const struct cpumask *src1p,
  706. const struct cpumask *src2p)
  707. {
  708. return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
  709. nr_cpumask_bits);
  710. }
  711. /**
  712. * cpumask_subset - (*src1p & ~*src2p) == 0
  713. * @src1p: the first input
  714. * @src2p: the second input
  715. */
  716. static inline int cpumask_subset(const struct cpumask *src1p,
  717. const struct cpumask *src2p)
  718. {
  719. return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
  720. nr_cpumask_bits);
  721. }
  722. /**
  723. * cpumask_empty - *srcp == 0
  724. * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
  725. */
  726. static inline bool cpumask_empty(const struct cpumask *srcp)
  727. {
  728. return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
  729. }
  730. /**
  731. * cpumask_full - *srcp == 0xFFFFFFFF...
  732. * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
  733. */
  734. static inline bool cpumask_full(const struct cpumask *srcp)
  735. {
  736. return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
  737. }
  738. /**
  739. * cpumask_weight - Count of bits in *srcp
  740. * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
  741. */
  742. static inline unsigned int cpumask_weight(const struct cpumask *srcp)
  743. {
  744. return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
  745. }
  746. /**
  747. * cpumask_shift_right - *dstp = *srcp >> n
  748. * @dstp: the cpumask result
  749. * @srcp: the input to shift
  750. * @n: the number of bits to shift by
  751. */
  752. static inline void cpumask_shift_right(struct cpumask *dstp,
  753. const struct cpumask *srcp, int n)
  754. {
  755. bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
  756. nr_cpumask_bits);
  757. }
  758. /**
  759. * cpumask_shift_left - *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_left(struct cpumask *dstp,
  765. const struct cpumask *srcp, int n)
  766. {
  767. bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
  768. nr_cpumask_bits);
  769. }
  770. /**
  771. * cpumask_copy - *dstp = *srcp
  772. * @dstp: the result
  773. * @srcp: the input cpumask
  774. */
  775. static inline void cpumask_copy(struct cpumask *dstp,
  776. const struct cpumask *srcp)
  777. {
  778. bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
  779. }
  780. /**
  781. * cpumask_any - pick a "random" cpu from *srcp
  782. * @srcp: the input cpumask
  783. *
  784. * Returns >= nr_cpu_ids if no cpus set.
  785. */
  786. #define cpumask_any(srcp) cpumask_first(srcp)
  787. /**
  788. * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
  789. * @src1p: the first input
  790. * @src2p: the second input
  791. *
  792. * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
  793. */
  794. #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
  795. /**
  796. * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
  797. * @mask1: the first input cpumask
  798. * @mask2: the second input cpumask
  799. *
  800. * Returns >= nr_cpu_ids if no cpus set.
  801. */
  802. #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
  803. /**
  804. * cpumask_of - the cpumask containing just a given cpu
  805. * @cpu: the cpu (<= nr_cpu_ids)
  806. */
  807. #define cpumask_of(cpu) (get_cpu_mask(cpu))
  808. /**
  809. * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
  810. * @buf: the buffer to sprintf into
  811. * @len: the length of the buffer
  812. * @srcp: the cpumask to print
  813. *
  814. * If len is zero, returns zero. Otherwise returns the length of the
  815. * (nul-terminated) @buf string.
  816. */
  817. static inline int cpumask_scnprintf(char *buf, int len,
  818. const struct cpumask *srcp)
  819. {
  820. return bitmap_scnprintf(buf, len, srcp->bits, nr_cpumask_bits);
  821. }
  822. /**
  823. * cpumask_parse_user - extract a cpumask from a user string
  824. * @buf: the buffer to extract from
  825. * @len: the length of the buffer
  826. * @dstp: the cpumask to set.
  827. *
  828. * Returns -errno, or 0 for success.
  829. */
  830. static inline int cpumask_parse_user(const char __user *buf, int len,
  831. struct cpumask *dstp)
  832. {
  833. return bitmap_parse_user(buf, len, dstp->bits, nr_cpumask_bits);
  834. }
  835. /**
  836. * cpulist_scnprintf - print a cpumask into a string as comma-separated list
  837. * @buf: the buffer to sprintf into
  838. * @len: the length of the buffer
  839. * @srcp: the cpumask to print
  840. *
  841. * If len is zero, returns zero. Otherwise returns the length of the
  842. * (nul-terminated) @buf string.
  843. */
  844. static inline int cpulist_scnprintf(char *buf, int len,
  845. const struct cpumask *srcp)
  846. {
  847. return bitmap_scnlistprintf(buf, len, srcp->bits, nr_cpumask_bits);
  848. }
  849. /**
  850. * cpulist_parse_user - extract a cpumask from a user string of ranges
  851. * @buf: the buffer to extract from
  852. * @len: the length of the buffer
  853. * @dstp: the cpumask to set.
  854. *
  855. * Returns -errno, or 0 for success.
  856. */
  857. static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
  858. {
  859. return bitmap_parselist(buf, dstp->bits, nr_cpumask_bits);
  860. }
  861. /**
  862. * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
  863. * @bitmap: the bitmap
  864. *
  865. * There are a few places where cpumask_var_t isn't appropriate and
  866. * static cpumasks must be used (eg. very early boot), yet we don't
  867. * expose the definition of 'struct cpumask'.
  868. *
  869. * This does the conversion, and can be used as a constant initializer.
  870. */
  871. #define to_cpumask(bitmap) \
  872. ((struct cpumask *)(1 ? (bitmap) \
  873. : (void *)sizeof(__check_is_bitmap(bitmap))))
  874. static inline int __check_is_bitmap(const unsigned long *bitmap)
  875. {
  876. return 1;
  877. }
  878. /**
  879. * cpumask_size - size to allocate for a 'struct cpumask' in bytes
  880. *
  881. * This will eventually be a runtime variable, depending on nr_cpu_ids.
  882. */
  883. static inline size_t cpumask_size(void)
  884. {
  885. /* FIXME: Once all cpumask assignments are eliminated, this
  886. * can be nr_cpumask_bits */
  887. return BITS_TO_LONGS(NR_CPUS) * sizeof(long);
  888. }
  889. /*
  890. * cpumask_var_t: struct cpumask for stack usage.
  891. *
  892. * Oh, the wicked games we play! In order to make kernel coding a
  893. * little more difficult, we typedef cpumask_var_t to an array or a
  894. * pointer: doing &mask on an array is a noop, so it still works.
  895. *
  896. * ie.
  897. * cpumask_var_t tmpmask;
  898. * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
  899. * return -ENOMEM;
  900. *
  901. * ... use 'tmpmask' like a normal struct cpumask * ...
  902. *
  903. * free_cpumask_var(tmpmask);
  904. */
  905. #ifdef CONFIG_CPUMASK_OFFSTACK
  906. typedef struct cpumask *cpumask_var_t;
  907. bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
  908. bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
  909. void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
  910. void free_cpumask_var(cpumask_var_t mask);
  911. void free_bootmem_cpumask_var(cpumask_var_t mask);
  912. #else
  913. typedef struct cpumask cpumask_var_t[1];
  914. static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
  915. {
  916. return true;
  917. }
  918. static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
  919. int node)
  920. {
  921. return true;
  922. }
  923. static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
  924. {
  925. }
  926. static inline void free_cpumask_var(cpumask_var_t mask)
  927. {
  928. }
  929. static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
  930. {
  931. }
  932. #endif /* CONFIG_CPUMASK_OFFSTACK */
  933. /* It's common to want to use cpu_all_mask in struct member initializers,
  934. * so it has to refer to an address rather than a pointer. */
  935. extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
  936. #define cpu_all_mask to_cpumask(cpu_all_bits)
  937. /* First bits of cpu_bit_bitmap are in fact unset. */
  938. #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
  939. /* Wrappers for arch boot code to manipulate normally-constant masks */
  940. static inline void set_cpu_possible(unsigned int cpu, bool possible)
  941. {
  942. if (possible)
  943. cpumask_set_cpu(cpu, &cpu_possible_map);
  944. else
  945. cpumask_clear_cpu(cpu, &cpu_possible_map);
  946. }
  947. static inline void set_cpu_present(unsigned int cpu, bool present)
  948. {
  949. if (present)
  950. cpumask_set_cpu(cpu, &cpu_present_map);
  951. else
  952. cpumask_clear_cpu(cpu, &cpu_present_map);
  953. }
  954. static inline void set_cpu_online(unsigned int cpu, bool online)
  955. {
  956. if (online)
  957. cpumask_set_cpu(cpu, &cpu_online_map);
  958. else
  959. cpumask_clear_cpu(cpu, &cpu_online_map);
  960. }
  961. static inline void set_cpu_active(unsigned int cpu, bool active)
  962. {
  963. if (active)
  964. cpumask_set_cpu(cpu, &cpu_active_map);
  965. else
  966. cpumask_clear_cpu(cpu, &cpu_active_map);
  967. }
  968. static inline void init_cpu_present(const struct cpumask *src)
  969. {
  970. cpumask_copy(&cpu_present_map, src);
  971. }
  972. static inline void init_cpu_possible(const struct cpumask *src)
  973. {
  974. cpumask_copy(&cpu_possible_map, src);
  975. }
  976. static inline void init_cpu_online(const struct cpumask *src)
  977. {
  978. cpumask_copy(&cpu_online_map, src);
  979. }
  980. #endif /* __LINUX_CPUMASK_H */