linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: Valentin Schneider <valentin.schneider@arm.com>
Cc: Yafang Shao <laoar.shao@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched, fair: try to prevent migration thread from preempting non-cfs task
Date: Tue, 15 Jun 2021 17:45:26 +0200	[thread overview]
Message-ID: <CAKfTPtDj6E00o4ZFDJ+kJKqy8J3oLm-mVSajUnHpufFCRiX_8g@mail.gmail.com> (raw)
In-Reply-To: <87mtrrb2jw.mognet@arm.com>

On Tue, 15 Jun 2021 at 16:55, Valentin Schneider
<valentin.schneider@arm.com> wrote:
>
>
> Hi,
>
> On 15/06/21 20:15, Yafang Shao wrote:
>
> > - Prev version
> >   https://lore.kernel.org/lkml/CAKfTPtBd349eyDhA5ThCAHFd83cGMQKb_LDxD4QvyP-cJOBjqA@mail.gmail.com/
> >
> > - Similar discussion
> >   https://lore.kernel.org/lkml/CAKfTPtBygNcVewbb0GQOP5xxO96am3YeTZNP5dK9BxKHJJAL-g@mail.gmail.com/
>
> I knew that sounded familiar :-)
>
> > ---
> >  kernel/sched/fair.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 3248e24a90b0..597c7a940746 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -9797,6 +9797,20 @@ static int load_balance(int this_cpu, struct rq *this_rq,
> >                       /* Record that we found at least one task that could run on this_cpu */
> >                       env.flags &= ~LBF_ALL_PINNED;
> >
> > +                     /*
> > +                      * There may be a race between load balance starting migration
> > +                      * thread to pull the cfs running thread and the RT thread
> > +                      * waking up and preempting cfs task before migration threads
> > +                      * which then preempt the RT thread.
> > +                      * We'd better do the last minute check before starting
> > +                      * migration thread to avoid preempting latency-sensitive thread.
> > +                      */
>
> This can be summarized as in the below, no?
>
>                         /*
>                          * Don't cause a higher-than-CFS task to be preempted by
>                          * the CPU stopper.
>                          */

IMO, it's worth keeping the explanation that we are there because:
- a CFS task that was running during the 1st step :  if
(busiest->nr_running > 1) { ...
so we didn't pull the task
- but it has been preempted while lb was deciding if it needs an
active load balance

so maybe something like:
                         /*
                          * Don't kick the active_load_balance_cpu_stop,
                          * if the CFS task has been preempted by higher
                          * priority task in the meantime.
                         */


>
> > +                     if (busiest->curr->sched_class != &fair_sched_class) {
> > +                             raw_spin_unlock_irqrestore(&busiest->lock,
> > +                                                        flags);
> > +                             goto out;
>
> Since you goto out this could be moved before the
>
>   env.flags &= ~LBF_ALL_PINNED;
>
> above (it only has an impact if you'd goto out_balanced).

Good point. My comment to move this test after  env.flags &=
~LBF_ALL_PINNED; was valid only with goto out_one_pinned

>
> > +                     }
> > +
>
> Other than the above, this looks OK to me.
>
> Back then I had argued that having a >CFS task and holding the remote rq
> lock could let us invoke detach_one_task() locally (rather than on the
> stopper thread), but realistically if we got to this !ld_moved condition
> then the chances of us actually pulling something here are very slim (we'd
> depend on enqueues happening between ~detach_tasks() and here).
>
> >                       /*
> >                        * ->active_balance synchronizes accesses to
> >                        * ->active_balance_work.  Once set, it's cleared
> > --
> > 2.17.1

  reply	other threads:[~2021-06-15 15:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 12:15 [PATCH] sched, fair: try to prevent migration thread from preempting non-cfs task Yafang Shao
2021-06-15 14:55 ` Valentin Schneider
2021-06-15 15:45   ` Vincent Guittot [this message]
2021-06-15 16:39     ` Valentin Schneider
2021-06-15 20:35 ` Peter Zijlstra
2021-06-16  1:44   ` Yafang Shao
2021-06-16  7:15     ` Peter Zijlstra
2021-06-16  7:29       ` Vincent Guittot
2021-06-16  8:29         ` Peter Zijlstra
2021-06-16  9:49           ` Yafang Shao
2021-06-16  9:45       ` Yafang Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKfTPtDj6E00o4ZFDJ+kJKqy8J3oLm-mVSajUnHpufFCRiX_8g@mail.gmail.com \
    --to=vincent.guittot@linaro.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=valentin.schneider@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).