cpu.c 16 KB

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