blob: 0e552e72a4c46685cd14a571aa8b68ce80b208a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_STOP_MACHINE
2#define _LINUX_STOP_MACHINE
Tejun Heo1142d812010-05-06 18:49:20 +02003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/cpu.h>
Rusty Russelleeec4fa2008-07-28 12:16:30 -05005#include <linux/cpumask.h>
Tejun Heo1142d812010-05-06 18:49:20 +02006#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/system.h>
8
9#if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
Jason Baron5c2aed62008-02-28 11:33:03 -050010
Tejun Heo1142d812010-05-06 18:49:20 +020011/*
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
22typedef int (*cpu_stop_fn_t)(void *arg);
23
24struct 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
31int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
32void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
33 struct cpu_stop_work *work_buf);
34int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg);
35int 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/**
Rusty Russelleeec4fa2008-07-28 12:16:30 -050045 * stop_machine: freeze the machine on all CPUs and run this function
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * @fn: the function to run
47 * @data: the data ptr for the @fn()
Rusty Russelleeec4fa2008-07-28 12:16:30 -050048 * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 *
Rusty Russellffdb5972008-07-28 12:16:28 -050050 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 *
55 * This can be thought of as a very heavy write lock, equivalent to
56 * grabbing every spinlock in the kernel. */
Rusty Russell41c7bb92009-01-01 10:12:28 +103057int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/**
Rusty Russelleeec4fa2008-07-28 12:16:30 -050060 * __stop_machine: freeze the machine on all CPUs and run this function
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * @fn: the function to run
62 * @data: the data ptr for the @fn
Rusty Russelleeec4fa2008-07-28 12:16:30 -050063 * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 *
Rusty Russellffdb5972008-07-28 12:16:28 -050065 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
Rusty Russell41c7bb92009-01-01 10:12:28 +103068int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
Heiko Carstens9ea09af2008-12-22 12:36:30 +010069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#else
71
Rusty Russelleeec4fa2008-07-28 12:16:30 -050072static inline int stop_machine(int (*fn)(void *), void *data,
Rusty Russell41c7bb92009-01-01 10:12:28 +103073 const struct cpumask *cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 int ret;
76 local_irq_disable();
77 ret = fn(data);
78 local_irq_enable();
79 return ret;
80}
Heiko Carstens9ea09af2008-12-22 12:36:30 +010081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#endif /* _LINUX_STOP_MACHINE */