cpumask.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_CPUMASK_H
  3. #define __LINUX_CPUMASK_H
  4. /*
  5. * Cpumasks provide a bitmap suitable for representing the
  6. * set of CPU's in a system, one bit position per CPU number. In general,
  7. * only nr_cpu_ids (<= NR_CPUS) bits are valid.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/threads.h>
  11. #include <linux/bitmap.h>
  12. #include <linux/atomic.h>
  13. #include <linux/bug.h>
  14. #include <linux/gfp_types.h>
  15. #include <linux/numa.h>
  16. /* Don't assign or return these: may not be this big! */
  17. typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
  18. /**
  19. * cpumask_bits - get the bits in a cpumask
  20. * @maskp: the struct cpumask *
  21. *
  22. * You should only assume nr_cpu_ids bits of this mask are valid. This is
  23. * a macro so it's const-correct.
  24. */
  25. #define cpumask_bits(maskp) ((maskp)->bits)
  26. /**
  27. * cpumask_pr_args - printf args to output a cpumask
  28. * @maskp: cpumask to be printed
  29. *
  30. * Can be used to provide arguments for '%*pb[l]' when printing a cpumask.
  31. */
  32. #define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp)
  33. #if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
  34. #define nr_cpu_ids ((unsigned int)NR_CPUS)
  35. #else
  36. extern unsigned int nr_cpu_ids;
  37. #endif
  38. static inline void set_nr_cpu_ids(unsigned int nr)
  39. {
  40. #if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
  41. WARN_ON(nr != nr_cpu_ids);
  42. #else
  43. nr_cpu_ids = nr;
  44. #endif
  45. }
  46. /* Deprecated. Always use nr_cpu_ids. */
  47. #define nr_cpumask_bits nr_cpu_ids
  48. /*
  49. * The following particular system cpumasks and operations manage
  50. * possible, present, active and online cpus.
  51. *
  52. * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
  53. * cpu_present_mask - has bit 'cpu' set iff cpu is populated
  54. * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
  55. * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
  56. *
  57. * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
  58. *
  59. * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
  60. * that it is possible might ever be plugged in at anytime during the
  61. * life of that system boot. The cpu_present_mask is dynamic(*),
  62. * representing which CPUs are currently plugged in. And
  63. * cpu_online_mask is the dynamic subset of cpu_present_mask,
  64. * indicating those CPUs available for scheduling.
  65. *
  66. * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
  67. * depending on what ACPI reports as currently plugged in, otherwise
  68. * cpu_present_mask is just a copy of cpu_possible_mask.
  69. *
  70. * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
  71. * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
  72. *
  73. * Subtleties:
  74. * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
  75. * assumption that their single CPU is online. The UP
  76. * cpu_{online,possible,present}_masks are placebos. Changing them
  77. * will have no useful affect on the following num_*_cpus()
  78. * and cpu_*() macros in the UP case. This ugliness is a UP
  79. * optimization - don't waste any instructions or memory references
  80. * asking if you're online or how many CPUs there are if there is
  81. * only one CPU.
  82. */
  83. extern struct cpumask __cpu_possible_mask;
  84. extern struct cpumask __cpu_online_mask;
  85. extern struct cpumask __cpu_present_mask;
  86. extern struct cpumask __cpu_active_mask;
  87. extern struct cpumask __cpu_dying_mask;
  88. #define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
  89. #define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask)
  90. #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask)
  91. #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask)
  92. #define cpu_dying_mask ((const struct cpumask *)&__cpu_dying_mask)
  93. extern atomic_t __num_online_cpus;
  94. extern cpumask_t cpus_booted_once_mask;
  95. static __always_inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
  96. {
  97. #ifdef CONFIG_DEBUG_PER_CPU_MAPS
  98. WARN_ON_ONCE(cpu >= bits);
  99. #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
  100. }
  101. /* verify cpu argument to cpumask_* operators */
  102. static __always_inline unsigned int cpumask_check(unsigned int cpu)
  103. {
  104. cpu_max_bits_warn(cpu, nr_cpumask_bits);
  105. return cpu;
  106. }
  107. /**
  108. * cpumask_first - get the first cpu in a cpumask
  109. * @srcp: the cpumask pointer
  110. *
  111. * Returns >= nr_cpu_ids if no cpus set.
  112. */
  113. static inline unsigned int cpumask_first(const struct cpumask *srcp)
  114. {
  115. return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
  116. }
  117. /**
  118. * cpumask_first_zero - get the first unset cpu in a cpumask
  119. * @srcp: the cpumask pointer
  120. *
  121. * Returns >= nr_cpu_ids if all cpus are set.
  122. */
  123. static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
  124. {
  125. return find_first_zero_bit(cpumask_bits(srcp), nr_cpumask_bits);
  126. }
  127. /**
  128. * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
  129. * @src1p: the first input
  130. * @src2p: the second input
  131. *
  132. * Returns >= nr_cpu_ids if no cpus set in both. See also cpumask_next_and().
  133. */
  134. static inline
  135. unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask *srcp2)
  136. {
  137. return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits);
  138. }
  139. /**
  140. * cpumask_last - get the last CPU in a cpumask
  141. * @srcp: - the cpumask pointer
  142. *
  143. * Returns >= nr_cpumask_bits if no CPUs set.
  144. */
  145. static inline unsigned int cpumask_last(const struct cpumask *srcp)
  146. {
  147. return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits);
  148. }
  149. /**
  150. * cpumask_next - get the next cpu in a cpumask
  151. * @n: the cpu prior to the place to search (ie. return will be > @n)
  152. * @srcp: the cpumask pointer
  153. *
  154. * Returns >= nr_cpu_ids if no further cpus set.
  155. */
  156. static inline
  157. unsigned int cpumask_next(int n, const struct cpumask *srcp)
  158. {
  159. /* -1 is a legal arg here. */
  160. if (n != -1)
  161. cpumask_check(n);
  162. return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
  163. }
  164. /**
  165. * cpumask_next_zero - get the next unset cpu in a cpumask
  166. * @n: the cpu prior to the place to search (ie. return will be > @n)
  167. * @srcp: the cpumask pointer
  168. *
  169. * Returns >= nr_cpu_ids if no further cpus unset.
  170. */
  171. static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  172. {
  173. /* -1 is a legal arg here. */
  174. if (n != -1)
  175. cpumask_check(n);
  176. return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
  177. }
  178. #if NR_CPUS == 1
  179. /* Uniprocessor: there is only one valid CPU */
  180. static inline unsigned int cpumask_local_spread(unsigned int i, int node)
  181. {
  182. return 0;
  183. }
  184. static inline unsigned int cpumask_any_and_distribute(const struct cpumask *src1p,
  185. const struct cpumask *src2p)
  186. {
  187. return cpumask_first_and(src1p, src2p);
  188. }
  189. static inline unsigned int cpumask_any_distribute(const struct cpumask *srcp)
  190. {
  191. return cpumask_first(srcp);
  192. }
  193. #else
  194. unsigned int cpumask_local_spread(unsigned int i, int node);
  195. unsigned int cpumask_any_and_distribute(const struct cpumask *src1p,
  196. const struct cpumask *src2p);
  197. unsigned int cpumask_any_distribute(const struct cpumask *srcp);
  198. #endif /* NR_CPUS */
  199. /**
  200. * cpumask_next_and - get the next cpu in *src1p & *src2p
  201. * @n: the cpu prior to the place to search (ie. return will be > @n)
  202. * @src1p: the first cpumask pointer
  203. * @src2p: the second cpumask pointer
  204. *
  205. * Returns >= nr_cpu_ids if no further cpus set in both.
  206. */
  207. static inline
  208. unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
  209. const struct cpumask *src2p)
  210. {
  211. /* -1 is a legal arg here. */
  212. if (n != -1)
  213. cpumask_check(n);
  214. return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
  215. nr_cpumask_bits, n + 1);
  216. }
  217. /**
  218. * for_each_cpu - iterate over every cpu in a mask
  219. * @cpu: the (optionally unsigned) integer iterator
  220. * @mask: the cpumask pointer
  221. *
  222. * After the loop, cpu is >= nr_cpu_ids.
  223. */
  224. #define for_each_cpu(cpu, mask) \
  225. for_each_set_bit(cpu, cpumask_bits(mask), nr_cpumask_bits)
  226. /**
  227. * for_each_cpu_not - iterate over every cpu in a complemented mask
  228. * @cpu: the (optionally unsigned) integer iterator
  229. * @mask: the cpumask pointer
  230. *
  231. * After the loop, cpu is >= nr_cpu_ids.
  232. */
  233. #define for_each_cpu_not(cpu, mask) \
  234. for_each_clear_bit(cpu, cpumask_bits(mask), nr_cpumask_bits)
  235. #if NR_CPUS == 1
  236. static inline
  237. unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
  238. {
  239. cpumask_check(start);
  240. if (n != -1)
  241. cpumask_check(n);
  242. /*
  243. * Return the first available CPU when wrapping, or when starting before cpu0,
  244. * since there is only one valid option.
  245. */
  246. if (wrap && n >= 0)
  247. return nr_cpumask_bits;
  248. return cpumask_first(mask);
  249. }
  250. #else
  251. unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
  252. #endif
  253. /**
  254. * for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location
  255. * @cpu: the (optionally unsigned) integer iterator
  256. * @mask: the cpumask pointer
  257. * @start: the start location
  258. *
  259. * The implementation does not assume any bit in @mask is set (including @start).
  260. *
  261. * After the loop, cpu is >= nr_cpu_ids.
  262. */
  263. #define for_each_cpu_wrap(cpu, mask, start) \
  264. for_each_set_bit_wrap(cpu, cpumask_bits(mask), nr_cpumask_bits, start)
  265. /**
  266. * for_each_cpu_and - iterate over every cpu in both masks
  267. * @cpu: the (optionally unsigned) integer iterator
  268. * @mask1: the first cpumask pointer
  269. * @mask2: the second cpumask pointer
  270. *
  271. * This saves a temporary CPU mask in many places. It is equivalent to:
  272. * struct cpumask tmp;
  273. * cpumask_and(&tmp, &mask1, &mask2);
  274. * for_each_cpu(cpu, &tmp)
  275. * ...
  276. *
  277. * After the loop, cpu is >= nr_cpu_ids.
  278. */
  279. #define for_each_cpu_and(cpu, mask1, mask2) \
  280. for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits)
  281. /**
  282. * for_each_cpu_andnot - iterate over every cpu present in one mask, excluding
  283. * those present in another.
  284. * @cpu: the (optionally unsigned) integer iterator
  285. * @mask1: the first cpumask pointer
  286. * @mask2: the second cpumask pointer
  287. *
  288. * This saves a temporary CPU mask in many places. It is equivalent to:
  289. * struct cpumask tmp;
  290. * cpumask_andnot(&tmp, &mask1, &mask2);
  291. * for_each_cpu(cpu, &tmp)
  292. * ...
  293. *
  294. * After the loop, cpu is >= nr_cpu_ids.
  295. */
  296. #define for_each_cpu_andnot(cpu, mask1, mask2) \
  297. for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits)
  298. /**
  299. * cpumask_any_but - return a "random" in a cpumask, but not this one.
  300. * @mask: the cpumask to search
  301. * @cpu: the cpu to ignore.
  302. *
  303. * Often used to find any cpu but smp_processor_id() in a mask.
  304. * Returns >= nr_cpu_ids if no cpus set.
  305. */
  306. static inline
  307. unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
  308. {
  309. unsigned int i;
  310. cpumask_check(cpu);
  311. for_each_cpu(i, mask)
  312. if (i != cpu)
  313. break;
  314. return i;
  315. }
  316. /**
  317. * cpumask_nth - get the first cpu in a cpumask
  318. * @srcp: the cpumask pointer
  319. * @cpu: the N'th cpu to find, starting from 0
  320. *
  321. * Returns >= nr_cpu_ids if such cpu doesn't exist.
  322. */
  323. static inline unsigned int cpumask_nth(unsigned int cpu, const struct cpumask *srcp)
  324. {
  325. return find_nth_bit(cpumask_bits(srcp), nr_cpumask_bits, cpumask_check(cpu));
  326. }
  327. /**
  328. * cpumask_nth_and - get the first cpu in 2 cpumasks
  329. * @srcp1: the cpumask pointer
  330. * @srcp2: the cpumask pointer
  331. * @cpu: the N'th cpu to find, starting from 0
  332. *
  333. * Returns >= nr_cpu_ids if such cpu doesn't exist.
  334. */
  335. static inline
  336. unsigned int cpumask_nth_and(unsigned int cpu, const struct cpumask *srcp1,
  337. const struct cpumask *srcp2)
  338. {
  339. return find_nth_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2),
  340. nr_cpumask_bits, cpumask_check(cpu));
  341. }
  342. /**
  343. * cpumask_nth_andnot - get the first cpu set in 1st cpumask, and clear in 2nd.
  344. * @srcp1: the cpumask pointer
  345. * @srcp2: the cpumask pointer
  346. * @cpu: the N'th cpu to find, starting from 0
  347. *
  348. * Returns >= nr_cpu_ids if such cpu doesn't exist.
  349. */
  350. static inline
  351. unsigned int cpumask_nth_andnot(unsigned int cpu, const struct cpumask *srcp1,
  352. const struct cpumask *srcp2)
  353. {
  354. return find_nth_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2),
  355. nr_cpumask_bits, cpumask_check(cpu));
  356. }
  357. #define CPU_BITS_NONE \
  358. { \
  359. [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
  360. }
  361. #define CPU_BITS_CPU0 \
  362. { \
  363. [0] = 1UL \
  364. }
  365. /**
  366. * cpumask_set_cpu - set a cpu in a cpumask
  367. * @cpu: cpu number (< nr_cpu_ids)
  368. * @dstp: the cpumask pointer
  369. */
  370. static __always_inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
  371. {
  372. set_bit(cpumask_check(cpu), cpumask_bits(dstp));
  373. }
  374. static __always_inline void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
  375. {
  376. __set_bit(cpumask_check(cpu), cpumask_bits(dstp));
  377. }
  378. /**
  379. * cpumask_clear_cpu - clear a cpu in a cpumask
  380. * @cpu: cpu number (< nr_cpu_ids)
  381. * @dstp: the cpumask pointer
  382. */
  383. static __always_inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
  384. {
  385. clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
  386. }
  387. static __always_inline void __cpumask_clear_cpu(int cpu, struct cpumask *dstp)
  388. {
  389. __clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
  390. }
  391. /**
  392. * cpumask_test_cpu - test for a cpu in a cpumask
  393. * @cpu: cpu number (< nr_cpu_ids)
  394. * @cpumask: the cpumask pointer
  395. *
  396. * Returns true if @cpu is set in @cpumask, else returns false
  397. */
  398. static __always_inline bool cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
  399. {
  400. return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
  401. }
  402. /**
  403. * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
  404. * @cpu: cpu number (< nr_cpu_ids)
  405. * @cpumask: the cpumask pointer
  406. *
  407. * Returns true if @cpu is set in old bitmap of @cpumask, else returns false
  408. *
  409. * test_and_set_bit wrapper for cpumasks.
  410. */
  411. static __always_inline bool cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
  412. {
  413. return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
  414. }
  415. /**
  416. * cpumask_test_and_clear_cpu - atomically test and clear a cpu in a cpumask
  417. * @cpu: cpu number (< nr_cpu_ids)
  418. * @cpumask: the cpumask pointer
  419. *
  420. * Returns true if @cpu is set in old bitmap of @cpumask, else returns false
  421. *
  422. * test_and_clear_bit wrapper for cpumasks.
  423. */
  424. static __always_inline bool cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
  425. {
  426. return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
  427. }
  428. /**
  429. * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask
  430. * @dstp: the cpumask pointer
  431. */
  432. static inline void cpumask_setall(struct cpumask *dstp)
  433. {
  434. bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits);
  435. }
  436. /**
  437. * cpumask_clear - clear all cpus (< nr_cpu_ids) in a cpumask
  438. * @dstp: the cpumask pointer
  439. */
  440. static inline void cpumask_clear(struct cpumask *dstp)
  441. {
  442. bitmap_zero(cpumask_bits(dstp), nr_cpumask_bits);
  443. }
  444. /**
  445. * cpumask_and - *dstp = *src1p & *src2p
  446. * @dstp: the cpumask result
  447. * @src1p: the first input
  448. * @src2p: the second input
  449. *
  450. * If *@dstp is empty, returns false, else returns true
  451. */
  452. static inline bool cpumask_and(struct cpumask *dstp,
  453. const struct cpumask *src1p,
  454. const struct cpumask *src2p)
  455. {
  456. return bitmap_and(cpumask_bits(dstp), cpumask_bits(src1p),
  457. cpumask_bits(src2p), nr_cpumask_bits);
  458. }
  459. /**
  460. * cpumask_or - *dstp = *src1p | *src2p
  461. * @dstp: the cpumask result
  462. * @src1p: the first input
  463. * @src2p: the second input
  464. */
  465. static inline void cpumask_or(struct cpumask *dstp, const struct cpumask *src1p,
  466. const struct cpumask *src2p)
  467. {
  468. bitmap_or(cpumask_bits(dstp), cpumask_bits(src1p),
  469. cpumask_bits(src2p), nr_cpumask_bits);
  470. }
  471. /**
  472. * cpumask_xor - *dstp = *src1p ^ *src2p
  473. * @dstp: the cpumask result
  474. * @src1p: the first input
  475. * @src2p: the second input
  476. */
  477. static inline void cpumask_xor(struct cpumask *dstp,
  478. const struct cpumask *src1p,
  479. const struct cpumask *src2p)
  480. {
  481. bitmap_xor(cpumask_bits(dstp), cpumask_bits(src1p),
  482. cpumask_bits(src2p), nr_cpumask_bits);
  483. }
  484. /**
  485. * cpumask_andnot - *dstp = *src1p & ~*src2p
  486. * @dstp: the cpumask result
  487. * @src1p: the first input
  488. * @src2p: the second input
  489. *
  490. * If *@dstp is empty, returns false, else returns true
  491. */
  492. static inline bool cpumask_andnot(struct cpumask *dstp,
  493. const struct cpumask *src1p,
  494. const struct cpumask *src2p)
  495. {
  496. return bitmap_andnot(cpumask_bits(dstp), cpumask_bits(src1p),
  497. cpumask_bits(src2p), nr_cpumask_bits);
  498. }
  499. /**
  500. * cpumask_complement - *dstp = ~*srcp
  501. * @dstp: the cpumask result
  502. * @srcp: the input to invert
  503. */
  504. static inline void cpumask_complement(struct cpumask *dstp,
  505. const struct cpumask *srcp)
  506. {
  507. bitmap_complement(cpumask_bits(dstp), cpumask_bits(srcp),
  508. nr_cpumask_bits);
  509. }
  510. /**
  511. * cpumask_equal - *src1p == *src2p
  512. * @src1p: the first input
  513. * @src2p: the second input
  514. */
  515. static inline bool cpumask_equal(const struct cpumask *src1p,
  516. const struct cpumask *src2p)
  517. {
  518. return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p),
  519. nr_cpumask_bits);
  520. }
  521. /**
  522. * cpumask_or_equal - *src1p | *src2p == *src3p
  523. * @src1p: the first input
  524. * @src2p: the second input
  525. * @src3p: the third input
  526. */
  527. static inline bool cpumask_or_equal(const struct cpumask *src1p,
  528. const struct cpumask *src2p,
  529. const struct cpumask *src3p)
  530. {
  531. return bitmap_or_equal(cpumask_bits(src1p), cpumask_bits(src2p),
  532. cpumask_bits(src3p), nr_cpumask_bits);
  533. }
  534. /**
  535. * cpumask_intersects - (*src1p & *src2p) != 0
  536. * @src1p: the first input
  537. * @src2p: the second input
  538. */
  539. static inline bool cpumask_intersects(const struct cpumask *src1p,
  540. const struct cpumask *src2p)
  541. {
  542. return bitmap_intersects(cpumask_bits(src1p), cpumask_bits(src2p),
  543. nr_cpumask_bits);
  544. }
  545. /**
  546. * cpumask_subset - (*src1p & ~*src2p) == 0
  547. * @src1p: the first input
  548. * @src2p: the second input
  549. *
  550. * Returns true if *@src1p is a subset of *@src2p, else returns false
  551. */
  552. static inline bool cpumask_subset(const struct cpumask *src1p,
  553. const struct cpumask *src2p)
  554. {
  555. return bitmap_subset(cpumask_bits(src1p), cpumask_bits(src2p),
  556. nr_cpumask_bits);
  557. }
  558. /**
  559. * cpumask_empty - *srcp == 0
  560. * @srcp: the cpumask to that all cpus < nr_cpu_ids are clear.
  561. */
  562. static inline bool cpumask_empty(const struct cpumask *srcp)
  563. {
  564. return bitmap_empty(cpumask_bits(srcp), nr_cpumask_bits);
  565. }
  566. /**
  567. * cpumask_full - *srcp == 0xFFFFFFFF...
  568. * @srcp: the cpumask to that all cpus < nr_cpu_ids are set.
  569. */
  570. static inline bool cpumask_full(const struct cpumask *srcp)
  571. {
  572. return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits);
  573. }
  574. /**
  575. * cpumask_weight - Count of bits in *srcp
  576. * @srcp: the cpumask to count bits (< nr_cpu_ids) in.
  577. */
  578. static inline unsigned int cpumask_weight(const struct cpumask *srcp)
  579. {
  580. return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits);
  581. }
  582. /**
  583. * cpumask_weight_and - Count of bits in (*srcp1 & *srcp2)
  584. * @srcp1: the cpumask to count bits (< nr_cpu_ids) in.
  585. * @srcp2: the cpumask to count bits (< nr_cpu_ids) in.
  586. */
  587. static inline unsigned int cpumask_weight_and(const struct cpumask *srcp1,
  588. const struct cpumask *srcp2)
  589. {
  590. return bitmap_weight_and(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits);
  591. }
  592. /**
  593. * cpumask_shift_right - *dstp = *srcp >> n
  594. * @dstp: the cpumask result
  595. * @srcp: the input to shift
  596. * @n: the number of bits to shift by
  597. */
  598. static inline void cpumask_shift_right(struct cpumask *dstp,
  599. const struct cpumask *srcp, int n)
  600. {
  601. bitmap_shift_right(cpumask_bits(dstp), cpumask_bits(srcp), n,
  602. nr_cpumask_bits);
  603. }
  604. /**
  605. * cpumask_shift_left - *dstp = *srcp << n
  606. * @dstp: the cpumask result
  607. * @srcp: the input to shift
  608. * @n: the number of bits to shift by
  609. */
  610. static inline void cpumask_shift_left(struct cpumask *dstp,
  611. const struct cpumask *srcp, int n)
  612. {
  613. bitmap_shift_left(cpumask_bits(dstp), cpumask_bits(srcp), n,
  614. nr_cpumask_bits);
  615. }
  616. /**
  617. * cpumask_copy - *dstp = *srcp
  618. * @dstp: the result
  619. * @srcp: the input cpumask
  620. */
  621. static inline void cpumask_copy(struct cpumask *dstp,
  622. const struct cpumask *srcp)
  623. {
  624. bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits);
  625. }
  626. /**
  627. * cpumask_any - pick a "random" cpu from *srcp
  628. * @srcp: the input cpumask
  629. *
  630. * Returns >= nr_cpu_ids if no cpus set.
  631. */
  632. #define cpumask_any(srcp) cpumask_first(srcp)
  633. /**
  634. * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
  635. * @mask1: the first input cpumask
  636. * @mask2: the second input cpumask
  637. *
  638. * Returns >= nr_cpu_ids if no cpus set.
  639. */
  640. #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
  641. /**
  642. * cpumask_of - the cpumask containing just a given cpu
  643. * @cpu: the cpu (<= nr_cpu_ids)
  644. */
  645. #define cpumask_of(cpu) (get_cpu_mask(cpu))
  646. /**
  647. * cpumask_parse_user - extract a cpumask from a user string
  648. * @buf: the buffer to extract from
  649. * @len: the length of the buffer
  650. * @dstp: the cpumask to set.
  651. *
  652. * Returns -errno, or 0 for success.
  653. */
  654. static inline int cpumask_parse_user(const char __user *buf, int len,
  655. struct cpumask *dstp)
  656. {
  657. return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
  658. }
  659. /**
  660. * cpumask_parselist_user - extract a cpumask from a user string
  661. * @buf: the buffer to extract from
  662. * @len: the length of the buffer
  663. * @dstp: the cpumask to set.
  664. *
  665. * Returns -errno, or 0 for success.
  666. */
  667. static inline int cpumask_parselist_user(const char __user *buf, int len,
  668. struct cpumask *dstp)
  669. {
  670. return bitmap_parselist_user(buf, len, cpumask_bits(dstp),
  671. nr_cpumask_bits);
  672. }
  673. /**
  674. * cpumask_parse - extract a cpumask from a string
  675. * @buf: the buffer to extract from
  676. * @dstp: the cpumask to set.
  677. *
  678. * Returns -errno, or 0 for success.
  679. */
  680. static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
  681. {
  682. return bitmap_parse(buf, UINT_MAX, cpumask_bits(dstp), nr_cpumask_bits);
  683. }
  684. /**
  685. * cpulist_parse - extract a cpumask from a user string of ranges
  686. * @buf: the buffer to extract from
  687. * @dstp: the cpumask to set.
  688. *
  689. * Returns -errno, or 0 for success.
  690. */
  691. static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
  692. {
  693. return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
  694. }
  695. /**
  696. * cpumask_size - size to allocate for a 'struct cpumask' in bytes
  697. */
  698. static inline unsigned int cpumask_size(void)
  699. {
  700. return BITS_TO_LONGS(nr_cpumask_bits) * sizeof(long);
  701. }
  702. /*
  703. * cpumask_var_t: struct cpumask for stack usage.
  704. *
  705. * Oh, the wicked games we play! In order to make kernel coding a
  706. * little more difficult, we typedef cpumask_var_t to an array or a
  707. * pointer: doing &mask on an array is a noop, so it still works.
  708. *
  709. * ie.
  710. * cpumask_var_t tmpmask;
  711. * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
  712. * return -ENOMEM;
  713. *
  714. * ... use 'tmpmask' like a normal struct cpumask * ...
  715. *
  716. * free_cpumask_var(tmpmask);
  717. *
  718. *
  719. * However, one notable exception is there. alloc_cpumask_var() allocates
  720. * only nr_cpumask_bits bits (in the other hand, real cpumask_t always has
  721. * NR_CPUS bits). Therefore you don't have to dereference cpumask_var_t.
  722. *
  723. * cpumask_var_t tmpmask;
  724. * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
  725. * return -ENOMEM;
  726. *
  727. * var = *tmpmask;
  728. *
  729. * This code makes NR_CPUS length memcopy and brings to a memory corruption.
  730. * cpumask_copy() provide safe copy functionality.
  731. *
  732. * Note that there is another evil here: If you define a cpumask_var_t
  733. * as a percpu variable then the way to obtain the address of the cpumask
  734. * structure differently influences what this_cpu_* operation needs to be
  735. * used. Please use this_cpu_cpumask_var_t in those cases. The direct use
  736. * of this_cpu_ptr() or this_cpu_read() will lead to failures when the
  737. * other type of cpumask_var_t implementation is configured.
  738. *
  739. * Please also note that __cpumask_var_read_mostly can be used to declare
  740. * a cpumask_var_t variable itself (not its content) as read mostly.
  741. */
  742. #ifdef CONFIG_CPUMASK_OFFSTACK
  743. typedef struct cpumask *cpumask_var_t;
  744. #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x)
  745. #define __cpumask_var_read_mostly __read_mostly
  746. bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
  747. static inline
  748. bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
  749. {
  750. return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
  751. }
  752. /**
  753. * alloc_cpumask_var - allocate a struct cpumask
  754. * @mask: pointer to cpumask_var_t where the cpumask is returned
  755. * @flags: GFP_ flags
  756. *
  757. * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
  758. * a nop returning a constant 1 (in <linux/cpumask.h>).
  759. *
  760. * See alloc_cpumask_var_node.
  761. */
  762. static inline
  763. bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
  764. {
  765. return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE);
  766. }
  767. static inline
  768. bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
  769. {
  770. return alloc_cpumask_var(mask, flags | __GFP_ZERO);
  771. }
  772. void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
  773. void free_cpumask_var(cpumask_var_t mask);
  774. void free_bootmem_cpumask_var(cpumask_var_t mask);
  775. static inline bool cpumask_available(cpumask_var_t mask)
  776. {
  777. return mask != NULL;
  778. }
  779. #else
  780. typedef struct cpumask cpumask_var_t[1];
  781. #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x)
  782. #define __cpumask_var_read_mostly
  783. static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
  784. {
  785. return true;
  786. }
  787. static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
  788. int node)
  789. {
  790. return true;
  791. }
  792. static inline bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
  793. {
  794. cpumask_clear(*mask);
  795. return true;
  796. }
  797. static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
  798. int node)
  799. {
  800. cpumask_clear(*mask);
  801. return true;
  802. }
  803. static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
  804. {
  805. }
  806. static inline void free_cpumask_var(cpumask_var_t mask)
  807. {
  808. }
  809. static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
  810. {
  811. }
  812. static inline bool cpumask_available(cpumask_var_t mask)
  813. {
  814. return true;
  815. }
  816. #endif /* CONFIG_CPUMASK_OFFSTACK */
  817. /* It's common to want to use cpu_all_mask in struct member initializers,
  818. * so it has to refer to an address rather than a pointer. */
  819. extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
  820. #define cpu_all_mask to_cpumask(cpu_all_bits)
  821. /* First bits of cpu_bit_bitmap are in fact unset. */
  822. #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
  823. #if NR_CPUS == 1
  824. /* Uniprocessor: the possible/online/present masks are always "1" */
  825. #define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
  826. #define for_each_online_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
  827. #define for_each_present_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
  828. #else
  829. #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
  830. #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
  831. #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
  832. #endif
  833. /* Wrappers for arch boot code to manipulate normally-constant masks */
  834. void init_cpu_present(const struct cpumask *src);
  835. void init_cpu_possible(const struct cpumask *src);
  836. void init_cpu_online(const struct cpumask *src);
  837. static inline void reset_cpu_possible_mask(void)
  838. {
  839. bitmap_zero(cpumask_bits(&__cpu_possible_mask), NR_CPUS);
  840. }
  841. static inline void
  842. set_cpu_possible(unsigned int cpu, bool possible)
  843. {
  844. if (possible)
  845. cpumask_set_cpu(cpu, &__cpu_possible_mask);
  846. else
  847. cpumask_clear_cpu(cpu, &__cpu_possible_mask);
  848. }
  849. static inline void
  850. set_cpu_present(unsigned int cpu, bool present)
  851. {
  852. if (present)
  853. cpumask_set_cpu(cpu, &__cpu_present_mask);
  854. else
  855. cpumask_clear_cpu(cpu, &__cpu_present_mask);
  856. }
  857. void set_cpu_online(unsigned int cpu, bool online);
  858. static inline void
  859. set_cpu_active(unsigned int cpu, bool active)
  860. {
  861. if (active)
  862. cpumask_set_cpu(cpu, &__cpu_active_mask);
  863. else
  864. cpumask_clear_cpu(cpu, &__cpu_active_mask);
  865. }
  866. static inline void
  867. set_cpu_dying(unsigned int cpu, bool dying)
  868. {
  869. if (dying)
  870. cpumask_set_cpu(cpu, &__cpu_dying_mask);
  871. else
  872. cpumask_clear_cpu(cpu, &__cpu_dying_mask);
  873. }
  874. /**
  875. * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
  876. * @bitmap: the bitmap
  877. *
  878. * There are a few places where cpumask_var_t isn't appropriate and
  879. * static cpumasks must be used (eg. very early boot), yet we don't
  880. * expose the definition of 'struct cpumask'.
  881. *
  882. * This does the conversion, and can be used as a constant initializer.
  883. */
  884. #define to_cpumask(bitmap) \
  885. ((struct cpumask *)(1 ? (bitmap) \
  886. : (void *)sizeof(__check_is_bitmap(bitmap))))
  887. static inline int __check_is_bitmap(const unsigned long *bitmap)
  888. {
  889. return 1;
  890. }
  891. /*
  892. * Special-case data structure for "single bit set only" constant CPU masks.
  893. *
  894. * We pre-generate all the 64 (or 32) possible bit positions, with enough
  895. * padding to the left and the right, and return the constant pointer
  896. * appropriately offset.
  897. */
  898. extern const unsigned long
  899. cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
  900. static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
  901. {
  902. const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
  903. p -= cpu / BITS_PER_LONG;
  904. return to_cpumask(p);
  905. }
  906. #if NR_CPUS > 1
  907. /**
  908. * num_online_cpus() - Read the number of online CPUs
  909. *
  910. * Despite the fact that __num_online_cpus is of type atomic_t, this
  911. * interface gives only a momentary snapshot and is not protected against
  912. * concurrent CPU hotplug operations unless invoked from a cpuhp_lock held
  913. * region.
  914. */
  915. static inline unsigned int num_online_cpus(void)
  916. {
  917. return atomic_read(&__num_online_cpus);
  918. }
  919. #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
  920. #define num_present_cpus() cpumask_weight(cpu_present_mask)
  921. #define num_active_cpus() cpumask_weight(cpu_active_mask)
  922. static inline bool cpu_online(unsigned int cpu)
  923. {
  924. return cpumask_test_cpu(cpu, cpu_online_mask);
  925. }
  926. static inline bool cpu_possible(unsigned int cpu)
  927. {
  928. return cpumask_test_cpu(cpu, cpu_possible_mask);
  929. }
  930. static inline bool cpu_present(unsigned int cpu)
  931. {
  932. return cpumask_test_cpu(cpu, cpu_present_mask);
  933. }
  934. static inline bool cpu_active(unsigned int cpu)
  935. {
  936. return cpumask_test_cpu(cpu, cpu_active_mask);
  937. }
  938. static inline bool cpu_dying(unsigned int cpu)
  939. {
  940. return cpumask_test_cpu(cpu, cpu_dying_mask);
  941. }
  942. #else
  943. #define num_online_cpus() 1U
  944. #define num_possible_cpus() 1U
  945. #define num_present_cpus() 1U
  946. #define num_active_cpus() 1U
  947. static inline bool cpu_online(unsigned int cpu)
  948. {
  949. return cpu == 0;
  950. }
  951. static inline bool cpu_possible(unsigned int cpu)
  952. {
  953. return cpu == 0;
  954. }
  955. static inline bool cpu_present(unsigned int cpu)
  956. {
  957. return cpu == 0;
  958. }
  959. static inline bool cpu_active(unsigned int cpu)
  960. {
  961. return cpu == 0;
  962. }
  963. static inline bool cpu_dying(unsigned int cpu)
  964. {
  965. return false;
  966. }
  967. #endif /* NR_CPUS > 1 */
  968. #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
  969. #if NR_CPUS <= BITS_PER_LONG
  970. #define CPU_BITS_ALL \
  971. { \
  972. [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
  973. }
  974. #else /* NR_CPUS > BITS_PER_LONG */
  975. #define CPU_BITS_ALL \
  976. { \
  977. [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
  978. [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
  979. }
  980. #endif /* NR_CPUS > BITS_PER_LONG */
  981. /**
  982. * cpumap_print_to_pagebuf - copies the cpumask into the buffer either
  983. * as comma-separated list of cpus or hex values of cpumask
  984. * @list: indicates whether the cpumap must be list
  985. * @mask: the cpumask to copy
  986. * @buf: the buffer to copy into
  987. *
  988. * Returns the length of the (null-terminated) @buf string, zero if
  989. * nothing is copied.
  990. */
  991. static inline ssize_t
  992. cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
  993. {
  994. return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
  995. nr_cpu_ids);
  996. }
  997. /**
  998. * cpumap_print_bitmask_to_buf - copies the cpumask into the buffer as
  999. * hex values of cpumask
  1000. *
  1001. * @buf: the buffer to copy into
  1002. * @mask: the cpumask to copy
  1003. * @off: in the string from which we are copying, we copy to @buf
  1004. * @count: the maximum number of bytes to print
  1005. *
  1006. * The function prints the cpumask into the buffer as hex values of
  1007. * cpumask; Typically used by bin_attribute to export cpumask bitmask
  1008. * ABI.
  1009. *
  1010. * Returns the length of how many bytes have been copied, excluding
  1011. * terminating '\0'.
  1012. */
  1013. static inline ssize_t
  1014. cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
  1015. loff_t off, size_t count)
  1016. {
  1017. return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
  1018. nr_cpu_ids, off, count) - 1;
  1019. }
  1020. /**
  1021. * cpumap_print_list_to_buf - copies the cpumask into the buffer as
  1022. * comma-separated list of cpus
  1023. *
  1024. * Everything is same with the above cpumap_print_bitmask_to_buf()
  1025. * except the print format.
  1026. */
  1027. static inline ssize_t
  1028. cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
  1029. loff_t off, size_t count)
  1030. {
  1031. return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
  1032. nr_cpu_ids, off, count) - 1;
  1033. }
  1034. #if NR_CPUS <= BITS_PER_LONG
  1035. #define CPU_MASK_ALL \
  1036. (cpumask_t) { { \
  1037. [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
  1038. } }
  1039. #else
  1040. #define CPU_MASK_ALL \
  1041. (cpumask_t) { { \
  1042. [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
  1043. [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \
  1044. } }
  1045. #endif /* NR_CPUS > BITS_PER_LONG */
  1046. #define CPU_MASK_NONE \
  1047. (cpumask_t) { { \
  1048. [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \
  1049. } }
  1050. #define CPU_MASK_CPU0 \
  1051. (cpumask_t) { { \
  1052. [0] = 1UL \
  1053. } }
  1054. /*
  1055. * Provide a valid theoretical max size for cpumap and cpulist sysfs files
  1056. * to avoid breaking userspace which may allocate a buffer based on the size
  1057. * reported by e.g. fstat.
  1058. *
  1059. * for cpumap NR_CPUS * 9/32 - 1 should be an exact length.
  1060. *
  1061. * For cpulist 7 is (ceil(log10(NR_CPUS)) + 1) allowing for NR_CPUS to be up
  1062. * to 2 orders of magnitude larger than 8192. And then we divide by 2 to
  1063. * cover a worst-case of every other cpu being on one of two nodes for a
  1064. * very large NR_CPUS.
  1065. *
  1066. * Use PAGE_SIZE as a minimum for smaller configurations while avoiding
  1067. * unsigned comparison to -1.
  1068. */
  1069. #define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \
  1070. ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)
  1071. #define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)
  1072. #endif /* __LINUX_CPUMASK_H */