diff options
Diffstat (limited to 'kernel/rcutree.c')
-rw-r--r-- | kernel/rcutree.c | 1010 |
1 files changed, 680 insertions, 330 deletions
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 7717b95c2027..53ae9598f798 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
@@ -25,7 +25,7 @@ | |||
25 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. | 25 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. |
26 | * | 26 | * |
27 | * For detailed explanation of Read-Copy Update mechanism see - | 27 | * For detailed explanation of Read-Copy Update mechanism see - |
28 | * Documentation/RCU | 28 | * Documentation/RCU |
29 | */ | 29 | */ |
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/rcupdate.h> | 35 | #include <linux/rcupdate.h> |
36 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
37 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
38 | #include <linux/nmi.h> | ||
38 | #include <asm/atomic.h> | 39 | #include <asm/atomic.h> |
39 | #include <linux/bitops.h> | 40 | #include <linux/bitops.h> |
40 | #include <linux/module.h> | 41 | #include <linux/module.h> |
@@ -45,57 +46,78 @@ | |||
45 | #include <linux/cpu.h> | 46 | #include <linux/cpu.h> |
46 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
47 | #include <linux/time.h> | 48 | #include <linux/time.h> |
49 | #include <linux/kernel_stat.h> | ||
48 | 50 | ||
49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 51 | #include "rcutree.h" |
50 | static struct lock_class_key rcu_lock_key; | ||
51 | struct lockdep_map rcu_lock_map = | ||
52 | STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key); | ||
53 | EXPORT_SYMBOL_GPL(rcu_lock_map); | ||
54 | #endif | ||
55 | 52 | ||
56 | /* Data structures. */ | 53 | /* Data structures. */ |
57 | 54 | ||
55 | static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; | ||
56 | |||
58 | #define RCU_STATE_INITIALIZER(name) { \ | 57 | #define RCU_STATE_INITIALIZER(name) { \ |
59 | .level = { &name.node[0] }, \ | 58 | .level = { &name.node[0] }, \ |
60 | .levelcnt = { \ | 59 | .levelcnt = { \ |
61 | NUM_RCU_LVL_0, /* root of hierarchy. */ \ | 60 | NUM_RCU_LVL_0, /* root of hierarchy. */ \ |
62 | NUM_RCU_LVL_1, \ | 61 | NUM_RCU_LVL_1, \ |
63 | NUM_RCU_LVL_2, \ | 62 | NUM_RCU_LVL_2, \ |
64 | NUM_RCU_LVL_3, /* == MAX_RCU_LVLS */ \ | 63 | NUM_RCU_LVL_3, \ |
64 | NUM_RCU_LVL_4, /* == MAX_RCU_LVLS */ \ | ||
65 | }, \ | 65 | }, \ |
66 | .signaled = RCU_SIGNAL_INIT, \ | 66 | .signaled = RCU_GP_IDLE, \ |
67 | .gpnum = -300, \ | 67 | .gpnum = -300, \ |
68 | .completed = -300, \ | 68 | .completed = -300, \ |
69 | .onofflock = __SPIN_LOCK_UNLOCKED(&name.onofflock), \ | 69 | .onofflock = __SPIN_LOCK_UNLOCKED(&name.onofflock), \ |
70 | .orphan_cbs_list = NULL, \ | ||
71 | .orphan_cbs_tail = &name.orphan_cbs_list, \ | ||
72 | .orphan_qlen = 0, \ | ||
70 | .fqslock = __SPIN_LOCK_UNLOCKED(&name.fqslock), \ | 73 | .fqslock = __SPIN_LOCK_UNLOCKED(&name.fqslock), \ |
71 | .n_force_qs = 0, \ | 74 | .n_force_qs = 0, \ |
72 | .n_force_qs_ngp = 0, \ | 75 | .n_force_qs_ngp = 0, \ |
73 | } | 76 | } |
74 | 77 | ||
75 | struct rcu_state rcu_state = RCU_STATE_INITIALIZER(rcu_state); | 78 | struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state); |
76 | DEFINE_PER_CPU(struct rcu_data, rcu_data); | 79 | DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); |
77 | 80 | ||
78 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); | 81 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); |
79 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | 82 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); |
80 | 83 | ||
84 | static int rcu_scheduler_active __read_mostly; | ||
85 | |||
86 | |||
87 | /* | ||
88 | * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s | ||
89 | * permit this function to be invoked without holding the root rcu_node | ||
90 | * structure's ->lock, but of course results can be subject to change. | ||
91 | */ | ||
92 | static int rcu_gp_in_progress(struct rcu_state *rsp) | ||
93 | { | ||
94 | return ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum); | ||
95 | } | ||
96 | |||
81 | /* | 97 | /* |
82 | * Increment the quiescent state counter. | 98 | * Note a quiescent state. Because we do not need to know |
83 | * The counter is a bit degenerated: We do not need to know | ||
84 | * how many quiescent states passed, just if there was at least | 99 | * how many quiescent states passed, just if there was at least |
85 | * one since the start of the grace period. Thus just a flag. | 100 | * one since the start of the grace period, this just sets a flag. |
86 | */ | 101 | */ |
87 | void rcu_qsctr_inc(int cpu) | 102 | void rcu_sched_qs(int cpu) |
88 | { | 103 | { |
89 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | 104 | struct rcu_data *rdp; |
105 | |||
106 | rdp = &per_cpu(rcu_sched_data, cpu); | ||
107 | rdp->passed_quiesc_completed = rdp->gpnum - 1; | ||
108 | barrier(); | ||
90 | rdp->passed_quiesc = 1; | 109 | rdp->passed_quiesc = 1; |
91 | rdp->passed_quiesc_completed = rdp->completed; | 110 | rcu_preempt_note_context_switch(cpu); |
92 | } | 111 | } |
93 | 112 | ||
94 | void rcu_bh_qsctr_inc(int cpu) | 113 | void rcu_bh_qs(int cpu) |
95 | { | 114 | { |
96 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); | 115 | struct rcu_data *rdp; |
116 | |||
117 | rdp = &per_cpu(rcu_bh_data, cpu); | ||
118 | rdp->passed_quiesc_completed = rdp->gpnum - 1; | ||
119 | barrier(); | ||
97 | rdp->passed_quiesc = 1; | 120 | rdp->passed_quiesc = 1; |
98 | rdp->passed_quiesc_completed = rdp->completed; | ||
99 | } | 121 | } |
100 | 122 | ||
101 | #ifdef CONFIG_NO_HZ | 123 | #ifdef CONFIG_NO_HZ |
@@ -109,16 +131,21 @@ static int blimit = 10; /* Maximum callbacks per softirq. */ | |||
109 | static int qhimark = 10000; /* If this many pending, ignore blimit. */ | 131 | static int qhimark = 10000; /* If this many pending, ignore blimit. */ |
110 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ | 132 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ |
111 | 133 | ||
134 | module_param(blimit, int, 0); | ||
135 | module_param(qhimark, int, 0); | ||
136 | module_param(qlowmark, int, 0); | ||
137 | |||
112 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); | 138 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); |
139 | static int rcu_pending(int cpu); | ||
113 | 140 | ||
114 | /* | 141 | /* |
115 | * Return the number of RCU batches processed thus far for debug & stats. | 142 | * Return the number of RCU-sched batches processed thus far for debug & stats. |
116 | */ | 143 | */ |
117 | long rcu_batches_completed(void) | 144 | long rcu_batches_completed_sched(void) |
118 | { | 145 | { |
119 | return rcu_state.completed; | 146 | return rcu_sched_state.completed; |
120 | } | 147 | } |
121 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | 148 | EXPORT_SYMBOL_GPL(rcu_batches_completed_sched); |
122 | 149 | ||
123 | /* | 150 | /* |
124 | * Return the number of RCU BH batches processed thus far for debug & stats. | 151 | * Return the number of RCU BH batches processed thus far for debug & stats. |
@@ -144,9 +171,7 @@ cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp) | |||
144 | static int | 171 | static int |
145 | cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp) | 172 | cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp) |
146 | { | 173 | { |
147 | /* ACCESS_ONCE() because we are accessing outside of lock. */ | 174 | return *rdp->nxttail[RCU_DONE_TAIL] && !rcu_gp_in_progress(rsp); |
148 | return *rdp->nxttail[RCU_DONE_TAIL] && | ||
149 | ACCESS_ONCE(rsp->completed) == ACCESS_ONCE(rsp->gpnum); | ||
150 | } | 175 | } |
151 | 176 | ||
152 | /* | 177 | /* |
@@ -181,6 +206,10 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
181 | return 1; | 206 | return 1; |
182 | } | 207 | } |
183 | 208 | ||
209 | /* If preemptable RCU, no point in sending reschedule IPI. */ | ||
210 | if (rdp->preemptable) | ||
211 | return 0; | ||
212 | |||
184 | /* The CPU is online, so send it a reschedule IPI. */ | 213 | /* The CPU is online, so send it a reschedule IPI. */ |
185 | if (rdp->cpu != smp_processor_id()) | 214 | if (rdp->cpu != smp_processor_id()) |
186 | smp_send_reschedule(rdp->cpu); | 215 | smp_send_reschedule(rdp->cpu); |
@@ -193,7 +222,6 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
193 | #endif /* #ifdef CONFIG_SMP */ | 222 | #endif /* #ifdef CONFIG_SMP */ |
194 | 223 | ||
195 | #ifdef CONFIG_NO_HZ | 224 | #ifdef CONFIG_NO_HZ |
196 | static DEFINE_RATELIMIT_STATE(rcu_rs, 10 * HZ, 5); | ||
197 | 225 | ||
198 | /** | 226 | /** |
199 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz | 227 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz |
@@ -213,7 +241,7 @@ void rcu_enter_nohz(void) | |||
213 | rdtp = &__get_cpu_var(rcu_dynticks); | 241 | rdtp = &__get_cpu_var(rcu_dynticks); |
214 | rdtp->dynticks++; | 242 | rdtp->dynticks++; |
215 | rdtp->dynticks_nesting--; | 243 | rdtp->dynticks_nesting--; |
216 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 244 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
217 | local_irq_restore(flags); | 245 | local_irq_restore(flags); |
218 | } | 246 | } |
219 | 247 | ||
@@ -232,7 +260,7 @@ void rcu_exit_nohz(void) | |||
232 | rdtp = &__get_cpu_var(rcu_dynticks); | 260 | rdtp = &__get_cpu_var(rcu_dynticks); |
233 | rdtp->dynticks++; | 261 | rdtp->dynticks++; |
234 | rdtp->dynticks_nesting++; | 262 | rdtp->dynticks_nesting++; |
235 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 263 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
236 | local_irq_restore(flags); | 264 | local_irq_restore(flags); |
237 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 265 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
238 | } | 266 | } |
@@ -251,7 +279,7 @@ void rcu_nmi_enter(void) | |||
251 | if (rdtp->dynticks & 0x1) | 279 | if (rdtp->dynticks & 0x1) |
252 | return; | 280 | return; |
253 | rdtp->dynticks_nmi++; | 281 | rdtp->dynticks_nmi++; |
254 | WARN_ON_RATELIMIT(!(rdtp->dynticks_nmi & 0x1), &rcu_rs); | 282 | WARN_ON_ONCE(!(rdtp->dynticks_nmi & 0x1)); |
255 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 283 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
256 | } | 284 | } |
257 | 285 | ||
@@ -270,7 +298,7 @@ void rcu_nmi_exit(void) | |||
270 | return; | 298 | return; |
271 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 299 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
272 | rdtp->dynticks_nmi++; | 300 | rdtp->dynticks_nmi++; |
273 | WARN_ON_RATELIMIT(rdtp->dynticks_nmi & 0x1, &rcu_rs); | 301 | WARN_ON_ONCE(rdtp->dynticks_nmi & 0x1); |
274 | } | 302 | } |
275 | 303 | ||
276 | /** | 304 | /** |
@@ -286,7 +314,7 @@ void rcu_irq_enter(void) | |||
286 | if (rdtp->dynticks_nesting++) | 314 | if (rdtp->dynticks_nesting++) |
287 | return; | 315 | return; |
288 | rdtp->dynticks++; | 316 | rdtp->dynticks++; |
289 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 317 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
290 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 318 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
291 | } | 319 | } |
292 | 320 | ||
@@ -305,39 +333,20 @@ void rcu_irq_exit(void) | |||
305 | return; | 333 | return; |
306 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 334 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
307 | rdtp->dynticks++; | 335 | rdtp->dynticks++; |
308 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 336 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
309 | 337 | ||
310 | /* If the interrupt queued a callback, get out of dyntick mode. */ | 338 | /* If the interrupt queued a callback, get out of dyntick mode. */ |
311 | if (__get_cpu_var(rcu_data).nxtlist || | 339 | if (__get_cpu_var(rcu_sched_data).nxtlist || |
312 | __get_cpu_var(rcu_bh_data).nxtlist) | 340 | __get_cpu_var(rcu_bh_data).nxtlist) |
313 | set_need_resched(); | 341 | set_need_resched(); |
314 | } | 342 | } |
315 | 343 | ||
316 | /* | ||
317 | * Record the specified "completed" value, which is later used to validate | ||
318 | * dynticks counter manipulations. Specify "rsp->completed - 1" to | ||
319 | * unconditionally invalidate any future dynticks manipulations (which is | ||
320 | * useful at the beginning of a grace period). | ||
321 | */ | ||
322 | static void dyntick_record_completed(struct rcu_state *rsp, long comp) | ||
323 | { | ||
324 | rsp->dynticks_completed = comp; | ||
325 | } | ||
326 | |||
327 | #ifdef CONFIG_SMP | 344 | #ifdef CONFIG_SMP |
328 | 345 | ||
329 | /* | 346 | /* |
330 | * Recall the previously recorded value of the completion for dynticks. | ||
331 | */ | ||
332 | static long dyntick_recall_completed(struct rcu_state *rsp) | ||
333 | { | ||
334 | return rsp->dynticks_completed; | ||
335 | } | ||
336 | |||
337 | /* | ||
338 | * Snapshot the specified CPU's dynticks counter so that we can later | 347 | * Snapshot the specified CPU's dynticks counter so that we can later |
339 | * credit them with an implicit quiescent state. Return 1 if this CPU | 348 | * credit them with an implicit quiescent state. Return 1 if this CPU |
340 | * is already in a quiescent state courtesy of dynticks idle mode. | 349 | * is in dynticks idle mode, which is an extended quiescent state. |
341 | */ | 350 | */ |
342 | static int dyntick_save_progress_counter(struct rcu_data *rdp) | 351 | static int dyntick_save_progress_counter(struct rcu_data *rdp) |
343 | { | 352 | { |
@@ -397,24 +406,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) | |||
397 | 406 | ||
398 | #else /* #ifdef CONFIG_NO_HZ */ | 407 | #else /* #ifdef CONFIG_NO_HZ */ |
399 | 408 | ||
400 | static void dyntick_record_completed(struct rcu_state *rsp, long comp) | ||
401 | { | ||
402 | } | ||
403 | |||
404 | #ifdef CONFIG_SMP | 409 | #ifdef CONFIG_SMP |
405 | 410 | ||
406 | /* | ||
407 | * If there are no dynticks, then the only way that a CPU can passively | ||
408 | * be in a quiescent state is to be offline. Unlike dynticks idle, which | ||
409 | * is a point in time during the prior (already finished) grace period, | ||
410 | * an offline CPU is always in a quiescent state, and thus can be | ||
411 | * unconditionally applied. So just return the current value of completed. | ||
412 | */ | ||
413 | static long dyntick_recall_completed(struct rcu_state *rsp) | ||
414 | { | ||
415 | return rsp->completed; | ||
416 | } | ||
417 | |||
418 | static int dyntick_save_progress_counter(struct rcu_data *rdp) | 411 | static int dyntick_save_progress_counter(struct rcu_data *rdp) |
419 | { | 412 | { |
420 | return 0; | 413 | return 0; |
@@ -443,32 +436,39 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
443 | long delta; | 436 | long delta; |
444 | unsigned long flags; | 437 | unsigned long flags; |
445 | struct rcu_node *rnp = rcu_get_root(rsp); | 438 | struct rcu_node *rnp = rcu_get_root(rsp); |
446 | struct rcu_node *rnp_cur = rsp->level[NUM_RCU_LVLS - 1]; | ||
447 | struct rcu_node *rnp_end = &rsp->node[NUM_RCU_NODES]; | ||
448 | 439 | ||
449 | /* Only let one CPU complain about others per time interval. */ | 440 | /* Only let one CPU complain about others per time interval. */ |
450 | 441 | ||
451 | spin_lock_irqsave(&rnp->lock, flags); | 442 | spin_lock_irqsave(&rnp->lock, flags); |
452 | delta = jiffies - rsp->jiffies_stall; | 443 | delta = jiffies - rsp->jiffies_stall; |
453 | if (delta < RCU_STALL_RAT_DELAY || rsp->gpnum == rsp->completed) { | 444 | if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) { |
454 | spin_unlock_irqrestore(&rnp->lock, flags); | 445 | spin_unlock_irqrestore(&rnp->lock, flags); |
455 | return; | 446 | return; |
456 | } | 447 | } |
457 | rsp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | 448 | rsp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK; |
449 | |||
450 | /* | ||
451 | * Now rat on any tasks that got kicked up to the root rcu_node | ||
452 | * due to CPU offlining. | ||
453 | */ | ||
454 | rcu_print_task_stall(rnp); | ||
458 | spin_unlock_irqrestore(&rnp->lock, flags); | 455 | spin_unlock_irqrestore(&rnp->lock, flags); |
459 | 456 | ||
460 | /* OK, time to rat on our buddy... */ | 457 | /* OK, time to rat on our buddy... */ |
461 | 458 | ||
462 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | 459 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); |
463 | for (; rnp_cur < rnp_end; rnp_cur++) { | 460 | rcu_for_each_leaf_node(rsp, rnp) { |
464 | if (rnp_cur->qsmask == 0) | 461 | rcu_print_task_stall(rnp); |
462 | if (rnp->qsmask == 0) | ||
465 | continue; | 463 | continue; |
466 | for (cpu = 0; cpu <= rnp_cur->grphi - rnp_cur->grplo; cpu++) | 464 | for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++) |
467 | if (rnp_cur->qsmask & (1UL << cpu)) | 465 | if (rnp->qsmask & (1UL << cpu)) |
468 | printk(" %d", rnp_cur->grplo + cpu); | 466 | printk(" %d", rnp->grplo + cpu); |
469 | } | 467 | } |
470 | printk(" (detected by %d, t=%ld jiffies)\n", | 468 | printk(" (detected by %d, t=%ld jiffies)\n", |
471 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); | 469 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); |
470 | trigger_all_cpu_backtrace(); | ||
471 | |||
472 | force_quiescent_state(rsp, 0); /* Kick them all. */ | 472 | force_quiescent_state(rsp, 0); /* Kick them all. */ |
473 | } | 473 | } |
474 | 474 | ||
@@ -479,12 +479,14 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
479 | 479 | ||
480 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", | 480 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", |
481 | smp_processor_id(), jiffies - rsp->gp_start); | 481 | smp_processor_id(), jiffies - rsp->gp_start); |
482 | dump_stack(); | 482 | trigger_all_cpu_backtrace(); |
483 | |||
483 | spin_lock_irqsave(&rnp->lock, flags); | 484 | spin_lock_irqsave(&rnp->lock, flags); |
484 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) | 485 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) |
485 | rsp->jiffies_stall = | 486 | rsp->jiffies_stall = |
486 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | 487 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; |
487 | spin_unlock_irqrestore(&rnp->lock, flags); | 488 | spin_unlock_irqrestore(&rnp->lock, flags); |
489 | |||
488 | set_need_resched(); /* kick ourselves to get things going. */ | 490 | set_need_resched(); /* kick ourselves to get things going. */ |
489 | } | 491 | } |
490 | 492 | ||
@@ -500,8 +502,7 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
500 | /* We haven't checked in, so go dump stack. */ | 502 | /* We haven't checked in, so go dump stack. */ |
501 | print_cpu_stall(rsp); | 503 | print_cpu_stall(rsp); |
502 | 504 | ||
503 | } else if (rsp->gpnum != rsp->completed && | 505 | } else if (rcu_gp_in_progress(rsp) && delta >= RCU_STALL_RAT_DELAY) { |
504 | delta >= RCU_STALL_RAT_DELAY) { | ||
505 | 506 | ||
506 | /* They had two time units to dump stack, so complain. */ | 507 | /* They had two time units to dump stack, so complain. */ |
507 | print_other_cpu_stall(rsp); | 508 | print_other_cpu_stall(rsp); |
@@ -523,13 +524,33 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
523 | /* | 524 | /* |
524 | * Update CPU-local rcu_data state to record the newly noticed grace period. | 525 | * Update CPU-local rcu_data state to record the newly noticed grace period. |
525 | * This is used both when we started the grace period and when we notice | 526 | * This is used both when we started the grace period and when we notice |
526 | * that someone else started the grace period. | 527 | * that someone else started the grace period. The caller must hold the |
528 | * ->lock of the leaf rcu_node structure corresponding to the current CPU, | ||
529 | * and must have irqs disabled. | ||
527 | */ | 530 | */ |
531 | static void __note_new_gpnum(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp) | ||
532 | { | ||
533 | if (rdp->gpnum != rnp->gpnum) { | ||
534 | rdp->qs_pending = 1; | ||
535 | rdp->passed_quiesc = 0; | ||
536 | rdp->gpnum = rnp->gpnum; | ||
537 | } | ||
538 | } | ||
539 | |||
528 | static void note_new_gpnum(struct rcu_state *rsp, struct rcu_data *rdp) | 540 | static void note_new_gpnum(struct rcu_state *rsp, struct rcu_data *rdp) |
529 | { | 541 | { |
530 | rdp->qs_pending = 1; | 542 | unsigned long flags; |
531 | rdp->passed_quiesc = 0; | 543 | struct rcu_node *rnp; |
532 | rdp->gpnum = rsp->gpnum; | 544 | |
545 | local_irq_save(flags); | ||
546 | rnp = rdp->mynode; | ||
547 | if (rdp->gpnum == ACCESS_ONCE(rnp->gpnum) || /* outside lock. */ | ||
548 | !spin_trylock(&rnp->lock)) { /* irqs already off, retry later. */ | ||
549 | local_irq_restore(flags); | ||
550 | return; | ||
551 | } | ||
552 | __note_new_gpnum(rsp, rnp, rdp); | ||
553 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
533 | } | 554 | } |
534 | 555 | ||
535 | /* | 556 | /* |
@@ -553,6 +574,79 @@ check_for_new_grace_period(struct rcu_state *rsp, struct rcu_data *rdp) | |||
553 | } | 574 | } |
554 | 575 | ||
555 | /* | 576 | /* |
577 | * Advance this CPU's callbacks, but only if the current grace period | ||
578 | * has ended. This may be called only from the CPU to whom the rdp | ||
579 | * belongs. In addition, the corresponding leaf rcu_node structure's | ||
580 | * ->lock must be held by the caller, with irqs disabled. | ||
581 | */ | ||
582 | static void | ||
583 | __rcu_process_gp_end(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp) | ||
584 | { | ||
585 | /* Did another grace period end? */ | ||
586 | if (rdp->completed != rnp->completed) { | ||
587 | |||
588 | /* Advance callbacks. No harm if list empty. */ | ||
589 | rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[RCU_WAIT_TAIL]; | ||
590 | rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_READY_TAIL]; | ||
591 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
592 | |||
593 | /* Remember that we saw this grace-period completion. */ | ||
594 | rdp->completed = rnp->completed; | ||
595 | } | ||
596 | } | ||
597 | |||
598 | /* | ||
599 | * Advance this CPU's callbacks, but only if the current grace period | ||
600 | * has ended. This may be called only from the CPU to whom the rdp | ||
601 | * belongs. | ||
602 | */ | ||
603 | static void | ||
604 | rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp) | ||
605 | { | ||
606 | unsigned long flags; | ||
607 | struct rcu_node *rnp; | ||
608 | |||
609 | local_irq_save(flags); | ||
610 | rnp = rdp->mynode; | ||
611 | if (rdp->completed == ACCESS_ONCE(rnp->completed) || /* outside lock. */ | ||
612 | !spin_trylock(&rnp->lock)) { /* irqs already off, retry later. */ | ||
613 | local_irq_restore(flags); | ||
614 | return; | ||
615 | } | ||
616 | __rcu_process_gp_end(rsp, rnp, rdp); | ||
617 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
618 | } | ||
619 | |||
620 | /* | ||
621 | * Do per-CPU grace-period initialization for running CPU. The caller | ||
622 | * must hold the lock of the leaf rcu_node structure corresponding to | ||
623 | * this CPU. | ||
624 | */ | ||
625 | static void | ||
626 | rcu_start_gp_per_cpu(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp) | ||
627 | { | ||
628 | /* Prior grace period ended, so advance callbacks for current CPU. */ | ||
629 | __rcu_process_gp_end(rsp, rnp, rdp); | ||
630 | |||
631 | /* | ||
632 | * Because this CPU just now started the new grace period, we know | ||
633 | * that all of its callbacks will be covered by this upcoming grace | ||
634 | * period, even the ones that were registered arbitrarily recently. | ||
635 | * Therefore, advance all outstanding callbacks to RCU_WAIT_TAIL. | ||
636 | * | ||
637 | * Other CPUs cannot be sure exactly when the grace period started. | ||
638 | * Therefore, their recently registered callbacks must pass through | ||
639 | * an additional RCU_NEXT_READY stage, so that they will be handled | ||
640 | * by the next RCU grace period. | ||
641 | */ | ||
642 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
643 | rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
644 | |||
645 | /* Set state so that this CPU will detect the next quiescent state. */ | ||
646 | __note_new_gpnum(rsp, rnp, rdp); | ||
647 | } | ||
648 | |||
649 | /* | ||
556 | * Start a new RCU grace period if warranted, re-initializing the hierarchy | 650 | * Start a new RCU grace period if warranted, re-initializing the hierarchy |
557 | * in preparation for detecting the next grace period. The caller must hold | 651 | * in preparation for detecting the next grace period. The caller must hold |
558 | * the root node's ->lock, which is released before return. Hard irqs must | 652 | * the root node's ->lock, which is released before return. Hard irqs must |
@@ -564,34 +658,43 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | |||
564 | { | 658 | { |
565 | struct rcu_data *rdp = rsp->rda[smp_processor_id()]; | 659 | struct rcu_data *rdp = rsp->rda[smp_processor_id()]; |
566 | struct rcu_node *rnp = rcu_get_root(rsp); | 660 | struct rcu_node *rnp = rcu_get_root(rsp); |
567 | struct rcu_node *rnp_cur; | ||
568 | struct rcu_node *rnp_end; | ||
569 | 661 | ||
570 | if (!cpu_needs_another_gp(rsp, rdp)) { | 662 | if (!cpu_needs_another_gp(rsp, rdp)) { |
571 | spin_unlock_irqrestore(&rnp->lock, flags); | 663 | if (rnp->completed == rsp->completed) { |
664 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
665 | return; | ||
666 | } | ||
667 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
668 | |||
669 | /* | ||
670 | * Propagate new ->completed value to rcu_node structures | ||
671 | * so that other CPUs don't have to wait until the start | ||
672 | * of the next grace period to process their callbacks. | ||
673 | */ | ||
674 | rcu_for_each_node_breadth_first(rsp, rnp) { | ||
675 | spin_lock(&rnp->lock); /* irqs already disabled. */ | ||
676 | rnp->completed = rsp->completed; | ||
677 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
678 | } | ||
679 | local_irq_restore(flags); | ||
572 | return; | 680 | return; |
573 | } | 681 | } |
574 | 682 | ||
575 | /* Advance to a new grace period and initialize state. */ | 683 | /* Advance to a new grace period and initialize state. */ |
576 | rsp->gpnum++; | 684 | rsp->gpnum++; |
685 | WARN_ON_ONCE(rsp->signaled == RCU_GP_INIT); | ||
577 | rsp->signaled = RCU_GP_INIT; /* Hold off force_quiescent_state. */ | 686 | rsp->signaled = RCU_GP_INIT; /* Hold off force_quiescent_state. */ |
578 | rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS; | 687 | rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS; |
579 | record_gp_stall_check_time(rsp); | 688 | record_gp_stall_check_time(rsp); |
580 | dyntick_record_completed(rsp, rsp->completed - 1); | ||
581 | note_new_gpnum(rsp, rdp); | ||
582 | |||
583 | /* | ||
584 | * Because we are first, we know that all our callbacks will | ||
585 | * be covered by this upcoming grace period, even the ones | ||
586 | * that were registered arbitrarily recently. | ||
587 | */ | ||
588 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
589 | rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
590 | 689 | ||
591 | /* Special-case the common single-level case. */ | 690 | /* Special-case the common single-level case. */ |
592 | if (NUM_RCU_NODES == 1) { | 691 | if (NUM_RCU_NODES == 1) { |
692 | rcu_preempt_check_blocked_tasks(rnp); | ||
593 | rnp->qsmask = rnp->qsmaskinit; | 693 | rnp->qsmask = rnp->qsmaskinit; |
694 | rnp->gpnum = rsp->gpnum; | ||
695 | rnp->completed = rsp->completed; | ||
594 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */ | 696 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */ |
697 | rcu_start_gp_per_cpu(rsp, rnp, rdp); | ||
595 | spin_unlock_irqrestore(&rnp->lock, flags); | 698 | spin_unlock_irqrestore(&rnp->lock, flags); |
596 | return; | 699 | return; |
597 | } | 700 | } |
@@ -603,88 +706,71 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | |||
603 | spin_lock(&rsp->onofflock); /* irqs already disabled. */ | 706 | spin_lock(&rsp->onofflock); /* irqs already disabled. */ |
604 | 707 | ||
605 | /* | 708 | /* |
606 | * Set the quiescent-state-needed bits in all the non-leaf RCU | 709 | * Set the quiescent-state-needed bits in all the rcu_node |
607 | * nodes for all currently online CPUs. This operation relies | 710 | * structures for all currently online CPUs in breadth-first |
608 | * on the layout of the hierarchy within the rsp->node[] array. | 711 | * order, starting from the root rcu_node structure. This |
609 | * Note that other CPUs will access only the leaves of the | 712 | * operation relies on the layout of the hierarchy within the |
610 | * hierarchy, which still indicate that no grace period is in | 713 | * rsp->node[] array. Note that other CPUs will access only |
611 | * progress. In addition, we have excluded CPU-hotplug operations. | 714 | * the leaves of the hierarchy, which still indicate that no |
612 | * | 715 | * grace period is in progress, at least until the corresponding |
613 | * We therefore do not need to hold any locks. Any required | 716 | * leaf node has been initialized. In addition, we have excluded |
614 | * memory barriers will be supplied by the locks guarding the | 717 | * CPU-hotplug operations. |
615 | * leaf rcu_nodes in the hierarchy. | ||
616 | */ | ||
617 | |||
618 | rnp_end = rsp->level[NUM_RCU_LVLS - 1]; | ||
619 | for (rnp_cur = &rsp->node[0]; rnp_cur < rnp_end; rnp_cur++) | ||
620 | rnp_cur->qsmask = rnp_cur->qsmaskinit; | ||
621 | |||
622 | /* | ||
623 | * Now set up the leaf nodes. Here we must be careful. First, | ||
624 | * we need to hold the lock in order to exclude other CPUs, which | ||
625 | * might be contending for the leaf nodes' locks. Second, as | ||
626 | * soon as we initialize a given leaf node, its CPUs might run | ||
627 | * up the rest of the hierarchy. We must therefore acquire locks | ||
628 | * for each node that we touch during this stage. (But we still | ||
629 | * are excluding CPU-hotplug operations.) | ||
630 | * | 718 | * |
631 | * Note that the grace period cannot complete until we finish | 719 | * Note that the grace period cannot complete until we finish |
632 | * the initialization process, as there will be at least one | 720 | * the initialization process, as there will be at least one |
633 | * qsmask bit set in the root node until that time, namely the | 721 | * qsmask bit set in the root node until that time, namely the |
634 | * one corresponding to this CPU. | 722 | * one corresponding to this CPU, due to the fact that we have |
723 | * irqs disabled. | ||
635 | */ | 724 | */ |
636 | rnp_end = &rsp->node[NUM_RCU_NODES]; | 725 | rcu_for_each_node_breadth_first(rsp, rnp) { |
637 | rnp_cur = rsp->level[NUM_RCU_LVLS - 1]; | 726 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
638 | for (; rnp_cur < rnp_end; rnp_cur++) { | 727 | rcu_preempt_check_blocked_tasks(rnp); |
639 | spin_lock(&rnp_cur->lock); /* irqs already disabled. */ | 728 | rnp->qsmask = rnp->qsmaskinit; |
640 | rnp_cur->qsmask = rnp_cur->qsmaskinit; | 729 | rnp->gpnum = rsp->gpnum; |
641 | spin_unlock(&rnp_cur->lock); /* irqs already disabled. */ | 730 | rnp->completed = rsp->completed; |
731 | if (rnp == rdp->mynode) | ||
732 | rcu_start_gp_per_cpu(rsp, rnp, rdp); | ||
733 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
642 | } | 734 | } |
643 | 735 | ||
736 | rnp = rcu_get_root(rsp); | ||
737 | spin_lock(&rnp->lock); /* irqs already disabled. */ | ||
644 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state now OK. */ | 738 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state now OK. */ |
739 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
645 | spin_unlock_irqrestore(&rsp->onofflock, flags); | 740 | spin_unlock_irqrestore(&rsp->onofflock, flags); |
646 | } | 741 | } |
647 | 742 | ||
648 | /* | 743 | /* |
649 | * Advance this CPU's callbacks, but only if the current grace period | 744 | * Report a full set of quiescent states to the specified rcu_state |
650 | * has ended. This may be called only from the CPU to whom the rdp | 745 | * data structure. This involves cleaning up after the prior grace |
651 | * belongs. | 746 | * period and letting rcu_start_gp() start up the next grace period |
747 | * if one is needed. Note that the caller must hold rnp->lock, as | ||
748 | * required by rcu_start_gp(), which will release it. | ||
652 | */ | 749 | */ |
653 | static void | 750 | static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags) |
654 | rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp) | 751 | __releases(rcu_get_root(rsp)->lock) |
655 | { | 752 | { |
656 | long completed_snap; | 753 | WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); |
657 | unsigned long flags; | 754 | rsp->completed = rsp->gpnum; |
658 | 755 | rsp->signaled = RCU_GP_IDLE; | |
659 | local_irq_save(flags); | 756 | rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ |
660 | completed_snap = ACCESS_ONCE(rsp->completed); /* outside of lock. */ | ||
661 | |||
662 | /* Did another grace period end? */ | ||
663 | if (rdp->completed != completed_snap) { | ||
664 | |||
665 | /* Advance callbacks. No harm if list empty. */ | ||
666 | rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[RCU_WAIT_TAIL]; | ||
667 | rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_READY_TAIL]; | ||
668 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | ||
669 | |||
670 | /* Remember that we saw this grace-period completion. */ | ||
671 | rdp->completed = completed_snap; | ||
672 | } | ||
673 | local_irq_restore(flags); | ||
674 | } | 757 | } |
675 | 758 | ||
676 | /* | 759 | /* |
677 | * Similar to cpu_quiet(), for which it is a helper function. Allows | 760 | * Similar to rcu_report_qs_rdp(), for which it is a helper function. |
678 | * a group of CPUs to be quieted at one go, though all the CPUs in the | 761 | * Allows quiescent states for a group of CPUs to be reported at one go |
679 | * group must be represented by the same leaf rcu_node structure. | 762 | * to the specified rcu_node structure, though all the CPUs in the group |
680 | * That structure's lock must be held upon entry, and it is released | 763 | * must be represented by the same rcu_node structure (which need not be |
681 | * before return. | 764 | * a leaf rcu_node structure, though it often will be). That structure's |
765 | * lock must be held upon entry, and it is released before return. | ||
682 | */ | 766 | */ |
683 | static void | 767 | static void |
684 | cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | 768 | rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp, |
685 | unsigned long flags) | 769 | struct rcu_node *rnp, unsigned long flags) |
686 | __releases(rnp->lock) | 770 | __releases(rnp->lock) |
687 | { | 771 | { |
772 | struct rcu_node *rnp_c; | ||
773 | |||
688 | /* Walk up the rcu_node hierarchy. */ | 774 | /* Walk up the rcu_node hierarchy. */ |
689 | for (;;) { | 775 | for (;;) { |
690 | if (!(rnp->qsmask & mask)) { | 776 | if (!(rnp->qsmask & mask)) { |
@@ -694,7 +780,7 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
694 | return; | 780 | return; |
695 | } | 781 | } |
696 | rnp->qsmask &= ~mask; | 782 | rnp->qsmask &= ~mask; |
697 | if (rnp->qsmask != 0) { | 783 | if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) { |
698 | 784 | ||
699 | /* Other bits still set at this level, so done. */ | 785 | /* Other bits still set at this level, so done. */ |
700 | spin_unlock_irqrestore(&rnp->lock, flags); | 786 | spin_unlock_irqrestore(&rnp->lock, flags); |
@@ -708,31 +794,31 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
708 | break; | 794 | break; |
709 | } | 795 | } |
710 | spin_unlock_irqrestore(&rnp->lock, flags); | 796 | spin_unlock_irqrestore(&rnp->lock, flags); |
797 | rnp_c = rnp; | ||
711 | rnp = rnp->parent; | 798 | rnp = rnp->parent; |
712 | spin_lock_irqsave(&rnp->lock, flags); | 799 | spin_lock_irqsave(&rnp->lock, flags); |
800 | WARN_ON_ONCE(rnp_c->qsmask); | ||
713 | } | 801 | } |
714 | 802 | ||
715 | /* | 803 | /* |
716 | * Get here if we are the last CPU to pass through a quiescent | 804 | * Get here if we are the last CPU to pass through a quiescent |
717 | * state for this grace period. Clean up and let rcu_start_gp() | 805 | * state for this grace period. Invoke rcu_report_qs_rsp() |
718 | * start up the next grace period if one is needed. Note that | 806 | * to clean up and start the next grace period if one is needed. |
719 | * we still hold rnp->lock, as required by rcu_start_gp(), which | ||
720 | * will release it. | ||
721 | */ | 807 | */ |
722 | rsp->completed = rsp->gpnum; | 808 | rcu_report_qs_rsp(rsp, flags); /* releases rnp->lock. */ |
723 | rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]); | ||
724 | rcu_start_gp(rsp, flags); /* releases rnp->lock. */ | ||
725 | } | 809 | } |
726 | 810 | ||
727 | /* | 811 | /* |
728 | * Record a quiescent state for the specified CPU, which must either be | 812 | * Record a quiescent state for the specified CPU to that CPU's rcu_data |
729 | * the current CPU or an offline CPU. The lastcomp argument is used to | 813 | * structure. This must be either called from the specified CPU, or |
730 | * make sure we are still in the grace period of interest. We don't want | 814 | * called when the specified CPU is known to be offline (and when it is |
731 | * to end the current grace period based on quiescent states detected in | 815 | * also known that no other CPU is concurrently trying to help the offline |
732 | * an earlier grace period! | 816 | * CPU). The lastcomp argument is used to make sure we are still in the |
817 | * grace period of interest. We don't want to end the current grace period | ||
818 | * based on quiescent states detected in an earlier grace period! | ||
733 | */ | 819 | */ |
734 | static void | 820 | static void |
735 | cpu_quiet(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastcomp) | 821 | rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastcomp) |
736 | { | 822 | { |
737 | unsigned long flags; | 823 | unsigned long flags; |
738 | unsigned long mask; | 824 | unsigned long mask; |
@@ -740,15 +826,15 @@ cpu_quiet(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastcomp) | |||
740 | 826 | ||
741 | rnp = rdp->mynode; | 827 | rnp = rdp->mynode; |
742 | spin_lock_irqsave(&rnp->lock, flags); | 828 | spin_lock_irqsave(&rnp->lock, flags); |
743 | if (lastcomp != ACCESS_ONCE(rsp->completed)) { | 829 | if (lastcomp != rnp->completed) { |
744 | 830 | ||
745 | /* | 831 | /* |
746 | * Someone beat us to it for this grace period, so leave. | 832 | * Someone beat us to it for this grace period, so leave. |
747 | * The race with GP start is resolved by the fact that we | 833 | * The race with GP start is resolved by the fact that we |
748 | * hold the leaf rcu_node lock, so that the per-CPU bits | 834 | * hold the leaf rcu_node lock, so that the per-CPU bits |
749 | * cannot yet be initialized -- so we would simply find our | 835 | * cannot yet be initialized -- so we would simply find our |
750 | * CPU's bit already cleared in cpu_quiet_msk() if this race | 836 | * CPU's bit already cleared in rcu_report_qs_rnp() if this |
751 | * occurred. | 837 | * race occurred. |
752 | */ | 838 | */ |
753 | rdp->passed_quiesc = 0; /* try again later! */ | 839 | rdp->passed_quiesc = 0; /* try again later! */ |
754 | spin_unlock_irqrestore(&rnp->lock, flags); | 840 | spin_unlock_irqrestore(&rnp->lock, flags); |
@@ -764,10 +850,9 @@ cpu_quiet(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastcomp) | |||
764 | * This GP can't end until cpu checks in, so all of our | 850 | * This GP can't end until cpu checks in, so all of our |
765 | * callbacks can be processed during the next GP. | 851 | * callbacks can be processed during the next GP. |
766 | */ | 852 | */ |
767 | rdp = rsp->rda[smp_processor_id()]; | ||
768 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | 853 | rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; |
769 | 854 | ||
770 | cpu_quiet_msk(mask, rsp, rnp, flags); /* releases rnp->lock */ | 855 | rcu_report_qs_rnp(mask, rsp, rnp, flags); /* rlses rnp->lock */ |
771 | } | 856 | } |
772 | } | 857 | } |
773 | 858 | ||
@@ -798,74 +883,113 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp) | |||
798 | if (!rdp->passed_quiesc) | 883 | if (!rdp->passed_quiesc) |
799 | return; | 884 | return; |
800 | 885 | ||
801 | /* Tell RCU we are done (but cpu_quiet() will be the judge of that). */ | 886 | /* |
802 | cpu_quiet(rdp->cpu, rsp, rdp, rdp->passed_quiesc_completed); | 887 | * Tell RCU we are done (but rcu_report_qs_rdp() will be the |
888 | * judge of that). | ||
889 | */ | ||
890 | rcu_report_qs_rdp(rdp->cpu, rsp, rdp, rdp->passed_quiesc_completed); | ||
803 | } | 891 | } |
804 | 892 | ||
805 | #ifdef CONFIG_HOTPLUG_CPU | 893 | #ifdef CONFIG_HOTPLUG_CPU |
806 | 894 | ||
807 | /* | 895 | /* |
896 | * Move a dying CPU's RCU callbacks to the ->orphan_cbs_list for the | ||
897 | * specified flavor of RCU. The callbacks will be adopted by the next | ||
898 | * _rcu_barrier() invocation or by the CPU_DEAD notifier, whichever | ||
899 | * comes first. Because this is invoked from the CPU_DYING notifier, | ||
900 | * irqs are already disabled. | ||
901 | */ | ||
902 | static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) | ||
903 | { | ||
904 | int i; | ||
905 | struct rcu_data *rdp = rsp->rda[smp_processor_id()]; | ||
906 | |||
907 | if (rdp->nxtlist == NULL) | ||
908 | return; /* irqs disabled, so comparison is stable. */ | ||
909 | spin_lock(&rsp->onofflock); /* irqs already disabled. */ | ||
910 | *rsp->orphan_cbs_tail = rdp->nxtlist; | ||
911 | rsp->orphan_cbs_tail = rdp->nxttail[RCU_NEXT_TAIL]; | ||
912 | rdp->nxtlist = NULL; | ||
913 | for (i = 0; i < RCU_NEXT_SIZE; i++) | ||
914 | rdp->nxttail[i] = &rdp->nxtlist; | ||
915 | rsp->orphan_qlen += rdp->qlen; | ||
916 | rdp->qlen = 0; | ||
917 | spin_unlock(&rsp->onofflock); /* irqs remain disabled. */ | ||
918 | } | ||
919 | |||
920 | /* | ||
921 | * Adopt previously orphaned RCU callbacks. | ||
922 | */ | ||
923 | static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) | ||
924 | { | ||
925 | unsigned long flags; | ||
926 | struct rcu_data *rdp; | ||
927 | |||
928 | spin_lock_irqsave(&rsp->onofflock, flags); | ||
929 | rdp = rsp->rda[smp_processor_id()]; | ||
930 | if (rsp->orphan_cbs_list == NULL) { | ||
931 | spin_unlock_irqrestore(&rsp->onofflock, flags); | ||
932 | return; | ||
933 | } | ||
934 | *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_list; | ||
935 | rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_tail; | ||
936 | rdp->qlen += rsp->orphan_qlen; | ||
937 | rsp->orphan_cbs_list = NULL; | ||
938 | rsp->orphan_cbs_tail = &rsp->orphan_cbs_list; | ||
939 | rsp->orphan_qlen = 0; | ||
940 | spin_unlock_irqrestore(&rsp->onofflock, flags); | ||
941 | } | ||
942 | |||
943 | /* | ||
808 | * Remove the outgoing CPU from the bitmasks in the rcu_node hierarchy | 944 | * Remove the outgoing CPU from the bitmasks in the rcu_node hierarchy |
809 | * and move all callbacks from the outgoing CPU to the current one. | 945 | * and move all callbacks from the outgoing CPU to the current one. |
810 | */ | 946 | */ |
811 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | 947 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) |
812 | { | 948 | { |
813 | int i; | ||
814 | unsigned long flags; | 949 | unsigned long flags; |
815 | long lastcomp; | ||
816 | unsigned long mask; | 950 | unsigned long mask; |
951 | int need_report = 0; | ||
817 | struct rcu_data *rdp = rsp->rda[cpu]; | 952 | struct rcu_data *rdp = rsp->rda[cpu]; |
818 | struct rcu_data *rdp_me; | ||
819 | struct rcu_node *rnp; | 953 | struct rcu_node *rnp; |
820 | 954 | ||
821 | /* Exclude any attempts to start a new grace period. */ | 955 | /* Exclude any attempts to start a new grace period. */ |
822 | spin_lock_irqsave(&rsp->onofflock, flags); | 956 | spin_lock_irqsave(&rsp->onofflock, flags); |
823 | 957 | ||
824 | /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */ | 958 | /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */ |
825 | rnp = rdp->mynode; | 959 | rnp = rdp->mynode; /* this is the outgoing CPU's rnp. */ |
826 | mask = rdp->grpmask; /* rnp->grplo is constant. */ | 960 | mask = rdp->grpmask; /* rnp->grplo is constant. */ |
827 | do { | 961 | do { |
828 | spin_lock(&rnp->lock); /* irqs already disabled. */ | 962 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
829 | rnp->qsmaskinit &= ~mask; | 963 | rnp->qsmaskinit &= ~mask; |
830 | if (rnp->qsmaskinit != 0) { | 964 | if (rnp->qsmaskinit != 0) { |
831 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 965 | if (rnp != rdp->mynode) |
966 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
832 | break; | 967 | break; |
833 | } | 968 | } |
969 | if (rnp == rdp->mynode) | ||
970 | need_report = rcu_preempt_offline_tasks(rsp, rnp, rdp); | ||
971 | else | ||
972 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | ||
834 | mask = rnp->grpmask; | 973 | mask = rnp->grpmask; |
835 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | ||
836 | rnp = rnp->parent; | 974 | rnp = rnp->parent; |
837 | } while (rnp != NULL); | 975 | } while (rnp != NULL); |
838 | lastcomp = rsp->completed; | ||
839 | |||
840 | spin_unlock(&rsp->onofflock); /* irqs remain disabled. */ | ||
841 | |||
842 | /* Being offline is a quiescent state, so go record it. */ | ||
843 | cpu_quiet(cpu, rsp, rdp, lastcomp); | ||
844 | 976 | ||
845 | /* | 977 | /* |
846 | * Move callbacks from the outgoing CPU to the running CPU. | 978 | * We still hold the leaf rcu_node structure lock here, and |
847 | * Note that the outgoing CPU is now quiscent, so it is now | 979 | * irqs are still disabled. The reason for this subterfuge is |
848 | * (uncharacteristically) safe to access it rcu_data structure. | 980 | * because invoking rcu_report_unblock_qs_rnp() with ->onofflock |
849 | * Note also that we must carefully retain the order of the | 981 | * held leads to deadlock. |
850 | * outgoing CPU's callbacks in order for rcu_barrier() to work | ||
851 | * correctly. Finally, note that we start all the callbacks | ||
852 | * afresh, even those that have passed through a grace period | ||
853 | * and are therefore ready to invoke. The theory is that hotplug | ||
854 | * events are rare, and that if they are frequent enough to | ||
855 | * indefinitely delay callbacks, you have far worse things to | ||
856 | * be worrying about. | ||
857 | */ | 982 | */ |
858 | rdp_me = rsp->rda[smp_processor_id()]; | 983 | spin_unlock(&rsp->onofflock); /* irqs remain disabled. */ |
859 | if (rdp->nxtlist != NULL) { | 984 | rnp = rdp->mynode; |
860 | *rdp_me->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist; | 985 | if (need_report & RCU_OFL_TASKS_NORM_GP) |
861 | rdp_me->nxttail[RCU_NEXT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; | 986 | rcu_report_unblock_qs_rnp(rnp, flags); |
862 | rdp->nxtlist = NULL; | 987 | else |
863 | for (i = 0; i < RCU_NEXT_SIZE; i++) | 988 | spin_unlock_irqrestore(&rnp->lock, flags); |
864 | rdp->nxttail[i] = &rdp->nxtlist; | 989 | if (need_report & RCU_OFL_TASKS_EXP_GP) |
865 | rdp_me->qlen += rdp->qlen; | 990 | rcu_report_exp_rnp(rsp, rnp); |
866 | rdp->qlen = 0; | 991 | |
867 | } | 992 | rcu_adopt_orphan_cbs(rsp); |
868 | local_irq_restore(flags); | ||
869 | } | 993 | } |
870 | 994 | ||
871 | /* | 995 | /* |
@@ -876,12 +1000,21 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
876 | */ | 1000 | */ |
877 | static void rcu_offline_cpu(int cpu) | 1001 | static void rcu_offline_cpu(int cpu) |
878 | { | 1002 | { |
879 | __rcu_offline_cpu(cpu, &rcu_state); | 1003 | __rcu_offline_cpu(cpu, &rcu_sched_state); |
880 | __rcu_offline_cpu(cpu, &rcu_bh_state); | 1004 | __rcu_offline_cpu(cpu, &rcu_bh_state); |
1005 | rcu_preempt_offline_cpu(cpu); | ||
881 | } | 1006 | } |
882 | 1007 | ||
883 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | 1008 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ |
884 | 1009 | ||
1010 | static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) | ||
1011 | { | ||
1012 | } | ||
1013 | |||
1014 | static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) | ||
1015 | { | ||
1016 | } | ||
1017 | |||
885 | static void rcu_offline_cpu(int cpu) | 1018 | static void rcu_offline_cpu(int cpu) |
886 | { | 1019 | { |
887 | } | 1020 | } |
@@ -892,7 +1025,7 @@ static void rcu_offline_cpu(int cpu) | |||
892 | * Invoke any RCU callbacks that have made it to the end of their grace | 1025 | * Invoke any RCU callbacks that have made it to the end of their grace |
893 | * period. Thottle as specified by rdp->blimit. | 1026 | * period. Thottle as specified by rdp->blimit. |
894 | */ | 1027 | */ |
895 | static void rcu_do_batch(struct rcu_data *rdp) | 1028 | static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp) |
896 | { | 1029 | { |
897 | unsigned long flags; | 1030 | unsigned long flags; |
898 | struct rcu_head *next, *list, **tail; | 1031 | struct rcu_head *next, *list, **tail; |
@@ -945,6 +1078,13 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
945 | if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark) | 1078 | if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark) |
946 | rdp->blimit = blimit; | 1079 | rdp->blimit = blimit; |
947 | 1080 | ||
1081 | /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */ | ||
1082 | if (rdp->qlen == 0 && rdp->qlen_last_fqs_check != 0) { | ||
1083 | rdp->qlen_last_fqs_check = 0; | ||
1084 | rdp->n_force_qs_snap = rsp->n_force_qs; | ||
1085 | } else if (rdp->qlen < rdp->qlen_last_fqs_check - qhimark) | ||
1086 | rdp->qlen_last_fqs_check = rdp->qlen; | ||
1087 | |||
948 | local_irq_restore(flags); | 1088 | local_irq_restore(flags); |
949 | 1089 | ||
950 | /* Re-raise the RCU softirq if there are callbacks remaining. */ | 1090 | /* Re-raise the RCU softirq if there are callbacks remaining. */ |
@@ -963,6 +1103,8 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
963 | */ | 1103 | */ |
964 | void rcu_check_callbacks(int cpu, int user) | 1104 | void rcu_check_callbacks(int cpu, int user) |
965 | { | 1105 | { |
1106 | if (!rcu_pending(cpu)) | ||
1107 | return; /* if nothing for RCU to do. */ | ||
966 | if (user || | 1108 | if (user || |
967 | (idle_cpu(cpu) && rcu_scheduler_active && | 1109 | (idle_cpu(cpu) && rcu_scheduler_active && |
968 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | 1110 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { |
@@ -971,17 +1113,16 @@ void rcu_check_callbacks(int cpu, int user) | |||
971 | * Get here if this CPU took its interrupt from user | 1113 | * Get here if this CPU took its interrupt from user |
972 | * mode or from the idle loop, and if this is not a | 1114 | * mode or from the idle loop, and if this is not a |
973 | * nested interrupt. In this case, the CPU is in | 1115 | * nested interrupt. In this case, the CPU is in |
974 | * a quiescent state, so count it. | 1116 | * a quiescent state, so note it. |
975 | * | 1117 | * |
976 | * No memory barrier is required here because both | 1118 | * No memory barrier is required here because both |
977 | * rcu_qsctr_inc() and rcu_bh_qsctr_inc() reference | 1119 | * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local |
978 | * only CPU-local variables that other CPUs neither | 1120 | * variables that other CPUs neither access nor modify, |
979 | * access nor modify, at least not while the corresponding | 1121 | * at least not while the corresponding CPU is online. |
980 | * CPU is online. | ||
981 | */ | 1122 | */ |
982 | 1123 | ||
983 | rcu_qsctr_inc(cpu); | 1124 | rcu_sched_qs(cpu); |
984 | rcu_bh_qsctr_inc(cpu); | 1125 | rcu_bh_qs(cpu); |
985 | 1126 | ||
986 | } else if (!in_softirq()) { | 1127 | } else if (!in_softirq()) { |
987 | 1128 | ||
@@ -989,11 +1130,12 @@ void rcu_check_callbacks(int cpu, int user) | |||
989 | * Get here if this CPU did not take its interrupt from | 1130 | * Get here if this CPU did not take its interrupt from |
990 | * softirq, in other words, if it is not interrupting | 1131 | * softirq, in other words, if it is not interrupting |
991 | * a rcu_bh read-side critical section. This is an _bh | 1132 | * a rcu_bh read-side critical section. This is an _bh |
992 | * critical section, so count it. | 1133 | * critical section, so note it. |
993 | */ | 1134 | */ |
994 | 1135 | ||
995 | rcu_bh_qsctr_inc(cpu); | 1136 | rcu_bh_qs(cpu); |
996 | } | 1137 | } |
1138 | rcu_preempt_check_callbacks(cpu); | ||
997 | raise_softirq(RCU_SOFTIRQ); | 1139 | raise_softirq(RCU_SOFTIRQ); |
998 | } | 1140 | } |
999 | 1141 | ||
@@ -1012,33 +1154,32 @@ static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp, | |||
1012 | int cpu; | 1154 | int cpu; |
1013 | unsigned long flags; | 1155 | unsigned long flags; |
1014 | unsigned long mask; | 1156 | unsigned long mask; |
1015 | struct rcu_node *rnp_cur = rsp->level[NUM_RCU_LVLS - 1]; | 1157 | struct rcu_node *rnp; |
1016 | struct rcu_node *rnp_end = &rsp->node[NUM_RCU_NODES]; | ||
1017 | 1158 | ||
1018 | for (; rnp_cur < rnp_end; rnp_cur++) { | 1159 | rcu_for_each_leaf_node(rsp, rnp) { |
1019 | mask = 0; | 1160 | mask = 0; |
1020 | spin_lock_irqsave(&rnp_cur->lock, flags); | 1161 | spin_lock_irqsave(&rnp->lock, flags); |
1021 | if (rsp->completed != lastcomp) { | 1162 | if (rnp->completed != lastcomp) { |
1022 | spin_unlock_irqrestore(&rnp_cur->lock, flags); | 1163 | spin_unlock_irqrestore(&rnp->lock, flags); |
1023 | return 1; | 1164 | return 1; |
1024 | } | 1165 | } |
1025 | if (rnp_cur->qsmask == 0) { | 1166 | if (rnp->qsmask == 0) { |
1026 | spin_unlock_irqrestore(&rnp_cur->lock, flags); | 1167 | spin_unlock_irqrestore(&rnp->lock, flags); |
1027 | continue; | 1168 | continue; |
1028 | } | 1169 | } |
1029 | cpu = rnp_cur->grplo; | 1170 | cpu = rnp->grplo; |
1030 | bit = 1; | 1171 | bit = 1; |
1031 | for (; cpu <= rnp_cur->grphi; cpu++, bit <<= 1) { | 1172 | for (; cpu <= rnp->grphi; cpu++, bit <<= 1) { |
1032 | if ((rnp_cur->qsmask & bit) != 0 && f(rsp->rda[cpu])) | 1173 | if ((rnp->qsmask & bit) != 0 && f(rsp->rda[cpu])) |
1033 | mask |= bit; | 1174 | mask |= bit; |
1034 | } | 1175 | } |
1035 | if (mask != 0 && rsp->completed == lastcomp) { | 1176 | if (mask != 0 && rnp->completed == lastcomp) { |
1036 | 1177 | ||
1037 | /* cpu_quiet_msk() releases rnp_cur->lock. */ | 1178 | /* rcu_report_qs_rnp() releases rnp->lock. */ |
1038 | cpu_quiet_msk(mask, rsp, rnp_cur, flags); | 1179 | rcu_report_qs_rnp(mask, rsp, rnp, flags); |
1039 | continue; | 1180 | continue; |
1040 | } | 1181 | } |
1041 | spin_unlock_irqrestore(&rnp_cur->lock, flags); | 1182 | spin_unlock_irqrestore(&rnp->lock, flags); |
1042 | } | 1183 | } |
1043 | return 0; | 1184 | return 0; |
1044 | } | 1185 | } |
@@ -1053,8 +1194,9 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed) | |||
1053 | long lastcomp; | 1194 | long lastcomp; |
1054 | struct rcu_node *rnp = rcu_get_root(rsp); | 1195 | struct rcu_node *rnp = rcu_get_root(rsp); |
1055 | u8 signaled; | 1196 | u8 signaled; |
1197 | u8 forcenow; | ||
1056 | 1198 | ||
1057 | if (ACCESS_ONCE(rsp->completed) == ACCESS_ONCE(rsp->gpnum)) | 1199 | if (!rcu_gp_in_progress(rsp)) |
1058 | return; /* No grace period in progress, nothing to force. */ | 1200 | return; /* No grace period in progress, nothing to force. */ |
1059 | if (!spin_trylock_irqsave(&rsp->fqslock, flags)) { | 1201 | if (!spin_trylock_irqsave(&rsp->fqslock, flags)) { |
1060 | rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */ | 1202 | rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */ |
@@ -1065,19 +1207,20 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed) | |||
1065 | goto unlock_ret; /* no emergency and done recently. */ | 1207 | goto unlock_ret; /* no emergency and done recently. */ |
1066 | rsp->n_force_qs++; | 1208 | rsp->n_force_qs++; |
1067 | spin_lock(&rnp->lock); | 1209 | spin_lock(&rnp->lock); |
1068 | lastcomp = rsp->completed; | 1210 | lastcomp = rsp->gpnum - 1; |
1069 | signaled = rsp->signaled; | 1211 | signaled = rsp->signaled; |
1070 | rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS; | 1212 | rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS; |
1071 | if (lastcomp == rsp->gpnum) { | 1213 | if(!rcu_gp_in_progress(rsp)) { |
1072 | rsp->n_force_qs_ngp++; | 1214 | rsp->n_force_qs_ngp++; |
1073 | spin_unlock(&rnp->lock); | 1215 | spin_unlock(&rnp->lock); |
1074 | goto unlock_ret; /* no GP in progress, time updated. */ | 1216 | goto unlock_ret; /* no GP in progress, time updated. */ |
1075 | } | 1217 | } |
1076 | spin_unlock(&rnp->lock); | 1218 | spin_unlock(&rnp->lock); |
1077 | switch (signaled) { | 1219 | switch (signaled) { |
1220 | case RCU_GP_IDLE: | ||
1078 | case RCU_GP_INIT: | 1221 | case RCU_GP_INIT: |
1079 | 1222 | ||
1080 | break; /* grace period still initializing, ignore. */ | 1223 | break; /* grace period idle or initializing, ignore. */ |
1081 | 1224 | ||
1082 | case RCU_SAVE_DYNTICK: | 1225 | case RCU_SAVE_DYNTICK: |
1083 | 1226 | ||
@@ -1088,20 +1231,29 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed) | |||
1088 | if (rcu_process_dyntick(rsp, lastcomp, | 1231 | if (rcu_process_dyntick(rsp, lastcomp, |
1089 | dyntick_save_progress_counter)) | 1232 | dyntick_save_progress_counter)) |
1090 | goto unlock_ret; | 1233 | goto unlock_ret; |
1234 | /* fall into next case. */ | ||
1235 | |||
1236 | case RCU_SAVE_COMPLETED: | ||
1091 | 1237 | ||
1092 | /* Update state, record completion counter. */ | 1238 | /* Update state, record completion counter. */ |
1239 | forcenow = 0; | ||
1093 | spin_lock(&rnp->lock); | 1240 | spin_lock(&rnp->lock); |
1094 | if (lastcomp == rsp->completed) { | 1241 | if (lastcomp + 1 == rsp->gpnum && |
1242 | lastcomp == rsp->completed && | ||
1243 | rsp->signaled == signaled) { | ||
1095 | rsp->signaled = RCU_FORCE_QS; | 1244 | rsp->signaled = RCU_FORCE_QS; |
1096 | dyntick_record_completed(rsp, lastcomp); | 1245 | rsp->completed_fqs = lastcomp; |
1246 | forcenow = signaled == RCU_SAVE_COMPLETED; | ||
1097 | } | 1247 | } |
1098 | spin_unlock(&rnp->lock); | 1248 | spin_unlock(&rnp->lock); |
1099 | break; | 1249 | if (!forcenow) |
1250 | break; | ||
1251 | /* fall into next case. */ | ||
1100 | 1252 | ||
1101 | case RCU_FORCE_QS: | 1253 | case RCU_FORCE_QS: |
1102 | 1254 | ||
1103 | /* Check dyntick-idle state, send IPI to laggarts. */ | 1255 | /* Check dyntick-idle state, send IPI to laggarts. */ |
1104 | if (rcu_process_dyntick(rsp, dyntick_recall_completed(rsp), | 1256 | if (rcu_process_dyntick(rsp, rsp->completed_fqs, |
1105 | rcu_implicit_dynticks_qs)) | 1257 | rcu_implicit_dynticks_qs)) |
1106 | goto unlock_ret; | 1258 | goto unlock_ret; |
1107 | 1259 | ||
@@ -1132,6 +1284,8 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1132 | { | 1284 | { |
1133 | unsigned long flags; | 1285 | unsigned long flags; |
1134 | 1286 | ||
1287 | WARN_ON_ONCE(rdp->beenonline == 0); | ||
1288 | |||
1135 | /* | 1289 | /* |
1136 | * If an RCU GP has gone long enough, go check for dyntick | 1290 | * If an RCU GP has gone long enough, go check for dyntick |
1137 | * idle CPUs and, if needed, send resched IPIs. | 1291 | * idle CPUs and, if needed, send resched IPIs. |
@@ -1155,7 +1309,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1155 | } | 1309 | } |
1156 | 1310 | ||
1157 | /* If there are callbacks ready, invoke them. */ | 1311 | /* If there are callbacks ready, invoke them. */ |
1158 | rcu_do_batch(rdp); | 1312 | rcu_do_batch(rsp, rdp); |
1159 | } | 1313 | } |
1160 | 1314 | ||
1161 | /* | 1315 | /* |
@@ -1170,8 +1324,10 @@ static void rcu_process_callbacks(struct softirq_action *unused) | |||
1170 | */ | 1324 | */ |
1171 | smp_mb(); /* See above block comment. */ | 1325 | smp_mb(); /* See above block comment. */ |
1172 | 1326 | ||
1173 | __rcu_process_callbacks(&rcu_state, &__get_cpu_var(rcu_data)); | 1327 | __rcu_process_callbacks(&rcu_sched_state, |
1328 | &__get_cpu_var(rcu_sched_data)); | ||
1174 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); | 1329 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); |
1330 | rcu_preempt_process_callbacks(); | ||
1175 | 1331 | ||
1176 | /* | 1332 | /* |
1177 | * Memory references from any later RCU read-side critical sections | 1333 | * Memory references from any later RCU read-side critical sections |
@@ -1209,7 +1365,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
1209 | rdp->nxttail[RCU_NEXT_TAIL] = &head->next; | 1365 | rdp->nxttail[RCU_NEXT_TAIL] = &head->next; |
1210 | 1366 | ||
1211 | /* Start a new grace period if one not already started. */ | 1367 | /* Start a new grace period if one not already started. */ |
1212 | if (ACCESS_ONCE(rsp->completed) == ACCESS_ONCE(rsp->gpnum)) { | 1368 | if (!rcu_gp_in_progress(rsp)) { |
1213 | unsigned long nestflag; | 1369 | unsigned long nestflag; |
1214 | struct rcu_node *rnp_root = rcu_get_root(rsp); | 1370 | struct rcu_node *rnp_root = rcu_get_root(rsp); |
1215 | 1371 | ||
@@ -1217,23 +1373,33 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
1217 | rcu_start_gp(rsp, nestflag); /* releases rnp_root->lock. */ | 1373 | rcu_start_gp(rsp, nestflag); /* releases rnp_root->lock. */ |
1218 | } | 1374 | } |
1219 | 1375 | ||
1220 | /* Force the grace period if too many callbacks or too long waiting. */ | 1376 | /* |
1221 | if (unlikely(++rdp->qlen > qhimark)) { | 1377 | * Force the grace period if too many callbacks or too long waiting. |
1378 | * Enforce hysteresis, and don't invoke force_quiescent_state() | ||
1379 | * if some other CPU has recently done so. Also, don't bother | ||
1380 | * invoking force_quiescent_state() if the newly enqueued callback | ||
1381 | * is the only one waiting for a grace period to complete. | ||
1382 | */ | ||
1383 | if (unlikely(++rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) { | ||
1222 | rdp->blimit = LONG_MAX; | 1384 | rdp->blimit = LONG_MAX; |
1223 | force_quiescent_state(rsp, 0); | 1385 | if (rsp->n_force_qs == rdp->n_force_qs_snap && |
1386 | *rdp->nxttail[RCU_DONE_TAIL] != head) | ||
1387 | force_quiescent_state(rsp, 0); | ||
1388 | rdp->n_force_qs_snap = rsp->n_force_qs; | ||
1389 | rdp->qlen_last_fqs_check = rdp->qlen; | ||
1224 | } else if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0) | 1390 | } else if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0) |
1225 | force_quiescent_state(rsp, 1); | 1391 | force_quiescent_state(rsp, 1); |
1226 | local_irq_restore(flags); | 1392 | local_irq_restore(flags); |
1227 | } | 1393 | } |
1228 | 1394 | ||
1229 | /* | 1395 | /* |
1230 | * Queue an RCU callback for invocation after a grace period. | 1396 | * Queue an RCU-sched callback for invocation after a grace period. |
1231 | */ | 1397 | */ |
1232 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | 1398 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
1233 | { | 1399 | { |
1234 | __call_rcu(head, func, &rcu_state); | 1400 | __call_rcu(head, func, &rcu_sched_state); |
1235 | } | 1401 | } |
1236 | EXPORT_SYMBOL_GPL(call_rcu); | 1402 | EXPORT_SYMBOL_GPL(call_rcu_sched); |
1237 | 1403 | ||
1238 | /* | 1404 | /* |
1239 | * Queue an RCU for invocation after a quicker grace period. | 1405 | * Queue an RCU for invocation after a quicker grace period. |
@@ -1244,6 +1410,68 @@ void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | |||
1244 | } | 1410 | } |
1245 | EXPORT_SYMBOL_GPL(call_rcu_bh); | 1411 | EXPORT_SYMBOL_GPL(call_rcu_bh); |
1246 | 1412 | ||
1413 | /** | ||
1414 | * synchronize_sched - wait until an rcu-sched grace period has elapsed. | ||
1415 | * | ||
1416 | * Control will return to the caller some time after a full rcu-sched | ||
1417 | * grace period has elapsed, in other words after all currently executing | ||
1418 | * rcu-sched read-side critical sections have completed. These read-side | ||
1419 | * critical sections are delimited by rcu_read_lock_sched() and | ||
1420 | * rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(), | ||
1421 | * local_irq_disable(), and so on may be used in place of | ||
1422 | * rcu_read_lock_sched(). | ||
1423 | * | ||
1424 | * This means that all preempt_disable code sequences, including NMI and | ||
1425 | * hardware-interrupt handlers, in progress on entry will have completed | ||
1426 | * before this primitive returns. However, this does not guarantee that | ||
1427 | * softirq handlers will have completed, since in some kernels, these | ||
1428 | * handlers can run in process context, and can block. | ||
1429 | * | ||
1430 | * This primitive provides the guarantees made by the (now removed) | ||
1431 | * synchronize_kernel() API. In contrast, synchronize_rcu() only | ||
1432 | * guarantees that rcu_read_lock() sections will have completed. | ||
1433 | * In "classic RCU", these two guarantees happen to be one and | ||
1434 | * the same, but can differ in realtime RCU implementations. | ||
1435 | */ | ||
1436 | void synchronize_sched(void) | ||
1437 | { | ||
1438 | struct rcu_synchronize rcu; | ||
1439 | |||
1440 | if (rcu_blocking_is_gp()) | ||
1441 | return; | ||
1442 | |||
1443 | init_completion(&rcu.completion); | ||
1444 | /* Will wake me after RCU finished. */ | ||
1445 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | ||
1446 | /* Wait for it. */ | ||
1447 | wait_for_completion(&rcu.completion); | ||
1448 | } | ||
1449 | EXPORT_SYMBOL_GPL(synchronize_sched); | ||
1450 | |||
1451 | /** | ||
1452 | * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed. | ||
1453 | * | ||
1454 | * Control will return to the caller some time after a full rcu_bh grace | ||
1455 | * period has elapsed, in other words after all currently executing rcu_bh | ||
1456 | * read-side critical sections have completed. RCU read-side critical | ||
1457 | * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(), | ||
1458 | * and may be nested. | ||
1459 | */ | ||
1460 | void synchronize_rcu_bh(void) | ||
1461 | { | ||
1462 | struct rcu_synchronize rcu; | ||
1463 | |||
1464 | if (rcu_blocking_is_gp()) | ||
1465 | return; | ||
1466 | |||
1467 | init_completion(&rcu.completion); | ||
1468 | /* Will wake me after RCU finished. */ | ||
1469 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | ||
1470 | /* Wait for it. */ | ||
1471 | wait_for_completion(&rcu.completion); | ||
1472 | } | ||
1473 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | ||
1474 | |||
1247 | /* | 1475 | /* |
1248 | * Check to see if there is any immediate RCU-related work to be done | 1476 | * Check to see if there is any immediate RCU-related work to be done |
1249 | * by the current CPU, for the specified type of RCU, returning 1 if so. | 1477 | * by the current CPU, for the specified type of RCU, returning 1 if so. |
@@ -1253,6 +1481,8 @@ EXPORT_SYMBOL_GPL(call_rcu_bh); | |||
1253 | */ | 1481 | */ |
1254 | static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | 1482 | static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) |
1255 | { | 1483 | { |
1484 | struct rcu_node *rnp = rdp->mynode; | ||
1485 | |||
1256 | rdp->n_rcu_pending++; | 1486 | rdp->n_rcu_pending++; |
1257 | 1487 | ||
1258 | /* Check for CPU stalls, if enabled. */ | 1488 | /* Check for CPU stalls, if enabled. */ |
@@ -1277,19 +1507,19 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1277 | } | 1507 | } |
1278 | 1508 | ||
1279 | /* Has another RCU grace period completed? */ | 1509 | /* Has another RCU grace period completed? */ |
1280 | if (ACCESS_ONCE(rsp->completed) != rdp->completed) { /* outside lock */ | 1510 | if (ACCESS_ONCE(rnp->completed) != rdp->completed) { /* outside lock */ |
1281 | rdp->n_rp_gp_completed++; | 1511 | rdp->n_rp_gp_completed++; |
1282 | return 1; | 1512 | return 1; |
1283 | } | 1513 | } |
1284 | 1514 | ||
1285 | /* Has a new RCU grace period started? */ | 1515 | /* Has a new RCU grace period started? */ |
1286 | if (ACCESS_ONCE(rsp->gpnum) != rdp->gpnum) { /* outside lock */ | 1516 | if (ACCESS_ONCE(rnp->gpnum) != rdp->gpnum) { /* outside lock */ |
1287 | rdp->n_rp_gp_started++; | 1517 | rdp->n_rp_gp_started++; |
1288 | return 1; | 1518 | return 1; |
1289 | } | 1519 | } |
1290 | 1520 | ||
1291 | /* Has an RCU GP gone long enough to send resched IPIs &c? */ | 1521 | /* Has an RCU GP gone long enough to send resched IPIs &c? */ |
1292 | if (ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum) && | 1522 | if (rcu_gp_in_progress(rsp) && |
1293 | ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)) { | 1523 | ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)) { |
1294 | rdp->n_rp_need_fqs++; | 1524 | rdp->n_rp_need_fqs++; |
1295 | return 1; | 1525 | return 1; |
@@ -1305,10 +1535,11 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1305 | * by the current CPU, returning 1 if so. This function is part of the | 1535 | * by the current CPU, returning 1 if so. This function is part of the |
1306 | * RCU implementation; it is -not- an exported member of the RCU API. | 1536 | * RCU implementation; it is -not- an exported member of the RCU API. |
1307 | */ | 1537 | */ |
1308 | int rcu_pending(int cpu) | 1538 | static int rcu_pending(int cpu) |
1309 | { | 1539 | { |
1310 | return __rcu_pending(&rcu_state, &per_cpu(rcu_data, cpu)) || | 1540 | return __rcu_pending(&rcu_sched_state, &per_cpu(rcu_sched_data, cpu)) || |
1311 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)); | 1541 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)) || |
1542 | rcu_preempt_pending(cpu); | ||
1312 | } | 1543 | } |
1313 | 1544 | ||
1314 | /* | 1545 | /* |
@@ -1320,51 +1551,150 @@ int rcu_pending(int cpu) | |||
1320 | int rcu_needs_cpu(int cpu) | 1551 | int rcu_needs_cpu(int cpu) |
1321 | { | 1552 | { |
1322 | /* RCU callbacks either ready or pending? */ | 1553 | /* RCU callbacks either ready or pending? */ |
1323 | return per_cpu(rcu_data, cpu).nxtlist || | 1554 | return per_cpu(rcu_sched_data, cpu).nxtlist || |
1324 | per_cpu(rcu_bh_data, cpu).nxtlist; | 1555 | per_cpu(rcu_bh_data, cpu).nxtlist || |
1556 | rcu_preempt_needs_cpu(cpu); | ||
1325 | } | 1557 | } |
1326 | 1558 | ||
1327 | /* | 1559 | /* |
1328 | * Initialize a CPU's per-CPU RCU data. We take this "scorched earth" | 1560 | * This function is invoked towards the end of the scheduler's initialization |
1329 | * approach so that we don't have to worry about how long the CPU has | 1561 | * process. Before this is called, the idle task might contain |
1330 | * been gone, or whether it ever was online previously. We do trust the | 1562 | * RCU read-side critical sections (during which time, this idle |
1331 | * ->mynode field, as it is constant for a given struct rcu_data and | 1563 | * task is booting the system). After this function is called, the |
1332 | * initialized during early boot. | 1564 | * idle tasks are prohibited from containing RCU read-side critical |
1333 | * | 1565 | * sections. |
1334 | * Note that only one online or offline event can be happening at a given | ||
1335 | * time. Note also that we can accept some slop in the rsp->completed | ||
1336 | * access due to the fact that this CPU cannot possibly have any RCU | ||
1337 | * callbacks in flight yet. | ||
1338 | */ | 1566 | */ |
1339 | static void __cpuinit | 1567 | void rcu_scheduler_starting(void) |
1340 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | 1568 | { |
1569 | WARN_ON(num_online_cpus() != 1); | ||
1570 | WARN_ON(nr_context_switches() > 0); | ||
1571 | rcu_scheduler_active = 1; | ||
1572 | } | ||
1573 | |||
1574 | static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL}; | ||
1575 | static atomic_t rcu_barrier_cpu_count; | ||
1576 | static DEFINE_MUTEX(rcu_barrier_mutex); | ||
1577 | static struct completion rcu_barrier_completion; | ||
1578 | |||
1579 | static void rcu_barrier_callback(struct rcu_head *notused) | ||
1580 | { | ||
1581 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | ||
1582 | complete(&rcu_barrier_completion); | ||
1583 | } | ||
1584 | |||
1585 | /* | ||
1586 | * Called with preemption disabled, and from cross-cpu IRQ context. | ||
1587 | */ | ||
1588 | static void rcu_barrier_func(void *type) | ||
1589 | { | ||
1590 | int cpu = smp_processor_id(); | ||
1591 | struct rcu_head *head = &per_cpu(rcu_barrier_head, cpu); | ||
1592 | void (*call_rcu_func)(struct rcu_head *head, | ||
1593 | void (*func)(struct rcu_head *head)); | ||
1594 | |||
1595 | atomic_inc(&rcu_barrier_cpu_count); | ||
1596 | call_rcu_func = type; | ||
1597 | call_rcu_func(head, rcu_barrier_callback); | ||
1598 | } | ||
1599 | |||
1600 | /* | ||
1601 | * Orchestrate the specified type of RCU barrier, waiting for all | ||
1602 | * RCU callbacks of the specified type to complete. | ||
1603 | */ | ||
1604 | static void _rcu_barrier(struct rcu_state *rsp, | ||
1605 | void (*call_rcu_func)(struct rcu_head *head, | ||
1606 | void (*func)(struct rcu_head *head))) | ||
1607 | { | ||
1608 | BUG_ON(in_interrupt()); | ||
1609 | /* Take mutex to serialize concurrent rcu_barrier() requests. */ | ||
1610 | mutex_lock(&rcu_barrier_mutex); | ||
1611 | init_completion(&rcu_barrier_completion); | ||
1612 | /* | ||
1613 | * Initialize rcu_barrier_cpu_count to 1, then invoke | ||
1614 | * rcu_barrier_func() on each CPU, so that each CPU also has | ||
1615 | * incremented rcu_barrier_cpu_count. Only then is it safe to | ||
1616 | * decrement rcu_barrier_cpu_count -- otherwise the first CPU | ||
1617 | * might complete its grace period before all of the other CPUs | ||
1618 | * did their increment, causing this function to return too | ||
1619 | * early. | ||
1620 | */ | ||
1621 | atomic_set(&rcu_barrier_cpu_count, 1); | ||
1622 | preempt_disable(); /* stop CPU_DYING from filling orphan_cbs_list */ | ||
1623 | rcu_adopt_orphan_cbs(rsp); | ||
1624 | on_each_cpu(rcu_barrier_func, (void *)call_rcu_func, 1); | ||
1625 | preempt_enable(); /* CPU_DYING can again fill orphan_cbs_list */ | ||
1626 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | ||
1627 | complete(&rcu_barrier_completion); | ||
1628 | wait_for_completion(&rcu_barrier_completion); | ||
1629 | mutex_unlock(&rcu_barrier_mutex); | ||
1630 | } | ||
1631 | |||
1632 | /** | ||
1633 | * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete. | ||
1634 | */ | ||
1635 | void rcu_barrier_bh(void) | ||
1636 | { | ||
1637 | _rcu_barrier(&rcu_bh_state, call_rcu_bh); | ||
1638 | } | ||
1639 | EXPORT_SYMBOL_GPL(rcu_barrier_bh); | ||
1640 | |||
1641 | /** | ||
1642 | * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks. | ||
1643 | */ | ||
1644 | void rcu_barrier_sched(void) | ||
1645 | { | ||
1646 | _rcu_barrier(&rcu_sched_state, call_rcu_sched); | ||
1647 | } | ||
1648 | EXPORT_SYMBOL_GPL(rcu_barrier_sched); | ||
1649 | |||
1650 | /* | ||
1651 | * Do boot-time initialization of a CPU's per-CPU RCU data. | ||
1652 | */ | ||
1653 | static void __init | ||
1654 | rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) | ||
1341 | { | 1655 | { |
1342 | unsigned long flags; | 1656 | unsigned long flags; |
1343 | int i; | 1657 | int i; |
1344 | long lastcomp; | ||
1345 | unsigned long mask; | ||
1346 | struct rcu_data *rdp = rsp->rda[cpu]; | 1658 | struct rcu_data *rdp = rsp->rda[cpu]; |
1347 | struct rcu_node *rnp = rcu_get_root(rsp); | 1659 | struct rcu_node *rnp = rcu_get_root(rsp); |
1348 | 1660 | ||
1349 | /* Set up local state, ensuring consistent view of global state. */ | 1661 | /* Set up local state, ensuring consistent view of global state. */ |
1350 | spin_lock_irqsave(&rnp->lock, flags); | 1662 | spin_lock_irqsave(&rnp->lock, flags); |
1351 | lastcomp = rsp->completed; | ||
1352 | rdp->completed = lastcomp; | ||
1353 | rdp->gpnum = lastcomp; | ||
1354 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ | ||
1355 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ | ||
1356 | rdp->beenonline = 1; /* We have now been online. */ | ||
1357 | rdp->passed_quiesc_completed = lastcomp - 1; | ||
1358 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); | 1663 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); |
1359 | rdp->nxtlist = NULL; | 1664 | rdp->nxtlist = NULL; |
1360 | for (i = 0; i < RCU_NEXT_SIZE; i++) | 1665 | for (i = 0; i < RCU_NEXT_SIZE; i++) |
1361 | rdp->nxttail[i] = &rdp->nxtlist; | 1666 | rdp->nxttail[i] = &rdp->nxtlist; |
1362 | rdp->qlen = 0; | 1667 | rdp->qlen = 0; |
1363 | rdp->blimit = blimit; | ||
1364 | #ifdef CONFIG_NO_HZ | 1668 | #ifdef CONFIG_NO_HZ |
1365 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); | 1669 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); |
1366 | #endif /* #ifdef CONFIG_NO_HZ */ | 1670 | #endif /* #ifdef CONFIG_NO_HZ */ |
1367 | rdp->cpu = cpu; | 1671 | rdp->cpu = cpu; |
1672 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
1673 | } | ||
1674 | |||
1675 | /* | ||
1676 | * Initialize a CPU's per-CPU RCU data. Note that only one online or | ||
1677 | * offline event can be happening at a given time. Note also that we | ||
1678 | * can accept some slop in the rsp->completed access due to the fact | ||
1679 | * that this CPU cannot possibly have any RCU callbacks in flight yet. | ||
1680 | */ | ||
1681 | static void __cpuinit | ||
1682 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | ||
1683 | { | ||
1684 | unsigned long flags; | ||
1685 | unsigned long mask; | ||
1686 | struct rcu_data *rdp = rsp->rda[cpu]; | ||
1687 | struct rcu_node *rnp = rcu_get_root(rsp); | ||
1688 | |||
1689 | /* Set up local state, ensuring consistent view of global state. */ | ||
1690 | spin_lock_irqsave(&rnp->lock, flags); | ||
1691 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ | ||
1692 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ | ||
1693 | rdp->beenonline = 1; /* We have now been online. */ | ||
1694 | rdp->preemptable = preemptable; | ||
1695 | rdp->qlen_last_fqs_check = 0; | ||
1696 | rdp->n_force_qs_snap = rsp->n_force_qs; | ||
1697 | rdp->blimit = blimit; | ||
1368 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | 1698 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
1369 | 1699 | ||
1370 | /* | 1700 | /* |
@@ -1383,38 +1713,30 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
1383 | spin_lock(&rnp->lock); /* irqs already disabled. */ | 1713 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
1384 | rnp->qsmaskinit |= mask; | 1714 | rnp->qsmaskinit |= mask; |
1385 | mask = rnp->grpmask; | 1715 | mask = rnp->grpmask; |
1716 | if (rnp == rdp->mynode) { | ||
1717 | rdp->gpnum = rnp->completed; /* if GP in progress... */ | ||
1718 | rdp->completed = rnp->completed; | ||
1719 | rdp->passed_quiesc_completed = rnp->completed - 1; | ||
1720 | } | ||
1386 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 1721 | spin_unlock(&rnp->lock); /* irqs already disabled. */ |
1387 | rnp = rnp->parent; | 1722 | rnp = rnp->parent; |
1388 | } while (rnp != NULL && !(rnp->qsmaskinit & mask)); | 1723 | } while (rnp != NULL && !(rnp->qsmaskinit & mask)); |
1389 | 1724 | ||
1390 | spin_unlock(&rsp->onofflock); /* irqs remain disabled. */ | 1725 | spin_unlock_irqrestore(&rsp->onofflock, flags); |
1391 | |||
1392 | /* | ||
1393 | * A new grace period might start here. If so, we will be part of | ||
1394 | * it, and its gpnum will be greater than ours, so we will | ||
1395 | * participate. It is also possible for the gpnum to have been | ||
1396 | * incremented before this function was called, and the bitmasks | ||
1397 | * to not be filled out until now, in which case we will also | ||
1398 | * participate due to our gpnum being behind. | ||
1399 | */ | ||
1400 | |||
1401 | /* Since it is coming online, the CPU is in a quiescent state. */ | ||
1402 | cpu_quiet(cpu, rsp, rdp, lastcomp); | ||
1403 | local_irq_restore(flags); | ||
1404 | } | 1726 | } |
1405 | 1727 | ||
1406 | static void __cpuinit rcu_online_cpu(int cpu) | 1728 | static void __cpuinit rcu_online_cpu(int cpu) |
1407 | { | 1729 | { |
1408 | rcu_init_percpu_data(cpu, &rcu_state); | 1730 | rcu_init_percpu_data(cpu, &rcu_sched_state, 0); |
1409 | rcu_init_percpu_data(cpu, &rcu_bh_state); | 1731 | rcu_init_percpu_data(cpu, &rcu_bh_state, 0); |
1410 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | 1732 | rcu_preempt_init_percpu_data(cpu); |
1411 | } | 1733 | } |
1412 | 1734 | ||
1413 | /* | 1735 | /* |
1414 | * Handle CPU online/offline notifcation events. | 1736 | * Handle CPU online/offline notification events. |
1415 | */ | 1737 | */ |
1416 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | 1738 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, |
1417 | unsigned long action, void *hcpu) | 1739 | unsigned long action, void *hcpu) |
1418 | { | 1740 | { |
1419 | long cpu = (long)hcpu; | 1741 | long cpu = (long)hcpu; |
1420 | 1742 | ||
@@ -1423,6 +1745,22 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | |||
1423 | case CPU_UP_PREPARE_FROZEN: | 1745 | case CPU_UP_PREPARE_FROZEN: |
1424 | rcu_online_cpu(cpu); | 1746 | rcu_online_cpu(cpu); |
1425 | break; | 1747 | break; |
1748 | case CPU_DYING: | ||
1749 | case CPU_DYING_FROZEN: | ||
1750 | /* | ||
1751 | * preempt_disable() in _rcu_barrier() prevents stop_machine(), | ||
1752 | * so when "on_each_cpu(rcu_barrier_func, (void *)type, 1);" | ||
1753 | * returns, all online cpus have queued rcu_barrier_func(). | ||
1754 | * The dying CPU clears its cpu_online_mask bit and | ||
1755 | * moves all of its RCU callbacks to ->orphan_cbs_list | ||
1756 | * in the context of stop_machine(), so subsequent calls | ||
1757 | * to _rcu_barrier() will adopt these callbacks and only | ||
1758 | * then queue rcu_barrier_func() on all remaining CPUs. | ||
1759 | */ | ||
1760 | rcu_send_cbs_to_orphanage(&rcu_bh_state); | ||
1761 | rcu_send_cbs_to_orphanage(&rcu_sched_state); | ||
1762 | rcu_preempt_send_cbs_to_orphanage(); | ||
1763 | break; | ||
1426 | case CPU_DEAD: | 1764 | case CPU_DEAD: |
1427 | case CPU_DEAD_FROZEN: | 1765 | case CPU_DEAD_FROZEN: |
1428 | case CPU_UP_CANCELED: | 1766 | case CPU_UP_CANCELED: |
@@ -1486,6 +1824,8 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
1486 | rnp = rsp->level[i]; | 1824 | rnp = rsp->level[i]; |
1487 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { | 1825 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { |
1488 | spin_lock_init(&rnp->lock); | 1826 | spin_lock_init(&rnp->lock); |
1827 | lockdep_set_class(&rnp->lock, &rcu_node_class[i]); | ||
1828 | rnp->gpnum = 0; | ||
1489 | rnp->qsmask = 0; | 1829 | rnp->qsmask = 0; |
1490 | rnp->qsmaskinit = 0; | 1830 | rnp->qsmaskinit = 0; |
1491 | rnp->grplo = j * cpustride; | 1831 | rnp->grplo = j * cpustride; |
@@ -1503,16 +1843,26 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
1503 | j / rsp->levelspread[i - 1]; | 1843 | j / rsp->levelspread[i - 1]; |
1504 | } | 1844 | } |
1505 | rnp->level = i; | 1845 | rnp->level = i; |
1846 | INIT_LIST_HEAD(&rnp->blocked_tasks[0]); | ||
1847 | INIT_LIST_HEAD(&rnp->blocked_tasks[1]); | ||
1848 | INIT_LIST_HEAD(&rnp->blocked_tasks[2]); | ||
1849 | INIT_LIST_HEAD(&rnp->blocked_tasks[3]); | ||
1506 | } | 1850 | } |
1507 | } | 1851 | } |
1508 | } | 1852 | } |
1509 | 1853 | ||
1510 | /* | 1854 | /* |
1511 | * Helper macro for __rcu_init(). To be used nowhere else! | 1855 | * Helper macro for __rcu_init() and __rcu_init_preempt(). To be used |
1512 | * Assigns leaf node pointers into each CPU's rcu_data structure. | 1856 | * nowhere else! Assigns leaf node pointers into each CPU's rcu_data |
1857 | * structure. | ||
1513 | */ | 1858 | */ |
1514 | #define RCU_DATA_PTR_INIT(rsp, rcu_data) \ | 1859 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ |
1515 | do { \ | 1860 | do { \ |
1861 | int i; \ | ||
1862 | int j; \ | ||
1863 | struct rcu_node *rnp; \ | ||
1864 | \ | ||
1865 | rcu_init_one(rsp); \ | ||
1516 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ | 1866 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ |
1517 | j = 0; \ | 1867 | j = 0; \ |
1518 | for_each_possible_cpu(i) { \ | 1868 | for_each_possible_cpu(i) { \ |
@@ -1520,34 +1870,34 @@ do { \ | |||
1520 | j++; \ | 1870 | j++; \ |
1521 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ | 1871 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ |
1522 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ | 1872 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ |
1873 | rcu_boot_init_percpu_data(i, rsp); \ | ||
1523 | } \ | 1874 | } \ |
1524 | } while (0) | 1875 | } while (0) |
1525 | 1876 | ||
1526 | static struct notifier_block __cpuinitdata rcu_nb = { | 1877 | void __init rcu_init(void) |
1527 | .notifier_call = rcu_cpu_notify, | ||
1528 | }; | ||
1529 | |||
1530 | void __init __rcu_init(void) | ||
1531 | { | 1878 | { |
1532 | int i; /* All used by RCU_DATA_PTR_INIT(). */ | 1879 | int i; |
1533 | int j; | ||
1534 | struct rcu_node *rnp; | ||
1535 | 1880 | ||
1536 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | 1881 | rcu_bootup_announce(); |
1537 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 1882 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR |
1538 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | 1883 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); |
1539 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 1884 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
1540 | rcu_init_one(&rcu_state); | 1885 | #if NUM_RCU_LVL_4 != 0 |
1541 | RCU_DATA_PTR_INIT(&rcu_state, rcu_data); | 1886 | printk(KERN_INFO "Experimental four-level hierarchy is enabled.\n"); |
1542 | rcu_init_one(&rcu_bh_state); | 1887 | #endif /* #if NUM_RCU_LVL_4 != 0 */ |
1543 | RCU_DATA_PTR_INIT(&rcu_bh_state, rcu_bh_data); | 1888 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); |
1889 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); | ||
1890 | __rcu_init_preempt(); | ||
1891 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
1544 | 1892 | ||
1893 | /* | ||
1894 | * We don't need protection against CPU-hotplug here because | ||
1895 | * this is called early in boot, before either interrupts | ||
1896 | * or the scheduler are operational. | ||
1897 | */ | ||
1898 | cpu_notifier(rcu_cpu_notify, 0); | ||
1545 | for_each_online_cpu(i) | 1899 | for_each_online_cpu(i) |
1546 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long)i); | 1900 | rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)i); |
1547 | /* Register notifier for non-boot CPUs */ | ||
1548 | register_cpu_notifier(&rcu_nb); | ||
1549 | } | 1901 | } |
1550 | 1902 | ||
1551 | module_param(blimit, int, 0); | 1903 | #include "rcutree_plugin.h" |
1552 | module_param(qhimark, int, 0); | ||
1553 | module_param(qlowmark, int, 0); | ||