diff options
Diffstat (limited to 'kernel/rcupdate.c')
-rw-r--r-- | kernel/rcupdate.c | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index a967c9feb90a..37ac45483082 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
@@ -19,7 +19,7 @@ | |||
19 | * | 19 | * |
20 | * Authors: Dipankar Sarma <dipankar@in.ibm.com> | 20 | * Authors: Dipankar Sarma <dipankar@in.ibm.com> |
21 | * Manfred Spraul <manfred@colorfullife.com> | 21 | * Manfred Spraul <manfred@colorfullife.com> |
22 | * | 22 | * |
23 | * Based on the original work by Paul McKenney <paulmck@us.ibm.com> | 23 | * Based on the original work by Paul McKenney <paulmck@us.ibm.com> |
24 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. | 24 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. |
25 | * Papers: | 25 | * Papers: |
@@ -27,7 +27,7 @@ | |||
27 | * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001) | 27 | * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001) |
28 | * | 28 | * |
29 | * For detailed explanation of Read-Copy Update mechanism see - | 29 | * For detailed explanation of Read-Copy Update mechanism see - |
30 | * http://lse.sourceforge.net/locking/rcupdate.html | 30 | * http://lse.sourceforge.net/locking/rcupdate.html |
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/types.h> | 33 | #include <linux/types.h> |
@@ -74,6 +74,8 @@ void wakeme_after_rcu(struct rcu_head *head) | |||
74 | complete(&rcu->completion); | 74 | complete(&rcu->completion); |
75 | } | 75 | } |
76 | 76 | ||
77 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
78 | |||
77 | /** | 79 | /** |
78 | * synchronize_rcu - wait until a grace period has elapsed. | 80 | * synchronize_rcu - wait until a grace period has elapsed. |
79 | * | 81 | * |
@@ -87,7 +89,7 @@ void synchronize_rcu(void) | |||
87 | { | 89 | { |
88 | struct rcu_synchronize rcu; | 90 | struct rcu_synchronize rcu; |
89 | 91 | ||
90 | if (rcu_blocking_is_gp()) | 92 | if (!rcu_scheduler_active) |
91 | return; | 93 | return; |
92 | 94 | ||
93 | init_completion(&rcu.completion); | 95 | init_completion(&rcu.completion); |
@@ -98,6 +100,70 @@ void synchronize_rcu(void) | |||
98 | } | 100 | } |
99 | EXPORT_SYMBOL_GPL(synchronize_rcu); | 101 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
100 | 102 | ||
103 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
104 | |||
105 | /** | ||
106 | * synchronize_sched - wait until an rcu-sched grace period has elapsed. | ||
107 | * | ||
108 | * Control will return to the caller some time after a full rcu-sched | ||
109 | * grace period has elapsed, in other words after all currently executing | ||
110 | * rcu-sched read-side critical sections have completed. These read-side | ||
111 | * critical sections are delimited by rcu_read_lock_sched() and | ||
112 | * rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(), | ||
113 | * local_irq_disable(), and so on may be used in place of | ||
114 | * rcu_read_lock_sched(). | ||
115 | * | ||
116 | * This means that all preempt_disable code sequences, including NMI and | ||
117 | * hardware-interrupt handlers, in progress on entry will have completed | ||
118 | * before this primitive returns. However, this does not guarantee that | ||
119 | * softirq handlers will have completed, since in some kernels, these | ||
120 | * handlers can run in process context, and can block. | ||
121 | * | ||
122 | * This primitive provides the guarantees made by the (now removed) | ||
123 | * synchronize_kernel() API. In contrast, synchronize_rcu() only | ||
124 | * guarantees that rcu_read_lock() sections will have completed. | ||
125 | * In "classic RCU", these two guarantees happen to be one and | ||
126 | * the same, but can differ in realtime RCU implementations. | ||
127 | */ | ||
128 | void synchronize_sched(void) | ||
129 | { | ||
130 | struct rcu_synchronize rcu; | ||
131 | |||
132 | if (rcu_blocking_is_gp()) | ||
133 | return; | ||
134 | |||
135 | init_completion(&rcu.completion); | ||
136 | /* Will wake me after RCU finished. */ | ||
137 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | ||
138 | /* Wait for it. */ | ||
139 | wait_for_completion(&rcu.completion); | ||
140 | } | ||
141 | EXPORT_SYMBOL_GPL(synchronize_sched); | ||
142 | |||
143 | /** | ||
144 | * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed. | ||
145 | * | ||
146 | * Control will return to the caller some time after a full rcu_bh grace | ||
147 | * period has elapsed, in other words after all currently executing rcu_bh | ||
148 | * read-side critical sections have completed. RCU read-side critical | ||
149 | * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(), | ||
150 | * and may be nested. | ||
151 | */ | ||
152 | void synchronize_rcu_bh(void) | ||
153 | { | ||
154 | struct rcu_synchronize rcu; | ||
155 | |||
156 | if (rcu_blocking_is_gp()) | ||
157 | return; | ||
158 | |||
159 | init_completion(&rcu.completion); | ||
160 | /* Will wake me after RCU finished. */ | ||
161 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | ||
162 | /* Wait for it. */ | ||
163 | wait_for_completion(&rcu.completion); | ||
164 | } | ||
165 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | ||
166 | |||
101 | static void rcu_barrier_callback(struct rcu_head *notused) | 167 | static void rcu_barrier_callback(struct rcu_head *notused) |
102 | { | 168 | { |
103 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | 169 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) |
@@ -129,6 +195,7 @@ static void rcu_barrier_func(void *type) | |||
129 | static inline void wait_migrated_callbacks(void) | 195 | static inline void wait_migrated_callbacks(void) |
130 | { | 196 | { |
131 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); | 197 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); |
198 | smp_mb(); /* In case we didn't sleep. */ | ||
132 | } | 199 | } |
133 | 200 | ||
134 | /* | 201 | /* |
@@ -192,9 +259,13 @@ static void rcu_migrate_callback(struct rcu_head *notused) | |||
192 | wake_up(&rcu_migrate_wq); | 259 | wake_up(&rcu_migrate_wq); |
193 | } | 260 | } |
194 | 261 | ||
262 | extern int rcu_cpu_notify(struct notifier_block *self, | ||
263 | unsigned long action, void *hcpu); | ||
264 | |||
195 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | 265 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, |
196 | unsigned long action, void *hcpu) | 266 | unsigned long action, void *hcpu) |
197 | { | 267 | { |
268 | rcu_cpu_notify(self, action, hcpu); | ||
198 | if (action == CPU_DYING) { | 269 | if (action == CPU_DYING) { |
199 | /* | 270 | /* |
200 | * preempt_disable() in on_each_cpu() prevents stop_machine(), | 271 | * preempt_disable() in on_each_cpu() prevents stop_machine(), |
@@ -209,7 +280,8 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
209 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); | 280 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); |
210 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); | 281 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); |
211 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); | 282 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); |
212 | } else if (action == CPU_POST_DEAD) { | 283 | } else if (action == CPU_DOWN_PREPARE) { |
284 | /* Don't need to wait until next removal operation. */ | ||
213 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ | 285 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ |
214 | wait_migrated_callbacks(); | 286 | wait_migrated_callbacks(); |
215 | } | 287 | } |
@@ -219,8 +291,18 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
219 | 291 | ||
220 | void __init rcu_init(void) | 292 | void __init rcu_init(void) |
221 | { | 293 | { |
294 | int i; | ||
295 | |||
222 | __rcu_init(); | 296 | __rcu_init(); |
223 | hotcpu_notifier(rcu_barrier_cpu_hotplug, 0); | 297 | cpu_notifier(rcu_barrier_cpu_hotplug, 0); |
298 | |||
299 | /* | ||
300 | * We don't need protection against CPU-hotplug here because | ||
301 | * this is called early in boot, before either interrupts | ||
302 | * or the scheduler are operational. | ||
303 | */ | ||
304 | for_each_online_cpu(i) | ||
305 | rcu_barrier_cpu_hotplug(NULL, CPU_UP_PREPARE, (void *)(long)i); | ||
224 | } | 306 | } |
225 | 307 | ||
226 | void rcu_scheduler_starting(void) | 308 | void rcu_scheduler_starting(void) |