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 |
Rusty Russell | bf20029 | 2008-08-26 00:19:27 -0500 | [diff] [blame] | 6 | disables 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 14 | * stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * @fn: the function to run |
| 16 | * @data: the data ptr for the @fn() |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 17 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 19 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
| 24 | * This can be thought of as a very heavy write lock, equivalent to |
| 25 | * grabbing every spinlock in the kernel. */ |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 26 | int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 29 | * __stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * @fn: the function to run |
| 31 | * @data: the data ptr for the @fn |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 32 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 34 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 37 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
Heiko Carstens | 9ea09af | 2008-12-22 12:36:30 +0100 | [diff] [blame] | 38 | |
| 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 | */ |
| 46 | int 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 | */ |
| 54 | void stop_machine_destroy(void); |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #else |
| 57 | |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 58 | static inline int stop_machine(int (*fn)(void *), void *data, |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 59 | const struct cpumask *cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | int ret; |
| 62 | local_irq_disable(); |
| 63 | ret = fn(data); |
| 64 | local_irq_enable(); |
| 65 | return ret; |
| 66 | } |
Heiko Carstens | 9ea09af | 2008-12-22 12:36:30 +0100 | [diff] [blame] | 67 | |
| 68 | static inline int stop_machine_create(void) { return 0; } |
| 69 | static inline void stop_machine_destroy(void) { } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #endif /* CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #endif /* _LINUX_STOP_MACHINE */ |