diff options
| -rw-r--r-- | include/linux/stop_machine.h | 69 | ||||
| -rw-r--r-- | kernel/Makefile | 2 | ||||
| -rw-r--r-- | kernel/stop_machine.c | 4 |
3 files changed, 68 insertions, 7 deletions
diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index 0e552e72a4c4..6b524a0d02e4 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h | |||
| @@ -6,8 +6,6 @@ | |||
| 6 | #include <linux/list.h> | 6 | #include <linux/list.h> |
| 7 | #include <asm/system.h> | 7 | #include <asm/system.h> |
| 8 | 8 | ||
| 9 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) | ||
| 10 | |||
| 11 | /* | 9 | /* |
| 12 | * stop_cpu[s]() is simplistic per-cpu maximum priority cpu | 10 | * stop_cpu[s]() is simplistic per-cpu maximum priority cpu |
| 13 | * monopolization mechanism. The caller can specify a non-sleeping | 11 | * monopolization mechanism. The caller can specify a non-sleeping |
| @@ -18,9 +16,10 @@ | |||
| 18 | * up and requests are guaranteed to be served as long as the target | 16 | * up and requests are guaranteed to be served as long as the target |
| 19 | * cpus are online. | 17 | * cpus are online. |
| 20 | */ | 18 | */ |
| 21 | |||
| 22 | typedef int (*cpu_stop_fn_t)(void *arg); | 19 | typedef int (*cpu_stop_fn_t)(void *arg); |
| 23 | 20 | ||
| 21 | #ifdef CONFIG_SMP | ||
| 22 | |||
| 24 | struct cpu_stop_work { | 23 | struct cpu_stop_work { |
| 25 | struct list_head list; /* cpu_stopper->works */ | 24 | struct list_head list; /* cpu_stopper->works */ |
| 26 | cpu_stop_fn_t fn; | 25 | cpu_stop_fn_t fn; |
| @@ -34,12 +33,70 @@ void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg, | |||
| 34 | int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); | 33 | 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); | 34 | int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); |
| 36 | 35 | ||
| 36 | #else /* CONFIG_SMP */ | ||
| 37 | |||
| 38 | #include <linux/workqueue.h> | ||
| 39 | |||
| 40 | struct cpu_stop_work { | ||
| 41 | struct work_struct work; | ||
| 42 | cpu_stop_fn_t fn; | ||
| 43 | void *arg; | ||
| 44 | }; | ||
| 45 | |||
| 46 | static inline int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg) | ||
| 47 | { | ||
| 48 | int ret = -ENOENT; | ||
| 49 | preempt_disable(); | ||
| 50 | if (cpu == smp_processor_id()) | ||
| 51 | ret = fn(arg); | ||
| 52 | preempt_enable(); | ||
| 53 | return ret; | ||
| 54 | } | ||
| 55 | |||
| 56 | static void stop_one_cpu_nowait_workfn(struct work_struct *work) | ||
| 57 | { | ||
| 58 | struct cpu_stop_work *stwork = | ||
| 59 | container_of(work, struct cpu_stop_work, work); | ||
| 60 | preempt_disable(); | ||
| 61 | stwork->fn(stwork->arg); | ||
| 62 | preempt_enable(); | ||
| 63 | } | ||
| 64 | |||
| 65 | static inline void stop_one_cpu_nowait(unsigned int cpu, | ||
| 66 | cpu_stop_fn_t fn, void *arg, | ||
| 67 | struct cpu_stop_work *work_buf) | ||
| 68 | { | ||
| 69 | if (cpu == smp_processor_id()) { | ||
| 70 | INIT_WORK(&work_buf->work, stop_one_cpu_nowait_workfn); | ||
| 71 | work_buf->fn = fn; | ||
| 72 | work_buf->arg = arg; | ||
| 73 | schedule_work(&work_buf->work); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | static inline int stop_cpus(const struct cpumask *cpumask, | ||
| 78 | cpu_stop_fn_t fn, void *arg) | ||
| 79 | { | ||
| 80 | if (cpumask_test_cpu(raw_smp_processor_id(), cpumask)) | ||
| 81 | return stop_one_cpu(raw_smp_processor_id(), fn, arg); | ||
| 82 | return -ENOENT; | ||
| 83 | } | ||
| 84 | |||
| 85 | static inline int try_stop_cpus(const struct cpumask *cpumask, | ||
| 86 | cpu_stop_fn_t fn, void *arg) | ||
| 87 | { | ||
| 88 | return stop_cpus(cpumask, fn, arg); | ||
| 89 | } | ||
| 90 | |||
| 91 | #endif /* CONFIG_SMP */ | ||
| 92 | |||
| 37 | /* | 93 | /* |
| 38 | * stop_machine "Bogolock": stop the entire machine, disable | 94 | * stop_machine "Bogolock": stop the entire machine, disable |
| 39 | * interrupts. This is a very heavy lock, which is equivalent to | 95 | * interrupts. This is a very heavy lock, which is equivalent to |
| 40 | * grabbing every spinlock (and more). So the "read" side to such a | 96 | * grabbing every spinlock (and more). So the "read" side to such a |
| 41 | * lock is anything which disables preeempt. | 97 | * lock is anything which disables preeempt. |
| 42 | */ | 98 | */ |
| 99 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) | ||
| 43 | 100 | ||
| 44 | /** | 101 | /** |
| 45 | * stop_machine: freeze the machine on all CPUs and run this function | 102 | * stop_machine: freeze the machine on all CPUs and run this function |
| @@ -67,7 +124,7 @@ int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); | |||
| 67 | */ | 124 | */ |
| 68 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); | 125 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
| 69 | 126 | ||
| 70 | #else | 127 | #else /* CONFIG_STOP_MACHINE && CONFIG_SMP */ |
| 71 | 128 | ||
| 72 | static inline int stop_machine(int (*fn)(void *), void *data, | 129 | static inline int stop_machine(int (*fn)(void *), void *data, |
| 73 | const struct cpumask *cpus) | 130 | const struct cpumask *cpus) |
| @@ -79,5 +136,5 @@ static inline int stop_machine(int (*fn)(void *), void *data, | |||
| 79 | return ret; | 136 | return ret; |
| 80 | } | 137 | } |
| 81 | 138 | ||
| 82 | #endif /* CONFIG_SMP */ | 139 | #endif /* CONFIG_STOP_MACHINE && CONFIG_SMP */ |
| 83 | #endif /* _LINUX_STOP_MACHINE */ | 140 | #endif /* _LINUX_STOP_MACHINE */ |
diff --git a/kernel/Makefile b/kernel/Makefile index a987aa1676b5..149e18ef1ab1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -68,7 +68,7 @@ obj-$(CONFIG_USER_NS) += user_namespace.o | |||
| 68 | obj-$(CONFIG_PID_NS) += pid_namespace.o | 68 | obj-$(CONFIG_PID_NS) += pid_namespace.o |
| 69 | obj-$(CONFIG_IKCONFIG) += configs.o | 69 | obj-$(CONFIG_IKCONFIG) += configs.o |
| 70 | obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o | 70 | obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o |
| 71 | obj-$(CONFIG_STOP_MACHINE) += stop_machine.o | 71 | obj-$(CONFIG_SMP) += stop_machine.o |
| 72 | obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o | 72 | obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o |
| 73 | obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o | 73 | obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o |
| 74 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o | 74 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 5b20141a5ec1..ef51d1fcf5e6 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
| @@ -375,6 +375,8 @@ static int __init cpu_stop_init(void) | |||
| 375 | } | 375 | } |
| 376 | early_initcall(cpu_stop_init); | 376 | early_initcall(cpu_stop_init); |
| 377 | 377 | ||
| 378 | #ifdef CONFIG_STOP_MACHINE | ||
| 379 | |||
| 378 | /* This controls the threads on each CPU. */ | 380 | /* This controls the threads on each CPU. */ |
| 379 | enum stopmachine_state { | 381 | enum stopmachine_state { |
| 380 | /* Dummy starting state for thread. */ | 382 | /* Dummy starting state for thread. */ |
| @@ -477,3 +479,5 @@ int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus) | |||
| 477 | return ret; | 479 | return ret; |
| 478 | } | 480 | } |
| 479 | EXPORT_SYMBOL_GPL(stop_machine); | 481 | EXPORT_SYMBOL_GPL(stop_machine); |
| 482 | |||
| 483 | #endif /* CONFIG_STOP_MACHINE */ | ||
