cpu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /* CPU control.
  2. * (C) 2001, 2002, 2003, 2004 Rusty Russell
  3. *
  4. * This code is licenced under the GPL.
  5. */
  6. #include <linux/proc_fs.h>
  7. #include <linux/smp.h>
  8. #include <linux/init.h>
  9. #include <linux/notifier.h>
  10. #include <linux/sched.h>
  11. #include <linux/unistd.h>
  12. #include <linux/cpu.h>
  13. #include <linux/oom.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/export.h>
  16. #include <linux/bug.h>
  17. #include <linux/kthread.h>
  18. #include <linux/stop_machine.h>
  19. #include <linux/mutex.h>
  20. #include <linux/gfp.h>
  21. #include <linux/suspend.h>
  22. #include "smpboot.h"
  23. #ifdef CONFIG_SMP
  24. /* Serializes the updates to cpu_online_mask, cpu_present_mask */
  25. static DEFINE_MUTEX(cpu_add_remove_lock);
  26. /*
  27. * The following two API's must be used when attempting
  28. * to serialize the updates to cpu_online_mask, cpu_present_mask.
  29. */
  30. void cpu_maps_update_begin(void)
  31. {
  32. mutex_lock(&cpu_add_remove_lock);
  33. }
  34. void cpu_maps_update_done(void)
  35. {
  36. mutex_unlock(&cpu_add_remove_lock);
  37. }
  38. static RAW_NOTIFIER_HEAD(cpu_chain);
  39. /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
  40. * Should always be manipulated under cpu_add_remove_lock
  41. */
  42. static int cpu_hotplug_disabled;
  43. #ifdef CONFIG_HOTPLUG_CPU
  44. static struct {
  45. struct task_struct *active_writer;
  46. struct mutex lock; /* Synchronizes accesses to refcount, */
  47. /*
  48. * Also blocks the new readers during
  49. * an ongoing cpu hotplug operation.
  50. */
  51. int refcount;
  52. } cpu_hotplug = {
  53. .active_writer = NULL,
  54. .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
  55. .refcount = 0,
  56. };
  57. void get_online_cpus(void)
  58. {
  59. might_sleep();
  60. if (cpu_hotplug.active_writer == current)
  61. return;
  62. mutex_lock(&cpu_hotplug.lock);
  63. cpu_hotplug.refcount++;
  64. mutex_unlock(&cpu_hotplug.lock);
  65. }
  66. EXPORT_SYMBOL_GPL(get_online_cpus);
  67. void put_online_cpus(void)
  68. {
  69. if (cpu_hotplug.active_writer == current)
  70. return;
  71. mutex_lock(&cpu_hotplug.lock);
  72. if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer))
  73. wake_up_process(cpu_hotplug.active_writer);
  74. mutex_unlock(&cpu_hotplug.lock);
  75. }
  76. EXPORT_SYMBOL_GPL(put_online_cpus);
  77. /*
  78. * This ensures that the hotplug operation can begin only when the
  79. * refcount goes to zero.
  80. *
  81. * Note that during a cpu-hotplug operation, the new readers, if any,
  82. * will be blocked by the cpu_hotplug.lock
  83. *
  84. * Since cpu_hotplug_begin() is always called after invoking
  85. * cpu_maps_update_begin(), we can be sure that only one writer is active.
  86. *
  87. * Note that theoretically, there is a possibility of a livelock:
  88. * - Refcount goes to zero, last reader wakes up the sleeping
  89. * writer.
  90. * - Last reader unlocks the cpu_hotplug.lock.
  91. * - A new reader arrives at this moment, bumps up the refcount.
  92. * - The writer acquires the cpu_hotplug.lock finds the refcount
  93. * non zero and goes to sleep again.
  94. *
  95. * However, this is very difficult to achieve in practice since
  96. * get_online_cpus() not an api which is called all that often.
  97. *
  98. */
  99. static void cpu_hotplug_begin(void)
  100. {
  101. cpu_hotplug.active_writer = current;
  102. for (;;) {
  103. mutex_lock(&cpu_hotplug.lock);
  104. if (likely(!cpu_hotplug.refcount))
  105. break;
  106. __set_current_state(TASK_UNINTERRUPTIBLE);
  107. mutex_unlock(&cpu_hotplug.lock);
  108. schedule();
  109. }
  110. }
  111. static void cpu_hotplug_done(void)
  112. {
  113. cpu_hotplug.active_writer = NULL;
  114. mutex_unlock(&cpu_hotplug.lock);
  115. }
  116. #else /* #if CONFIG_HOTPLUG_CPU */
  117. static void cpu_hotplug_begin(void) {}
  118. static void cpu_hotplug_done(void) {}
  119. #endif /* #else #if CONFIG_HOTPLUG_CPU */
  120. /* Need to know about CPUs going up/down? */
  121. int __ref register_cpu_notifier(struct notifier_block *nb)
  122. {
  123. int ret;
  124. cpu_maps_update_begin();
  125. ret = raw_notifier_chain_register(&cpu_chain, nb);
  126. cpu_maps_update_done();
  127. return ret;
  128. }
  129. static int __cpu_notify(unsigned long val, void *v, int nr_to_call,
  130. int *nr_calls)
  131. {
  132. int ret;
  133. ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call,
  134. nr_calls);
  135. return notifier_to_errno(ret);
  136. }
  137. static int cpu_notify(unsigned long val, void *v)
  138. {
  139. return __cpu_notify(val, v, -1, NULL);
  140. }
  141. #ifdef CONFIG_HOTPLUG_CPU
  142. static void cpu_notify_nofail(unsigned long val, void *v)
  143. {
  144. BUG_ON(cpu_notify(val, v));
  145. }
  146. EXPORT_SYMBOL(register_cpu_notifier);
  147. void __ref unregister_cpu_notifier(struct notifier_block *nb)
  148. {
  149. cpu_maps_update_begin();
  150. raw_notifier_chain_unregister(&cpu_chain, nb);
  151. cpu_maps_update_done();
  152. }
  153. EXPORT_SYMBOL(unregister_cpu_notifier);
  154. /**
  155. * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
  156. * @cpu: a CPU id
  157. *
  158. * This function walks all processes, finds a valid mm struct for each one and
  159. * then clears a corresponding bit in mm's cpumask. While this all sounds
  160. * trivial, there are various non-obvious corner cases, which this function
  161. * tries to solve in a safe manner.
  162. *
  163. * Also note that the function uses a somewhat relaxed locking scheme, so it may
  164. * be called only for an already offlined CPU.
  165. */
  166. void clear_tasks_mm_cpumask(int cpu)
  167. {
  168. struct task_struct *p;
  169. /*
  170. * This function is called after the cpu is taken down and marked
  171. * offline, so its not like new tasks will ever get this cpu set in
  172. * their mm mask. -- Peter Zijlstra
  173. * Thus, we may use rcu_read_lock() here, instead of grabbing
  174. * full-fledged tasklist_lock.
  175. */
  176. WARN_ON(cpu_online(cpu));
  177. rcu_read_lock();
  178. for_each_process(p) {
  179. struct task_struct *t;
  180. /*
  181. * Main thread might exit, but other threads may still have
  182. * a valid mm. Find one.
  183. */
  184. t = find_lock_task_mm(p);
  185. if (!t)
  186. continue;
  187. cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
  188. task_unlock(t);
  189. }
  190. rcu_read_unlock();
  191. }
  192. static inline void check_for_tasks(int cpu)
  193. {
  194. struct task_struct *p;
  195. write_lock_irq(&tasklist_lock);
  196. for_each_process(p) {
  197. if (task_cpu(p) == cpu && p->state == TASK_RUNNING &&
  198. (p->utime || p->stime))
  199. printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d "
  200. "(state = %ld, flags = %x)\n",
  201. p->comm, task_pid_nr(p), cpu,
  202. p->state, p->flags);
  203. }
  204. write_unlock_irq(&tasklist_lock);
  205. }
  206. struct take_cpu_down_param {
  207. unsigned long mod;
  208. void *hcpu;
  209. };
  210. /* Take this CPU down. */
  211. static int __ref take_cpu_down(void *_param)
  212. {
  213. struct take_cpu_down_param *param = _param;
  214. int err;
  215. /* Ensure this CPU doesn't handle any more interrupts. */
  216. err = __cpu_disable();
  217. if (err < 0)
  218. return err;
  219. cpu_notify(CPU_DYING | param->mod, param->hcpu);
  220. return 0;
  221. }
  222. /* Requires cpu_add_remove_lock to be held */
  223. static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
  224. {
  225. int err, nr_calls = 0;
  226. void *hcpu = (void *)(long)cpu;
  227. unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
  228. struct take_cpu_down_param tcd_param = {
  229. .mod = mod,
  230. .hcpu = hcpu,
  231. };
  232. if (num_online_cpus() == 1)
  233. return -EBUSY;
  234. if (!cpu_online(cpu))
  235. return -EINVAL;
  236. cpu_hotplug_begin();
  237. err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
  238. if (err) {
  239. nr_calls--;
  240. __cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL);
  241. printk("%s: attempt to take down CPU %u failed\n",
  242. __func__, cpu);
  243. goto out_release;
  244. }
  245. err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
  246. if (err) {
  247. /* CPU didn't die: tell everyone. Can't complain. */
  248. cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu);
  249. goto out_release;
  250. }
  251. BUG_ON(cpu_online(cpu));
  252. /*
  253. * The migration_call() CPU_DYING callback will have removed all
  254. * runnable tasks from the cpu, there's only the idle task left now
  255. * that the migration thread is done doing the stop_machine thing.
  256. *
  257. * Wait for the stop thread to go away.
  258. */
  259. while (!idle_cpu(cpu))
  260. cpu_relax();
  261. /* This actually kills the CPU. */
  262. __cpu_die(cpu);
  263. /* CPU is completely dead: tell everyone. Too late to complain. */
  264. cpu_notify_nofail(CPU_DEAD | mod, hcpu);
  265. check_for_tasks(cpu);
  266. out_release:
  267. cpu_hotplug_done();
  268. if (!err)
  269. cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
  270. return err;
  271. }
  272. int __ref cpu_down(unsigned int cpu)
  273. {
  274. int err;
  275. cpu_maps_update_begin();
  276. if (cpu_hotplug_disabled) {
  277. err = -EBUSY;
  278. goto out;
  279. }
  280. err = _cpu_down(cpu, 0);
  281. out:
  282. cpu_maps_update_done();
  283. return err;
  284. }
  285. EXPORT_SYMBOL(cpu_down);
  286. #endif /*CONFIG_HOTPLUG_CPU*/
  287. /* Requires cpu_add_remove_lock to be held */
  288. static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
  289. {
  290. int ret, nr_calls = 0;
  291. void *hcpu = (void *)(long)cpu;
  292. unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
  293. struct task_struct *idle;
  294. if (cpu_online(cpu) || !cpu_present(cpu))
  295. return -EINVAL;
  296. cpu_hotplug_begin();
  297. idle = idle_thread_get(cpu);
  298. if (IS_ERR(idle)) {
  299. ret = PTR_ERR(idle);
  300. goto out;
  301. }
  302. ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
  303. if (ret) {
  304. nr_calls--;
  305. printk(KERN_WARNING "%s: attempt to bring up CPU %u failed\n",
  306. __func__, cpu);
  307. goto out_notify;
  308. }
  309. /* Arch-specific enabling code. */
  310. ret = __cpu_up(cpu, idle);
  311. if (ret != 0)
  312. goto out_notify;
  313. BUG_ON(!cpu_online(cpu));
  314. /* Now call notifier in preparation. */
  315. cpu_notify(CPU_ONLINE | mod, hcpu);
  316. out_notify:
  317. if (ret != 0)
  318. __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL);
  319. out:
  320. cpu_hotplug_done();
  321. return ret;
  322. }
  323. int __cpuinit cpu_up(unsigned int cpu)
  324. {
  325. int err = 0;
  326. #ifdef CONFIG_MEMORY_HOTPLUG
  327. int nid;
  328. pg_data_t *pgdat;
  329. #endif
  330. if (!cpu_possible(cpu)) {
  331. printk(KERN_ERR "can't online cpu %d because it is not "
  332. "configured as may-hotadd at boot time\n", cpu);
  333. #if defined(CONFIG_IA64)
  334. printk(KERN_ERR "please check additional_cpus= boot "
  335. "parameter\n");
  336. #endif
  337. return -EINVAL;
  338. }
  339. #ifdef CONFIG_MEMORY_HOTPLUG
  340. nid = cpu_to_node(cpu);
  341. if (!node_online(nid)) {
  342. err = mem_online_node(nid);
  343. if (err)
  344. return err;
  345. }
  346. pgdat = NODE_DATA(nid);
  347. if (!pgdat) {
  348. printk(KERN_ERR
  349. "Can't online cpu %d due to NULL pgdat\n", cpu);
  350. return -ENOMEM;
  351. }
  352. if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
  353. mutex_lock(&zonelists_mutex);
  354. build_all_zonelists(NULL, NULL);
  355. mutex_unlock(&zonelists_mutex);
  356. }
  357. #endif
  358. cpu_maps_update_begin();
  359. if (cpu_hotplug_disabled) {
  360. err = -EBUSY;
  361. goto out;
  362. }
  363. err = _cpu_up(cpu, 0);
  364. out:
  365. cpu_maps_update_done();
  366. return err;
  367. }
  368. EXPORT_SYMBOL_GPL(cpu_up);
  369. #ifdef CONFIG_PM_SLEEP_SMP
  370. static cpumask_var_t frozen_cpus;
  371. void __weak arch_disable_nonboot_cpus_begin(void)
  372. {
  373. }
  374. void __weak arch_disable_nonboot_cpus_end(void)
  375. {
  376. }
  377. int disable_nonboot_cpus(void)
  378. {
  379. int cpu, first_cpu, error = 0;
  380. cpu_maps_update_begin();
  381. first_cpu = cpumask_first(cpu_online_mask);
  382. /*
  383. * We take down all of the non-boot CPUs in one shot to avoid races
  384. * with the userspace trying to use the CPU hotplug at the same time
  385. */
  386. cpumask_clear(frozen_cpus);
  387. arch_disable_nonboot_cpus_begin();
  388. printk("Disabling non-boot CPUs ...\n");
  389. for_each_online_cpu(cpu) {
  390. if (cpu == first_cpu)
  391. continue;
  392. error = _cpu_down(cpu, 1);
  393. if (!error)
  394. cpumask_set_cpu(cpu, frozen_cpus);
  395. else {
  396. printk(KERN_ERR "Error taking CPU%d down: %d\n",
  397. cpu, error);
  398. break;
  399. }
  400. }
  401. arch_disable_nonboot_cpus_end();
  402. if (!error) {
  403. BUG_ON(num_online_cpus() > 1);
  404. /* Make sure the CPUs won't be enabled by someone else */
  405. cpu_hotplug_disabled = 1;
  406. } else {
  407. printk(KERN_ERR "Non-boot CPUs are not disabled\n");
  408. }
  409. cpu_maps_update_done();
  410. return error;
  411. }
  412. void __weak arch_enable_nonboot_cpus_begin(void)
  413. {
  414. }
  415. void __weak arch_enable_nonboot_cpus_end(void)
  416. {
  417. }
  418. void __ref enable_nonboot_cpus(void)
  419. {
  420. int cpu, error;
  421. /* Allow everyone to use the CPU hotplug again */
  422. cpu_maps_update_begin();
  423. cpu_hotplug_disabled = 0;
  424. if (cpumask_empty(frozen_cpus))
  425. goto out;
  426. printk(KERN_INFO "Enabling non-boot CPUs ...\n");
  427. arch_enable_nonboot_cpus_begin();
  428. for_each_cpu(cpu, frozen_cpus) {
  429. error = _cpu_up(cpu, 1);
  430. if (!error) {
  431. printk(KERN_INFO "CPU%d is up\n", cpu);
  432. continue;
  433. }
  434. printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error);
  435. }
  436. arch_enable_nonboot_cpus_end();
  437. cpumask_clear(frozen_cpus);
  438. out:
  439. cpu_maps_update_done();
  440. }
  441. static int __init alloc_frozen_cpus(void)
  442. {
  443. if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO))
  444. return -ENOMEM;
  445. return 0;
  446. }
  447. core_initcall(alloc_frozen_cpus);
  448. /*
  449. * Prevent regular CPU hotplug from racing with the freezer, by disabling CPU
  450. * hotplug when tasks are about to be frozen. Also, don't allow the freezer
  451. * to continue until any currently running CPU hotplug operation gets
  452. * completed.
  453. * To modify the 'cpu_hotplug_disabled' flag, we need to acquire the
  454. * 'cpu_add_remove_lock'. And this same lock is also taken by the regular
  455. * CPU hotplug path and released only after it is complete. Thus, we
  456. * (and hence the freezer) will block here until any currently running CPU
  457. * hotplug operation gets completed.
  458. */
  459. void cpu_hotplug_disable_before_freeze(void)
  460. {
  461. cpu_maps_update_begin();
  462. cpu_hotplug_disabled = 1;
  463. cpu_maps_update_done();
  464. }
  465. /*
  466. * When tasks have been thawed, re-enable regular CPU hotplug (which had been
  467. * disabled while beginning to freeze tasks).
  468. */
  469. void cpu_hotplug_enable_after_thaw(void)
  470. {
  471. cpu_maps_update_begin();
  472. cpu_hotplug_disabled = 0;
  473. cpu_maps_update_done();
  474. }
  475. /*
  476. * When callbacks for CPU hotplug notifications are being executed, we must
  477. * ensure that the state of the system with respect to the tasks being frozen
  478. * or not, as reported by the notification, remains unchanged *throughout the
  479. * duration* of the execution of the callbacks.
  480. * Hence we need to prevent the freezer from racing with regular CPU hotplug.
  481. *
  482. * This synchronization is implemented by mutually excluding regular CPU
  483. * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/
  484. * Hibernate notifications.
  485. */
  486. static int
  487. cpu_hotplug_pm_callback(struct notifier_block *nb,
  488. unsigned long action, void *ptr)
  489. {
  490. switch (action) {
  491. case PM_SUSPEND_PREPARE:
  492. case PM_HIBERNATION_PREPARE:
  493. cpu_hotplug_disable_before_freeze();
  494. break;
  495. case PM_POST_SUSPEND:
  496. case PM_POST_HIBERNATION:
  497. cpu_hotplug_enable_after_thaw();
  498. break;
  499. default:
  500. return NOTIFY_DONE;
  501. }
  502. return NOTIFY_OK;
  503. }
  504. static int __init cpu_hotplug_pm_sync_init(void)
  505. {
  506. pm_notifier(cpu_hotplug_pm_callback, 0);
  507. return 0;
  508. }
  509. core_initcall(cpu_hotplug_pm_sync_init);
  510. #endif /* CONFIG_PM_SLEEP_SMP */
  511. /**
  512. * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers
  513. * @cpu: cpu that just started
  514. *
  515. * This function calls the cpu_chain notifiers with CPU_STARTING.
  516. * It must be called by the arch code on the new cpu, before the new cpu
  517. * enables interrupts and before the "boot" cpu returns from __cpu_up().
  518. */
  519. void __cpuinit notify_cpu_starting(unsigned int cpu)
  520. {
  521. unsigned long val = CPU_STARTING;
  522. #ifdef CONFIG_PM_SLEEP_SMP
  523. if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus))
  524. val = CPU_STARTING_FROZEN;
  525. #endif /* CONFIG_PM_SLEEP_SMP */
  526. cpu_notify(val, (void *)(long)cpu);
  527. }
  528. #endif /* CONFIG_SMP */
  529. /*
  530. * cpu_bit_bitmap[] is a special, "compressed" data structure that
  531. * represents all NR_CPUS bits binary values of 1<<nr.
  532. *
  533. * It is used by cpumask_of() to get a constant address to a CPU
  534. * mask value that has a single bit set only.
  535. */
  536. /* cpu_bit_bitmap[0] is empty - so we can back into it */
  537. #define MASK_DECLARE_1(x) [x+1][0] = (1UL << (x))
  538. #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
  539. #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
  540. #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
  541. const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
  542. MASK_DECLARE_8(0), MASK_DECLARE_8(8),
  543. MASK_DECLARE_8(16), MASK_DECLARE_8(24),
  544. #if BITS_PER_LONG > 32
  545. MASK_DECLARE_8(32), MASK_DECLARE_8(40),
  546. MASK_DECLARE_8(48), MASK_DECLARE_8(56),
  547. #endif
  548. };
  549. EXPORT_SYMBOL_GPL(cpu_bit_bitmap);
  550. const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
  551. EXPORT_SYMBOL(cpu_all_bits);
  552. #ifdef CONFIG_INIT_ALL_POSSIBLE
  553. static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly
  554. = CPU_BITS_ALL;
  555. #else
  556. static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;
  557. #endif
  558. const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits);
  559. EXPORT_SYMBOL(cpu_possible_mask);
  560. static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;
  561. const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits);
  562. EXPORT_SYMBOL(cpu_online_mask);
  563. static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;
  564. const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits);
  565. EXPORT_SYMBOL(cpu_present_mask);
  566. static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;
  567. const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits);
  568. EXPORT_SYMBOL(cpu_active_mask);
  569. void set_cpu_possible(unsigned int cpu, bool possible)
  570. {
  571. if (possible)
  572. cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits));
  573. else
  574. cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits));
  575. }
  576. void set_cpu_present(unsigned int cpu, bool present)
  577. {
  578. if (present)
  579. cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits));
  580. else
  581. cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits));
  582. }
  583. void set_cpu_online(unsigned int cpu, bool online)
  584. {
  585. if (online)
  586. cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits));
  587. else
  588. cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits));
  589. }
  590. void set_cpu_active(unsigned int cpu, bool active)
  591. {
  592. if (active)
  593. cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
  594. else
  595. cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits));
  596. }
  597. void init_cpu_present(const struct cpumask *src)
  598. {
  599. cpumask_copy(to_cpumask(cpu_present_bits), src);
  600. }
  601. void init_cpu_possible(const struct cpumask *src)
  602. {
  603. cpumask_copy(to_cpumask(cpu_possible_bits), src);
  604. }
  605. void init_cpu_online(const struct cpumask *src)
  606. {
  607. cpumask_copy(to_cpumask(cpu_online_bits), src);
  608. }