diff options
Diffstat (limited to 'kernel/rcutree_plugin.h')
-rw-r--r-- | kernel/rcutree_plugin.h | 191 |
1 files changed, 137 insertions, 54 deletions
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h index 47789369ea59..c0cb783aa16a 100644 --- a/kernel/rcutree_plugin.h +++ b/kernel/rcutree_plugin.h | |||
@@ -64,22 +64,31 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed); | |||
64 | * not in a quiescent state. There might be any number of tasks blocked | 64 | * not in a quiescent state. There might be any number of tasks blocked |
65 | * while in an RCU read-side critical section. | 65 | * while in an RCU read-side critical section. |
66 | */ | 66 | */ |
67 | static void rcu_preempt_qs_record(int cpu) | 67 | static void rcu_preempt_qs(int cpu) |
68 | { | 68 | { |
69 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); | 69 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); |
70 | rdp->passed_quiesc = 1; | ||
71 | rdp->passed_quiesc_completed = rdp->completed; | 70 | rdp->passed_quiesc_completed = rdp->completed; |
71 | barrier(); | ||
72 | rdp->passed_quiesc = 1; | ||
72 | } | 73 | } |
73 | 74 | ||
74 | /* | 75 | /* |
75 | * We have entered the scheduler or are between softirqs in ksoftirqd. | 76 | * We have entered the scheduler, and the current task might soon be |
76 | * If we are in an RCU read-side critical section, we need to reflect | 77 | * context-switched away from. If this task is in an RCU read-side |
77 | * that in the state of the rcu_node structure corresponding to this CPU. | 78 | * critical section, we will no longer be able to rely on the CPU to |
78 | * Caller must disable hardirqs. | 79 | * record that fact, so we enqueue the task on the appropriate entry |
80 | * of the blocked_tasks[] array. The task will dequeue itself when | ||
81 | * it exits the outermost enclosing RCU read-side critical section. | ||
82 | * Therefore, the current grace period cannot be permitted to complete | ||
83 | * until the blocked_tasks[] entry indexed by the low-order bit of | ||
84 | * rnp->gpnum empties. | ||
85 | * | ||
86 | * Caller must disable preemption. | ||
79 | */ | 87 | */ |
80 | static void rcu_preempt_qs(int cpu) | 88 | static void rcu_preempt_note_context_switch(int cpu) |
81 | { | 89 | { |
82 | struct task_struct *t = current; | 90 | struct task_struct *t = current; |
91 | unsigned long flags; | ||
83 | int phase; | 92 | int phase; |
84 | struct rcu_data *rdp; | 93 | struct rcu_data *rdp; |
85 | struct rcu_node *rnp; | 94 | struct rcu_node *rnp; |
@@ -90,7 +99,7 @@ static void rcu_preempt_qs(int cpu) | |||
90 | /* Possibly blocking in an RCU read-side critical section. */ | 99 | /* Possibly blocking in an RCU read-side critical section. */ |
91 | rdp = rcu_preempt_state.rda[cpu]; | 100 | rdp = rcu_preempt_state.rda[cpu]; |
92 | rnp = rdp->mynode; | 101 | rnp = rdp->mynode; |
93 | spin_lock(&rnp->lock); | 102 | spin_lock_irqsave(&rnp->lock, flags); |
94 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; | 103 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; |
95 | t->rcu_blocked_node = rnp; | 104 | t->rcu_blocked_node = rnp; |
96 | 105 | ||
@@ -103,11 +112,15 @@ static void rcu_preempt_qs(int cpu) | |||
103 | * state for the current grace period), then as long | 112 | * state for the current grace period), then as long |
104 | * as that task remains queued, the current grace period | 113 | * as that task remains queued, the current grace period |
105 | * cannot end. | 114 | * cannot end. |
115 | * | ||
116 | * But first, note that the current CPU must still be | ||
117 | * on line! | ||
106 | */ | 118 | */ |
107 | phase = !(rnp->qsmask & rdp->grpmask) ^ (rnp->gpnum & 0x1); | 119 | WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0); |
120 | WARN_ON_ONCE(!list_empty(&t->rcu_node_entry)); | ||
121 | phase = (rnp->gpnum + !(rnp->qsmask & rdp->grpmask)) & 0x1; | ||
108 | list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]); | 122 | list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]); |
109 | smp_mb(); /* Ensure later ctxt swtch seen after above. */ | 123 | spin_unlock_irqrestore(&rnp->lock, flags); |
110 | spin_unlock(&rnp->lock); | ||
111 | } | 124 | } |
112 | 125 | ||
113 | /* | 126 | /* |
@@ -119,9 +132,10 @@ static void rcu_preempt_qs(int cpu) | |||
119 | * grace period, then the fact that the task has been enqueued | 132 | * grace period, then the fact that the task has been enqueued |
120 | * means that we continue to block the current grace period. | 133 | * means that we continue to block the current grace period. |
121 | */ | 134 | */ |
122 | rcu_preempt_qs_record(cpu); | 135 | rcu_preempt_qs(cpu); |
123 | t->rcu_read_unlock_special &= ~(RCU_READ_UNLOCK_NEED_QS | | 136 | local_irq_save(flags); |
124 | RCU_READ_UNLOCK_GOT_QS); | 137 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; |
138 | local_irq_restore(flags); | ||
125 | } | 139 | } |
126 | 140 | ||
127 | /* | 141 | /* |
@@ -136,6 +150,16 @@ void __rcu_read_lock(void) | |||
136 | } | 150 | } |
137 | EXPORT_SYMBOL_GPL(__rcu_read_lock); | 151 | EXPORT_SYMBOL_GPL(__rcu_read_lock); |
138 | 152 | ||
153 | /* | ||
154 | * Check for preempted RCU readers blocking the current grace period | ||
155 | * for the specified rcu_node structure. If the caller needs a reliable | ||
156 | * answer, it must hold the rcu_node's ->lock. | ||
157 | */ | ||
158 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
159 | { | ||
160 | return !list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | ||
161 | } | ||
162 | |||
139 | static void rcu_read_unlock_special(struct task_struct *t) | 163 | static void rcu_read_unlock_special(struct task_struct *t) |
140 | { | 164 | { |
141 | int empty; | 165 | int empty; |
@@ -157,7 +181,7 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
157 | special = t->rcu_read_unlock_special; | 181 | special = t->rcu_read_unlock_special; |
158 | if (special & RCU_READ_UNLOCK_NEED_QS) { | 182 | if (special & RCU_READ_UNLOCK_NEED_QS) { |
159 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | 183 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; |
160 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_GOT_QS; | 184 | rcu_preempt_qs(smp_processor_id()); |
161 | } | 185 | } |
162 | 186 | ||
163 | /* Hardware IRQ handlers cannot block. */ | 187 | /* Hardware IRQ handlers cannot block. */ |
@@ -177,12 +201,12 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
177 | */ | 201 | */ |
178 | for (;;) { | 202 | for (;;) { |
179 | rnp = t->rcu_blocked_node; | 203 | rnp = t->rcu_blocked_node; |
180 | spin_lock(&rnp->lock); | 204 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
181 | if (rnp == t->rcu_blocked_node) | 205 | if (rnp == t->rcu_blocked_node) |
182 | break; | 206 | break; |
183 | spin_unlock(&rnp->lock); | 207 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
184 | } | 208 | } |
185 | empty = list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | 209 | empty = !rcu_preempted_readers(rnp); |
186 | list_del_init(&t->rcu_node_entry); | 210 | list_del_init(&t->rcu_node_entry); |
187 | t->rcu_blocked_node = NULL; | 211 | t->rcu_blocked_node = NULL; |
188 | 212 | ||
@@ -193,10 +217,9 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
193 | * drop rnp->lock and restore irq. | 217 | * drop rnp->lock and restore irq. |
194 | */ | 218 | */ |
195 | if (!empty && rnp->qsmask == 0 && | 219 | if (!empty && rnp->qsmask == 0 && |
196 | list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1])) { | 220 | !rcu_preempted_readers(rnp)) { |
197 | t->rcu_read_unlock_special &= | 221 | struct rcu_node *rnp_p; |
198 | ~(RCU_READ_UNLOCK_NEED_QS | | 222 | |
199 | RCU_READ_UNLOCK_GOT_QS); | ||
200 | if (rnp->parent == NULL) { | 223 | if (rnp->parent == NULL) { |
201 | /* Only one rcu_node in the tree. */ | 224 | /* Only one rcu_node in the tree. */ |
202 | cpu_quiet_msk_finish(&rcu_preempt_state, flags); | 225 | cpu_quiet_msk_finish(&rcu_preempt_state, flags); |
@@ -205,9 +228,10 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
205 | /* Report up the rest of the hierarchy. */ | 228 | /* Report up the rest of the hierarchy. */ |
206 | mask = rnp->grpmask; | 229 | mask = rnp->grpmask; |
207 | spin_unlock_irqrestore(&rnp->lock, flags); | 230 | spin_unlock_irqrestore(&rnp->lock, flags); |
208 | rnp = rnp->parent; | 231 | rnp_p = rnp->parent; |
209 | spin_lock_irqsave(&rnp->lock, flags); | 232 | spin_lock_irqsave(&rnp_p->lock, flags); |
210 | cpu_quiet_msk(mask, &rcu_preempt_state, rnp, flags); | 233 | WARN_ON_ONCE(rnp->qsmask); |
234 | cpu_quiet_msk(mask, &rcu_preempt_state, rnp_p, flags); | ||
211 | return; | 235 | return; |
212 | } | 236 | } |
213 | spin_unlock(&rnp->lock); | 237 | spin_unlock(&rnp->lock); |
@@ -243,12 +267,12 @@ static void rcu_print_task_stall(struct rcu_node *rnp) | |||
243 | { | 267 | { |
244 | unsigned long flags; | 268 | unsigned long flags; |
245 | struct list_head *lp; | 269 | struct list_head *lp; |
246 | int phase = rnp->gpnum & 0x1; | 270 | int phase; |
247 | struct task_struct *t; | 271 | struct task_struct *t; |
248 | 272 | ||
249 | if (!list_empty(&rnp->blocked_tasks[phase])) { | 273 | if (rcu_preempted_readers(rnp)) { |
250 | spin_lock_irqsave(&rnp->lock, flags); | 274 | spin_lock_irqsave(&rnp->lock, flags); |
251 | phase = rnp->gpnum & 0x1; /* re-read under lock. */ | 275 | phase = rnp->gpnum & 0x1; |
252 | lp = &rnp->blocked_tasks[phase]; | 276 | lp = &rnp->blocked_tasks[phase]; |
253 | list_for_each_entry(t, lp, rcu_node_entry) | 277 | list_for_each_entry(t, lp, rcu_node_entry) |
254 | printk(" P%d", t->pid); | 278 | printk(" P%d", t->pid); |
@@ -259,13 +283,16 @@ static void rcu_print_task_stall(struct rcu_node *rnp) | |||
259 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 283 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
260 | 284 | ||
261 | /* | 285 | /* |
262 | * Check for preempted RCU readers for the specified rcu_node structure. | 286 | * Check that the list of blocked tasks for the newly completed grace |
263 | * If the caller needs a reliable answer, it must hold the rcu_node's | 287 | * period is in fact empty. It is a serious bug to complete a grace |
264 | * >lock. | 288 | * period that still has RCU readers blocked! This function must be |
289 | * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock | ||
290 | * must be held by the caller. | ||
265 | */ | 291 | */ |
266 | static int rcu_preempted_readers(struct rcu_node *rnp) | 292 | static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) |
267 | { | 293 | { |
268 | return !list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | 294 | WARN_ON_ONCE(rcu_preempted_readers(rnp)); |
295 | WARN_ON_ONCE(rnp->qsmask); | ||
269 | } | 296 | } |
270 | 297 | ||
271 | #ifdef CONFIG_HOTPLUG_CPU | 298 | #ifdef CONFIG_HOTPLUG_CPU |
@@ -280,7 +307,8 @@ static int rcu_preempted_readers(struct rcu_node *rnp) | |||
280 | * The caller must hold rnp->lock with irqs disabled. | 307 | * The caller must hold rnp->lock with irqs disabled. |
281 | */ | 308 | */ |
282 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | 309 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, |
283 | struct rcu_node *rnp) | 310 | struct rcu_node *rnp, |
311 | struct rcu_data *rdp) | ||
284 | { | 312 | { |
285 | int i; | 313 | int i; |
286 | struct list_head *lp; | 314 | struct list_head *lp; |
@@ -292,6 +320,9 @@ static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | |||
292 | WARN_ONCE(1, "Last CPU thought to be offlined?"); | 320 | WARN_ONCE(1, "Last CPU thought to be offlined?"); |
293 | return; /* Shouldn't happen: at least one CPU online. */ | 321 | return; /* Shouldn't happen: at least one CPU online. */ |
294 | } | 322 | } |
323 | WARN_ON_ONCE(rnp != rdp->mynode && | ||
324 | (!list_empty(&rnp->blocked_tasks[0]) || | ||
325 | !list_empty(&rnp->blocked_tasks[1]))); | ||
295 | 326 | ||
296 | /* | 327 | /* |
297 | * Move tasks up to root rcu_node. Rely on the fact that the | 328 | * Move tasks up to root rcu_node. Rely on the fact that the |
@@ -335,20 +366,12 @@ static void rcu_preempt_check_callbacks(int cpu) | |||
335 | struct task_struct *t = current; | 366 | struct task_struct *t = current; |
336 | 367 | ||
337 | if (t->rcu_read_lock_nesting == 0) { | 368 | if (t->rcu_read_lock_nesting == 0) { |
338 | t->rcu_read_unlock_special &= | 369 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; |
339 | ~(RCU_READ_UNLOCK_NEED_QS | RCU_READ_UNLOCK_GOT_QS); | 370 | rcu_preempt_qs(cpu); |
340 | rcu_preempt_qs_record(cpu); | ||
341 | return; | 371 | return; |
342 | } | 372 | } |
343 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) { | 373 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) |
344 | if (t->rcu_read_unlock_special & RCU_READ_UNLOCK_GOT_QS) { | 374 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; |
345 | rcu_preempt_qs_record(cpu); | ||
346 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_GOT_QS; | ||
347 | } else if (!(t->rcu_read_unlock_special & | ||
348 | RCU_READ_UNLOCK_NEED_QS)) { | ||
349 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; | ||
350 | } | ||
351 | } | ||
352 | } | 375 | } |
353 | 376 | ||
354 | /* | 377 | /* |
@@ -387,6 +410,15 @@ static int rcu_preempt_needs_cpu(int cpu) | |||
387 | return !!per_cpu(rcu_preempt_data, cpu).nxtlist; | 410 | return !!per_cpu(rcu_preempt_data, cpu).nxtlist; |
388 | } | 411 | } |
389 | 412 | ||
413 | /** | ||
414 | * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete. | ||
415 | */ | ||
416 | void rcu_barrier(void) | ||
417 | { | ||
418 | _rcu_barrier(&rcu_preempt_state, call_rcu); | ||
419 | } | ||
420 | EXPORT_SYMBOL_GPL(rcu_barrier); | ||
421 | |||
390 | /* | 422 | /* |
391 | * Initialize preemptable RCU's per-CPU data. | 423 | * Initialize preemptable RCU's per-CPU data. |
392 | */ | 424 | */ |
@@ -396,6 +428,22 @@ static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | |||
396 | } | 428 | } |
397 | 429 | ||
398 | /* | 430 | /* |
431 | * Move preemptable RCU's callbacks to ->orphan_cbs_list. | ||
432 | */ | ||
433 | static void rcu_preempt_send_cbs_to_orphanage(void) | ||
434 | { | ||
435 | rcu_send_cbs_to_orphanage(&rcu_preempt_state); | ||
436 | } | ||
437 | |||
438 | /* | ||
439 | * Initialize preemptable RCU's state structures. | ||
440 | */ | ||
441 | static void __init __rcu_init_preempt(void) | ||
442 | { | ||
443 | RCU_INIT_FLAVOR(&rcu_preempt_state, rcu_preempt_data); | ||
444 | } | ||
445 | |||
446 | /* | ||
399 | * Check for a task exiting while in a preemptable-RCU read-side | 447 | * Check for a task exiting while in a preemptable-RCU read-side |
400 | * critical section, clean up if so. No need to issue warnings, | 448 | * critical section, clean up if so. No need to issue warnings, |
401 | * as debug_check_no_locks_held() already does this if lockdep | 449 | * as debug_check_no_locks_held() already does this if lockdep |
@@ -434,8 +482,17 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed); | |||
434 | * Because preemptable RCU does not exist, we never have to check for | 482 | * Because preemptable RCU does not exist, we never have to check for |
435 | * CPUs being in quiescent states. | 483 | * CPUs being in quiescent states. |
436 | */ | 484 | */ |
437 | static void rcu_preempt_qs(int cpu) | 485 | static void rcu_preempt_note_context_switch(int cpu) |
486 | { | ||
487 | } | ||
488 | |||
489 | /* | ||
490 | * Because preemptable RCU does not exist, there are never any preempted | ||
491 | * RCU readers. | ||
492 | */ | ||
493 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
438 | { | 494 | { |
495 | return 0; | ||
439 | } | 496 | } |
440 | 497 | ||
441 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 498 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR |
@@ -451,12 +508,13 @@ static void rcu_print_task_stall(struct rcu_node *rnp) | |||
451 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 508 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
452 | 509 | ||
453 | /* | 510 | /* |
454 | * Because preemptable RCU does not exist, there are never any preempted | 511 | * Because there is no preemptable RCU, there can be no readers blocked, |
455 | * RCU readers. | 512 | * so there is no need to check for blocked tasks. So check only for |
513 | * bogus qsmask values. | ||
456 | */ | 514 | */ |
457 | static int rcu_preempted_readers(struct rcu_node *rnp) | 515 | static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) |
458 | { | 516 | { |
459 | return 0; | 517 | WARN_ON_ONCE(rnp->qsmask); |
460 | } | 518 | } |
461 | 519 | ||
462 | #ifdef CONFIG_HOTPLUG_CPU | 520 | #ifdef CONFIG_HOTPLUG_CPU |
@@ -466,7 +524,8 @@ static int rcu_preempted_readers(struct rcu_node *rnp) | |||
466 | * tasks that were blocked within RCU read-side critical sections. | 524 | * tasks that were blocked within RCU read-side critical sections. |
467 | */ | 525 | */ |
468 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | 526 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, |
469 | struct rcu_node *rnp) | 527 | struct rcu_node *rnp, |
528 | struct rcu_data *rdp) | ||
470 | { | 529 | { |
471 | } | 530 | } |
472 | 531 | ||
@@ -484,7 +543,7 @@ static void rcu_preempt_offline_cpu(int cpu) | |||
484 | * Because preemptable RCU does not exist, it never has any callbacks | 543 | * Because preemptable RCU does not exist, it never has any callbacks |
485 | * to check. | 544 | * to check. |
486 | */ | 545 | */ |
487 | void rcu_preempt_check_callbacks(int cpu) | 546 | static void rcu_preempt_check_callbacks(int cpu) |
488 | { | 547 | { |
489 | } | 548 | } |
490 | 549 | ||
@@ -492,7 +551,7 @@ void rcu_preempt_check_callbacks(int cpu) | |||
492 | * Because preemptable RCU does not exist, it never has any callbacks | 551 | * Because preemptable RCU does not exist, it never has any callbacks |
493 | * to process. | 552 | * to process. |
494 | */ | 553 | */ |
495 | void rcu_preempt_process_callbacks(void) | 554 | static void rcu_preempt_process_callbacks(void) |
496 | { | 555 | { |
497 | } | 556 | } |
498 | 557 | ||
@@ -522,6 +581,16 @@ static int rcu_preempt_needs_cpu(int cpu) | |||
522 | } | 581 | } |
523 | 582 | ||
524 | /* | 583 | /* |
584 | * Because preemptable RCU does not exist, rcu_barrier() is just | ||
585 | * another name for rcu_barrier_sched(). | ||
586 | */ | ||
587 | void rcu_barrier(void) | ||
588 | { | ||
589 | rcu_barrier_sched(); | ||
590 | } | ||
591 | EXPORT_SYMBOL_GPL(rcu_barrier); | ||
592 | |||
593 | /* | ||
525 | * Because preemptable RCU does not exist, there is no per-CPU | 594 | * Because preemptable RCU does not exist, there is no per-CPU |
526 | * data to initialize. | 595 | * data to initialize. |
527 | */ | 596 | */ |
@@ -529,4 +598,18 @@ static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | |||
529 | { | 598 | { |
530 | } | 599 | } |
531 | 600 | ||
601 | /* | ||
602 | * Because there is no preemptable RCU, there are no callbacks to move. | ||
603 | */ | ||
604 | static void rcu_preempt_send_cbs_to_orphanage(void) | ||
605 | { | ||
606 | } | ||
607 | |||
608 | /* | ||
609 | * Because preemptable RCU does not exist, it need not be initialized. | ||
610 | */ | ||
611 | static void __init __rcu_init_preempt(void) | ||
612 | { | ||
613 | } | ||
614 | |||
532 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | 615 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ |