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: Thu, 2 Apr 2026 15:13:59 +0200 [thread overview]
Message-ID: <20260402131359.GZ2872@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260331162352.551501-1-vincent.guittot@linaro.org>
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);
>
> - se->vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_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);
> }
Would you mind terribly if I write this like so?
---
--- 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
+ * 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.
+ * 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)
+static __always_inline
+bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
- s64 vlag;
+ s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
+ bool ret;
WARN_ON_ONCE(!se->on_rq);
- vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
-
- if (se->sched_delayed)
+ 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;
+ vlag = max(vlag, se->vlag);
+ if (sched_feat(DELAY_ZERO))
+ vlag = min(vlag, 0);
+ }
+ ret = (vlag == se->vlag);
+ se->vlag = vlag;
- return (vlag != se->vlag);
+ return ret;
}
/*
next prev parent reply other threads:[~2026-04-02 13:14 UTC|newest]
Thread overview: 9+ 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 [this message]
2026-04-02 13:17 ` 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=20260402131359.GZ2872@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