lkml.org 
[lkml]   [2018]   [Jul]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [RFC] Make need_resched() return true when rcu_urgent_qs requested
On Mon, Jul 09, 2018 at 09:45:45PM +0100, David Woodhouse wrote:
> On Mon, 2018-07-09 at 13:42 -0700, Paul E. McKenney wrote:
> > On Mon, Jul 09, 2018 at 09:35:38PM +0100, David Woodhouse wrote:
> > > 
> > > 
> > > On Mon, 2018-07-09 at 13:34 -0700, Paul E. McKenney wrote:
> > > > 
> > > > So here are the possible code paths when .rcu_urgent_qs is set to true:
> > > > 
> > > > 1.      A context switch will record the quiescent state and clear
> > > >         .rcu_urgent_qs.  (The failure to do the clearing in current -rcu
> > > >         for PREEMPT builds is a performance bug that I need to fix.)
> > > 
> > > What if there's nothing else runnable and there is no actual context
> > > switch?
> >
> > The scheduler invokes rcu_note_context_switch() before looking to see
> > if there really will or won't be a context switch.
> >
> > I am sure that Peter will correct me if I am confused on this point.  ;-)
>
> Ah, OK. Yes, that looks correct. Thanks.

Here is hoping!

> I'll give your patch a spin tomorrow, unless Marius beats me to it.

Please see below for the version that I eventually queued. Should Marius
have a Reported-by? If so, please tell me his full name so I can add that.

Thanx, Paul

------------------------------------------------------------------------

commit e1e91fd0796dc544a77ddfaa5afbfc1f5fb42ecd
Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Date: Mon Jul 9 13:47:30 2018 -0700

rcu: Make need_resched() respond to urgent RCU-QS needs

The per-CPU rcu_dynticks.rcu_urgent_qs variable communicates an urgent
need for an RCU quiescent state from the force-quiescent-state processing
within the grace-period kthread to context switches and to cond_resched().
Unfortunately, such urgent needs are not communicated to need_resched(),
which is sometimes used to decide when to invoke cond_resched(), for
but one example, within the KVM vcpu_run() function. As of v4.15, this
can result in synchronize_sched() being delayed by up to ten seconds,
which can be problematic, to say nothing of annoying.

This commit therefore checks rcu_dynticks.rcu_urgent_qs from within
rcu_check_callbacks(), which is invoked from the scheduling-clock
interrupt handler. If the current task is not an idle task and is
not executing in usermode, a context switch is forced, and either way,
the rcu_dynticks.rcu_urgent_qs variable is set to false. If the current
task is an idle task, then RCU's dyntick-idle code will detect the
quiescent state, so no further action is required. Similarly, if the
task is executing in usermode, other code in rcu_check_callbacks() and
its called functions will report the corresponding quiescent state.

Reported-by: David Woodhouse <dwmw2@infradead.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 51919985f6cf..ea756bb64eb3 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2496,6 +2496,15 @@ void rcu_check_callbacks(int user)
{
trace_rcu_utilization(TPS("Start scheduler-tick"));
raw_cpu_inc(rcu_data.ticks_this_gp);
+ /* The load-acquire pairs with the store-release setting to true. */
+ if (smp_load_acquire(this_cpu_ptr(&rcu_dynticks.rcu_urgent_qs))) {
+ /* Idle and userspace execution already are quiescent states. */
+ if (!is_idle_task(current) && !user) {
+ set_tsk_need_resched(current);
+ set_preempt_need_resched();
+ }
+ __this_cpu_write(rcu_dynticks.rcu_urgent_qs, false);
+ }
rcu_flavor_check_callbacks(user);
if (rcu_pending())
invoke_rcu_core();
\
 
 \ /
  Last update: 2018-07-09 23:03    [W:0.141 / U:6.024 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site