smp.c 18 KB

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