cpu.c 17 KB

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