smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Generic helpers for smp ipi calls
  3. *
  4. * (C) Jens Axboe <jens.axboe@oracle.com> 2008
  5. */
  6. #include <linux/rcupdate.h>
  7. #include <linux/rculist.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/percpu.h>
  11. #include <linux/init.h>
  12. #include <linux/gfp.h>
  13. #include <linux/smp.h>
  14. #include <linux/cpu.h>
  15. #ifdef CONFIG_USE_GENERIC_SMP_HELPERS
  16. static struct {
  17. struct list_head queue;
  18. raw_spinlock_t lock;
  19. } call_function __cacheline_aligned_in_smp =
  20. {
  21. .queue = LIST_HEAD_INIT(call_function.queue),
  22. .lock = __RAW_SPIN_LOCK_UNLOCKED(call_function.lock),
  23. };
  24. enum {
  25. CSD_FLAG_LOCK = 0x01,
  26. };
  27. struct call_function_data {
  28. struct call_single_data csd;
  29. atomic_t refs;
  30. cpumask_var_t cpumask;
  31. };
  32. static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_function_data, cfd_data);
  33. struct call_single_queue {
  34. struct list_head list;
  35. raw_spinlock_t lock;
  36. };
  37. static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_queue, call_single_queue);
  38. static int
  39. hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
  40. {
  41. long cpu = (long)hcpu;
  42. struct call_function_data *cfd = &per_cpu(cfd_data, cpu);
  43. switch (action) {
  44. case CPU_UP_PREPARE:
  45. case CPU_UP_PREPARE_FROZEN:
  46. if (!zalloc_cpumask_var_node(&cfd->cpumask, GFP_KERNEL,
  47. cpu_to_node(cpu)))
  48. return notifier_from_errno(-ENOMEM);
  49. break;
  50. #ifdef CONFIG_HOTPLUG_CPU
  51. case CPU_UP_CANCELED:
  52. case CPU_UP_CANCELED_FROZEN:
  53. case CPU_DEAD:
  54. case CPU_DEAD_FROZEN:
  55. free_cpumask_var(cfd->cpumask);
  56. break;
  57. #endif
  58. };
  59. return NOTIFY_OK;
  60. }
  61. static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
  62. .notifier_call = hotplug_cfd,
  63. };
  64. void __init call_function_init(void)
  65. {
  66. void *cpu = (void *)(long)smp_processor_id();
  67. int i;
  68. for_each_possible_cpu(i) {
  69. struct call_single_queue *q = &per_cpu(call_single_queue, i);
  70. raw_spin_lock_init(&q->lock);
  71. INIT_LIST_HEAD(&q->list);
  72. }
  73. hotplug_cfd(&hotplug_cfd_notifier, CPU_UP_PREPARE, cpu);
  74. register_cpu_notifier(&hotplug_cfd_notifier);
  75. }
  76. /*
  77. * csd_lock/csd_unlock used to serialize access to per-cpu csd resources
  78. *
  79. * For non-synchronous ipi calls the csd can still be in use by the
  80. * previous function call. For multi-cpu calls its even more interesting
  81. * as we'll have to ensure no other cpu is observing our csd.
  82. */
  83. static void csd_lock_wait(struct call_single_data *data)
  84. {
  85. while (data->flags & CSD_FLAG_LOCK)
  86. cpu_relax();
  87. }
  88. static void csd_lock(struct call_single_data *data)
  89. {
  90. csd_lock_wait(data);
  91. data->flags = CSD_FLAG_LOCK;
  92. /*
  93. * prevent CPU from reordering the above assignment
  94. * to ->flags with any subsequent assignments to other
  95. * fields of the specified call_single_data structure:
  96. */
  97. smp_mb();
  98. }
  99. static void csd_unlock(struct call_single_data *data)
  100. {
  101. WARN_ON(!(data->flags & CSD_FLAG_LOCK));
  102. /*
  103. * ensure we're all done before releasing data:
  104. */
  105. smp_mb();
  106. data->flags &= ~CSD_FLAG_LOCK;
  107. }
  108. /*
  109. * Insert a previously allocated call_single_data element
  110. * for execution on the given CPU. data must already have
  111. * ->func, ->info, and ->flags set.
  112. */
  113. static
  114. void generic_exec_single(int cpu, struct call_single_data *data, int wait)
  115. {
  116. struct call_single_queue *dst = &per_cpu(call_single_queue, cpu);
  117. unsigned long flags;
  118. int ipi;
  119. raw_spin_lock_irqsave(&dst->lock, flags);
  120. ipi = list_empty(&dst->list);
  121. list_add_tail(&data->list, &dst->list);
  122. raw_spin_unlock_irqrestore(&dst->lock, flags);
  123. /*
  124. * The list addition should be visible before sending the IPI
  125. * handler locks the list to pull the entry off it because of
  126. * normal cache coherency rules implied by spinlocks.
  127. *
  128. * If IPIs can go out of order to the cache coherency protocol
  129. * in an architecture, sufficient synchronisation should be added
  130. * to arch code to make it appear to obey cache coherency WRT
  131. * locking and barrier primitives. Generic code isn't really
  132. * equipped to do the right thing...
  133. */
  134. if (ipi)
  135. arch_send_call_function_single_ipi(cpu);
  136. if (wait)
  137. csd_lock_wait(data);
  138. }
  139. /*
  140. * Invoked by arch to handle an IPI for call function. Must be called with
  141. * interrupts disabled.
  142. */
  143. void generic_smp_call_function_interrupt(void)
  144. {
  145. struct call_function_data *data;
  146. int cpu = smp_processor_id();
  147. /*
  148. * Shouldn't receive this interrupt on a cpu that is not yet online.
  149. */
  150. WARN_ON_ONCE(!cpu_online(cpu));
  151. /*
  152. * Ensure entry is visible on call_function_queue after we have
  153. * entered the IPI. See comment in smp_call_function_many.
  154. * If we don't have this, then we may miss an entry on the list
  155. * and never get another IPI to process it.
  156. */
  157. smp_mb();
  158. /*
  159. * It's ok to use list_for_each_rcu() here even though we may
  160. * delete 'pos', since list_del_rcu() doesn't clear ->next
  161. */
  162. list_for_each_entry_rcu(data, &call_function.queue, csd.list) {
  163. int refs;
  164. smp_call_func_t func;
  165. /*
  166. * Since we walk the list without any locks, we might
  167. * see an entry that was completed, removed from the
  168. * list and is in the process of being reused.
  169. *
  170. * We must check that the cpu is in the cpumask before
  171. * checking the refs, and both must be set before
  172. * executing the callback on this cpu.
  173. */
  174. if (!cpumask_test_cpu(cpu, data->cpumask))
  175. continue;
  176. smp_rmb();
  177. if (atomic_read(&data->refs) == 0)
  178. continue;
  179. func = data->csd.func; /* save for later warn */
  180. func(data->csd.info);
  181. /*
  182. * If the cpu mask is not still set then func enabled
  183. * interrupts (BUG), and this cpu took another smp call
  184. * function interrupt and executed func(info) twice
  185. * on this cpu. That nested execution decremented refs.
  186. */
  187. if (!cpumask_test_and_clear_cpu(cpu, data->cpumask)) {
  188. WARN(1, "%pf enabled interrupts and double executed\n", func);
  189. continue;
  190. }
  191. refs = atomic_dec_return(&data->refs);
  192. WARN_ON(refs < 0);
  193. if (refs)
  194. continue;
  195. WARN_ON(!cpumask_empty(data->cpumask));
  196. raw_spin_lock(&call_function.lock);
  197. list_del_rcu(&data->csd.list);
  198. raw_spin_unlock(&call_function.lock);
  199. csd_unlock(&data->csd);
  200. }
  201. }
  202. /*
  203. * Invoked by arch to handle an IPI for call function single. Must be
  204. * called from the arch with interrupts disabled.
  205. */
  206. void generic_smp_call_function_single_interrupt(void)
  207. {
  208. struct call_single_queue *q = &__get_cpu_var(call_single_queue);
  209. unsigned int data_flags;
  210. LIST_HEAD(list);
  211. /*
  212. * Shouldn't receive this interrupt on a cpu that is not yet online.
  213. */
  214. WARN_ON_ONCE(!cpu_online(smp_processor_id()));
  215. raw_spin_lock(&q->lock);
  216. list_replace_init(&q->list, &list);
  217. raw_spin_unlock(&q->lock);
  218. while (!list_empty(&list)) {
  219. struct call_single_data *data;
  220. data = list_entry(list.next, struct call_single_data, list);
  221. list_del(&data->list);
  222. /*
  223. * 'data' can be invalid after this call if flags == 0
  224. * (when called through generic_exec_single()),
  225. * so save them away before making the call:
  226. */
  227. data_flags = data->flags;
  228. data->func(data->info);
  229. /*
  230. * Unlocked CSDs are valid through generic_exec_single():
  231. */
  232. if (data_flags & CSD_FLAG_LOCK)
  233. csd_unlock(data);
  234. }
  235. }
  236. static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data);
  237. /*
  238. * smp_call_function_single - Run a function on a specific CPU
  239. * @func: The function to run. This must be fast and non-blocking.
  240. * @info: An arbitrary pointer to pass to the function.
  241. * @wait: If true, wait until function has completed on other CPUs.
  242. *
  243. * Returns 0 on success, else a negative status code.
  244. */
  245. int smp_call_function_single(int cpu, smp_call_func_t func, void *info,
  246. int wait)
  247. {
  248. struct call_single_data d = {
  249. .flags = 0,
  250. };
  251. unsigned long flags;
  252. int this_cpu;
  253. int err = 0;
  254. /*
  255. * prevent preemption and reschedule on another processor,
  256. * as well as CPU removal
  257. */
  258. this_cpu = get_cpu();
  259. /*
  260. * Can deadlock when called with interrupts disabled.
  261. * We allow cpu's that are not yet online though, as no one else can
  262. * send smp call function interrupt to this cpu and as such deadlocks
  263. * can't happen.
  264. */
  265. WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
  266. && !oops_in_progress);
  267. if (cpu == this_cpu) {
  268. local_irq_save(flags);
  269. func(info);
  270. local_irq_restore(flags);
  271. } else {
  272. if ((unsigned)cpu < nr_cpu_ids && cpu_online(cpu)) {
  273. struct call_single_data *data = &d;
  274. if (!wait)
  275. data = &__get_cpu_var(csd_data);
  276. csd_lock(data);
  277. data->func = func;
  278. data->info = info;
  279. generic_exec_single(cpu, data, wait);
  280. } else {
  281. err = -ENXIO; /* CPU not online */
  282. }
  283. }
  284. put_cpu();
  285. return err;
  286. }
  287. EXPORT_SYMBOL(smp_call_function_single);
  288. /*
  289. * smp_call_function_any - Run a function on any of the given cpus
  290. * @mask: The mask of cpus it can run on.
  291. * @func: The function to run. This must be fast and non-blocking.
  292. * @info: An arbitrary pointer to pass to the function.
  293. * @wait: If true, wait until function has completed.
  294. *
  295. * Returns 0 on success, else a negative status code (if no cpus were online).
  296. * Note that @wait will be implicitly turned on in case of allocation failures,
  297. * since we fall back to on-stack allocation.
  298. *
  299. * Selection preference:
  300. * 1) current cpu if in @mask
  301. * 2) any cpu of current node if in @mask
  302. * 3) any other online cpu in @mask
  303. */
  304. int smp_call_function_any(const struct cpumask *mask,
  305. smp_call_func_t func, void *info, int wait)
  306. {
  307. unsigned int cpu;
  308. const struct cpumask *nodemask;
  309. int ret;
  310. /* Try for same CPU (cheapest) */
  311. cpu = get_cpu();
  312. if (cpumask_test_cpu(cpu, mask))
  313. goto call;
  314. /* Try for same node. */
  315. nodemask = cpumask_of_node(cpu_to_node(cpu));
  316. for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
  317. cpu = cpumask_next_and(cpu, nodemask, mask)) {
  318. if (cpu_online(cpu))
  319. goto call;
  320. }
  321. /* Any online will do: smp_call_function_single handles nr_cpu_ids. */
  322. cpu = cpumask_any_and(mask, cpu_online_mask);
  323. call:
  324. ret = smp_call_function_single(cpu, func, info, wait);
  325. put_cpu();
  326. return ret;
  327. }
  328. EXPORT_SYMBOL_GPL(smp_call_function_any);
  329. /**
  330. * __smp_call_function_single(): Run a function on a specific CPU
  331. * @cpu: The CPU to run on.
  332. * @data: Pre-allocated and setup data structure
  333. * @wait: If true, wait until function has completed on specified CPU.
  334. *
  335. * Like smp_call_function_single(), but allow caller to pass in a
  336. * pre-allocated data structure. Useful for embedding @data inside
  337. * other structures, for instance.
  338. */
  339. void __smp_call_function_single(int cpu, struct call_single_data *data,
  340. int wait)
  341. {
  342. unsigned int this_cpu;
  343. unsigned long flags;
  344. this_cpu = get_cpu();
  345. /*
  346. * Can deadlock when called with interrupts disabled.
  347. * We allow cpu's that are not yet online though, as no one else can
  348. * send smp call function interrupt to this cpu and as such deadlocks
  349. * can't happen.
  350. */
  351. WARN_ON_ONCE(cpu_online(smp_processor_id()) && wait && irqs_disabled()
  352. && !oops_in_progress);
  353. if (cpu == this_cpu) {
  354. local_irq_save(flags);
  355. data->func(data->info);
  356. local_irq_restore(flags);
  357. } else {
  358. csd_lock(data);
  359. generic_exec_single(cpu, data, wait);
  360. }
  361. put_cpu();
  362. }
  363. /**
  364. * smp_call_function_many(): Run a function on a set of other CPUs.
  365. * @mask: The set of cpus to run on (only runs on online subset).
  366. * @func: The function to run. This must be fast and non-blocking.
  367. * @info: An arbitrary pointer to pass to the function.
  368. * @wait: If true, wait (atomically) until function has completed
  369. * on other CPUs.
  370. *
  371. * If @wait is true, then returns once @func has returned.
  372. *
  373. * You must not call this function with disabled interrupts or from a
  374. * hardware interrupt handler or from a bottom half handler. Preemption
  375. * must be disabled when calling this function.
  376. */
  377. void smp_call_function_many(const struct cpumask *mask,
  378. smp_call_func_t func, void *info, bool wait)
  379. {
  380. struct call_function_data *data;
  381. unsigned long flags;
  382. int refs, cpu, next_cpu, this_cpu = smp_processor_id();
  383. /*
  384. * Can deadlock when called with interrupts disabled.
  385. * We allow cpu's that are not yet online though, as no one else can
  386. * send smp call function interrupt to this cpu and as such deadlocks
  387. * can't happen.
  388. */
  389. WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
  390. && !oops_in_progress && !early_boot_irqs_disabled);
  391. /* Try to fastpath. So, what's a CPU they want? Ignoring this one. */
  392. cpu = cpumask_first_and(mask, cpu_online_mask);
  393. if (cpu == this_cpu)
  394. cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
  395. /* No online cpus? We're done. */
  396. if (cpu >= nr_cpu_ids)
  397. return;
  398. /* Do we have another CPU which isn't us? */
  399. next_cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
  400. if (next_cpu == this_cpu)
  401. next_cpu = cpumask_next_and(next_cpu, mask, cpu_online_mask);
  402. /* Fastpath: do that cpu by itself. */
  403. if (next_cpu >= nr_cpu_ids) {
  404. smp_call_function_single(cpu, func, info, wait);
  405. return;
  406. }
  407. data = &__get_cpu_var(cfd_data);
  408. csd_lock(&data->csd);
  409. /* This BUG_ON verifies our reuse assertions and can be removed */
  410. BUG_ON(atomic_read(&data->refs) || !cpumask_empty(data->cpumask));
  411. /*
  412. * The global call function queue list add and delete are protected
  413. * by a lock, but the list is traversed without any lock, relying
  414. * on the rcu list add and delete to allow safe concurrent traversal.
  415. * We reuse the call function data without waiting for any grace
  416. * period after some other cpu removes it from the global queue.
  417. * This means a cpu might find our data block as it is being
  418. * filled out.
  419. *
  420. * We hold off the interrupt handler on the other cpu by
  421. * ordering our writes to the cpu mask vs our setting of the
  422. * refs counter. We assert only the cpu owning the data block
  423. * will set a bit in cpumask, and each bit will only be cleared
  424. * by the subject cpu. Each cpu must first find its bit is
  425. * set and then check that refs is set indicating the element is
  426. * ready to be processed, otherwise it must skip the entry.
  427. *
  428. * On the previous iteration refs was set to 0 by another cpu.
  429. * To avoid the use of transitivity, set the counter to 0 here
  430. * so the wmb will pair with the rmb in the interrupt handler.
  431. */
  432. atomic_set(&data->refs, 0); /* convert 3rd to 1st party write */
  433. data->csd.func = func;
  434. data->csd.info = info;
  435. /* Ensure 0 refs is visible before mask. Also orders func and info */
  436. smp_wmb();
  437. /* We rely on the "and" being processed before the store */
  438. cpumask_and(data->cpumask, mask, cpu_online_mask);
  439. cpumask_clear_cpu(this_cpu, data->cpumask);
  440. refs = cpumask_weight(data->cpumask);
  441. /* Some callers race with other cpus changing the passed mask */
  442. if (unlikely(!refs)) {
  443. csd_unlock(&data->csd);
  444. return;
  445. }
  446. raw_spin_lock_irqsave(&call_function.lock, flags);
  447. /*
  448. * Place entry at the _HEAD_ of the list, so that any cpu still
  449. * observing the entry in generic_smp_call_function_interrupt()
  450. * will not miss any other list entries:
  451. */
  452. list_add_rcu(&data->csd.list, &call_function.queue);
  453. /*
  454. * We rely on the wmb() in list_add_rcu to complete our writes
  455. * to the cpumask before this write to refs, which indicates
  456. * data is on the list and is ready to be processed.
  457. */
  458. atomic_set(&data->refs, refs);
  459. raw_spin_unlock_irqrestore(&call_function.lock, flags);
  460. /*
  461. * Make the list addition visible before sending the ipi.
  462. * (IPIs must obey or appear to obey normal Linux cache
  463. * coherency rules -- see comment in generic_exec_single).
  464. */
  465. smp_mb();
  466. /* Send a message to all CPUs in the map */
  467. arch_send_call_function_ipi_mask(data->cpumask);
  468. /* Optionally wait for the CPUs to complete */
  469. if (wait)
  470. csd_lock_wait(&data->csd);
  471. }
  472. EXPORT_SYMBOL(smp_call_function_many);
  473. /**
  474. * smp_call_function(): Run a function on all other CPUs.
  475. * @func: The function to run. This must be fast and non-blocking.
  476. * @info: An arbitrary pointer to pass to the function.
  477. * @wait: If true, wait (atomically) until function has completed
  478. * on other CPUs.
  479. *
  480. * Returns 0.
  481. *
  482. * If @wait is true, then returns once @func has returned; otherwise
  483. * it returns just before the target cpu calls @func.
  484. *
  485. * You must not call this function with disabled interrupts or from a
  486. * hardware interrupt handler or from a bottom half handler.
  487. */
  488. int smp_call_function(smp_call_func_t func, void *info, int wait)
  489. {
  490. preempt_disable();
  491. smp_call_function_many(cpu_online_mask, func, info, wait);
  492. preempt_enable();
  493. return 0;
  494. }
  495. EXPORT_SYMBOL(smp_call_function);
  496. void ipi_call_lock(void)
  497. {
  498. raw_spin_lock(&call_function.lock);
  499. }
  500. void ipi_call_unlock(void)
  501. {
  502. raw_spin_unlock(&call_function.lock);
  503. }
  504. void ipi_call_lock_irq(void)
  505. {
  506. raw_spin_lock_irq(&call_function.lock);
  507. }
  508. void ipi_call_unlock_irq(void)
  509. {
  510. raw_spin_unlock_irq(&call_function.lock);
  511. }
  512. #endif /* USE_GENERIC_SMP_HELPERS */
  513. /* Setup configured maximum number of CPUs to activate */
  514. unsigned int setup_max_cpus = NR_CPUS;
  515. EXPORT_SYMBOL(setup_max_cpus);
  516. /*
  517. * Setup routine for controlling SMP activation
  518. *
  519. * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
  520. * activation entirely (the MPS table probe still happens, though).
  521. *
  522. * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
  523. * greater than 0, limits the maximum number of CPUs activated in
  524. * SMP mode to <NUM>.
  525. */
  526. void __weak arch_disable_smp_support(void) { }
  527. static int __init nosmp(char *str)
  528. {
  529. setup_max_cpus = 0;
  530. arch_disable_smp_support();
  531. return 0;
  532. }
  533. early_param("nosmp", nosmp);
  534. /* this is hard limit */
  535. static int __init nrcpus(char *str)
  536. {
  537. int nr_cpus;
  538. get_option(&str, &nr_cpus);
  539. if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
  540. nr_cpu_ids = nr_cpus;
  541. return 0;
  542. }
  543. early_param("nr_cpus", nrcpus);
  544. static int __init maxcpus(char *str)
  545. {
  546. get_option(&str, &setup_max_cpus);
  547. if (setup_max_cpus == 0)
  548. arch_disable_smp_support();
  549. return 0;
  550. }
  551. early_param("maxcpus", maxcpus);
  552. /* Setup number of possible processor ids */
  553. int nr_cpu_ids __read_mostly = NR_CPUS;
  554. EXPORT_SYMBOL(nr_cpu_ids);
  555. /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
  556. void __init setup_nr_cpu_ids(void)
  557. {
  558. nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
  559. }
  560. /* Called by boot processor to activate the rest. */
  561. void __init smp_init(void)
  562. {
  563. unsigned int cpu;
  564. /* FIXME: This should be done in userspace --RR */
  565. for_each_present_cpu(cpu) {
  566. if (num_online_cpus() >= setup_max_cpus)
  567. break;
  568. if (!cpu_online(cpu))
  569. cpu_up(cpu);
  570. }
  571. /* Any cleanup work */
  572. printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
  573. smp_cpus_done(setup_max_cpus);
  574. }
  575. /*
  576. * Call a function on all processors. May be used during early boot while
  577. * early_boot_irqs_disabled is set. Use local_irq_save/restore() instead
  578. * of local_irq_disable/enable().
  579. */
  580. int on_each_cpu(void (*func) (void *info), void *info, int wait)
  581. {
  582. unsigned long flags;
  583. int ret = 0;
  584. preempt_disable();
  585. ret = smp_call_function(func, info, wait);
  586. local_irq_save(flags);
  587. func(info);
  588. local_irq_restore(flags);
  589. preempt_enable();
  590. return ret;
  591. }
  592. EXPORT_SYMBOL(on_each_cpu);