Re: [RFC PATCH 1/3] sched/fair: Call newidle_balance() from finish_task_switch()

From: Scott Wood
Date: Tue Apr 28 2020 - 18:55:14 EST


On Wed, 2020-04-29 at 00:09 +0200, Peter Zijlstra wrote:
> On Tue, Apr 28, 2020 at 10:37:18PM +0100, Valentin Schneider wrote:
> > On 28/04/20 06:02, Scott Wood wrote:
> > > Thus, newidle_balance() is entered with interrupts enabled, which
> > > allows
> > > (in the next patch) enabling interrupts when the lock is dropped.
> > >
> > > Signed-off-by: Scott Wood <swood@xxxxxxxxxx>
> > > ---
> > > kernel/sched/core.c | 7 ++++---
> > > kernel/sched/fair.c | 45 ++++++++++++++++---------------------------
> > > -
> > > kernel/sched/sched.h | 6 ++----
> > > 3 files changed, 22 insertions(+), 36 deletions(-)
> > >
> > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > index 9a2fbf98fd6f..0294beb8d16c 100644
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -3241,6 +3241,10 @@ static struct rq *finish_task_switch(struct
> > > task_struct *prev)
> > > }
> > >
> > > tick_nohz_task_switch();
> > > +
> > > + if (is_idle_task(current))
> > > + newidle_balance();
> > > +
> >
> > This means we must go through a switch_to(idle) before figuring out we
> > could've switched to a CFS task, and do it then. I'm curious to see the
> > performance impact of that.
>
> Also, if you move it this late, this is entirely the wrong place. If you
> do it after the context switch either use the balance_callback or put it
> in the idle path.
>
> But what Valentin said; this needs a fair bit of support, the whole
> reason we've never done this is to avoid that double context switch...
>

balance_callback() enters with the rq lock held but BH not separately
disabled, which interferes with the ability to enable interrupts but not BH.
It also gets called from rt_mutex_setprio() and __sched_setscheduler(), and
I didn't want the caller of those to be stuck with the latency.

-Scott