From: Wenwu Hou <hwenwur@gmail.com>
To: Ingo Molnar <mingo@redhat.com>
Cc: Wenwu Hou <hwenwur@gmail.com>,
stable@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] sched/core: Avoid counting sleep time as run delay after migration
Date: Wed, 25 Nov 2026 19:55:19 +0800 [thread overview]
Message-ID: <20261125115519.2373653-1-hwenwur@gmail.com> (raw)
A task with sched_delayed set is sleeping even though it remains on
its runqueue. Migrating such a task calls enqueue_task() on the
destination CPU, where sched_info_enqueue() starts last_queued despite
the task still being asleep. A subsequent wakeup does not replace the
nonzero timestamp, so sched_info_arrive() includes the intervening
sleep in run_delay.
The timestamp can also survive final delayed dequeue: pick_next_entity()
calls __dequeue_task() directly, bypassing sched_info_dequeue(). A later
ordinary wakeup therefore retains the migration timestamp as well.
Reproduce with the Python script [1] on a four-vCPU KVM guest with
DELAY_DEQUEUE enabled.
With competing loads on CPU0 and CPU1, a worker runs on CPU0 for 8 ms
and sleeps for 40 ms. Migrate it to CPU1 while sleeping on alternate
trials, and compare run_delay against trials without migration.
Output excerpts from python3 repro.py:
Before this patch:
worker=697, CPUs=[0, 1, 2]
trial=00 migrate=True state=S run_delay_delta_ms=40.259
trial=01 migrate=False state=S run_delay_delta_ms=0.223
trial=02 migrate=True state=S run_delay_delta_ms=40.194
trial=03 migrate=False state=S run_delay_delta_ms=0.229
trial=04 migrate=True state=S run_delay_delta_ms=40.202
trial=05 migrate=False state=S run_delay_delta_ms=0.230
After this patch:
worker=350, CPUs=[0, 1, 2]
trial=00 migrate=True state=S run_delay_delta_ms=0.005
trial=01 migrate=False state=S run_delay_delta_ms=0.225
trial=02 migrate=True state=S run_delay_delta_ms=0.620
trial=03 migrate=False state=S run_delay_delta_ms=0.232
trial=04 migrate=True state=S run_delay_delta_ms=0.236
trial=05 migrate=False state=S run_delay_delta_ms=0.234
Across 15 trials per group, migrated-task run_delay increments fall
from 40.167-40.259 ms to 0.005-0.624 ms. Controls measure
0.223-0.234 ms before and 0.201-0.620 ms after.
Link: https://gist.github.com/hwenwur/61cf383f8df72d4270ad9918b1d4edc8 [1]
Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue")
Cc: stable@vger.kernel.org
Signed-off-by: Wenwu Hou <hwenwur@gmail.com>
---
kernel/sched/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 515b9d0353ce9..043885c66365e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2198,7 +2198,8 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
psi_enqueue(p, flags);
- if (!(flags & ENQUEUE_RESTORE))
+ /* Delayed tasks remain asleep across migration requeues. */
+ if (!(flags & ENQUEUE_RESTORE) && !p->se.sched_delayed)
sched_info_enqueue(rq, p);
if (sched_core_enabled(rq))
--
2.43.0
next reply other threads:[~2026-11-25 11:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:55 Wenwu Hou [this message]
2026-11-25 12:09 ` Kayra Cizmeci
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=20261125115519.2373653-1-hwenwur@gmail.com \
--to=hwenwur@gmail.com \
--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=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.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®