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