1 #ifndef _LINUX_STOP_MACHINE
2 #define _LINUX_STOP_MACHINE
5 #include <linux/cpumask.h>
6 #include <linux/list.h>
7 #include <asm/system.h>
9 #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
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.
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
22 typedef int (*cpu_stop_fn_t)(void *arg);
24 struct cpu_stop_work {
25 struct list_head list; /* cpu_stopper->works */
28 struct cpu_stop_done *done;
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);
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.
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)
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
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);
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)
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.
68 int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
71 * stop_machine_create: create all stop_machine threads
73 * Description: This causes all stop_machine threads to be created before
74 * stop_machine actually gets called. This can be used by subsystems that
75 * need a non failing stop_machine infrastructure.
77 int stop_machine_create(void);
80 * stop_machine_destroy: destroy all stop_machine threads
82 * Description: This causes all stop_machine threads which were created with
83 * stop_machine_create to be destroyed again.
85 void stop_machine_destroy(void);
89 static inline int stop_machine(int (*fn)(void *), void *data,
90 const struct cpumask *cpus)
99 static inline int stop_machine_create(void) { return 0; }
100 static inline void stop_machine_destroy(void) { }
102 #endif /* CONFIG_SMP */
103 #endif /* _LINUX_STOP_MACHINE */