blob: baba3a23a8145c6106177f924dd712b63e7b2f17 [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
Rusty Russellbf200292008-08-26 00:19:27 -05006 disables preeempt. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/cpu.h>
Rusty Russelleeec4fa2008-07-28 12:16:30 -05008#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/system.h>
10
11#if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
Jason Baron5c2aed62008-02-28 11:33:03 -050012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013/**
Rusty Russelleeec4fa2008-07-28 12:16:30 -050014 * stop_machine: freeze the machine on all CPUs and run this function
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * @fn: the function to run
16 * @data: the data ptr for the @fn()
Rusty Russelleeec4fa2008-07-28 12:16:30 -050017 * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 *
Rusty Russellffdb5972008-07-28 12:16:28 -050019 * Description: This causes a thread to be scheduled on every cpu,
20 * each of which disables interrupts. The result is that noone is
21 * holding a spinlock or inside any other preempt-disabled region when
22 * @fn() runs.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 *
24 * This can be thought of as a very heavy write lock, equivalent to
25 * grabbing every spinlock in the kernel. */
Rusty Russell41c7bb92009-01-01 10:12:28 +103026int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/**
Rusty Russelleeec4fa2008-07-28 12:16:30 -050029 * __stop_machine: freeze the machine on all CPUs and run this function
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * @fn: the function to run
31 * @data: the data ptr for the @fn
Rusty Russelleeec4fa2008-07-28 12:16:30 -050032 * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 *
Rusty Russellffdb5972008-07-28 12:16:28 -050034 * Description: This is a special version of the above, which assumes cpus
35 * won't come or go while it's being called. Used by hotplug cpu.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 */
Rusty Russell41c7bb92009-01-01 10:12:28 +103037int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
Heiko Carstens9ea09af2008-12-22 12:36:30 +010038
39/**
40 * stop_machine_create: create all stop_machine threads
41 *
42 * Description: This causes all stop_machine threads to be created before
43 * stop_machine actually gets called. This can be used by subsystems that
44 * need a non failing stop_machine infrastructure.
45 */
46int stop_machine_create(void);
47
48/**
49 * stop_machine_destroy: destroy all stop_machine threads
50 *
51 * Description: This causes all stop_machine threads which were created with
52 * stop_machine_create to be destroyed again.
53 */
54void stop_machine_destroy(void);
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#else
57
Rusty Russelleeec4fa2008-07-28 12:16:30 -050058static inline int stop_machine(int (*fn)(void *), void *data,
Rusty Russell41c7bb92009-01-01 10:12:28 +103059 const struct cpumask *cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 int ret;
62 local_irq_disable();
63 ret = fn(data);
64 local_irq_enable();
65 return ret;
66}
Heiko Carstens9ea09af2008-12-22 12:36:30 +010067
68static inline int stop_machine_create(void) { return 0; }
69static inline void stop_machine_destroy(void) { }
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif /* _LINUX_STOP_MACHINE */