diff options
Diffstat (limited to 'kernel/rcutree.c')
-rw-r--r-- | kernel/rcutree.c | 573 |
1 files changed, 348 insertions, 225 deletions
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index d5bc43976c5a..ba06207b1dd3 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
@@ -36,7 +36,7 @@ | |||
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 <linux/nmi.h> |
39 | #include <asm/atomic.h> | 39 | #include <linux/atomic.h> |
40 | #include <linux/bitops.h> | 40 | #include <linux/bitops.h> |
41 | #include <linux/module.h> | 41 | #include <linux/module.h> |
42 | #include <linux/completion.h> | 42 | #include <linux/completion.h> |
@@ -47,6 +47,9 @@ | |||
47 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
48 | #include <linux/time.h> | 48 | #include <linux/time.h> |
49 | #include <linux/kernel_stat.h> | 49 | #include <linux/kernel_stat.h> |
50 | #include <linux/wait.h> | ||
51 | #include <linux/kthread.h> | ||
52 | #include <linux/prefetch.h> | ||
50 | 53 | ||
51 | #include "rcutree.h" | 54 | #include "rcutree.h" |
52 | 55 | ||
@@ -67,9 +70,6 @@ static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; | |||
67 | .gpnum = -300, \ | 70 | .gpnum = -300, \ |
68 | .completed = -300, \ | 71 | .completed = -300, \ |
69 | .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&structname.onofflock), \ | 72 | .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&structname.onofflock), \ |
70 | .orphan_cbs_list = NULL, \ | ||
71 | .orphan_cbs_tail = &structname.orphan_cbs_list, \ | ||
72 | .orphan_qlen = 0, \ | ||
73 | .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&structname.fqslock), \ | 73 | .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&structname.fqslock), \ |
74 | .n_force_qs = 0, \ | 74 | .n_force_qs = 0, \ |
75 | .n_force_qs_ngp = 0, \ | 75 | .n_force_qs_ngp = 0, \ |
@@ -82,10 +82,67 @@ DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); | |||
82 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); | 82 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); |
83 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | 83 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); |
84 | 84 | ||
85 | static struct rcu_state *rcu_state; | ||
86 | |||
87 | /* | ||
88 | * The rcu_scheduler_active variable transitions from zero to one just | ||
89 | * before the first task is spawned. So when this variable is zero, RCU | ||
90 | * can assume that there is but one task, allowing RCU to (for example) | ||
91 | * optimized synchronize_sched() to a simple barrier(). When this variable | ||
92 | * is one, RCU must actually do all the hard work required to detect real | ||
93 | * grace periods. This variable is also used to suppress boot-time false | ||
94 | * positives from lockdep-RCU error checking. | ||
95 | */ | ||
85 | int rcu_scheduler_active __read_mostly; | 96 | int rcu_scheduler_active __read_mostly; |
86 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); | 97 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); |
87 | 98 | ||
88 | /* | 99 | /* |
100 | * The rcu_scheduler_fully_active variable transitions from zero to one | ||
101 | * during the early_initcall() processing, which is after the scheduler | ||
102 | * is capable of creating new tasks. So RCU processing (for example, | ||
103 | * creating tasks for RCU priority boosting) must be delayed until after | ||
104 | * rcu_scheduler_fully_active transitions from zero to one. We also | ||
105 | * currently delay invocation of any RCU callbacks until after this point. | ||
106 | * | ||
107 | * It might later prove better for people registering RCU callbacks during | ||
108 | * early boot to take responsibility for these callbacks, but one step at | ||
109 | * a time. | ||
110 | */ | ||
111 | static int rcu_scheduler_fully_active __read_mostly; | ||
112 | |||
113 | #ifdef CONFIG_RCU_BOOST | ||
114 | |||
115 | /* | ||
116 | * Control variables for per-CPU and per-rcu_node kthreads. These | ||
117 | * handle all flavors of RCU. | ||
118 | */ | ||
119 | static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task); | ||
120 | DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status); | ||
121 | DEFINE_PER_CPU(int, rcu_cpu_kthread_cpu); | ||
122 | DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops); | ||
123 | DEFINE_PER_CPU(char, rcu_cpu_has_work); | ||
124 | |||
125 | #endif /* #ifdef CONFIG_RCU_BOOST */ | ||
126 | |||
127 | static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu); | ||
128 | static void invoke_rcu_core(void); | ||
129 | static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp); | ||
130 | |||
131 | #define RCU_KTHREAD_PRIO 1 /* RT priority for per-CPU kthreads. */ | ||
132 | |||
133 | /* | ||
134 | * Track the rcutorture test sequence number and the update version | ||
135 | * number within a given test. The rcutorture_testseq is incremented | ||
136 | * on every rcutorture module load and unload, so has an odd value | ||
137 | * when a test is running. The rcutorture_vernum is set to zero | ||
138 | * when rcutorture starts and is incremented on each rcutorture update. | ||
139 | * These variables enable correlating rcutorture output with the | ||
140 | * RCU tracing information. | ||
141 | */ | ||
142 | unsigned long rcutorture_testseq; | ||
143 | unsigned long rcutorture_vernum; | ||
144 | |||
145 | /* | ||
89 | * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s | 146 | * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s |
90 | * permit this function to be invoked without holding the root rcu_node | 147 | * permit this function to be invoked without holding the root rcu_node |
91 | * structure's ->lock, but of course results can be subject to change. | 148 | * structure's ->lock, but of course results can be subject to change. |
@@ -127,11 +184,12 @@ void rcu_note_context_switch(int cpu) | |||
127 | rcu_sched_qs(cpu); | 184 | rcu_sched_qs(cpu); |
128 | rcu_preempt_note_context_switch(cpu); | 185 | rcu_preempt_note_context_switch(cpu); |
129 | } | 186 | } |
187 | EXPORT_SYMBOL_GPL(rcu_note_context_switch); | ||
130 | 188 | ||
131 | #ifdef CONFIG_NO_HZ | 189 | #ifdef CONFIG_NO_HZ |
132 | DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { | 190 | DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { |
133 | .dynticks_nesting = 1, | 191 | .dynticks_nesting = 1, |
134 | .dynticks = 1, | 192 | .dynticks = ATOMIC_INIT(1), |
135 | }; | 193 | }; |
136 | #endif /* #ifdef CONFIG_NO_HZ */ | 194 | #endif /* #ifdef CONFIG_NO_HZ */ |
137 | 195 | ||
@@ -143,6 +201,9 @@ module_param(blimit, int, 0); | |||
143 | module_param(qhimark, int, 0); | 201 | module_param(qhimark, int, 0); |
144 | module_param(qlowmark, int, 0); | 202 | module_param(qlowmark, int, 0); |
145 | 203 | ||
204 | int rcu_cpu_stall_suppress __read_mostly; | ||
205 | module_param(rcu_cpu_stall_suppress, int, 0644); | ||
206 | |||
146 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); | 207 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); |
147 | static int rcu_pending(int cpu); | 208 | static int rcu_pending(int cpu); |
148 | 209 | ||
@@ -174,6 +235,31 @@ void rcu_bh_force_quiescent_state(void) | |||
174 | EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state); | 235 | EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state); |
175 | 236 | ||
176 | /* | 237 | /* |
238 | * Record the number of times rcutorture tests have been initiated and | ||
239 | * terminated. This information allows the debugfs tracing stats to be | ||
240 | * correlated to the rcutorture messages, even when the rcutorture module | ||
241 | * is being repeatedly loaded and unloaded. In other words, we cannot | ||
242 | * store this state in rcutorture itself. | ||
243 | */ | ||
244 | void rcutorture_record_test_transition(void) | ||
245 | { | ||
246 | rcutorture_testseq++; | ||
247 | rcutorture_vernum = 0; | ||
248 | } | ||
249 | EXPORT_SYMBOL_GPL(rcutorture_record_test_transition); | ||
250 | |||
251 | /* | ||
252 | * Record the number of writer passes through the current rcutorture test. | ||
253 | * This is also used to correlate debugfs tracing stats with the rcutorture | ||
254 | * messages. | ||
255 | */ | ||
256 | void rcutorture_record_progress(unsigned long vernum) | ||
257 | { | ||
258 | rcutorture_vernum++; | ||
259 | } | ||
260 | EXPORT_SYMBOL_GPL(rcutorture_record_progress); | ||
261 | |||
262 | /* | ||
177 | * Force a quiescent state for RCU-sched. | 263 | * Force a quiescent state for RCU-sched. |
178 | */ | 264 | */ |
179 | void rcu_sched_force_quiescent_state(void) | 265 | void rcu_sched_force_quiescent_state(void) |
@@ -232,8 +318,8 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
232 | return 1; | 318 | return 1; |
233 | } | 319 | } |
234 | 320 | ||
235 | /* If preemptable RCU, no point in sending reschedule IPI. */ | 321 | /* If preemptible RCU, no point in sending reschedule IPI. */ |
236 | if (rdp->preemptable) | 322 | if (rdp->preemptible) |
237 | return 0; | 323 | return 0; |
238 | 324 | ||
239 | /* The CPU is online, so send it a reschedule IPI. */ | 325 | /* The CPU is online, so send it a reschedule IPI. */ |
@@ -262,13 +348,25 @@ void rcu_enter_nohz(void) | |||
262 | unsigned long flags; | 348 | unsigned long flags; |
263 | struct rcu_dynticks *rdtp; | 349 | struct rcu_dynticks *rdtp; |
264 | 350 | ||
265 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | ||
266 | local_irq_save(flags); | 351 | local_irq_save(flags); |
267 | rdtp = &__get_cpu_var(rcu_dynticks); | 352 | rdtp = &__get_cpu_var(rcu_dynticks); |
268 | rdtp->dynticks++; | 353 | if (--rdtp->dynticks_nesting) { |
269 | rdtp->dynticks_nesting--; | 354 | local_irq_restore(flags); |
270 | WARN_ON_ONCE(rdtp->dynticks & 0x1); | 355 | return; |
356 | } | ||
357 | /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */ | ||
358 | smp_mb__before_atomic_inc(); /* See above. */ | ||
359 | atomic_inc(&rdtp->dynticks); | ||
360 | smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */ | ||
361 | WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1); | ||
271 | local_irq_restore(flags); | 362 | local_irq_restore(flags); |
363 | |||
364 | /* If the interrupt queued a callback, get out of dyntick mode. */ | ||
365 | if (in_irq() && | ||
366 | (__get_cpu_var(rcu_sched_data).nxtlist || | ||
367 | __get_cpu_var(rcu_bh_data).nxtlist || | ||
368 | rcu_preempt_needs_cpu(smp_processor_id()))) | ||
369 | set_need_resched(); | ||
272 | } | 370 | } |
273 | 371 | ||
274 | /* | 372 | /* |
@@ -284,11 +382,16 @@ void rcu_exit_nohz(void) | |||
284 | 382 | ||
285 | local_irq_save(flags); | 383 | local_irq_save(flags); |
286 | rdtp = &__get_cpu_var(rcu_dynticks); | 384 | rdtp = &__get_cpu_var(rcu_dynticks); |
287 | rdtp->dynticks++; | 385 | if (rdtp->dynticks_nesting++) { |
288 | rdtp->dynticks_nesting++; | 386 | local_irq_restore(flags); |
289 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); | 387 | return; |
388 | } | ||
389 | smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */ | ||
390 | atomic_inc(&rdtp->dynticks); | ||
391 | /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */ | ||
392 | smp_mb__after_atomic_inc(); /* See above. */ | ||
393 | WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1)); | ||
290 | local_irq_restore(flags); | 394 | local_irq_restore(flags); |
291 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | ||
292 | } | 395 | } |
293 | 396 | ||
294 | /** | 397 | /** |
@@ -302,11 +405,15 @@ void rcu_nmi_enter(void) | |||
302 | { | 405 | { |
303 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); | 406 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); |
304 | 407 | ||
305 | if (rdtp->dynticks & 0x1) | 408 | if (rdtp->dynticks_nmi_nesting == 0 && |
409 | (atomic_read(&rdtp->dynticks) & 0x1)) | ||
306 | return; | 410 | return; |
307 | rdtp->dynticks_nmi++; | 411 | rdtp->dynticks_nmi_nesting++; |
308 | WARN_ON_ONCE(!(rdtp->dynticks_nmi & 0x1)); | 412 | smp_mb__before_atomic_inc(); /* Force delay from prior write. */ |
309 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 413 | atomic_inc(&rdtp->dynticks); |
414 | /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */ | ||
415 | smp_mb__after_atomic_inc(); /* See above. */ | ||
416 | WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1)); | ||
310 | } | 417 | } |
311 | 418 | ||
312 | /** | 419 | /** |
@@ -320,11 +427,14 @@ void rcu_nmi_exit(void) | |||
320 | { | 427 | { |
321 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); | 428 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); |
322 | 429 | ||
323 | if (rdtp->dynticks & 0x1) | 430 | if (rdtp->dynticks_nmi_nesting == 0 || |
431 | --rdtp->dynticks_nmi_nesting != 0) | ||
324 | return; | 432 | return; |
325 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 433 | /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */ |
326 | rdtp->dynticks_nmi++; | 434 | smp_mb__before_atomic_inc(); /* See above. */ |
327 | WARN_ON_ONCE(rdtp->dynticks_nmi & 0x1); | 435 | atomic_inc(&rdtp->dynticks); |
436 | smp_mb__after_atomic_inc(); /* Force delay to next write. */ | ||
437 | WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1); | ||
328 | } | 438 | } |
329 | 439 | ||
330 | /** | 440 | /** |
@@ -335,13 +445,7 @@ void rcu_nmi_exit(void) | |||
335 | */ | 445 | */ |
336 | void rcu_irq_enter(void) | 446 | void rcu_irq_enter(void) |
337 | { | 447 | { |
338 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); | 448 | rcu_exit_nohz(); |
339 | |||
340 | if (rdtp->dynticks_nesting++) | ||
341 | return; | ||
342 | rdtp->dynticks++; | ||
343 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); | ||
344 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | ||
345 | } | 449 | } |
346 | 450 | ||
347 | /** | 451 | /** |
@@ -353,18 +457,7 @@ void rcu_irq_enter(void) | |||
353 | */ | 457 | */ |
354 | void rcu_irq_exit(void) | 458 | void rcu_irq_exit(void) |
355 | { | 459 | { |
356 | struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks); | 460 | rcu_enter_nohz(); |
357 | |||
358 | if (--rdtp->dynticks_nesting) | ||
359 | return; | ||
360 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | ||
361 | rdtp->dynticks++; | ||
362 | WARN_ON_ONCE(rdtp->dynticks & 0x1); | ||
363 | |||
364 | /* If the interrupt queued a callback, get out of dyntick mode. */ | ||
365 | if (__get_cpu_var(rcu_sched_data).nxtlist || | ||
366 | __get_cpu_var(rcu_bh_data).nxtlist) | ||
367 | set_need_resched(); | ||
368 | } | 461 | } |
369 | 462 | ||
370 | #ifdef CONFIG_SMP | 463 | #ifdef CONFIG_SMP |
@@ -376,19 +469,8 @@ void rcu_irq_exit(void) | |||
376 | */ | 469 | */ |
377 | static int dyntick_save_progress_counter(struct rcu_data *rdp) | 470 | static int dyntick_save_progress_counter(struct rcu_data *rdp) |
378 | { | 471 | { |
379 | int ret; | 472 | rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks); |
380 | int snap; | 473 | return 0; |
381 | int snap_nmi; | ||
382 | |||
383 | snap = rdp->dynticks->dynticks; | ||
384 | snap_nmi = rdp->dynticks->dynticks_nmi; | ||
385 | smp_mb(); /* Order sampling of snap with end of grace period. */ | ||
386 | rdp->dynticks_snap = snap; | ||
387 | rdp->dynticks_nmi_snap = snap_nmi; | ||
388 | ret = ((snap & 0x1) == 0) && ((snap_nmi & 0x1) == 0); | ||
389 | if (ret) | ||
390 | rdp->dynticks_fqs++; | ||
391 | return ret; | ||
392 | } | 474 | } |
393 | 475 | ||
394 | /* | 476 | /* |
@@ -399,16 +481,11 @@ static int dyntick_save_progress_counter(struct rcu_data *rdp) | |||
399 | */ | 481 | */ |
400 | static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) | 482 | static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) |
401 | { | 483 | { |
402 | long curr; | 484 | unsigned long curr; |
403 | long curr_nmi; | 485 | unsigned long snap; |
404 | long snap; | ||
405 | long snap_nmi; | ||
406 | 486 | ||
407 | curr = rdp->dynticks->dynticks; | 487 | curr = (unsigned long)atomic_add_return(0, &rdp->dynticks->dynticks); |
408 | snap = rdp->dynticks_snap; | 488 | snap = (unsigned long)rdp->dynticks_snap; |
409 | curr_nmi = rdp->dynticks->dynticks_nmi; | ||
410 | snap_nmi = rdp->dynticks_nmi_snap; | ||
411 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
412 | 489 | ||
413 | /* | 490 | /* |
414 | * If the CPU passed through or entered a dynticks idle phase with | 491 | * If the CPU passed through or entered a dynticks idle phase with |
@@ -418,8 +495,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) | |||
418 | * read-side critical section that started before the beginning | 495 | * read-side critical section that started before the beginning |
419 | * of the current RCU grace period. | 496 | * of the current RCU grace period. |
420 | */ | 497 | */ |
421 | if ((curr != snap || (curr & 0x1) == 0) && | 498 | if ((curr & 0x1) == 0 || ULONG_CMP_GE(curr, snap + 2)) { |
422 | (curr_nmi != snap_nmi || (curr_nmi & 0x1) == 0)) { | ||
423 | rdp->dynticks_fqs++; | 499 | rdp->dynticks_fqs++; |
424 | return 1; | 500 | return 1; |
425 | } | 501 | } |
@@ -448,9 +524,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) | |||
448 | 524 | ||
449 | #endif /* #else #ifdef CONFIG_NO_HZ */ | 525 | #endif /* #else #ifdef CONFIG_NO_HZ */ |
450 | 526 | ||
451 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 527 | int rcu_cpu_stall_suppress __read_mostly; |
452 | |||
453 | int rcu_cpu_stall_panicking __read_mostly; | ||
454 | 528 | ||
455 | static void record_gp_stall_check_time(struct rcu_state *rsp) | 529 | static void record_gp_stall_check_time(struct rcu_state *rsp) |
456 | { | 530 | { |
@@ -482,8 +556,11 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
482 | rcu_print_task_stall(rnp); | 556 | rcu_print_task_stall(rnp); |
483 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 557 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
484 | 558 | ||
485 | /* OK, time to rat on our buddy... */ | 559 | /* |
486 | 560 | * OK, time to rat on our buddy... | |
561 | * See Documentation/RCU/stallwarn.txt for info on how to debug | ||
562 | * RCU CPU stall warnings. | ||
563 | */ | ||
487 | printk(KERN_ERR "INFO: %s detected stalls on CPUs/tasks: {", | 564 | printk(KERN_ERR "INFO: %s detected stalls on CPUs/tasks: {", |
488 | rsp->name); | 565 | rsp->name); |
489 | rcu_for_each_leaf_node(rsp, rnp) { | 566 | rcu_for_each_leaf_node(rsp, rnp) { |
@@ -512,6 +589,11 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
512 | unsigned long flags; | 589 | unsigned long flags; |
513 | struct rcu_node *rnp = rcu_get_root(rsp); | 590 | struct rcu_node *rnp = rcu_get_root(rsp); |
514 | 591 | ||
592 | /* | ||
593 | * OK, time to rat on ourselves... | ||
594 | * See Documentation/RCU/stallwarn.txt for info on how to debug | ||
595 | * RCU CPU stall warnings. | ||
596 | */ | ||
515 | printk(KERN_ERR "INFO: %s detected stall on CPU %d (t=%lu jiffies)\n", | 597 | printk(KERN_ERR "INFO: %s detected stall on CPU %d (t=%lu jiffies)\n", |
516 | rsp->name, smp_processor_id(), jiffies - rsp->gp_start); | 598 | rsp->name, smp_processor_id(), jiffies - rsp->gp_start); |
517 | trigger_all_cpu_backtrace(); | 599 | trigger_all_cpu_backtrace(); |
@@ -527,31 +609,50 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
527 | 609 | ||
528 | static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | 610 | static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) |
529 | { | 611 | { |
530 | long delta; | 612 | unsigned long j; |
613 | unsigned long js; | ||
531 | struct rcu_node *rnp; | 614 | struct rcu_node *rnp; |
532 | 615 | ||
533 | if (rcu_cpu_stall_panicking) | 616 | if (rcu_cpu_stall_suppress) |
534 | return; | 617 | return; |
535 | delta = jiffies - rsp->jiffies_stall; | 618 | j = ACCESS_ONCE(jiffies); |
619 | js = ACCESS_ONCE(rsp->jiffies_stall); | ||
536 | rnp = rdp->mynode; | 620 | rnp = rdp->mynode; |
537 | if ((rnp->qsmask & rdp->grpmask) && delta >= 0) { | 621 | if ((ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) { |
538 | 622 | ||
539 | /* We haven't checked in, so go dump stack. */ | 623 | /* We haven't checked in, so go dump stack. */ |
540 | print_cpu_stall(rsp); | 624 | print_cpu_stall(rsp); |
541 | 625 | ||
542 | } else if (rcu_gp_in_progress(rsp) && delta >= RCU_STALL_RAT_DELAY) { | 626 | } else if (rcu_gp_in_progress(rsp) && |
627 | ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) { | ||
543 | 628 | ||
544 | /* They had two time units to dump stack, so complain. */ | 629 | /* They had a few time units to dump stack, so complain. */ |
545 | print_other_cpu_stall(rsp); | 630 | print_other_cpu_stall(rsp); |
546 | } | 631 | } |
547 | } | 632 | } |
548 | 633 | ||
549 | static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr) | 634 | static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr) |
550 | { | 635 | { |
551 | rcu_cpu_stall_panicking = 1; | 636 | rcu_cpu_stall_suppress = 1; |
552 | return NOTIFY_DONE; | 637 | return NOTIFY_DONE; |
553 | } | 638 | } |
554 | 639 | ||
640 | /** | ||
641 | * rcu_cpu_stall_reset - prevent further stall warnings in current grace period | ||
642 | * | ||
643 | * Set the stall-warning timeout way off into the future, thus preventing | ||
644 | * any RCU CPU stall-warning messages from appearing in the current set of | ||
645 | * RCU grace periods. | ||
646 | * | ||
647 | * The caller must disable hard irqs. | ||
648 | */ | ||
649 | void rcu_cpu_stall_reset(void) | ||
650 | { | ||
651 | rcu_sched_state.jiffies_stall = jiffies + ULONG_MAX / 2; | ||
652 | rcu_bh_state.jiffies_stall = jiffies + ULONG_MAX / 2; | ||
653 | rcu_preempt_stall_reset(); | ||
654 | } | ||
655 | |||
555 | static struct notifier_block rcu_panic_block = { | 656 | static struct notifier_block rcu_panic_block = { |
556 | .notifier_call = rcu_panic, | 657 | .notifier_call = rcu_panic, |
557 | }; | 658 | }; |
@@ -561,22 +662,6 @@ static void __init check_cpu_stall_init(void) | |||
561 | atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block); | 662 | atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block); |
562 | } | 663 | } |
563 | 664 | ||
564 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
565 | |||
566 | static void record_gp_stall_check_time(struct rcu_state *rsp) | ||
567 | { | ||
568 | } | ||
569 | |||
570 | static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | ||
571 | { | ||
572 | } | ||
573 | |||
574 | static void __init check_cpu_stall_init(void) | ||
575 | { | ||
576 | } | ||
577 | |||
578 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
579 | |||
580 | /* | 665 | /* |
581 | * Update CPU-local rcu_data state to record the newly noticed grace period. | 666 | * Update CPU-local rcu_data state to record the newly noticed grace period. |
582 | * This is used both when we started the grace period and when we notice | 667 | * This is used both when we started the grace period and when we notice |
@@ -587,9 +672,17 @@ static void __init check_cpu_stall_init(void) | |||
587 | static void __note_new_gpnum(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp) | 672 | static void __note_new_gpnum(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp) |
588 | { | 673 | { |
589 | if (rdp->gpnum != rnp->gpnum) { | 674 | if (rdp->gpnum != rnp->gpnum) { |
590 | rdp->qs_pending = 1; | 675 | /* |
591 | rdp->passed_quiesc = 0; | 676 | * If the current grace period is waiting for this CPU, |
677 | * set up to detect a quiescent state, otherwise don't | ||
678 | * go looking for one. | ||
679 | */ | ||
592 | rdp->gpnum = rnp->gpnum; | 680 | rdp->gpnum = rnp->gpnum; |
681 | if (rnp->qsmask & rdp->grpmask) { | ||
682 | rdp->qs_pending = 1; | ||
683 | rdp->passed_quiesc = 0; | ||
684 | } else | ||
685 | rdp->qs_pending = 0; | ||
593 | } | 686 | } |
594 | } | 687 | } |
595 | 688 | ||
@@ -648,6 +741,24 @@ __rcu_process_gp_end(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_dat | |||
648 | 741 | ||
649 | /* Remember that we saw this grace-period completion. */ | 742 | /* Remember that we saw this grace-period completion. */ |
650 | rdp->completed = rnp->completed; | 743 | rdp->completed = rnp->completed; |
744 | |||
745 | /* | ||
746 | * If we were in an extended quiescent state, we may have | ||
747 | * missed some grace periods that others CPUs handled on | ||
748 | * our behalf. Catch up with this state to avoid noting | ||
749 | * spurious new grace periods. If another grace period | ||
750 | * has started, then rnp->gpnum will have advanced, so | ||
751 | * we will detect this later on. | ||
752 | */ | ||
753 | if (ULONG_CMP_LT(rdp->gpnum, rdp->completed)) | ||
754 | rdp->gpnum = rdp->completed; | ||
755 | |||
756 | /* | ||
757 | * If RCU does not need a quiescent state from this CPU, | ||
758 | * then make sure that this CPU doesn't go looking for one. | ||
759 | */ | ||
760 | if ((rnp->qsmask & rdp->grpmask) == 0) | ||
761 | rdp->qs_pending = 0; | ||
651 | } | 762 | } |
652 | } | 763 | } |
653 | 764 | ||
@@ -712,7 +823,7 @@ static void | |||
712 | rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | 823 | rcu_start_gp(struct rcu_state *rsp, unsigned long flags) |
713 | __releases(rcu_get_root(rsp)->lock) | 824 | __releases(rcu_get_root(rsp)->lock) |
714 | { | 825 | { |
715 | struct rcu_data *rdp = rsp->rda[smp_processor_id()]; | 826 | struct rcu_data *rdp = this_cpu_ptr(rsp->rda); |
716 | struct rcu_node *rnp = rcu_get_root(rsp); | 827 | struct rcu_node *rnp = rcu_get_root(rsp); |
717 | 828 | ||
718 | if (!cpu_needs_another_gp(rsp, rdp) || rsp->fqs_active) { | 829 | if (!cpu_needs_another_gp(rsp, rdp) || rsp->fqs_active) { |
@@ -753,6 +864,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | |||
753 | rnp->completed = rsp->completed; | 864 | rnp->completed = rsp->completed; |
754 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */ | 865 | rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */ |
755 | rcu_start_gp_per_cpu(rsp, rnp, rdp); | 866 | rcu_start_gp_per_cpu(rsp, rnp, rdp); |
867 | rcu_preempt_boost_start_gp(rnp); | ||
756 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 868 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
757 | return; | 869 | return; |
758 | } | 870 | } |
@@ -788,6 +900,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | |||
788 | rnp->completed = rsp->completed; | 900 | rnp->completed = rsp->completed; |
789 | if (rnp == rdp->mynode) | 901 | if (rnp == rdp->mynode) |
790 | rcu_start_gp_per_cpu(rsp, rnp, rdp); | 902 | rcu_start_gp_per_cpu(rsp, rnp, rdp); |
903 | rcu_preempt_boost_start_gp(rnp); | ||
791 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ | 904 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
792 | } | 905 | } |
793 | 906 | ||
@@ -808,7 +921,18 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) | |||
808 | static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags) | 921 | static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags) |
809 | __releases(rcu_get_root(rsp)->lock) | 922 | __releases(rcu_get_root(rsp)->lock) |
810 | { | 923 | { |
924 | unsigned long gp_duration; | ||
925 | |||
811 | WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); | 926 | WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); |
927 | |||
928 | /* | ||
929 | * Ensure that all grace-period and pre-grace-period activity | ||
930 | * is seen before the assignment to rsp->completed. | ||
931 | */ | ||
932 | smp_mb(); /* See above block comment. */ | ||
933 | gp_duration = jiffies - rsp->gp_start; | ||
934 | if (gp_duration > rsp->gp_max) | ||
935 | rsp->gp_max = gp_duration; | ||
812 | rsp->completed = rsp->gpnum; | 936 | rsp->completed = rsp->gpnum; |
813 | rsp->signaled = RCU_GP_IDLE; | 937 | rsp->signaled = RCU_GP_IDLE; |
814 | rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ | 938 | rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ |
@@ -838,7 +962,7 @@ rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp, | |||
838 | return; | 962 | return; |
839 | } | 963 | } |
840 | rnp->qsmask &= ~mask; | 964 | rnp->qsmask &= ~mask; |
841 | if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) { | 965 | if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) { |
842 | 966 | ||
843 | /* Other bits still set at this level, so done. */ | 967 | /* Other bits still set at this level, so done. */ |
844 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 968 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
@@ -951,65 +1075,49 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp) | |||
951 | #ifdef CONFIG_HOTPLUG_CPU | 1075 | #ifdef CONFIG_HOTPLUG_CPU |
952 | 1076 | ||
953 | /* | 1077 | /* |
954 | * Move a dying CPU's RCU callbacks to the ->orphan_cbs_list for the | 1078 | * Move a dying CPU's RCU callbacks to online CPU's callback list. |
955 | * specified flavor of RCU. The callbacks will be adopted by the next | 1079 | * Synchronization is not required because this function executes |
956 | * _rcu_barrier() invocation or by the CPU_DEAD notifier, whichever | 1080 | * in stop_machine() context. |
957 | * comes first. Because this is invoked from the CPU_DYING notifier, | ||
958 | * irqs are already disabled. | ||
959 | */ | 1081 | */ |
960 | static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) | 1082 | static void rcu_send_cbs_to_online(struct rcu_state *rsp) |
961 | { | 1083 | { |
962 | int i; | 1084 | int i; |
963 | struct rcu_data *rdp = rsp->rda[smp_processor_id()]; | 1085 | /* current DYING CPU is cleared in the cpu_online_mask */ |
1086 | int receive_cpu = cpumask_any(cpu_online_mask); | ||
1087 | struct rcu_data *rdp = this_cpu_ptr(rsp->rda); | ||
1088 | struct rcu_data *receive_rdp = per_cpu_ptr(rsp->rda, receive_cpu); | ||
964 | 1089 | ||
965 | if (rdp->nxtlist == NULL) | 1090 | if (rdp->nxtlist == NULL) |
966 | return; /* irqs disabled, so comparison is stable. */ | 1091 | return; /* irqs disabled, so comparison is stable. */ |
967 | raw_spin_lock(&rsp->onofflock); /* irqs already disabled. */ | 1092 | |
968 | *rsp->orphan_cbs_tail = rdp->nxtlist; | 1093 | *receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist; |
969 | rsp->orphan_cbs_tail = rdp->nxttail[RCU_NEXT_TAIL]; | 1094 | receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL]; |
1095 | receive_rdp->qlen += rdp->qlen; | ||
1096 | receive_rdp->n_cbs_adopted += rdp->qlen; | ||
1097 | rdp->n_cbs_orphaned += rdp->qlen; | ||
1098 | |||
970 | rdp->nxtlist = NULL; | 1099 | rdp->nxtlist = NULL; |
971 | for (i = 0; i < RCU_NEXT_SIZE; i++) | 1100 | for (i = 0; i < RCU_NEXT_SIZE; i++) |
972 | rdp->nxttail[i] = &rdp->nxtlist; | 1101 | rdp->nxttail[i] = &rdp->nxtlist; |
973 | rsp->orphan_qlen += rdp->qlen; | ||
974 | rdp->qlen = 0; | 1102 | rdp->qlen = 0; |
975 | raw_spin_unlock(&rsp->onofflock); /* irqs remain disabled. */ | ||
976 | } | ||
977 | |||
978 | /* | ||
979 | * Adopt previously orphaned RCU callbacks. | ||
980 | */ | ||
981 | static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) | ||
982 | { | ||
983 | unsigned long flags; | ||
984 | struct rcu_data *rdp; | ||
985 | |||
986 | raw_spin_lock_irqsave(&rsp->onofflock, flags); | ||
987 | rdp = rsp->rda[smp_processor_id()]; | ||
988 | if (rsp->orphan_cbs_list == NULL) { | ||
989 | raw_spin_unlock_irqrestore(&rsp->onofflock, flags); | ||
990 | return; | ||
991 | } | ||
992 | *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_list; | ||
993 | rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_tail; | ||
994 | rdp->qlen += rsp->orphan_qlen; | ||
995 | rsp->orphan_cbs_list = NULL; | ||
996 | rsp->orphan_cbs_tail = &rsp->orphan_cbs_list; | ||
997 | rsp->orphan_qlen = 0; | ||
998 | raw_spin_unlock_irqrestore(&rsp->onofflock, flags); | ||
999 | } | 1103 | } |
1000 | 1104 | ||
1001 | /* | 1105 | /* |
1002 | * Remove the outgoing CPU from the bitmasks in the rcu_node hierarchy | 1106 | * Remove the outgoing CPU from the bitmasks in the rcu_node hierarchy |
1003 | * and move all callbacks from the outgoing CPU to the current one. | 1107 | * and move all callbacks from the outgoing CPU to the current one. |
1108 | * There can only be one CPU hotplug operation at a time, so no other | ||
1109 | * CPU can be attempting to update rcu_cpu_kthread_task. | ||
1004 | */ | 1110 | */ |
1005 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | 1111 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) |
1006 | { | 1112 | { |
1007 | unsigned long flags; | 1113 | unsigned long flags; |
1008 | unsigned long mask; | 1114 | unsigned long mask; |
1009 | int need_report = 0; | 1115 | int need_report = 0; |
1010 | struct rcu_data *rdp = rsp->rda[cpu]; | 1116 | struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); |
1011 | struct rcu_node *rnp; | 1117 | struct rcu_node *rnp; |
1012 | 1118 | ||
1119 | rcu_stop_cpu_kthread(cpu); | ||
1120 | |||
1013 | /* Exclude any attempts to start a new grace period. */ | 1121 | /* Exclude any attempts to start a new grace period. */ |
1014 | raw_spin_lock_irqsave(&rsp->onofflock, flags); | 1122 | raw_spin_lock_irqsave(&rsp->onofflock, flags); |
1015 | 1123 | ||
@@ -1046,8 +1154,7 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
1046 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1154 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
1047 | if (need_report & RCU_OFL_TASKS_EXP_GP) | 1155 | if (need_report & RCU_OFL_TASKS_EXP_GP) |
1048 | rcu_report_exp_rnp(rsp, rnp); | 1156 | rcu_report_exp_rnp(rsp, rnp); |
1049 | 1157 | rcu_node_kthread_setaffinity(rnp, -1); | |
1050 | rcu_adopt_orphan_cbs(rsp); | ||
1051 | } | 1158 | } |
1052 | 1159 | ||
1053 | /* | 1160 | /* |
@@ -1065,11 +1172,7 @@ static void rcu_offline_cpu(int cpu) | |||
1065 | 1172 | ||
1066 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | 1173 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ |
1067 | 1174 | ||
1068 | static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) | 1175 | static void rcu_send_cbs_to_online(struct rcu_state *rsp) |
1069 | { | ||
1070 | } | ||
1071 | |||
1072 | static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) | ||
1073 | { | 1176 | { |
1074 | } | 1177 | } |
1075 | 1178 | ||
@@ -1113,7 +1216,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1113 | next = list->next; | 1216 | next = list->next; |
1114 | prefetch(next); | 1217 | prefetch(next); |
1115 | debug_rcu_head_unqueue(list); | 1218 | debug_rcu_head_unqueue(list); |
1116 | list->func(list); | 1219 | __rcu_reclaim(list); |
1117 | list = next; | 1220 | list = next; |
1118 | if (++count >= rdp->blimit) | 1221 | if (++count >= rdp->blimit) |
1119 | break; | 1222 | break; |
@@ -1123,6 +1226,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1123 | 1226 | ||
1124 | /* Update count, and requeue any remaining callbacks. */ | 1227 | /* Update count, and requeue any remaining callbacks. */ |
1125 | rdp->qlen -= count; | 1228 | rdp->qlen -= count; |
1229 | rdp->n_cbs_invoked += count; | ||
1126 | if (list != NULL) { | 1230 | if (list != NULL) { |
1127 | *tail = rdp->nxtlist; | 1231 | *tail = rdp->nxtlist; |
1128 | rdp->nxtlist = list; | 1232 | rdp->nxtlist = list; |
@@ -1148,7 +1252,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1148 | 1252 | ||
1149 | /* Re-raise the RCU softirq if there are callbacks remaining. */ | 1253 | /* Re-raise the RCU softirq if there are callbacks remaining. */ |
1150 | if (cpu_has_callbacks_ready_to_invoke(rdp)) | 1254 | if (cpu_has_callbacks_ready_to_invoke(rdp)) |
1151 | raise_softirq(RCU_SOFTIRQ); | 1255 | invoke_rcu_core(); |
1152 | } | 1256 | } |
1153 | 1257 | ||
1154 | /* | 1258 | /* |
@@ -1194,7 +1298,7 @@ void rcu_check_callbacks(int cpu, int user) | |||
1194 | } | 1298 | } |
1195 | rcu_preempt_check_callbacks(cpu); | 1299 | rcu_preempt_check_callbacks(cpu); |
1196 | if (rcu_pending(cpu)) | 1300 | if (rcu_pending(cpu)) |
1197 | raise_softirq(RCU_SOFTIRQ); | 1301 | invoke_rcu_core(); |
1198 | } | 1302 | } |
1199 | 1303 | ||
1200 | #ifdef CONFIG_SMP | 1304 | #ifdef CONFIG_SMP |
@@ -1202,6 +1306,8 @@ void rcu_check_callbacks(int cpu, int user) | |||
1202 | /* | 1306 | /* |
1203 | * Scan the leaf rcu_node structures, processing dyntick state for any that | 1307 | * Scan the leaf rcu_node structures, processing dyntick state for any that |
1204 | * have not yet encountered a quiescent state, using the function specified. | 1308 | * have not yet encountered a quiescent state, using the function specified. |
1309 | * Also initiate boosting for any threads blocked on the root rcu_node. | ||
1310 | * | ||
1205 | * The caller must have suppressed start of new grace periods. | 1311 | * The caller must have suppressed start of new grace periods. |
1206 | */ | 1312 | */ |
1207 | static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *)) | 1313 | static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *)) |
@@ -1220,13 +1326,14 @@ static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *)) | |||
1220 | return; | 1326 | return; |
1221 | } | 1327 | } |
1222 | if (rnp->qsmask == 0) { | 1328 | if (rnp->qsmask == 0) { |
1223 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1329 | rcu_initiate_boost(rnp, flags); /* releases rnp->lock */ |
1224 | continue; | 1330 | continue; |
1225 | } | 1331 | } |
1226 | cpu = rnp->grplo; | 1332 | cpu = rnp->grplo; |
1227 | bit = 1; | 1333 | bit = 1; |
1228 | for (; cpu <= rnp->grphi; cpu++, bit <<= 1) { | 1334 | for (; cpu <= rnp->grphi; cpu++, bit <<= 1) { |
1229 | if ((rnp->qsmask & bit) != 0 && f(rsp->rda[cpu])) | 1335 | if ((rnp->qsmask & bit) != 0 && |
1336 | f(per_cpu_ptr(rsp->rda, cpu))) | ||
1230 | mask |= bit; | 1337 | mask |= bit; |
1231 | } | 1338 | } |
1232 | if (mask != 0) { | 1339 | if (mask != 0) { |
@@ -1237,6 +1344,11 @@ static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *)) | |||
1237 | } | 1344 | } |
1238 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1345 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
1239 | } | 1346 | } |
1347 | rnp = rcu_get_root(rsp); | ||
1348 | if (rnp->qsmask == 0) { | ||
1349 | raw_spin_lock_irqsave(&rnp->lock, flags); | ||
1350 | rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */ | ||
1351 | } | ||
1240 | } | 1352 | } |
1241 | 1353 | ||
1242 | /* | 1354 | /* |
@@ -1351,7 +1463,8 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1351 | } | 1463 | } |
1352 | 1464 | ||
1353 | /* If there are callbacks ready, invoke them. */ | 1465 | /* If there are callbacks ready, invoke them. */ |
1354 | rcu_do_batch(rsp, rdp); | 1466 | if (cpu_has_callbacks_ready_to_invoke(rdp)) |
1467 | invoke_rcu_callbacks(rsp, rdp); | ||
1355 | } | 1468 | } |
1356 | 1469 | ||
1357 | /* | 1470 | /* |
@@ -1359,29 +1472,37 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1359 | */ | 1472 | */ |
1360 | static void rcu_process_callbacks(struct softirq_action *unused) | 1473 | static void rcu_process_callbacks(struct softirq_action *unused) |
1361 | { | 1474 | { |
1362 | /* | ||
1363 | * Memory references from any prior RCU read-side critical sections | ||
1364 | * executed by the interrupted code must be seen before any RCU | ||
1365 | * grace-period manipulations below. | ||
1366 | */ | ||
1367 | smp_mb(); /* See above block comment. */ | ||
1368 | |||
1369 | __rcu_process_callbacks(&rcu_sched_state, | 1475 | __rcu_process_callbacks(&rcu_sched_state, |
1370 | &__get_cpu_var(rcu_sched_data)); | 1476 | &__get_cpu_var(rcu_sched_data)); |
1371 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); | 1477 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); |
1372 | rcu_preempt_process_callbacks(); | 1478 | rcu_preempt_process_callbacks(); |
1373 | 1479 | ||
1374 | /* | ||
1375 | * Memory references from any later RCU read-side critical sections | ||
1376 | * executed by the interrupted code must be seen after any RCU | ||
1377 | * grace-period manipulations above. | ||
1378 | */ | ||
1379 | smp_mb(); /* See above block comment. */ | ||
1380 | |||
1381 | /* If we are last CPU on way to dyntick-idle mode, accelerate it. */ | 1480 | /* If we are last CPU on way to dyntick-idle mode, accelerate it. */ |
1382 | rcu_needs_cpu_flush(); | 1481 | rcu_needs_cpu_flush(); |
1383 | } | 1482 | } |
1384 | 1483 | ||
1484 | /* | ||
1485 | * Wake up the current CPU's kthread. This replaces raise_softirq() | ||
1486 | * in earlier versions of RCU. Note that because we are running on | ||
1487 | * the current CPU with interrupts disabled, the rcu_cpu_kthread_task | ||
1488 | * cannot disappear out from under us. | ||
1489 | */ | ||
1490 | static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | ||
1491 | { | ||
1492 | if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active))) | ||
1493 | return; | ||
1494 | if (likely(!rsp->boost)) { | ||
1495 | rcu_do_batch(rsp, rdp); | ||
1496 | return; | ||
1497 | } | ||
1498 | invoke_rcu_callbacks_kthread(); | ||
1499 | } | ||
1500 | |||
1501 | static void invoke_rcu_core(void) | ||
1502 | { | ||
1503 | raise_softirq(RCU_SOFTIRQ); | ||
1504 | } | ||
1505 | |||
1385 | static void | 1506 | static void |
1386 | __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | 1507 | __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), |
1387 | struct rcu_state *rsp) | 1508 | struct rcu_state *rsp) |
@@ -1402,21 +1523,17 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
1402 | * a quiescent state betweentimes. | 1523 | * a quiescent state betweentimes. |
1403 | */ | 1524 | */ |
1404 | local_irq_save(flags); | 1525 | local_irq_save(flags); |
1405 | rdp = rsp->rda[smp_processor_id()]; | 1526 | rdp = this_cpu_ptr(rsp->rda); |
1406 | rcu_process_gp_end(rsp, rdp); | ||
1407 | check_for_new_grace_period(rsp, rdp); | ||
1408 | 1527 | ||
1409 | /* Add the callback to our list. */ | 1528 | /* Add the callback to our list. */ |
1410 | *rdp->nxttail[RCU_NEXT_TAIL] = head; | 1529 | *rdp->nxttail[RCU_NEXT_TAIL] = head; |
1411 | rdp->nxttail[RCU_NEXT_TAIL] = &head->next; | 1530 | rdp->nxttail[RCU_NEXT_TAIL] = &head->next; |
1531 | rdp->qlen++; | ||
1412 | 1532 | ||
1413 | /* Start a new grace period if one not already started. */ | 1533 | /* If interrupts were disabled, don't dive into RCU core. */ |
1414 | if (!rcu_gp_in_progress(rsp)) { | 1534 | if (irqs_disabled_flags(flags)) { |
1415 | unsigned long nestflag; | 1535 | local_irq_restore(flags); |
1416 | struct rcu_node *rnp_root = rcu_get_root(rsp); | 1536 | return; |
1417 | |||
1418 | raw_spin_lock_irqsave(&rnp_root->lock, nestflag); | ||
1419 | rcu_start_gp(rsp, nestflag); /* releases rnp_root->lock. */ | ||
1420 | } | 1537 | } |
1421 | 1538 | ||
1422 | /* | 1539 | /* |
@@ -1426,13 +1543,28 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
1426 | * invoking force_quiescent_state() if the newly enqueued callback | 1543 | * invoking force_quiescent_state() if the newly enqueued callback |
1427 | * is the only one waiting for a grace period to complete. | 1544 | * is the only one waiting for a grace period to complete. |
1428 | */ | 1545 | */ |
1429 | if (unlikely(++rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) { | 1546 | if (unlikely(rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) { |
1430 | rdp->blimit = LONG_MAX; | 1547 | |
1431 | if (rsp->n_force_qs == rdp->n_force_qs_snap && | 1548 | /* Are we ignoring a completed grace period? */ |
1432 | *rdp->nxttail[RCU_DONE_TAIL] != head) | 1549 | rcu_process_gp_end(rsp, rdp); |
1433 | force_quiescent_state(rsp, 0); | 1550 | check_for_new_grace_period(rsp, rdp); |
1434 | rdp->n_force_qs_snap = rsp->n_force_qs; | 1551 | |
1435 | rdp->qlen_last_fqs_check = rdp->qlen; | 1552 | /* Start a new grace period if one not already started. */ |
1553 | if (!rcu_gp_in_progress(rsp)) { | ||
1554 | unsigned long nestflag; | ||
1555 | struct rcu_node *rnp_root = rcu_get_root(rsp); | ||
1556 | |||
1557 | raw_spin_lock_irqsave(&rnp_root->lock, nestflag); | ||
1558 | rcu_start_gp(rsp, nestflag); /* rlses rnp_root->lock */ | ||
1559 | } else { | ||
1560 | /* Give the grace period a kick. */ | ||
1561 | rdp->blimit = LONG_MAX; | ||
1562 | if (rsp->n_force_qs == rdp->n_force_qs_snap && | ||
1563 | *rdp->nxttail[RCU_DONE_TAIL] != head) | ||
1564 | force_quiescent_state(rsp, 0); | ||
1565 | rdp->n_force_qs_snap = rsp->n_force_qs; | ||
1566 | rdp->qlen_last_fqs_check = rdp->qlen; | ||
1567 | } | ||
1436 | } else if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies)) | 1568 | } else if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies)) |
1437 | force_quiescent_state(rsp, 1); | 1569 | force_quiescent_state(rsp, 1); |
1438 | local_irq_restore(flags); | 1570 | local_irq_restore(flags); |
@@ -1547,7 +1679,7 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1547 | * or RCU-bh, force a local reschedule. | 1679 | * or RCU-bh, force a local reschedule. |
1548 | */ | 1680 | */ |
1549 | rdp->n_rp_qs_pending++; | 1681 | rdp->n_rp_qs_pending++; |
1550 | if (!rdp->preemptable && | 1682 | if (!rdp->preemptible && |
1551 | ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs) - 1, | 1683 | ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs) - 1, |
1552 | jiffies)) | 1684 | jiffies)) |
1553 | set_need_resched(); | 1685 | set_need_resched(); |
@@ -1662,13 +1794,12 @@ static void _rcu_barrier(struct rcu_state *rsp, | |||
1662 | * decrement rcu_barrier_cpu_count -- otherwise the first CPU | 1794 | * decrement rcu_barrier_cpu_count -- otherwise the first CPU |
1663 | * might complete its grace period before all of the other CPUs | 1795 | * might complete its grace period before all of the other CPUs |
1664 | * did their increment, causing this function to return too | 1796 | * did their increment, causing this function to return too |
1665 | * early. | 1797 | * early. Note that on_each_cpu() disables irqs, which prevents |
1798 | * any CPUs from coming online or going offline until each online | ||
1799 | * CPU has queued its RCU-barrier callback. | ||
1666 | */ | 1800 | */ |
1667 | atomic_set(&rcu_barrier_cpu_count, 1); | 1801 | atomic_set(&rcu_barrier_cpu_count, 1); |
1668 | preempt_disable(); /* stop CPU_DYING from filling orphan_cbs_list */ | ||
1669 | rcu_adopt_orphan_cbs(rsp); | ||
1670 | on_each_cpu(rcu_barrier_func, (void *)call_rcu_func, 1); | 1802 | on_each_cpu(rcu_barrier_func, (void *)call_rcu_func, 1); |
1671 | preempt_enable(); /* CPU_DYING can again fill orphan_cbs_list */ | ||
1672 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | 1803 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) |
1673 | complete(&rcu_barrier_completion); | 1804 | complete(&rcu_barrier_completion); |
1674 | wait_for_completion(&rcu_barrier_completion); | 1805 | wait_for_completion(&rcu_barrier_completion); |
@@ -1701,7 +1832,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
1701 | { | 1832 | { |
1702 | unsigned long flags; | 1833 | unsigned long flags; |
1703 | int i; | 1834 | int i; |
1704 | struct rcu_data *rdp = rsp->rda[cpu]; | 1835 | struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); |
1705 | struct rcu_node *rnp = rcu_get_root(rsp); | 1836 | struct rcu_node *rnp = rcu_get_root(rsp); |
1706 | 1837 | ||
1707 | /* Set up local state, ensuring consistent view of global state. */ | 1838 | /* Set up local state, ensuring consistent view of global state. */ |
@@ -1725,11 +1856,11 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
1725 | * that this CPU cannot possibly have any RCU callbacks in flight yet. | 1856 | * that this CPU cannot possibly have any RCU callbacks in flight yet. |
1726 | */ | 1857 | */ |
1727 | static void __cpuinit | 1858 | static void __cpuinit |
1728 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | 1859 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible) |
1729 | { | 1860 | { |
1730 | unsigned long flags; | 1861 | unsigned long flags; |
1731 | unsigned long mask; | 1862 | unsigned long mask; |
1732 | struct rcu_data *rdp = rsp->rda[cpu]; | 1863 | struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); |
1733 | struct rcu_node *rnp = rcu_get_root(rsp); | 1864 | struct rcu_node *rnp = rcu_get_root(rsp); |
1734 | 1865 | ||
1735 | /* Set up local state, ensuring consistent view of global state. */ | 1866 | /* Set up local state, ensuring consistent view of global state. */ |
@@ -1737,7 +1868,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | |||
1737 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ | 1868 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ |
1738 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ | 1869 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ |
1739 | rdp->beenonline = 1; /* We have now been online. */ | 1870 | rdp->beenonline = 1; /* We have now been online. */ |
1740 | rdp->preemptable = preemptable; | 1871 | rdp->preemptible = preemptible; |
1741 | rdp->qlen_last_fqs_check = 0; | 1872 | rdp->qlen_last_fqs_check = 0; |
1742 | rdp->n_force_qs_snap = rsp->n_force_qs; | 1873 | rdp->n_force_qs_snap = rsp->n_force_qs; |
1743 | rdp->blimit = blimit; | 1874 | rdp->blimit = blimit; |
@@ -1771,7 +1902,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | |||
1771 | raw_spin_unlock_irqrestore(&rsp->onofflock, flags); | 1902 | raw_spin_unlock_irqrestore(&rsp->onofflock, flags); |
1772 | } | 1903 | } |
1773 | 1904 | ||
1774 | static void __cpuinit rcu_online_cpu(int cpu) | 1905 | static void __cpuinit rcu_prepare_cpu(int cpu) |
1775 | { | 1906 | { |
1776 | rcu_init_percpu_data(cpu, &rcu_sched_state, 0); | 1907 | rcu_init_percpu_data(cpu, &rcu_sched_state, 0); |
1777 | rcu_init_percpu_data(cpu, &rcu_bh_state, 0); | 1908 | rcu_init_percpu_data(cpu, &rcu_bh_state, 0); |
@@ -1785,27 +1916,34 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | |||
1785 | unsigned long action, void *hcpu) | 1916 | unsigned long action, void *hcpu) |
1786 | { | 1917 | { |
1787 | long cpu = (long)hcpu; | 1918 | long cpu = (long)hcpu; |
1919 | struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu); | ||
1920 | struct rcu_node *rnp = rdp->mynode; | ||
1788 | 1921 | ||
1789 | switch (action) { | 1922 | switch (action) { |
1790 | case CPU_UP_PREPARE: | 1923 | case CPU_UP_PREPARE: |
1791 | case CPU_UP_PREPARE_FROZEN: | 1924 | case CPU_UP_PREPARE_FROZEN: |
1792 | rcu_online_cpu(cpu); | 1925 | rcu_prepare_cpu(cpu); |
1926 | rcu_prepare_kthreads(cpu); | ||
1927 | break; | ||
1928 | case CPU_ONLINE: | ||
1929 | case CPU_DOWN_FAILED: | ||
1930 | rcu_node_kthread_setaffinity(rnp, -1); | ||
1931 | rcu_cpu_kthread_setrt(cpu, 1); | ||
1932 | break; | ||
1933 | case CPU_DOWN_PREPARE: | ||
1934 | rcu_node_kthread_setaffinity(rnp, cpu); | ||
1935 | rcu_cpu_kthread_setrt(cpu, 0); | ||
1793 | break; | 1936 | break; |
1794 | case CPU_DYING: | 1937 | case CPU_DYING: |
1795 | case CPU_DYING_FROZEN: | 1938 | case CPU_DYING_FROZEN: |
1796 | /* | 1939 | /* |
1797 | * preempt_disable() in _rcu_barrier() prevents stop_machine(), | 1940 | * The whole machine is "stopped" except this CPU, so we can |
1798 | * so when "on_each_cpu(rcu_barrier_func, (void *)type, 1);" | 1941 | * touch any data without introducing corruption. We send the |
1799 | * returns, all online cpus have queued rcu_barrier_func(). | 1942 | * dying CPU's callbacks to an arbitrarily chosen online CPU. |
1800 | * The dying CPU clears its cpu_online_mask bit and | ||
1801 | * moves all of its RCU callbacks to ->orphan_cbs_list | ||
1802 | * in the context of stop_machine(), so subsequent calls | ||
1803 | * to _rcu_barrier() will adopt these callbacks and only | ||
1804 | * then queue rcu_barrier_func() on all remaining CPUs. | ||
1805 | */ | 1943 | */ |
1806 | rcu_send_cbs_to_orphanage(&rcu_bh_state); | 1944 | rcu_send_cbs_to_online(&rcu_bh_state); |
1807 | rcu_send_cbs_to_orphanage(&rcu_sched_state); | 1945 | rcu_send_cbs_to_online(&rcu_sched_state); |
1808 | rcu_preempt_send_cbs_to_orphanage(); | 1946 | rcu_preempt_send_cbs_to_online(); |
1809 | break; | 1947 | break; |
1810 | case CPU_DEAD: | 1948 | case CPU_DEAD: |
1811 | case CPU_DEAD_FROZEN: | 1949 | case CPU_DEAD_FROZEN: |
@@ -1843,8 +1981,9 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp) | |||
1843 | { | 1981 | { |
1844 | int i; | 1982 | int i; |
1845 | 1983 | ||
1846 | for (i = NUM_RCU_LVLS - 1; i >= 0; i--) | 1984 | for (i = NUM_RCU_LVLS - 1; i > 0; i--) |
1847 | rsp->levelspread[i] = CONFIG_RCU_FANOUT; | 1985 | rsp->levelspread[i] = CONFIG_RCU_FANOUT; |
1986 | rsp->levelspread[0] = RCU_FANOUT_LEAF; | ||
1848 | } | 1987 | } |
1849 | #else /* #ifdef CONFIG_RCU_FANOUT_EXACT */ | 1988 | #else /* #ifdef CONFIG_RCU_FANOUT_EXACT */ |
1850 | static void __init rcu_init_levelspread(struct rcu_state *rsp) | 1989 | static void __init rcu_init_levelspread(struct rcu_state *rsp) |
@@ -1865,7 +2004,8 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp) | |||
1865 | /* | 2004 | /* |
1866 | * Helper function for rcu_init() that initializes one rcu_state structure. | 2005 | * Helper function for rcu_init() that initializes one rcu_state structure. |
1867 | */ | 2006 | */ |
1868 | static void __init rcu_init_one(struct rcu_state *rsp) | 2007 | static void __init rcu_init_one(struct rcu_state *rsp, |
2008 | struct rcu_data __percpu *rda) | ||
1869 | { | 2009 | { |
1870 | static char *buf[] = { "rcu_node_level_0", | 2010 | static char *buf[] = { "rcu_node_level_0", |
1871 | "rcu_node_level_1", | 2011 | "rcu_node_level_1", |
@@ -1911,46 +2051,29 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
1911 | j / rsp->levelspread[i - 1]; | 2051 | j / rsp->levelspread[i - 1]; |
1912 | } | 2052 | } |
1913 | rnp->level = i; | 2053 | rnp->level = i; |
1914 | INIT_LIST_HEAD(&rnp->blocked_tasks[0]); | 2054 | INIT_LIST_HEAD(&rnp->blkd_tasks); |
1915 | INIT_LIST_HEAD(&rnp->blocked_tasks[1]); | ||
1916 | INIT_LIST_HEAD(&rnp->blocked_tasks[2]); | ||
1917 | INIT_LIST_HEAD(&rnp->blocked_tasks[3]); | ||
1918 | } | 2055 | } |
1919 | } | 2056 | } |
1920 | 2057 | ||
2058 | rsp->rda = rda; | ||
1921 | rnp = rsp->level[NUM_RCU_LVLS - 1]; | 2059 | rnp = rsp->level[NUM_RCU_LVLS - 1]; |
1922 | for_each_possible_cpu(i) { | 2060 | for_each_possible_cpu(i) { |
1923 | while (i > rnp->grphi) | 2061 | while (i > rnp->grphi) |
1924 | rnp++; | 2062 | rnp++; |
1925 | rsp->rda[i]->mynode = rnp; | 2063 | per_cpu_ptr(rsp->rda, i)->mynode = rnp; |
1926 | rcu_boot_init_percpu_data(i, rsp); | 2064 | rcu_boot_init_percpu_data(i, rsp); |
1927 | } | 2065 | } |
1928 | } | 2066 | } |
1929 | 2067 | ||
1930 | /* | ||
1931 | * Helper macro for __rcu_init() and __rcu_init_preempt(). To be used | ||
1932 | * nowhere else! Assigns leaf node pointers into each CPU's rcu_data | ||
1933 | * structure. | ||
1934 | */ | ||
1935 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ | ||
1936 | do { \ | ||
1937 | int i; \ | ||
1938 | \ | ||
1939 | for_each_possible_cpu(i) { \ | ||
1940 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ | ||
1941 | } \ | ||
1942 | rcu_init_one(rsp); \ | ||
1943 | } while (0) | ||
1944 | |||
1945 | void __init rcu_init(void) | 2068 | void __init rcu_init(void) |
1946 | { | 2069 | { |
1947 | int cpu; | 2070 | int cpu; |
1948 | 2071 | ||
1949 | rcu_bootup_announce(); | 2072 | rcu_bootup_announce(); |
1950 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); | 2073 | rcu_init_one(&rcu_sched_state, &rcu_sched_data); |
1951 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); | 2074 | rcu_init_one(&rcu_bh_state, &rcu_bh_data); |
1952 | __rcu_init_preempt(); | 2075 | __rcu_init_preempt(); |
1953 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | 2076 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); |
1954 | 2077 | ||
1955 | /* | 2078 | /* |
1956 | * We don't need protection against CPU-hotplug here because | 2079 | * We don't need protection against CPU-hotplug here because |