cpumask.h 34 KB

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