Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/cpu.h> |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 8 | #include <linux/cpumask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/system.h> |
| 10 | |
| 11 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) |
Jason Baron | 5c2aed6 | 2008-02-28 11:33:03 -0500 | [diff] [blame] | 12 | |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 13 | /* Deprecated, but useful for transition. */ |
Jason Baron | 5c2aed6 | 2008-02-28 11:33:03 -0500 | [diff] [blame] | 14 | #define ALL_CPUS ~0U |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 17 | * stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * @fn: the function to run |
| 19 | * @data: the data ptr for the @fn() |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 20 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 22 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * |
| 27 | * This can be thought of as a very heavy write lock, equivalent to |
| 28 | * grabbing every spinlock in the kernel. */ |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 29 | int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 32 | * __stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * @fn: the function to run |
| 34 | * @data: the data ptr for the @fn |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 35 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 37 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 40 | int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #else |
| 42 | |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 43 | static inline int stop_machine(int (*fn)(void *), void *data, |
| 44 | const cpumask_t *cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | int ret; |
| 47 | local_irq_disable(); |
| 48 | ret = fn(data); |
| 49 | local_irq_enable(); |
| 50 | return ret; |
| 51 | } |
| 52 | #endif /* CONFIG_SMP */ |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame^] | 53 | |
| 54 | static inline int __deprecated stop_machine_run(int (*fn)(void *), void *data, |
| 55 | unsigned int cpu) |
| 56 | { |
| 57 | /* If they don't care which cpu fn runs on, just pick one. */ |
| 58 | if (cpu == NR_CPUS) |
| 59 | return stop_machine(fn, data, NULL); |
| 60 | else if (cpu == ~0U) |
| 61 | return stop_machine(fn, data, &cpu_possible_map); |
| 62 | else { |
| 63 | cpumask_t cpus = cpumask_of_cpu(cpu); |
| 64 | return stop_machine(fn, data, &cpus); |
| 65 | } |
| 66 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #endif /* _LINUX_STOP_MACHINE */ |