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,
qyousef@layalina.io
Subject: Re: [PATCH 2/6 v2] sched/eevdf: Take into account current's lag when updating slice protection
Date: Tue, 16 Jun 2026 11:29:59 +0200 [thread overview]
Message-ID: <20260616092959.GH42921@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260615162420.420957-3-vincent.guittot@linaro.org>
On Mon, Jun 15, 2026 at 06:24:16PM +0200, Vincent Guittot wrote:
> Take into account the lag of current task when setting the slice protection
> in order to ensure that the absolute value of lags will remain in the
> range [0 : slice+tick]
> A task that already has a negative lag will see its protection reduced
> whereas a task with positive lag will keep a full slice protection.
>
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
> kernel/sched/fair.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 83bce5a04f3d..b8d5d9bcc014 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1083,6 +1083,7 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
> */
> static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
> {
> + u64 vruntime = min_vruntime(se->vruntime, avg_vruntime(cfs_rq));
> u64 slice = normalized_sysctl_sched_base_slice;
> u64 vprot = se->deadline;
>
> @@ -1090,8 +1091,8 @@ static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity
> slice = cfs_rq_min_slice(cfs_rq);
>
> slice = min(slice, se->slice);
> - if (slice != se->slice)
> - vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se));
> + if (vruntime != se->vruntime || slice != se->slice)
> + vprot = min_vruntime(vprot, vruntime + calc_delta_fair(slice, se));
>
> se->vprot = vprot;
> }
As already noted by Prateek, this doesn't seem to make much sense, since
we just got selected by schedule(), we *must* be left of avg_vruntime(),
otherwise we'd not be eligible and all that.
> @@ -1099,8 +1100,9 @@ static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity
> static inline void update_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
> {
> u64 slice = cfs_rq_min_slice(cfs_rq);
> + u64 vruntime = min_vruntime(se->vruntime, avg_vruntime(cfs_rq));
>
> - se->vprot = min_vruntime(se->vprot, se->vruntime + calc_delta_fair(slice, se));
> + se->vprot = min_vruntime(se->vprot, vruntime + calc_delta_fair(slice, se));
> }
>
> static inline bool protect_slice(struct sched_entity *se)
So:
- set_protect_slice() is called at: set_next_task(.first = true),
eg, only when the task gets scheduled().
- set_protect_slice() takes se->deadline as the baseline, and (when
RUN_TO_PARITY) computes a shorter vprot [ min_slice vs slice ].
- update_protect_slice() is called upon (failed) wakeup preemption,
new tasks have been added and as such the goal is to re-compute the
min_slice and possibly reduce vprot.
Right?
And while update_protect_slice() would ideally use the original
se->vruntime (as per set_next_task(.first = true) to compute any new
(shorter) vprot, per its use of min_vruntime() it can not in fact end up
with a vprot that is longer than the initial.
Now, your change is to use min(se->vruntime, avg_vruntime()) to increase
the chance of actually computing a shorter vprot. Still very much wrong,
but possibly less wrong.
Rather than taking avg_vruntime(), would it make sense to do something
like:
slice = cfs_rq_min_slice(cfs_rq);
slice -= se->sum_exec_runtime - se->prev_sum_exec_runtime;
vprot = se->vruntime;
if (slice < 0)
vprot -= calc_delta_fair(-slice, se);
else
vprot += calc_delta_fair(slice, se);
se->vprot = min_vruntime(se->vprot, vprot);
That is, reduce the slice with the time already ran.
Now, this will go sideways in the unlikely case of renice, and possibly
sched_change pattern (it seems we update prev_sum_exec_runtime for
!first), but overall it might be a better approximation, no?
next prev parent reply other threads:[~2026-06-16 9:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 16:24 [PATCH 0/6 v2] sched/eevdf: Improve scheduling latency of short slice task Vincent Guittot
2026-06-15 16:24 ` [PATCH 1/6 v2] sched/fair: Set next buddy for preempt short Vincent Guittot
2026-06-16 8:51 ` Peter Zijlstra
2026-06-16 13:52 ` Vincent Guittot
2026-06-15 16:24 ` [PATCH 2/6 v2] sched/eevdf: Take into account current's lag when updating slice protection Vincent Guittot
2026-06-16 3:52 ` K Prateek Nayak
2026-06-16 12:11 ` Vincent Guittot
2026-06-16 9:29 ` Peter Zijlstra [this message]
2026-06-16 12:49 ` Vincent Guittot
2026-06-15 16:24 ` [PATCH 3/6 v2] sched/eevdf: Update slice protection even when resched is already set Vincent Guittot
2026-06-16 9:37 ` Peter Zijlstra
2026-06-16 13:57 ` Vincent Guittot
2026-06-15 16:24 ` [PATCH 4/6 v2] sched/eevdf: Cancel slice protection if short slice task is eligible Vincent Guittot
2026-06-16 5:34 ` K Prateek Nayak
2026-06-16 12:51 ` Vincent Guittot
2026-06-15 16:24 ` [PATCH 5/6 v2] sched/eevdf: Always update slice protection Vincent Guittot
2026-06-15 16:24 ` [PATCH 6/6 v2] sched/eevdf: Speedup short slice task scheduling Vincent Guittot
2026-06-16 10:57 ` Peter Zijlstra
2026-06-16 15:18 ` Vincent Guittot
2026-06-17 16:01 ` Vincent Guittot
2026-06-16 7:43 ` [PATCH 0/6 v2] sched/eevdf: Improve scheduling latency of short slice task K Prateek Nayak
2026-06-16 13:58 ` 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=20260616092959.GH42921@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=qyousef@layalina.io \
--cc=rostedt@goodmis.org \
--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
all inboxes | Powered by JetHome®