All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: "Mike Galbraith" <efault@gmx.de>, "Jakub Okoński" <jakub@okonski.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	mingo@kernel.org, longman@redhat.com, chenridong@huaweicloud.com,
	juri.lelli@redhat.com, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, tj@kernel.org, hannes@cmpxchg.org,
	mkoutny@suse.com, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, jstultz@google.com,
	kprateek.nayak@amd.com, qyousef@layalina.io
Subject: Re: [PATCH v3 7/7] sched/eevdf: Move to a single runqueue
Date: Mon, 19 Oct 2026 19:01:30 +0200	[thread overview]
Message-ID: <atZM6uF0CqCNh__I@vingu-cube> (raw)
In-Reply-To: <b1002150c3e4f877d04790cd8e85d2149d17722f.camel@gmx.de>

Le dimanche 18 oct. 2026 à 08:49:29 (+0200), Mike Galbraith a écrit :
> Greetings!
> 
> On Fri, 2026-10-16 at 15:18 +0200, Jakub Okoński wrote:
> > Hi Peter,
> > 
> > On 6/5/26 14:40, Peter Zijlstra wrote:
> > 
> > > Change fair/cgroup to a single runqueue.
> > > 
> > > [...]
> > > 
> > > --- a/kernel/sched/fair.c
> > > +++ b/kernel/sched/fair.c
> > > @@ -9916,7 +9837,6 @@ static void wakeup_preempt_fair(struct r
> > >  	if (!sched_feat(WAKEUP_PREEMPTION))
> > >  		return;
> > >  
> > > -	find_matching_se(&se, &pse);
> > >  	WARN_ON_ONCE(!pse);
> > >  
> > >  	cse_is_idle = se_is_idle(se);
> > 
> > I think this changes how cpu.idle affects wakeup preemption.
> 
> My box claims this to be unrelated to the jitter you're seeing, as it
> is present in 7.2.11, with and without the sched-flat set applied.

Yes, we don't take into account whether the task group is sched_idle

Jakub, Mike,
Could you try the patch below ? It solves the problem on my setup

---
 kernel/sched/fair.c | 80 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 68 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0f2364479f9d..d17e88ad12a5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -433,6 +433,38 @@ static inline struct sched_entity *parent_entity(const struct sched_entity *se)
 	return se->parent;
 }
 
+static void
+find_matching_se(struct sched_entity **se, struct sched_entity **pse)
+{
+	int se_depth, pse_depth;
+
+	/*
+	 * preemption test can be made between sibling entities who are in the
+	 * same cfs_rq i.e who have a common parent. Walk up the hierarchy of
+	 * both tasks until we find their ancestors who are siblings of common
+	 * parent.
+	 */
+
+	/* First walk up until both entities are at same depth */
+	se_depth = (*se)->depth;
+	pse_depth = (*pse)->depth;
+
+	while (se_depth > pse_depth) {
+		se_depth--;
+		*se = parent_entity(*se);
+	}
+
+	while (pse_depth > se_depth) {
+		pse_depth--;
+		*pse = parent_entity(*pse);
+	}
+
+	while (!is_same_group(*se, *pse)) {
+		*se = parent_entity(*se);
+		*pse = parent_entity(*pse);
+	}
+}
+
 static int tg_is_idle(struct task_group *tg)
 {
 	return tg->idle > 0;
@@ -476,6 +508,11 @@ static inline struct sched_entity *parent_entity(struct sched_entity *se)
 	return NULL;
 }
 
+static inline void
+find_matching_se(struct sched_entity **se, struct sched_entity **pse)
+{
+}
+
 static inline int tg_is_idle(struct task_group *tg)
 {
 	return 0;
@@ -10129,7 +10166,34 @@ preempt_sync(struct rq *rq, int wake_flags,
 }
 
 /*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */
+static bool wakeup_preempt_sched_idle(struct sched_entity *cse, struct sched_entity *pse)
+{
+	int cse_is_idle, pse_is_idle;
+
+	find_matching_se(&cse, &pse);
+	WARN_ON_ONCE(!pse);
+
+	cse_is_idle = se_is_idle(cse);
+	pse_is_idle = se_is_idle(pse);
+
+	/*
+	 * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+	 * in the inverse case).
+	 */
+	if (cse_is_idle && !pse_is_idle)
+		return PREEMPT_WAKEUP_RESCHED;
+
+	if (cse_is_idle != pse_is_idle)
+		return PREEMPT_WAKEUP_NONE;
+
+	return PREEMPT_WAKEUP_PICK;
+}
+
+/*
+ * Preempt the current task with a newly woken task if needed.
  */
 static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_flags)
 {
@@ -10174,22 +10238,14 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f
 	if (!sched_feat(WAKEUP_PREEMPTION))
 		return;
 
-	WARN_ON_ONCE(!pse);
-
-	cse_is_idle = se_is_idle(se);
-	pse_is_idle = se_is_idle(pse);
+	preempt_action = wakeup_preempt_sched_idle(se, pse);
 
-	nse = se;
-	/*
-	 * Preempt an idle entity in favor of a non-idle entity (and don't preempt
-	 * in the inverse case).
-	 */
-	if (cse_is_idle && !pse_is_idle)
+	if (preempt_action == PREEMPT_WAKEUP_RESCHED)
 		goto preempt;
 
 	update_curr_fair(rq);
 
-	if (cse_is_idle != pse_is_idle)
+	if (preempt_action == PREEMPT_WAKEUP_NONE)
 		goto update;
 
 	/*
-- 
2.53.0


> 
> > With the single runqueue, find_matching_se() is gone and se_is_idle()
> > reduces to task_has_idle_policy(). Wouldn't this mean that SCHED_NORMAL
> > tasks in a cpu.idle cgroup are no longer treated as idle for
> > wakeup_preempt_fair()?
> >
> > 
> > I tested my existing 7.2.9 desktop against 7.3-rc6 with the setup below.
> > cyclictest doesn't reproduce it because it just sleeps and wakes, no CPU
> > burn and therefore its accrued EEVDF lag keeps the latency low?
> > 
> > cc -O2 -o wakelat wakelat.c
> > systemd-run --user --collect --unit=spin -p AllowedCPUs=7 -p CPUWeight=idle sh -c 'while :; do :; done'
> > systemd-run --user --collect --wait --pipe --same-dir -p AllowedCPUs=7 ./wakelat 1000 15 200 |
> >   mlr --inidx --ifs space --opprint --barred --right label lat \
> >     then stats1 -a count,p50,p90,p99,max -f lat then rename -r '^lat_,' \
> >     then put -q 'emit mapsum({"kernel": system("uname -r")}, $*)'
> > systemctl --user stop spin
> > 
> > wakelat wakes on a fixed 1 ms schedule, records how late each wakeup
> > was, then busy-loops for 200 micros (wall clock).
> > 
> > +-----------+-------+-----+-----+------+------+
> > >    kernel | count | p50 | p90 |  p99 |  max |
> > +-----------+-------+-----+-----+------+------+
> > >     7.2.9 | 14998 |  11 |  11 |   12 | 1869 |
> > > 7.3.0-rc6 | 13853 |  11 |  12 | 2029 | 2116 |
> > +-----------+-------+-----+-----+------+------+
> > 
> > count is out of 15000 periods. rc6 had 1147 wakeups delayed by over 1 ms.
> 
> Thanks a bunch for the proggy. I've been looking for a clear signal
> with various loads, and stuffing wakelat+awk into one of my scripts
> provided a perfectly clear signal, which I bisected and confirmed.
> 
> Note: below is box pointing it's little silicon finger at the source of
> aforementioned jitter, not necessarily at breakage.
> 
> Reverting the fingered commit removed the jitter from 7.2.11, and force
> reverting 68e37487810a + 333238da9a19 removed it from master as well.
> 
> 333238da9a193ffc58792995f3e951e4cb87bfd2 is the first 'bad' commit
> commit 333238da9a193ffc58792995f3e951e4cb87bfd2
> Author: Vincent Guittot <vincent.guittot@linaro.org>
> Date:   Fri Aug 14 15:52:41 2026 +0200
> 
>     sched: Update time before requeueing delayed entities
>     
>     In order to compute the right lag, it is required to update time to 'now'.
>     Without this, the delayed entity might appear younger than it really is and
>     receive less compensation for having waited.
>     
>     Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
>     Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> 
>  kernel/sched/fair.c | 2 ++
>  1 file changed, 2 insertions(+)
> 

  reply	other threads:[~2026-10-19 17:01 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 12:40 [PATCH v3 0/7] sched: Flatten the pick Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 1/7] sched/fair: Add cgroup_mode switch Peter Zijlstra
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 2/7] sched/fair: Add cgroup_mode: up Peter Zijlstra
2026-06-05 15:07   ` Peter Zijlstra
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 3/7] sched/fair: Add cgroup_mode: max Peter Zijlstra
2026-06-10 15:09   ` Waiman Long
2026-06-10 15:42     ` Waiman Long
2026-06-11 13:49       ` Peter Zijlstra
2026-06-11 13:47     ` Peter Zijlstra
2026-06-11 20:57       ` Waiman Long
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 4/7] sched/fair: Add cgroup_mode: concur Peter Zijlstra
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 5/7] sched/fair: Add cgroup_mode: tasks Peter Zijlstra
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 6/7] sched/fair: Change the default cgroup_mode to concur Peter Zijlstra
2026-06-30  9:03   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-06-05 12:40 ` [PATCH v3 7/7] sched/eevdf: Move to a single runqueue Peter Zijlstra
2026-06-20  3:54   ` Chen, Yu C
2026-06-26 11:40     ` Peter Zijlstra
2026-06-29 14:02       ` Vincent Guittot
2026-06-30  9:03     ` [tip: sched/core] sched/fair: Fix overflow in update_tg_cfs_runnable() tip-bot2 for Chen, Yu C
2026-06-30  9:03   ` [tip: sched/core] sched/eevdf: Move to a single runqueue tip-bot2 for Peter Zijlstra (Intel)
2026-09-23 14:21   ` [REGRESSION] [PATCH v3 7/7] " Aishwarya Rambhadran
2026-09-23 16:48     ` Chen Yu
2026-09-24  7:05       ` K Prateek Nayak
2026-09-24  8:19       ` Mike Galbraith
2026-09-28  3:12         ` Chen Yu
2026-09-28 13:00           ` Mike Galbraith
2026-10-07 12:05             ` Aishwarya Rambhadran
2026-10-12 11:27               ` Mike Galbraith
2026-10-16 13:18   ` Jakub Okoński
2026-10-18  6:49     ` Mike Galbraith
2026-10-19 17:01       ` Vincent Guittot [this message]
2026-10-19 17:35         ` Jakub Okoński
2026-10-19 18:04           ` Vincent Guittot
2026-10-19 18:24             ` Jakub Okoński
2026-10-19 18:26               ` Vincent Guittot
2026-10-21 11:55                 ` Vincent Guittot
2026-10-22 12:05                   ` Jakub Okoński
2026-10-22  2:12     ` Mike Galbraith
2026-06-09  5:37 ` [PATCH v3 0/7] sched: Flatten the pick K Prateek Nayak
2026-06-12  2:29 ` Shubhang Kaushik
2026-08-17 16:05 ` Szabina Korbai
2026-08-17 16:35   ` K Prateek Nayak
2026-08-18  9:04     ` Szabina Korbai
2026-08-18  9:16       ` Peter Zijlstra
2026-08-21 10:37         ` Szabina Korbai
2026-08-24 14:51         ` Chen Yu
2026-08-24 13:53           ` Peter Zijlstra

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=atZM6uF0CqCNh__I@vingu-cube \
    --to=vincent.guittot@linaro.org \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@huaweicloud.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=efault@gmx.de \
    --cc=hannes@cmpxchg.org \
    --cc=jakub@okonski.org \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.