smp.c 18 KB

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