aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcu/tree.c
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2014-12-13 23:32:04 -0500
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2015-01-16 02:33:14 -0500
commit5cd37193ce8539be1e6ef76be226f4bcc984e0f5 (patch)
tree7bba4e3fd57b669d60e37fd32011db4860016505 /kernel/rcu/tree.c
parenta94844b22a2e2b9155bbc0878c507850477221c2 (diff)
rcu: Make cond_resched_rcu_qs() apply to normal RCU flavors
Although cond_resched_rcu_qs() only applies to TASKS_RCU, it is used in places where it would be useful for it to apply to the normal RCU flavors, rcu_preempt, rcu_sched, and rcu_bh. This is especially the case for workloads that aggressively overload the system, particularly those that generate large numbers of RCU updates on systems running NO_HZ_FULL CPUs. This commit therefore communicates quiescent states from cond_resched_rcu_qs() to the normal RCU flavors. Note that it is unfortunately necessary to leave the old ->passed_quiesce mechanism in place to allow quiescent states that apply to only one flavor to be recorded. (Yes, we could decrement ->rcu_qs_ctr_snap in that case, but that is not so good for debugging of RCU internals.) In addition, if one of the RCU flavor's grace period has stalled, this will invoke rcu_momentary_dyntick_idle(), resulting in a heavy-weight quiescent state visible from other CPUs. Reported-by: Sasha Levin <sasha.levin@oracle.com> Reported-by: Dave Jones <davej@redhat.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> [ paulmck: Merge commit from Sasha Levin fixing a bug where __this_cpu() was used in preemptible code. ]
Diffstat (limited to 'kernel/rcu/tree.c')
-rw-r--r--kernel/rcu/tree.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 75ce12316b4c..cb00e038c2f2 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -219,6 +219,9 @@ static DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
219#endif /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */ 219#endif /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
220}; 220};
221 221
222DEFINE_PER_CPU_SHARED_ALIGNED(unsigned long, rcu_qs_ctr);
223EXPORT_PER_CPU_SYMBOL_GPL(rcu_qs_ctr);
224
222/* 225/*
223 * Let the RCU core know that this CPU has gone through the scheduler, 226 * Let the RCU core know that this CPU has gone through the scheduler,
224 * which is a quiescent state. This is called when the need for a 227 * which is a quiescent state. This is called when the need for a
@@ -288,6 +291,22 @@ void rcu_note_context_switch(void)
288} 291}
289EXPORT_SYMBOL_GPL(rcu_note_context_switch); 292EXPORT_SYMBOL_GPL(rcu_note_context_switch);
290 293
294/*
295 * Register a quiesecent state for all RCU flavors. If there is an
296 * emergency, invoke rcu_momentary_dyntick_idle() to do a heavy-weight
297 * dyntick-idle quiescent state visible to other CPUs (but only for those
298 * RCU flavors in desparate need of a quiescent state, which will normally
299 * be none of them). Either way, do a lightweight quiescent state for
300 * all RCU flavors.
301 */
302void rcu_all_qs(void)
303{
304 if (unlikely(raw_cpu_read(rcu_sched_qs_mask)))
305 rcu_momentary_dyntick_idle();
306 this_cpu_inc(rcu_qs_ctr);
307}
308EXPORT_SYMBOL_GPL(rcu_all_qs);
309
291static long blimit = 10; /* Maximum callbacks per rcu_do_batch. */ 310static long blimit = 10; /* Maximum callbacks per rcu_do_batch. */
292static long qhimark = 10000; /* If this many pending, ignore blimit. */ 311static long qhimark = 10000; /* If this many pending, ignore blimit. */
293static long qlowmark = 100; /* Once only this many pending, use blimit. */ 312static long qlowmark = 100; /* Once only this many pending, use blimit. */
@@ -1609,6 +1628,7 @@ static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,
1609 rdp->gpnum = rnp->gpnum; 1628 rdp->gpnum = rnp->gpnum;
1610 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpustart")); 1629 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpustart"));
1611 rdp->passed_quiesce = 0; 1630 rdp->passed_quiesce = 0;
1631 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
1612 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask); 1632 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
1613 zero_cpu_stall_ticks(rdp); 1633 zero_cpu_stall_ticks(rdp);
1614 ACCESS_ONCE(rdp->gpwrap) = false; 1634 ACCESS_ONCE(rdp->gpwrap) = false;
@@ -2075,8 +2095,10 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
2075 rnp = rdp->mynode; 2095 rnp = rdp->mynode;
2076 raw_spin_lock_irqsave(&rnp->lock, flags); 2096 raw_spin_lock_irqsave(&rnp->lock, flags);
2077 smp_mb__after_unlock_lock(); 2097 smp_mb__after_unlock_lock();
2078 if (rdp->passed_quiesce == 0 || rdp->gpnum != rnp->gpnum || 2098 if ((rdp->passed_quiesce == 0 &&
2079 rnp->completed == rnp->gpnum || rdp->gpwrap) { 2099 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr)) ||
2100 rdp->gpnum != rnp->gpnum || rnp->completed == rnp->gpnum ||
2101 rdp->gpwrap) {
2080 2102
2081 /* 2103 /*
2082 * The grace period in which this quiescent state was 2104 * The grace period in which this quiescent state was
@@ -2085,6 +2107,7 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
2085 * within the current grace period. 2107 * within the current grace period.
2086 */ 2108 */
2087 rdp->passed_quiesce = 0; /* need qs for new gp. */ 2109 rdp->passed_quiesce = 0; /* need qs for new gp. */
2110 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
2088 raw_spin_unlock_irqrestore(&rnp->lock, flags); 2111 raw_spin_unlock_irqrestore(&rnp->lock, flags);
2089 return; 2112 return;
2090 } 2113 }
@@ -2129,7 +2152,8 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
2129 * Was there a quiescent state since the beginning of the grace 2152 * Was there a quiescent state since the beginning of the grace
2130 * period? If no, then exit and wait for the next call. 2153 * period? If no, then exit and wait for the next call.
2131 */ 2154 */
2132 if (!rdp->passed_quiesce) 2155 if (!rdp->passed_quiesce &&
2156 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr))
2133 return; 2157 return;
2134 2158
2135 /* 2159 /*
@@ -3174,9 +3198,12 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
3174 3198
3175 /* Is the RCU core waiting for a quiescent state from this CPU? */ 3199 /* Is the RCU core waiting for a quiescent state from this CPU? */
3176 if (rcu_scheduler_fully_active && 3200 if (rcu_scheduler_fully_active &&
3177 rdp->qs_pending && !rdp->passed_quiesce) { 3201 rdp->qs_pending && !rdp->passed_quiesce &&
3202 rdp->rcu_qs_ctr_snap == __this_cpu_read(rcu_qs_ctr)) {
3178 rdp->n_rp_qs_pending++; 3203 rdp->n_rp_qs_pending++;
3179 } else if (rdp->qs_pending && rdp->passed_quiesce) { 3204 } else if (rdp->qs_pending &&
3205 (rdp->passed_quiesce ||
3206 rdp->rcu_qs_ctr_snap != __this_cpu_read(rcu_qs_ctr))) {
3180 rdp->n_rp_report_qs++; 3207 rdp->n_rp_report_qs++;
3181 return 1; 3208 return 1;
3182 } 3209 }
@@ -3510,6 +3537,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
3510 rdp->gpnum = rnp->completed; 3537 rdp->gpnum = rnp->completed;
3511 rdp->completed = rnp->completed; 3538 rdp->completed = rnp->completed;
3512 rdp->passed_quiesce = 0; 3539 rdp->passed_quiesce = 0;
3540 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
3513 rdp->qs_pending = 0; 3541 rdp->qs_pending = 0;
3514 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl")); 3542 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl"));
3515 } 3543 }