blob: 36c2c7284eb3a0354a69b3112401bec4a0c24c92 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_STOP_MACHINE
2#define _LINUX_STOP_MACHINE
3/* "Bogolock": stop the entire machine, disable interrupts. This is a
4 very heavy lock, which is equivalent to grabbing every spinlock
5 (and more). So the "read" side to such a lock is anything which
6 diables preeempt. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/cpu.h>
8#include <asm/system.h>
9
10#if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
Jason Baron5c2aed62008-02-28 11:33:03 -050011
12#define ALL_CPUS ~0U
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/**
15 * stop_machine_run: freeze the machine on all CPUs and run this function
16 * @fn: the function to run
17 * @data: the data ptr for the @fn()
Jason Baron5c2aed62008-02-28 11:33:03 -050018 * @cpu: if @cpu == n, run @fn() on cpu n
19 * if @cpu == NR_CPUS, run @fn() on any cpu
Rusty Russellffdb5972008-07-28 12:16:28 -050020 * if @cpu == ALL_CPUS, run @fn() on every online CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
Rusty Russellffdb5972008-07-28 12:16:28 -050022 * Description: This causes a thread to be scheduled on every cpu,
23 * each of which disables interrupts. The result is that noone is
24 * holding a spinlock or inside any other preempt-disabled region when
25 * @fn() runs.
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
27 * This can be thought of as a very heavy write lock, equivalent to
28 * grabbing every spinlock in the kernel. */
29int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
30
31/**
32 * __stop_machine_run: freeze the machine on all CPUs and run this function
33 * @fn: the function to run
34 * @data: the data ptr for the @fn
35 * @cpu: the cpu to run @fn on (or any, if @cpu == NR_CPUS.
36 *
Rusty Russellffdb5972008-07-28 12:16:28 -050037 * Description: This is a special version of the above, which assumes cpus
38 * won't come or go while it's being called. Used by hotplug cpu.
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 */
Rusty Russellffdb5972008-07-28 12:16:28 -050040int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#else
42
43static inline int stop_machine_run(int (*fn)(void *), void *data,
44 unsigned int cpu)
45{
46 int ret;
47 local_irq_disable();
48 ret = fn(data);
49 local_irq_enable();
50 return ret;
51}
52#endif /* CONFIG_SMP */
53#endif /* _LINUX_STOP_MACHINE */