stop_machine: reimplement using cpu_stop
[safe/jmp/linux-2.6] / include / linux / stop_machine.h
1 #ifndef _LINUX_STOP_MACHINE
2 #define _LINUX_STOP_MACHINE
3
4 #include <linux/cpu.h>
5 #include <linux/cpumask.h>
6 #include <linux/list.h>
7 #include <asm/system.h>
8
9 #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
10
11 /*
12  * stop_cpu[s]() is simplistic per-cpu maximum priority cpu
13  * monopolization mechanism.  The caller can specify a non-sleeping
14  * function to be executed on a single or multiple cpus preempting all
15  * other processes and monopolizing those cpus until it finishes.
16  *
17  * Resources for this mechanism are preallocated when a cpu is brought
18  * up and requests are guaranteed to be served as long as the target
19  * cpus are online.
20  */
21
22 typedef int (*cpu_stop_fn_t)(void *arg);
23
24 struct cpu_stop_work {
25         struct list_head        list;           /* cpu_stopper->works */
26         cpu_stop_fn_t           fn;
27         void                    *arg;
28         struct cpu_stop_done    *done;
29 };
30
31 int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
32 void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
33                          struct cpu_stop_work *work_buf);
34 int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg);
35 int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg);
36
37 /*
38  * stop_machine "Bogolock": stop the entire machine, disable
39  * interrupts.  This is a very heavy lock, which is equivalent to
40  * grabbing every spinlock (and more).  So the "read" side to such a
41  * lock is anything which disables preeempt.
42  */
43
44 /**
45  * stop_machine: freeze the machine on all CPUs and run this function
46  * @fn: the function to run
47  * @data: the data ptr for the @fn()
48  * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
49  *
50  * Description: This causes a thread to be scheduled on every cpu,
51  * each of which disables interrupts.  The result is that noone is
52  * holding a spinlock or inside any other preempt-disabled region when
53  * @fn() runs.
54  *
55  * This can be thought of as a very heavy write lock, equivalent to
56  * grabbing every spinlock in the kernel. */
57 int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
58
59 /**
60  * __stop_machine: freeze the machine on all CPUs and run this function
61  * @fn: the function to run
62  * @data: the data ptr for the @fn
63  * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
64  *
65  * Description: This is a special version of the above, which assumes cpus
66  * won't come or go while it's being called.  Used by hotplug cpu.
67  */
68 int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
69
70 #else
71
72 static inline int stop_machine(int (*fn)(void *), void *data,
73                                const struct cpumask *cpus)
74 {
75         int ret;
76         local_irq_disable();
77         ret = fn(data);
78         local_irq_enable();
79         return ret;
80 }
81
82 #endif /* CONFIG_SMP */
83 #endif /* _LINUX_STOP_MACHINE */