Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_STOP_MACHINE |
| 2 | #define _LINUX_STOP_MACHINE |
Tejun Heo | 1142d81 | 2010-05-06 18:49:20 +0200 | [diff] [blame^] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/cpu.h> |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 5 | #include <linux/cpumask.h> |
Tejun Heo | 1142d81 | 2010-05-06 18:49:20 +0200 | [diff] [blame^] | 6 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <asm/system.h> |
| 8 | |
| 9 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) |
Jason Baron | 5c2aed6 | 2008-02-28 11:33:03 -0500 | [diff] [blame] | 10 | |
Tejun Heo | 1142d81 | 2010-05-06 18:49:20 +0200 | [diff] [blame^] | 11 | /* |
| 12 | * stop_cpu[s]() is simplistic per-cpu maximum priority cpu |
| 13 | * monopolization mechanism. The caller can specify a non-sleeping |
| 14 | * function to be executed on a single or multiple cpus preempting all |
| 15 | * other processes and monopolizing those cpus until it finishes. |
| 16 | * |
| 17 | * Resources for this mechanism are preallocated when a cpu is brought |
| 18 | * up and requests are guaranteed to be served as long as the target |
| 19 | * cpus are online. |
| 20 | */ |
| 21 | |
| 22 | typedef int (*cpu_stop_fn_t)(void *arg); |
| 23 | |
| 24 | struct cpu_stop_work { |
| 25 | struct list_head list; /* cpu_stopper->works */ |
| 26 | cpu_stop_fn_t fn; |
| 27 | void *arg; |
| 28 | struct cpu_stop_done *done; |
| 29 | }; |
| 30 | |
| 31 | int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg); |
| 32 | void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg, |
| 33 | struct cpu_stop_work *work_buf); |
| 34 | int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); |
| 35 | int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); |
| 36 | |
| 37 | /* |
| 38 | * stop_machine "Bogolock": stop the entire machine, disable |
| 39 | * interrupts. This is a very heavy lock, which is equivalent to |
| 40 | * grabbing every spinlock (and more). So the "read" side to such a |
| 41 | * lock is anything which disables preeempt. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 45 | * stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | * @fn: the function to run |
| 47 | * @data: the data ptr for the @fn() |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 48 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 50 | * Description: This causes a thread to be scheduled on every cpu, |
| 51 | * each of which disables interrupts. The result is that noone is |
| 52 | * holding a spinlock or inside any other preempt-disabled region when |
| 53 | * @fn() runs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * |
| 55 | * This can be thought of as a very heavy write lock, equivalent to |
| 56 | * grabbing every spinlock in the kernel. */ |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 57 | int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 60 | * __stop_machine: freeze the machine on all CPUs and run this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * @fn: the function to run |
| 62 | * @data: the data ptr for the @fn |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 63 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * |
Rusty Russell | ffdb597 | 2008-07-28 12:16:28 -0500 | [diff] [blame] | 65 | * Description: This is a special version of the above, which assumes cpus |
| 66 | * 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] | 67 | */ |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 68 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
Heiko Carstens | 9ea09af | 2008-12-22 12:36:30 +0100 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * stop_machine_create: create all stop_machine threads |
| 72 | * |
| 73 | * Description: This causes all stop_machine threads to be created before |
| 74 | * stop_machine actually gets called. This can be used by subsystems that |
| 75 | * need a non failing stop_machine infrastructure. |
| 76 | */ |
| 77 | int stop_machine_create(void); |
| 78 | |
| 79 | /** |
| 80 | * stop_machine_destroy: destroy all stop_machine threads |
| 81 | * |
| 82 | * Description: This causes all stop_machine threads which were created with |
| 83 | * stop_machine_create to be destroyed again. |
| 84 | */ |
| 85 | void stop_machine_destroy(void); |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #else |
| 88 | |
Rusty Russell | eeec4fa | 2008-07-28 12:16:30 -0500 | [diff] [blame] | 89 | static inline int stop_machine(int (*fn)(void *), void *data, |
Rusty Russell | 41c7bb9 | 2009-01-01 10:12:28 +1030 | [diff] [blame] | 90 | const struct cpumask *cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | int ret; |
| 93 | local_irq_disable(); |
| 94 | ret = fn(data); |
| 95 | local_irq_enable(); |
| 96 | return ret; |
| 97 | } |
Heiko Carstens | 9ea09af | 2008-12-22 12:36:30 +0100 | [diff] [blame] | 98 | |
| 99 | static inline int stop_machine_create(void) { return 0; } |
| 100 | static inline void stop_machine_destroy(void) { } |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #endif /* CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #endif /* _LINUX_STOP_MACHINE */ |