public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	kprateek.nayak@amd.com, linux-kernel@vger.kernel.org,
	shubhang@os.amperecomputing.com
Subject: Re: [PATCH v2] sched: fair: Prevent negative lag increase during delayed dequeue
Date: Wed, 22 Apr 2026 15:39:14 +0200	[thread overview]
Message-ID: <20260422133914.GP3102624@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAKfTPtDOeFM=fkqryiS+wTAcEP-hcyt42cbMrqTZPpf3zD+i8g@mail.gmail.com>

On Fri, Apr 17, 2026 at 07:18:48PM +0200, Vincent Guittot wrote:
> On Thu, 2 Apr 2026 at 15:17, Vincent Guittot <vincent.guittot@linaro.org> wrote:
> > On Thu, 2 Apr 2026 at 15:14, Peter Zijlstra <peterz@infradead.org> wrote:
> > > On Tue, Mar 31, 2026 at 06:23:52PM +0200, Vincent Guittot wrote:
> > > > +/*
> > > > + * Delayed dequeue aims to reduce the negative lag of a dequeued task.
> > > > + * While updating the lag of an entity, check that negative lag didn't increase
> > > > + * during the delayed dequeue period which would be unfair.
> > > > + * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO is
> > > > + * set.
> > > > + *
> > > > + * Return true if the lag has been adjusted.
> > > > + */
> > > > +static bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
> > > >  {
> > > > +     s64 vlag;
> > > > +
> > > >       WARN_ON_ONCE(!se->on_rq);
> > > >
> > > > +     vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
> > > > +
> > > > +     if (se->sched_delayed)
> > > > +             /* previous vlag < 0 otherwise se would not be delayed */
> > > > +             se->vlag = clamp(vlag, se->vlag, sched_feat(DELAY_ZERO) ? 0 : S64_MAX);
> > > > +     else
> > > > +             se->vlag = vlag;
> > > > +
> > > > +     return (vlag != se->vlag);
> > > >  }

> > > --- a/kernel/sched/fair.c
> > > +++ b/kernel/sched/fair.c
> > > @@ -841,29 +841,32 @@ static s64 entity_lag(struct cfs_rq *cfs
> > >  }
> > >
> > >  /*
> > > + * Delayed dequeue aims to reduce the negative lag of a dequeued task. While
> > > + * updating the lag of an entity, check that negative lag didn't increase
> > >   * during the delayed dequeue period which would be unfair.
> > > + * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO
> > > + * is set.
> > >   *
> > >   * Return true if the lag has been adjusted.
> > >   */
> > > +static __always_inline
> > > +bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
> > >  {
> > > +       s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
> > > +       bool ret;
> > >
> > >         WARN_ON_ONCE(!se->on_rq);
> > >
> > > +       if (se->sched_delayed) {
> > >                 /* previous vlag < 0 otherwise se would not be delayed */
> > > +               vlag = max(vlag, se->vlag);
> > > +               if (sched_feat(DELAY_ZERO))
> > > +                       vlag = min(vlag, 0);
> > > +       }
> > > +       ret = (vlag == se->vlag);
> 
> hmm, I missed that we now return false when the lag has been updated
> instead of true
> 
> I sent a fix
> https://lore.kernel.org/all/20260417171642.3539914-1-vincent.guittot@linaro.org/

D'oh.

That said, on IRQ you mentioned that this wasn't quite good enough and
that your original patch is best.

The trouble is, your original patch can update vlag (!se->sched_delayed)
and report it hasn't changed; because then vlag == se->clag, obviously.

This invalidates the comment on the return value of the function. In
fact, it makes the function have a very non-obvious return meaning.

So I'm a little confused -- what do we actually want this function to
do?


> > > +       se->vlag = vlag;
> > >
> > > +       return ret;
> > >  }
> > >
> > >  /*
> > >

  reply	other threads:[~2026-04-22 13:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 16:23 [PATCH v2] sched: fair: Prevent negative lag increase during delayed dequeue Vincent Guittot
2026-04-02 13:13 ` Peter Zijlstra
2026-04-02 13:17   ` Vincent Guittot
2026-04-17 17:18     ` Vincent Guittot
2026-04-22 13:39       ` Peter Zijlstra [this message]
2026-04-22 14:06         ` Vincent Guittot
2026-04-22 14:24           ` Peter Zijlstra
2026-04-22 14:28             ` Peter Zijlstra
2026-04-22 14:46               ` Vincent Guittot
2026-04-22 22:20               ` Peter Zijlstra
2026-04-23  7:28                 ` Vincent Guittot
2026-04-23  9:41                   ` Peter Zijlstra
2026-04-23 10:27                     ` Vincent Guittot
2026-04-23 12:12                       ` Vincent Guittot
2026-04-02 13:42 ` Peter Zijlstra
2026-04-02 19:27 ` Shubhang Kaushik
2026-04-03  8:37   ` Vincent Guittot
2026-04-04  8:08     ` Shubhang Kaushik
2026-04-03  8:46   ` Vincent Guittot
2026-04-03 12:30 ` [tip: sched/core] sched/fair: " tip-bot2 for Vincent Guittot

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=20260422133914.GP3102624@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=shubhang@os.amperecomputing.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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