smp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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/export.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. #include "smpboot.h"
  16. enum {
  17. CSD_FLAG_LOCK = 0x01,
  18. CSD_FLAG_WAIT = 0x02,
  19. };
  20. struct call_function_data {
  21. struct call_single_data __percpu *csd;
  22. cpumask_var_t cpumask;
  23. };
  24. static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_function_data, cfd_data);
  25. static DEFINE_PER_CPU_SHARED_ALIGNED(struct llist_head, call_single_queue);
  26. static void flush_smp_call_function_queue(bool warn_cpu_offline);
  27. static int
  28. hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
  29. {
  30. long cpu = (long)hcpu;
  31. struct call_function_data *cfd = &per_cpu(cfd_data, cpu);
  32. switch (action) {
  33. case CPU_UP_PREPARE:
  34. case CPU_UP_PREPARE_FROZEN:
  35. if (!zalloc_cpumask_var_node(&cfd->cpumask, GFP_KERNEL,
  36. cpu_to_node(cpu)))
  37. return notifier_from_errno(-ENOMEM);
  38. cfd->csd = alloc_percpu(struct call_single_data);
  39. if (!cfd->csd) {
  40. free_cpumask_var(cfd->cpumask);
  41. return notifier_from_errno(-ENOMEM);
  42. }
  43. break;
  44. #ifdef CONFIG_HOTPLUG_CPU
  45. case CPU_UP_CANCELED:
  46. case CPU_UP_CANCELED_FROZEN:
  47. /* Fall-through to the CPU_DEAD[_FROZEN] case. */
  48. case CPU_DEAD:
  49. case CPU_DEAD_FROZEN:
  50. free_cpumask_var(cfd->cpumask);
  51. free_percpu(cfd->csd);
  52. break;
  53. case CPU_DYING:
  54. case CPU_DYING_FROZEN:
  55. /*
  56. * The IPIs for the smp-call-function callbacks queued by other
  57. * CPUs might arrive late, either due to hardware latencies or
  58. * because this CPU disabled interrupts (inside stop-machine)
  59. * before the IPIs were sent. So flush out any pending callbacks
  60. * explicitly (without waiting for the IPIs to arrive), to
  61. * ensure that the outgoing CPU doesn't go offline with work
  62. * still pending.
  63. */
  64. flush_smp_call_function_queue(false);
  65. break;
  66. #endif
  67. };
  68. return NOTIFY_OK;
  69. }
  70. static struct notifier_block hotplug_cfd_notifier = {
  71. .notifier_call = hotplug_cfd,
  72. };
  73. void __init call_function_init(void)
  74. {
  75. void *cpu = (void *)(long)smp_processor_id();
  76. int i;
  77. for_each_possible_cpu(i)
  78. init_llist_head(&per_cpu(call_single_queue, i));
  79. hotplug_cfd(&hotplug_cfd_notifier, CPU_UP_PREPARE, cpu);
  80. register_cpu_notifier(&hotplug_cfd_notifier);
  81. }
  82. /*
  83. * csd_lock/csd_unlock used to serialize access to per-cpu csd resources
  84. *
  85. * For non-synchronous ipi calls the csd can still be in use by the
  86. * previous function call. For multi-cpu calls its even more interesting
  87. * as we'll have to ensure no other cpu is observing our csd.
  88. */
  89. static void csd_lock_wait(struct call_single_data *csd)
  90. {
  91. while (csd->flags & CSD_FLAG_LOCK)
  92. cpu_relax();
  93. }
  94. static void csd_lock(struct call_single_data *csd)
  95. {
  96. csd_lock_wait(csd);
  97. csd->flags |= CSD_FLAG_LOCK;
  98. /*
  99. * prevent CPU from reordering the above assignment
  100. * to ->flags with any subsequent assignments to other
  101. * fields of the specified call_single_data structure:
  102. */
  103. smp_mb();
  104. }
  105. static void csd_unlock(struct call_single_data *csd)
  106. {
  107. WARN_ON((csd->flags & CSD_FLAG_WAIT) && !(csd->flags & CSD_FLAG_LOCK));
  108. /*
  109. * ensure we're all done before releasing data:
  110. */
  111. smp_mb();
  112. csd->flags &= ~CSD_FLAG_LOCK;
  113. }
  114. static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data);
  115. /*
  116. * Insert a previously allocated call_single_data element
  117. * for execution on the given CPU. data must already have
  118. * ->func, ->info, and ->flags set.
  119. */
  120. static int generic_exec_single(int cpu, struct call_single_data *csd,
  121. smp_call_func_t func, void *info, int wait)
  122. {
  123. struct call_single_data csd_stack = { .flags = 0 };
  124. unsigned long flags;
  125. if (cpu == smp_processor_id()) {
  126. local_irq_save(flags);
  127. func(info);
  128. local_irq_restore(flags);
  129. return 0;
  130. }
  131. if ((unsigned)cpu >= nr_cpu_ids || !cpu_online(cpu))
  132. return -ENXIO;
  133. if (!csd) {
  134. csd = &csd_stack;
  135. if (!wait)
  136. csd = &__get_cpu_var(csd_data);
  137. }
  138. csd_lock(csd);
  139. csd->func = func;
  140. csd->info = info;
  141. if (wait)
  142. csd->flags |= CSD_FLAG_WAIT;
  143. /*
  144. * The list addition should be visible before sending the IPI
  145. * handler locks the list to pull the entry off it because of
  146. * normal cache coherency rules implied by spinlocks.
  147. *
  148. * If IPIs can go out of order to the cache coherency protocol
  149. * in an architecture, sufficient synchronisation should be added
  150. * to arch code to make it appear to obey cache coherency WRT
  151. * locking and barrier primitives. Generic code isn't really
  152. * equipped to do the right thing...
  153. */
  154. if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu)))
  155. arch_send_call_function_single_ipi(cpu);
  156. if (wait)
  157. csd_lock_wait(csd);
  158. return 0;
  159. }
  160. /**
  161. * generic_smp_call_function_single_interrupt - Execute SMP IPI callbacks
  162. *
  163. * Invoked by arch to handle an IPI for call function single.
  164. * Must be called with interrupts disabled.
  165. */
  166. void generic_smp_call_function_single_interrupt(void)
  167. {
  168. flush_smp_call_function_queue(true);
  169. }
  170. /**
  171. * flush_smp_call_function_queue - Flush pending smp-call-function callbacks
  172. *
  173. * @warn_cpu_offline: If set to 'true', warn if callbacks were queued on an
  174. * offline CPU. Skip this check if set to 'false'.
  175. *
  176. * Flush any pending smp-call-function callbacks queued on this CPU. This is
  177. * invoked by the generic IPI handler, as well as by a CPU about to go offline,
  178. * to ensure that all pending IPI callbacks are run before it goes completely
  179. * offline.
  180. *
  181. * Loop through the call_single_queue and run all the queued callbacks.
  182. * Must be called with interrupts disabled.
  183. */
  184. static void flush_smp_call_function_queue(bool warn_cpu_offline)
  185. {
  186. struct llist_head *head;
  187. struct llist_node *entry;
  188. struct call_single_data *csd, *csd_next;
  189. static bool warned;
  190. WARN_ON(!irqs_disabled());
  191. head = &__get_cpu_var(call_single_queue);
  192. entry = llist_del_all(head);
  193. entry = llist_reverse_order(entry);
  194. /* There shouldn't be any pending callbacks on an offline CPU. */
  195. if (unlikely(warn_cpu_offline && !cpu_online(smp_processor_id()) &&
  196. !warned && !llist_empty(head))) {
  197. warned = true;
  198. WARN(1, "IPI on offline CPU %d\n", smp_processor_id());
  199. /*
  200. * We don't have to use the _safe() variant here
  201. * because we are not invoking the IPI handlers yet.
  202. */
  203. llist_for_each_entry(csd, entry, llist)
  204. pr_warn("IPI callback %pS sent to offline CPU\n",
  205. csd->func);
  206. }
  207. llist_for_each_entry_safe(csd, csd_next, entry, llist) {
  208. csd->func(csd->info);
  209. csd_unlock(csd);
  210. }
  211. }
  212. /*
  213. * smp_call_function_single - Run a function on a specific CPU
  214. * @func: The function to run. This must be fast and non-blocking.
  215. * @info: An arbitrary pointer to pass to the function.
  216. * @wait: If true, wait until function has completed on other CPUs.
  217. *
  218. * Returns 0 on success, else a negative status code.
  219. */
  220. int smp_call_function_single(int cpu, smp_call_func_t func, void *info,
  221. int wait)
  222. {
  223. int this_cpu;
  224. int err;
  225. /*
  226. * prevent preemption and reschedule on another processor,
  227. * as well as CPU removal
  228. */
  229. this_cpu = get_cpu();
  230. /*
  231. * Can deadlock when called with interrupts disabled.
  232. * We allow cpu's that are not yet online though, as no one else can
  233. * send smp call function interrupt to this cpu and as such deadlocks
  234. * can't happen.
  235. */
  236. WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
  237. && !oops_in_progress);
  238. err = generic_exec_single(cpu, NULL, func, info, wait);
  239. put_cpu();
  240. return err;
  241. }
  242. EXPORT_SYMBOL(smp_call_function_single);
  243. /**
  244. * smp_call_function_single_async(): Run an asynchronous function on a
  245. * specific CPU.
  246. * @cpu: The CPU to run on.
  247. * @csd: Pre-allocated and setup data structure
  248. *
  249. * Like smp_call_function_single(), but the call is asynchonous and
  250. * can thus be done from contexts with disabled interrupts.
  251. *
  252. * The caller passes his own pre-allocated data structure
  253. * (ie: embedded in an object) and is responsible for synchronizing it
  254. * such that the IPIs performed on the @csd are strictly serialized.
  255. *
  256. * NOTE: Be careful, there is unfortunately no current debugging facility to
  257. * validate the correctness of this serialization.
  258. */
  259. int smp_call_function_single_async(int cpu, struct call_single_data *csd)
  260. {
  261. int err = 0;
  262. preempt_disable();
  263. err = generic_exec_single(cpu, csd, csd->func, csd->info, 0);
  264. preempt_enable();
  265. return err;
  266. }
  267. EXPORT_SYMBOL_GPL(smp_call_function_single_async);
  268. /*
  269. * smp_call_function_any - Run a function on any of the given cpus
  270. * @mask: The mask of cpus it can run on.
  271. * @func: The function to run. This must be fast and non-blocking.
  272. * @info: An arbitrary pointer to pass to the function.
  273. * @wait: If true, wait until function has completed.
  274. *
  275. * Returns 0 on success, else a negative status code (if no cpus were online).
  276. *
  277. * Selection preference:
  278. * 1) current cpu if in @mask
  279. * 2) any cpu of current node if in @mask
  280. * 3) any other online cpu in @mask
  281. */
  282. int smp_call_function_any(const struct cpumask *mask,
  283. smp_call_func_t func, void *info, int wait)
  284. {
  285. unsigned int cpu;
  286. const struct cpumask *nodemask;
  287. int ret;
  288. /* Try for same CPU (cheapest) */
  289. cpu = get_cpu();
  290. if (cpumask_test_cpu(cpu, mask))
  291. goto call;
  292. /* Try for same node. */
  293. nodemask = cpumask_of_node(cpu_to_node(cpu));
  294. for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
  295. cpu = cpumask_next_and(cpu, nodemask, mask)) {
  296. if (cpu_online(cpu))
  297. goto call;
  298. }
  299. /* Any online will do: smp_call_function_single handles nr_cpu_ids. */
  300. cpu = cpumask_any_and(mask, cpu_online_mask);
  301. call:
  302. ret = smp_call_function_single(cpu, func, info, wait);
  303. put_cpu();
  304. return ret;
  305. }
  306. EXPORT_SYMBOL_GPL(smp_call_function_any);
  307. /**
  308. * smp_call_function_many(): Run a function on a set of other CPUs.
  309. * @mask: The set of cpus to run on (only runs on online subset).
  310. * @func: The function to run. This must be fast and non-blocking.
  311. * @info: An arbitrary pointer to pass to the function.
  312. * @wait: If true, wait (atomically) until function has completed
  313. * on other CPUs.
  314. *
  315. * If @wait is true, then returns once @func has returned.
  316. *
  317. * You must not call this function with disabled interrupts or from a
  318. * hardware interrupt handler or from a bottom half handler. Preemption
  319. * must be disabled when calling this function.
  320. */
  321. void smp_call_function_many(const struct cpumask *mask,
  322. smp_call_func_t func, void *info, bool wait)
  323. {
  324. struct call_function_data *cfd;
  325. int cpu, next_cpu, this_cpu = smp_processor_id();
  326. /*
  327. * Can deadlock when called with interrupts disabled.
  328. * We allow cpu's that are not yet online though, as no one else can
  329. * send smp call function interrupt to this cpu and as such deadlocks
  330. * can't happen.
  331. */
  332. WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
  333. && !oops_in_progress && !early_boot_irqs_disabled);
  334. /* Try to fastpath. So, what's a CPU they want? Ignoring this one. */
  335. cpu = cpumask_first_and(mask, cpu_online_mask);
  336. if (cpu == this_cpu)
  337. cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
  338. /* No online cpus? We're done. */
  339. if (cpu >= nr_cpu_ids)
  340. return;
  341. /* Do we have another CPU which isn't us? */
  342. next_cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
  343. if (next_cpu == this_cpu)
  344. next_cpu = cpumask_next_and(next_cpu, mask, cpu_online_mask);
  345. /* Fastpath: do that cpu by itself. */
  346. if (next_cpu >= nr_cpu_ids) {
  347. smp_call_function_single(cpu, func, info, wait);
  348. return;
  349. }
  350. cfd = &__get_cpu_var(cfd_data);
  351. cpumask_and(cfd->cpumask, mask, cpu_online_mask);
  352. cpumask_clear_cpu(this_cpu, cfd->cpumask);
  353. /* Some callers race with other cpus changing the passed mask */
  354. if (unlikely(!cpumask_weight(cfd->cpumask)))
  355. return;
  356. for_each_cpu(cpu, cfd->cpumask) {
  357. struct call_single_data *csd = per_cpu_ptr(cfd->csd, cpu);
  358. csd_lock(csd);
  359. csd->func = func;
  360. csd->info = info;
  361. llist_add(&csd->llist, &per_cpu(call_single_queue, cpu));
  362. }
  363. /* Send a message to all CPUs in the map */
  364. arch_send_call_function_ipi_mask(cfd->cpumask);
  365. if (wait) {
  366. for_each_cpu(cpu, cfd->cpumask) {
  367. struct call_single_data *csd;
  368. csd = per_cpu_ptr(cfd->csd, cpu);
  369. csd_lock_wait(csd);
  370. }
  371. }
  372. }
  373. EXPORT_SYMBOL(smp_call_function_many);
  374. /**
  375. * smp_call_function(): Run a function on all other CPUs.
  376. * @func: The function to run. This must be fast and non-blocking.
  377. * @info: An arbitrary pointer to pass to the function.
  378. * @wait: If true, wait (atomically) until function has completed
  379. * on other CPUs.
  380. *
  381. * Returns 0.
  382. *
  383. * If @wait is true, then returns once @func has returned; otherwise
  384. * it returns just before the target cpu calls @func.
  385. *
  386. * You must not call this function with disabled interrupts or from a
  387. * hardware interrupt handler or from a bottom half handler.
  388. */
  389. int smp_call_function(smp_call_func_t func, void *info, int wait)
  390. {
  391. preempt_disable();
  392. smp_call_function_many(cpu_online_mask, func, info, wait);
  393. preempt_enable();
  394. return 0;
  395. }
  396. EXPORT_SYMBOL(smp_call_function);
  397. /* Setup configured maximum number of CPUs to activate */
  398. unsigned int setup_max_cpus = NR_CPUS;
  399. EXPORT_SYMBOL(setup_max_cpus);
  400. /*
  401. * Setup routine for controlling SMP activation
  402. *
  403. * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
  404. * activation entirely (the MPS table probe still happens, though).
  405. *
  406. * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
  407. * greater than 0, limits the maximum number of CPUs activated in
  408. * SMP mode to <NUM>.
  409. */
  410. void __weak arch_disable_smp_support(void) { }
  411. static int __init nosmp(char *str)
  412. {
  413. setup_max_cpus = 0;
  414. arch_disable_smp_support();
  415. return 0;
  416. }
  417. early_param("nosmp", nosmp);
  418. /* this is hard limit */
  419. static int __init nrcpus(char *str)
  420. {
  421. int nr_cpus;
  422. get_option(&str, &nr_cpus);
  423. if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
  424. nr_cpu_ids = nr_cpus;
  425. return 0;
  426. }
  427. early_param("nr_cpus", nrcpus);
  428. static int __init maxcpus(char *str)
  429. {
  430. get_option(&str, &setup_max_cpus);
  431. if (setup_max_cpus == 0)
  432. arch_disable_smp_support();
  433. return 0;
  434. }
  435. early_param("maxcpus", maxcpus);
  436. /* Setup number of possible processor ids */
  437. int nr_cpu_ids __read_mostly = NR_CPUS;
  438. EXPORT_SYMBOL(nr_cpu_ids);
  439. /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
  440. void __init setup_nr_cpu_ids(void)
  441. {
  442. nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
  443. }
  444. void __weak smp_announce(void)
  445. {
  446. printk(KERN_INFO "Brought up %d CPUs\n", num_online_cpus());
  447. }
  448. /* Called by boot processor to activate the rest. */
  449. void __init smp_init(void)
  450. {
  451. unsigned int cpu;
  452. idle_threads_init();
  453. /* FIXME: This should be done in userspace --RR */
  454. for_each_present_cpu(cpu) {
  455. if (num_online_cpus() >= setup_max_cpus)
  456. break;
  457. if (!cpu_online(cpu))
  458. cpu_up(cpu);
  459. }
  460. /* Any cleanup work */
  461. smp_announce();
  462. smp_cpus_done(setup_max_cpus);
  463. }
  464. /*
  465. * Call a function on all processors. May be used during early boot while
  466. * early_boot_irqs_disabled is set. Use local_irq_save/restore() instead
  467. * of local_irq_disable/enable().
  468. */
  469. int on_each_cpu(void (*func) (void *info), void *info, int wait)
  470. {
  471. unsigned long flags;
  472. int ret = 0;
  473. preempt_disable();
  474. ret = smp_call_function(func, info, wait);
  475. local_irq_save(flags);
  476. func(info);
  477. local_irq_restore(flags);
  478. preempt_enable();
  479. return ret;
  480. }
  481. EXPORT_SYMBOL(on_each_cpu);
  482. /**
  483. * on_each_cpu_mask(): Run a function on processors specified by
  484. * cpumask, which may include the local processor.
  485. * @mask: The set of cpus to run on (only runs on online subset).
  486. * @func: The function to run. This must be fast and non-blocking.
  487. * @info: An arbitrary pointer to pass to the function.
  488. * @wait: If true, wait (atomically) until function has completed
  489. * on other CPUs.
  490. *
  491. * If @wait is true, then returns once @func has returned.
  492. *
  493. * You must not call this function with disabled interrupts or from a
  494. * hardware interrupt handler or from a bottom half handler. The
  495. * exception is that it may be used during early boot while
  496. * early_boot_irqs_disabled is set.
  497. */
  498. void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
  499. void *info, bool wait)
  500. {
  501. int cpu = get_cpu();
  502. smp_call_function_many(mask, func, info, wait);
  503. if (cpumask_test_cpu(cpu, mask)) {
  504. unsigned long flags;
  505. local_irq_save(flags);
  506. func(info);
  507. local_irq_restore(flags);
  508. }
  509. put_cpu();
  510. }
  511. EXPORT_SYMBOL(on_each_cpu_mask);
  512. /*
  513. * on_each_cpu_cond(): Call a function on each processor for which
  514. * the supplied function cond_func returns true, optionally waiting
  515. * for all the required CPUs to finish. This may include the local
  516. * processor.
  517. * @cond_func: A callback function that is passed a cpu id and
  518. * the the info parameter. The function is called
  519. * with preemption disabled. The function should
  520. * return a blooean value indicating whether to IPI
  521. * the specified CPU.
  522. * @func: The function to run on all applicable CPUs.
  523. * This must be fast and non-blocking.
  524. * @info: An arbitrary pointer to pass to both functions.
  525. * @wait: If true, wait (atomically) until function has
  526. * completed on other CPUs.
  527. * @gfp_flags: GFP flags to use when allocating the cpumask
  528. * used internally by the function.
  529. *
  530. * The function might sleep if the GFP flags indicates a non
  531. * atomic allocation is allowed.
  532. *
  533. * Preemption is disabled to protect against CPUs going offline but not online.
  534. * CPUs going online during the call will not be seen or sent an IPI.
  535. *
  536. * You must not call this function with disabled interrupts or
  537. * from a hardware interrupt handler or from a bottom half handler.
  538. */
  539. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  540. smp_call_func_t func, void *info, bool wait,
  541. gfp_t gfp_flags)
  542. {
  543. cpumask_var_t cpus;
  544. int cpu, ret;
  545. might_sleep_if(gfp_flags & __GFP_WAIT);
  546. if (likely(zalloc_cpumask_var(&cpus, (gfp_flags|__GFP_NOWARN)))) {
  547. preempt_disable();
  548. for_each_online_cpu(cpu)
  549. if (cond_func(cpu, info))
  550. cpumask_set_cpu(cpu, cpus);
  551. on_each_cpu_mask(cpus, func, info, wait);
  552. preempt_enable();
  553. free_cpumask_var(cpus);
  554. } else {
  555. /*
  556. * No free cpumask, bother. No matter, we'll
  557. * just have to IPI them one by one.
  558. */
  559. preempt_disable();
  560. for_each_online_cpu(cpu)
  561. if (cond_func(cpu, info)) {
  562. ret = smp_call_function_single(cpu, func,
  563. info, wait);
  564. WARN_ON_ONCE(!ret);
  565. }
  566. preempt_enable();
  567. }
  568. }
  569. EXPORT_SYMBOL(on_each_cpu_cond);
  570. static void do_nothing(void *unused)
  571. {
  572. }
  573. /**
  574. * kick_all_cpus_sync - Force all cpus out of idle
  575. *
  576. * Used to synchronize the update of pm_idle function pointer. It's
  577. * called after the pointer is updated and returns after the dummy
  578. * callback function has been executed on all cpus. The execution of
  579. * the function can only happen on the remote cpus after they have
  580. * left the idle function which had been called via pm_idle function
  581. * pointer. So it's guaranteed that nothing uses the previous pointer
  582. * anymore.
  583. */
  584. void kick_all_cpus_sync(void)
  585. {
  586. /* Make sure the change is visible before we kick the cpus */
  587. smp_mb();
  588. smp_call_function(do_nothing, NULL, 1);
  589. }
  590. EXPORT_SYMBOL_GPL(kick_all_cpus_sync);