blob: 18af011c13af390d2746db739c98347caacb4ddf [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
20 * if @cpu == ALL_CPUS, run @fn() first on the calling cpu, and then
21 * concurrently on all the other cpus
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * Description: This causes a thread to be scheduled on every other cpu,
24 * each of which disables interrupts, and finally interrupts are disabled
25 * on the current CPU. The result is that noone is holding a spinlock
26 * or inside any other preempt-disabled region when @fn() runs.
27 *
28 * This can be thought of as a very heavy write lock, equivalent to
29 * grabbing every spinlock in the kernel. */
30int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
31
32/**
33 * __stop_machine_run: freeze the machine on all CPUs and run this function
34 * @fn: the function to run
35 * @data: the data ptr for the @fn
36 * @cpu: the cpu to run @fn on (or any, if @cpu == NR_CPUS.
37 *
38 * Description: This is a special version of the above, which returns the
39 * thread which has run @fn(): kthread_stop will return the return value
40 * of @fn(). Used by hotplug cpu.
41 */
42struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
43 unsigned int cpu);
44
45#else
46
47static inline int stop_machine_run(int (*fn)(void *), void *data,
48 unsigned int cpu)
49{
50 int ret;
51 local_irq_disable();
52 ret = fn(data);
53 local_irq_enable();
54 return ret;
55}
56#endif /* CONFIG_SMP */
57#endif /* _LINUX_STOP_MACHINE */