diff options
Diffstat (limited to 'kernel/rcupdate.c')
| -rw-r--r-- | kernel/rcupdate.c | 140 |
1 files changed, 7 insertions, 133 deletions
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index 37ac45483082..400183346ad2 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
| @@ -46,22 +46,15 @@ | |||
| 46 | #include <linux/module.h> | 46 | #include <linux/module.h> |
| 47 | #include <linux/kernel_stat.h> | 47 | #include <linux/kernel_stat.h> |
| 48 | 48 | ||
| 49 | enum rcu_barrier { | 49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 50 | RCU_BARRIER_STD, | 50 | static struct lock_class_key rcu_lock_key; |
| 51 | RCU_BARRIER_BH, | 51 | struct lockdep_map rcu_lock_map = |
| 52 | RCU_BARRIER_SCHED, | 52 | STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key); |
| 53 | }; | 53 | EXPORT_SYMBOL_GPL(rcu_lock_map); |
| 54 | #endif | ||
| 54 | 55 | ||
| 55 | static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL}; | ||
| 56 | static atomic_t rcu_barrier_cpu_count; | ||
| 57 | static DEFINE_MUTEX(rcu_barrier_mutex); | ||
| 58 | static struct completion rcu_barrier_completion; | ||
| 59 | int rcu_scheduler_active __read_mostly; | 56 | int rcu_scheduler_active __read_mostly; |
| 60 | 57 | ||
| 61 | static atomic_t rcu_migrate_type_count = ATOMIC_INIT(0); | ||
| 62 | static struct rcu_head rcu_migrate_head[3]; | ||
| 63 | static DECLARE_WAIT_QUEUE_HEAD(rcu_migrate_wq); | ||
| 64 | |||
| 65 | /* | 58 | /* |
| 66 | * Awaken the corresponding synchronize_rcu() instance now that a | 59 | * Awaken the corresponding synchronize_rcu() instance now that a |
| 67 | * grace period has elapsed. | 60 | * grace period has elapsed. |
| @@ -164,129 +157,10 @@ void synchronize_rcu_bh(void) | |||
| 164 | } | 157 | } |
| 165 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | 158 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); |
| 166 | 159 | ||
| 167 | static void rcu_barrier_callback(struct rcu_head *notused) | ||
| 168 | { | ||
| 169 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | ||
| 170 | complete(&rcu_barrier_completion); | ||
| 171 | } | ||
| 172 | |||
| 173 | /* | ||
| 174 | * Called with preemption disabled, and from cross-cpu IRQ context. | ||
| 175 | */ | ||
| 176 | static void rcu_barrier_func(void *type) | ||
| 177 | { | ||
| 178 | int cpu = smp_processor_id(); | ||
| 179 | struct rcu_head *head = &per_cpu(rcu_barrier_head, cpu); | ||
| 180 | |||
| 181 | atomic_inc(&rcu_barrier_cpu_count); | ||
| 182 | switch ((enum rcu_barrier)type) { | ||
| 183 | case RCU_BARRIER_STD: | ||
| 184 | call_rcu(head, rcu_barrier_callback); | ||
| 185 | break; | ||
| 186 | case RCU_BARRIER_BH: | ||
| 187 | call_rcu_bh(head, rcu_barrier_callback); | ||
| 188 | break; | ||
| 189 | case RCU_BARRIER_SCHED: | ||
| 190 | call_rcu_sched(head, rcu_barrier_callback); | ||
| 191 | break; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | static inline void wait_migrated_callbacks(void) | ||
| 196 | { | ||
| 197 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); | ||
| 198 | smp_mb(); /* In case we didn't sleep. */ | ||
| 199 | } | ||
| 200 | |||
| 201 | /* | ||
| 202 | * Orchestrate the specified type of RCU barrier, waiting for all | ||
| 203 | * RCU callbacks of the specified type to complete. | ||
| 204 | */ | ||
| 205 | static void _rcu_barrier(enum rcu_barrier type) | ||
| 206 | { | ||
| 207 | BUG_ON(in_interrupt()); | ||
| 208 | /* Take cpucontrol mutex to protect against CPU hotplug */ | ||
| 209 | mutex_lock(&rcu_barrier_mutex); | ||
| 210 | init_completion(&rcu_barrier_completion); | ||
| 211 | /* | ||
| 212 | * Initialize rcu_barrier_cpu_count to 1, then invoke | ||
| 213 | * rcu_barrier_func() on each CPU, so that each CPU also has | ||
| 214 | * incremented rcu_barrier_cpu_count. Only then is it safe to | ||
| 215 | * decrement rcu_barrier_cpu_count -- otherwise the first CPU | ||
| 216 | * might complete its grace period before all of the other CPUs | ||
| 217 | * did their increment, causing this function to return too | ||
| 218 | * early. | ||
| 219 | */ | ||
| 220 | atomic_set(&rcu_barrier_cpu_count, 1); | ||
| 221 | on_each_cpu(rcu_barrier_func, (void *)type, 1); | ||
| 222 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | ||
| 223 | complete(&rcu_barrier_completion); | ||
| 224 | wait_for_completion(&rcu_barrier_completion); | ||
| 225 | mutex_unlock(&rcu_barrier_mutex); | ||
| 226 | wait_migrated_callbacks(); | ||
| 227 | } | ||
| 228 | |||
| 229 | /** | ||
| 230 | * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete. | ||
| 231 | */ | ||
| 232 | void rcu_barrier(void) | ||
| 233 | { | ||
| 234 | _rcu_barrier(RCU_BARRIER_STD); | ||
| 235 | } | ||
| 236 | EXPORT_SYMBOL_GPL(rcu_barrier); | ||
| 237 | |||
| 238 | /** | ||
| 239 | * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete. | ||
| 240 | */ | ||
| 241 | void rcu_barrier_bh(void) | ||
| 242 | { | ||
| 243 | _rcu_barrier(RCU_BARRIER_BH); | ||
| 244 | } | ||
| 245 | EXPORT_SYMBOL_GPL(rcu_barrier_bh); | ||
| 246 | |||
| 247 | /** | ||
| 248 | * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks. | ||
| 249 | */ | ||
| 250 | void rcu_barrier_sched(void) | ||
| 251 | { | ||
| 252 | _rcu_barrier(RCU_BARRIER_SCHED); | ||
| 253 | } | ||
| 254 | EXPORT_SYMBOL_GPL(rcu_barrier_sched); | ||
| 255 | |||
| 256 | static void rcu_migrate_callback(struct rcu_head *notused) | ||
| 257 | { | ||
| 258 | if (atomic_dec_and_test(&rcu_migrate_type_count)) | ||
| 259 | wake_up(&rcu_migrate_wq); | ||
| 260 | } | ||
| 261 | |||
| 262 | extern int rcu_cpu_notify(struct notifier_block *self, | ||
| 263 | unsigned long action, void *hcpu); | ||
| 264 | |||
| 265 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | 160 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, |
| 266 | unsigned long action, void *hcpu) | 161 | unsigned long action, void *hcpu) |
| 267 | { | 162 | { |
| 268 | rcu_cpu_notify(self, action, hcpu); | 163 | return rcu_cpu_notify(self, action, hcpu); |
| 269 | if (action == CPU_DYING) { | ||
| 270 | /* | ||
| 271 | * preempt_disable() in on_each_cpu() prevents stop_machine(), | ||
| 272 | * so when "on_each_cpu(rcu_barrier_func, (void *)type, 1);" | ||
| 273 | * returns, all online cpus have queued rcu_barrier_func(), | ||
| 274 | * and the dead cpu(if it exist) queues rcu_migrate_callback()s. | ||
| 275 | * | ||
| 276 | * These callbacks ensure _rcu_barrier() waits for all | ||
| 277 | * RCU callbacks of the specified type to complete. | ||
| 278 | */ | ||
| 279 | atomic_set(&rcu_migrate_type_count, 3); | ||
| 280 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); | ||
| 281 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); | ||
| 282 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); | ||
| 283 | } else if (action == CPU_DOWN_PREPARE) { | ||
| 284 | /* Don't need to wait until next removal operation. */ | ||
| 285 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ | ||
| 286 | wait_migrated_callbacks(); | ||
| 287 | } | ||
| 288 | |||
| 289 | return NOTIFY_OK; | ||
| 290 | } | 164 | } |
| 291 | 165 | ||
| 292 | void __init rcu_init(void) | 166 | void __init rcu_init(void) |
