From: Fernand Sieber <sieberf@amazon.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Fernand Sieber <sieberf@amazon.com>,
Karl Mehltretter <kmehltretter@gmail.com>,
<stable@vger.kernel.org>, Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Shuah Khan <shuah@kernel.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>,
"Daniel Bristot de Oliveira" <bristot@kernel.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
Josh Don <joshdon@google.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <nh-open-source@amazon.com>,
Fahad Mubeen <fmubeen@amazon.de>,
"David Woodhouse" <dwmw@amazon.co.uk>,
Misha Karataiev <karataev@amazon.com>,
Hendrik Borghorst <hborghor@amazon.de>,
Ibrahim Elshahed <lshahed@amazon.de>
Subject: [PATCH 1/2] sched/deadline: Keep forced idle uncharged when a sibling ends it
Date: Tue, 24 Nov 2026 11:40:30 +0200 [thread overview]
Message-ID: <0eb24d6c957d45f9f7274eb9e92d9dbd3c76117d.1795510960.git.sieberf@amazon.com> (raw)
In-Reply-To: <cover.1795510960.git.sieberf@amazon.com>
Commit f4626e1c3c14 ("sched/deadline: Don't charge core-sched forced
idle to the DL servers") keeps forced idle from being charged to the
fair and ext servers. But it tests forced_idle_rq() when the idle time
is charged, not when the idle task started running. When the sibling
ends the forced idle, the test reads false by then and the forced-idle
span is charged anyway.
The timeline below describes the issue:
Setup. CPU0 and CPU1 are SMT siblings.
- CPU1 runs R, a SCHED_FIFO task with cookie X, which spins and
sleeps briefly in a loop.
- CPU0 has C, a CFS task with no cookie, which only runs through
CPU0's fair server.
t0, CPU0 is forced idle. The core cookie is X and CPU0 has no
cookie-X task, so CPU0 runs idle. core_forceidle_count is set and
idle->se.exec_start is stamped.
t1, R blocks. CPU1 does the core-wide pick. No cookie-X task is
left, so forced idle ends: the pick clears core_forceidle_count and
picks C for CPU0.
t2, CPU0 switches from idle to C. update_curr_idle() charges the
idle time since its last update to the fair and ext servers.
forced_idle_rq(rq0) reads false, since t1 cleared the count, so the
forced-idle span up to t1 is charged.
t3, result. The fair server spends its runtime on time in which C
could not run, and C gets throttled. With R spinning 800us and
sleeping 10us (HZ=1000, 2-core 2-thread KVM guest), C gets 0.8-1.8%
of the CPU instead of the 5% reservation.
With this patch, the core-wide pick settles the idle time of each idle
sibling under the state from before the pick: at t1 it drops CPU0's
forced-idle span, and a pick that starts forced idle charges the idle
time before it. As only this pick changes core_forceidle_count,
forced_idle_rq() then holds for the whole span that update_curr_idle()
charges.
With this, C gets 5.6-5.8% in the same setup.
Fixes: f4626e1c3c14 ("sched/deadline: Don't charge core-sched forced idle to the DL servers")
Reported-by: Karl Mehltretter <kmehltretter@gmail.com>
Closes: https://lore.kernel.org/all/20261124080737.1988-1-kmehltretter@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Fernand Sieber <sieberf@amazon.com>
---
kernel/sched/core.c | 8 ++++++++
kernel/sched/idle.c | 25 +++++++++++++++++++------
kernel/sched/sched.h | 1 +
3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ea89471d4743c..825d9bbea3128 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6451,6 +6451,14 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
if (i != cpu && (rq_i != rq->core || !core_clock_updated))
update_rq_clock(rq_i);
+ /*
+ * This pick can start or end forced idle on rq_i while its
+ * idle task runs on, and the old state is already reset.
+ * Charge the idle time so far under the old state.
+ */
+ if (rq_i->curr == rq_i->idle)
+ charge_idle_to_dl_servers(rq_i, fi_before && rq_i->nr_running);
+
p = pick_task(rq_i, rf);
if (unlikely(p == RETRY_TASK)) {
/* rq lock may have been dropped, clocks invalidated */
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 451b4846219d5..0449ccefba6c7 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -561,7 +561,14 @@ prio_changed_idle(struct rq *rq, struct task_struct *p, u64 oldprio)
BUG();
}
-static void update_curr_idle(struct rq *rq)
+/*
+ * Charge the time the idle task of @rq ran since its se.exec_start to the
+ * fair and ext servers, and advance se.exec_start to now. Nothing is
+ * charged if @span_was_forced_idle: forced idle was not time available to
+ * any class on @rq, so the deferred servers must not consume their runtime
+ * on it.
+ */
+void charge_idle_to_dl_servers(struct rq *rq, bool span_was_forced_idle)
{
struct sched_entity *se = &rq->idle->se;
u64 now = rq_clock_task(rq);
@@ -573,11 +580,7 @@ static void update_curr_idle(struct rq *rq)
se->exec_start = now;
- /*
- * Forced idle was not time available to any class on this rq, so
- * don't let the deferred servers consume their runtime on it.
- */
- if (forced_idle_rq(rq))
+ if (span_was_forced_idle)
return;
dl_server_update_idle(&rq->fair_server, delta_exec);
@@ -586,6 +589,16 @@ static void update_curr_idle(struct rq *rq)
#endif
}
+/*
+ * Only the core-wide pick starts or ends forced idle, and it charges the
+ * idle time up to that point under the old state, so the current state is
+ * the state of the whole span here.
+ */
+static void update_curr_idle(struct rq *rq)
+{
+ charge_idle_to_dl_servers(rq, forced_idle_rq(rq));
+}
+
/*
* Simple, special scheduling class for the per-CPU idle tasks:
*/
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 32f76551a0c5e..1c61a1a9309a0 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3005,6 +3005,7 @@ static inline bool sched_fair_runnable(struct rq *rq)
extern struct task_struct *pick_task_fair(struct rq *rq, struct rq_flags *rf);
extern struct task_struct *pick_task_idle(struct rq *rq, struct rq_flags *rf);
+void charge_idle_to_dl_servers(struct rq *rq, bool span_was_forced_idle);
#define SCA_CHECK 0x01
#define SCA_MIGRATE_DISABLE 0x02
--
2.47.3
Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07
next prev parent reply other threads:[~2026-11-24 9:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 16:15 [PATCH 0/5] sched: Fix DL server starvation under core scheduling Fernand Sieber
2026-11-12 16:15 ` [PATCH 1/5] sched/core: Clear stale rq->dl_server when core-sched replaces a pick Fernand Sieber
2026-11-22 22:49 ` [tip: sched/urgent] sched/deadline: " tip-bot2 for Fernand Sieber
2026-11-23 9:44 ` tip-bot2 for Fernand Sieber
2026-11-12 16:15 ` [PATCH 2/5] sched/core: Keep a sibling's DL server link in the core-wide pick Fernand Sieber
2026-11-18 13:50 ` Peter Zijlstra
2026-11-18 13:58 ` Peter Zijlstra
2026-11-12 16:15 ` [PATCH 3/5] sched/core: Rank DL server picks as deadline " Fernand Sieber
2026-11-18 13:52 ` Peter Zijlstra
2026-11-23 9:55 ` [tip: sched/core] " tip-bot2 for Fernand Sieber
2026-11-12 16:15 ` [PATCH 4/5] sched/deadline: Don't charge core-sched forced idle to the DL servers Fernand Sieber
2026-11-22 22:49 ` [tip: sched/urgent] " tip-bot2 for Fernand Sieber
2026-11-23 9:44 ` tip-bot2 for Fernand Sieber
2026-11-24 8:07 ` [PATCH 4/5] " Karl Mehltretter
2026-11-24 9:40 ` [PATCH 0/2] sched/deadline: Fix forced idle charged when a sibling ends it Fernand Sieber
2026-11-24 9:40 ` Fernand Sieber [this message]
2026-11-24 9:40 ` [PATCH 2/2] selftests/sched: Let the FIFO task block in cs_dl_server_test Fernand Sieber
2026-11-24 9:46 ` [PATCH 4/5] sched/deadline: Don't charge core-sched forced idle to the DL servers Fernand Sieber
2026-11-12 16:15 ` [PATCH 5/5] selftests/sched: Add a core-sched forced-idle DL server test Fernand Sieber
2026-11-22 22:49 ` [tip: sched/urgent] " tip-bot2 for Fernand Sieber
2026-11-23 15:37 ` Fernand Sieber
2026-11-23 9:44 ` tip-bot2 for Fernand Sieber
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=0eb24d6c957d45f9f7274eb9e92d9dbd3c76117d.1795510960.git.sieberf@amazon.com \
--to=sieberf@amazon.com \
--cc=bristot@kernel.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dwmw@amazon.co.uk \
--cc=fmubeen@amazon.de \
--cc=hborghor@amazon.de \
--cc=joelagnelf@nvidia.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=karataev@amazon.com \
--cc=kmehltretter@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lshahed@amazon.de \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.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®