diff options
author | Tejun Heo <tj@kernel.org> | 2010-05-08 10:20:53 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2010-05-08 11:12:33 -0400 |
commit | bbf1bb3eee86f2eef2baa14e600be454d09109ee (patch) | |
tree | f7c200742a2d6ce20e72ad976b66d30d1aa6a04d /include/linux/stop_machine.h | |
parent | fc390cde362309f6892bb719194f242c466a978b (diff) |
cpu_stop: add dummy implementation for UP
When !CONFIG_SMP, cpu_stop functions weren't defined at all which
could lead to build failures if UP code uses cpu_stop facility. Add
dummy cpu_stop implementation for UP. The waiting variants execute
the work function directly with preempt disabled and
stop_one_cpu_nowait() schedules a workqueue work.
Makefile and ifdefs around stop_machine implementation are updated to
accomodate CONFIG_SMP && !CONFIG_STOP_MACHINE case.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/stop_machine.h')
-rw-r--r-- | include/linux/stop_machine.h | 69 |
1 files changed, 63 insertions, 6 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 */ |