cpu.c 18 KB

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