* [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19)
@ 2026-11-20 15:09 Florent Carli
2026-11-20 17:09 ` Juri Lelli
0 siblings, 1 reply; 10+ messages in thread
From: Florent Carli @ 2026-11-20 15:09 UTC (permalink / raw)
To: stable; +Cc: Peter Zijlstra, Juri Lelli, Vincent Guittot, linux-rt-users
Hello,
As I understand it, the fair server is deferred: it should run
SCHED_OTHER tasks ahead of RT tasks only when RT tasks have kept the
CPU busy for most of a period (about 950 ms out of 1 s), so that fair
tasks do not starve.
On 6.12.y and 6.18.y, I see it run SCHED_OTHER tasks ahead of RT tasks
on a CPU where nothing starves. My setup is a PREEMPT_RT system (Debian
trixie, 6.12.117 rt) with a time critical SCHED_FIFO 98 thread on an
isolated CPU. That CPU is idle most of the time. The thread wakes up
every 300 us and runs for a few us. From time to time, a SCHED_OTHER
task that wakes up on that CPU runs ahead of the FIFO thread, for as
long as it wants to run: a container health check (bash) delayed the
FIFO thread by 3.4 ms this way.
6.19.y and later do not show this.
My reading of the 6.12.y code: about one second after the last fair
activity on the CPU, the zero-laxity timer fires and replenishes the
server with dl_defer_running = 1. Idle time then drains its runtime,
and dl_server_update_idle_time() clears dl_defer_running after about
50 ms of idle. A fair task that wakes up inside those ~50 ms runs under
the server, ahead of any FIFO task, until it sleeps.
Reproducer, as root, on an isolated CPU with nothing else on it:
CPU=22
python3 - "$CPU" <<'EOF' &
import os, sys, time
os.sched_setaffinity(0, {int(sys.argv[1])})
while True:
time.sleep(1.02)
end = time.monotonic() + 0.003
while time.monotonic() < end:
pass
EOF
cyclictest -m -p 98 -a $CPU --mainaffinity=0 -t 1 -i 200 -D 30 -q
--mainaffinity matters: cyclictest's main thread is SCHED_OTHER, and
when it stays on $CPU its activity every ~60 ms keeps pushing the
server's period out and hides the problem. Any other fair activity on
the CPU more often than every ~950 ms does the same.
Results, sleep between 1.00 and 1.04 s, 3 ms spin. Max FIFO latency,
and wake-ups later than 500 us:
bare metal, 6.12.117 Debian rt 3001 us, 10 per 20 s
(10 ms spin instead of 3 ms) 9986 us
KVM guest on dedicated host CPUs:
6.12.117 Debian rt 3000 us, 10 per 20 s
6.12.118, vanilla PREEMPT_RT 2900 us, 8 in 270 s
6.12.118 + v6.12-rt queue 3000 us, 14-15 per 30 s
6.18.15 Debian rt 3000 us, 10 per 20 s
6.19.14, 7.3.4 Debian rt < 25 us, 0
all of the above with
fair_server/cpuN/runtime = 0 < 25 us, 0
The lazy preemption patches of the -rt queue make the window much
easier to hit, but vanilla 6.12.118 is affected too.
The fix went into 6.19:
e636ffb9e31b ("sched/deadline: Fix dl_server time accounting")
f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
1e0a2ba7afb1 ("sched: Provide idle_rq() helper")
ca1e8eede4fc ("sched/deadline: Fix server stopping with runnable tasks")
None of them carries a stable tag, and only 1e0a2ba7afb1 applies
cleanly to 6.12.y or 6.18.y.
I have a backport of the four to 6.12.118, with small adaptations
(rq->donor does not exist in 6.12, so rq->curr is used). With it, the
reproducer shows no late wake-up, both on vanilla 6.12.118 and with the
-rt queue, and the starvation guard still works: under a SCHED_FIFO
busy loop, a SCHED_OTHER task on the same CPU still gets 4.7 to 4.9%
of it, as without the backport (0% with the server runtime at 0).
Would you take this series for 6.18.y and 6.12.y? I can send the 6.12.y
backport as patches and prepare the 6.18.y one, or leave it to the
authors if they prefer.
Until then, writing 0 to /sys/kernel/debug/sched/fair_server/cpuN/runtime
on the isolated CPUs avoids the problem.
Thanks,
Florent.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19)
2026-11-20 15:09 [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19) Florent Carli
@ 2026-11-20 17:09 ` Juri Lelli
2026-11-20 18:19 ` Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
0 siblings, 2 replies; 10+ messages in thread
From: Juri Lelli @ 2026-11-20 17:09 UTC (permalink / raw)
To: Florent Carli; +Cc: stable, Peter Zijlstra, Vincent Guittot, linux-rt-users
Hello,
On 20/11/26 16:09, Florent Carli wrote:
...
> On 6.12.y and 6.18.y, I see it run SCHED_OTHER tasks ahead of RT tasks
> on a CPU where nothing starves.
...
> The fix went into 6.19:
>
> e636ffb9e31b ("sched/deadline: Fix dl_server time accounting")
> f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
> 1e0a2ba7afb1 ("sched: Provide idle_rq() helper")
> ca1e8eede4fc ("sched/deadline: Fix server stopping with runnable tasks")
>
> None of them carries a stable tag, and only 1e0a2ba7afb1 applies
> cleanly to 6.12.y or 6.18.y.
Thanks for the detailed report and the reproducer, much appreciated.
I had a look and I agree with your analysis. Comparing v6.19 with the
current stable heads (6.12.118 and 6.18.64), these four are the only
dl_server changes not yet in either branch. The other dl_server fixes
from that period (including 115135422562 "Fix 'stuck' dl_server" and
the two "revised wakeup rule" follow-ups) are already in stable.
On applying them: with git am (no -3) I get exactly what you report,
on both 6.18.15 and 6.18.64: only 1e0a2ba7afb1 applies on its own. The
rejects are context only, though (upstream refactors around the
sched_class callbacks that stable doesn't carry), and a 3-way merge
takes care of them. With git cherry-pick, applying them in order:
- 6.18.y: all four apply cleanly, and the result matches upstream.
- 6.12.y: e636ffb9e31b and f5a538c07df2 apply cleanly.
ca1e8eede4fc only has a context conflict in dl_server_start() and
1e0a2ba7afb1 needs a adaptation.
So I'm in favor of taking these for 6.18.y and 6.12.y. 6.18.y should
go first, so that 6.12.y never carries the fix without the newer
stable branch also having it.
For 6.18.y, since the commits cherry-pick cleanly, it might be enough
to ask the stable team to pick them by SHA.
For 6.12.y, could you then send your backport, rebased on the current
head? Please Cc Peter and Gabriele on both requests, since they authored
the commits and myself.
It would also help if you could rerun your numbers (latency and the
starvation check) on current 6.18.y (64), as 6.18.15 is quite a bit
older and a few dl_server fixes went in since. I tried to reproduce on a
local VM, but I think my system was too noisy to see what you reported.
Until then, setting fair_server runtime to 0 on the isolated CPUs is
a reasonable workaround. Just keep in mind that it removes starvation
protection for all fair tasks on those CPUs (kworkers included).
Thanks,
Juri
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19)
2026-11-20 17:09 ` Juri Lelli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-21 15:27 ` Sasha Levin
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
1 sibling, 1 reply; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: Juri Lelli
Cc: stable, Peter Zijlstra, Vincent Guittot, linux-rt-users,
Gabriele Monaco
Hi Juri,
Thanks a lot for checking.
> It would also help if you could rerun your numbers (latency and the
> starvation check) on current 6.18.y (64)
Done, with v6.18.64 built with the Debian 6.18 rt config (PREEMPT_RT,
PREEMPT_DYNAMIC, default preempt=full), in the same KVM guest as
before, 30 s runs, 3 ms spin:
max FIFO latency, late wake-ups (> 500 us)
sleep 1.00 s sleep 1.02 s sleep 1.04 s
6.18.64 3010 us, 15 2998 us, 15 3012 us, 14
6.18.64 + 4 commits 23 us, 0 13 us, 0 12 us, 0
Starvation check (SCHED_OTHER task on the CPU of a SCHED_FIFO 50 busy
loop, 4.5 s window): 4.7% of the CPU on both, 0% with the fair_server
runtime at 0. So 6.18.64 is affected as much as 6.18.15 was, and the
four commits fix it there.
Stable team: please pick the following for 6.18.y, in this order. They
cherry-pick cleanly on v6.18.64:
e636ffb9e31b ("sched/deadline: Fix dl_server time accounting")
f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
1e0a2ba7afb1 ("sched: Provide idle_rq() helper")
ca1e8eede4fc ("sched/deadline: Fix server stopping with runnable tasks")
> - 6.12.y: e636ffb9e31b and f5a538c07df2 apply cleanly.
They apply, but they don't build as is: both use rq->donor, which
6.12 doesn't have, so my backport uses rq->curr there. I'll send the
6.12.y series in reply to this thread, rebased on v6.12.118.
> Just keep in mind that it removes starvation protection for all fair
> tasks on those CPUs (kworkers included).
Noted, thanks. We only use it until we run a kernel with the fix.
Thanks,
Florent
On Fri, Nov 20, 2026 at 6:10 PM Juri Lelli <juri.lelli@redhat.com> wrote:
>
> Hello,
>
> On 20/11/26 16:09, Florent Carli wrote:
>
> ...
>
> > On 6.12.y and 6.18.y, I see it run SCHED_OTHER tasks ahead of RT tasks
> > on a CPU where nothing starves.
>
> ...
>
> > The fix went into 6.19:
> >
> > e636ffb9e31b ("sched/deadline: Fix dl_server time accounting")
> > f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
> > 1e0a2ba7afb1 ("sched: Provide idle_rq() helper")
> > ca1e8eede4fc ("sched/deadline: Fix server stopping with runnable tasks")
> >
> > None of them carries a stable tag, and only 1e0a2ba7afb1 applies
> > cleanly to 6.12.y or 6.18.y.
>
> Thanks for the detailed report and the reproducer, much appreciated.
>
> I had a look and I agree with your analysis. Comparing v6.19 with the
> current stable heads (6.12.118 and 6.18.64), these four are the only
> dl_server changes not yet in either branch. The other dl_server fixes
> from that period (including 115135422562 "Fix 'stuck' dl_server" and
> the two "revised wakeup rule" follow-ups) are already in stable.
>
> On applying them: with git am (no -3) I get exactly what you report,
> on both 6.18.15 and 6.18.64: only 1e0a2ba7afb1 applies on its own. The
> rejects are context only, though (upstream refactors around the
> sched_class callbacks that stable doesn't carry), and a 3-way merge
> takes care of them. With git cherry-pick, applying them in order:
>
> - 6.18.y: all four apply cleanly, and the result matches upstream.
>
> - 6.12.y: e636ffb9e31b and f5a538c07df2 apply cleanly.
> ca1e8eede4fc only has a context conflict in dl_server_start() and
> 1e0a2ba7afb1 needs a adaptation.
>
> So I'm in favor of taking these for 6.18.y and 6.12.y. 6.18.y should
> go first, so that 6.12.y never carries the fix without the newer
> stable branch also having it.
>
> For 6.18.y, since the commits cherry-pick cleanly, it might be enough
> to ask the stable team to pick them by SHA.
>
> For 6.12.y, could you then send your backport, rebased on the current
> head? Please Cc Peter and Gabriele on both requests, since they authored
> the commits and myself.
>
> It would also help if you could rerun your numbers (latency and the
> starvation check) on current 6.18.y (64), as 6.18.15 is quite a bit
> older and a few dl_server fixes went in since. I tried to reproduce on a
> local VM, but I think my system was too noisy to see what you reported.
>
> Until then, setting fair_server runtime to 0 on the isolated CPUs is
> a reasonable workaround. Just keep in mind that it removes starvation
> protection for all fair tasks on those CPUs (kworkers included).
>
> Thanks,
> Juri
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19
2026-11-20 17:09 ` Juri Lelli
2026-11-20 18:19 ` Florent Carli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting Florent Carli
` (4 more replies)
1 sibling, 5 replies; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: stable; +Cc: Juri Lelli, Peter Zijlstra, Gabriele Monaco, linux-rt-users
Hello,
This is the 6.12.y backport of the dl_server fixes discussed in the
parent thread: on 6.12.y, the deferred fair server can run a
SCHED_OTHER task ahead of SCHED_FIFO tasks on an almost idle CPU.
The same four commits are requested for 6.18.y, where they cherry-pick
cleanly.
Adaptations for 6.12 (noted in each patch):
- 1/4: rq->donor does not exist in 6.12, rq->curr is used.
- 3/4: rq->ttwu_pending only exists with CONFIG_SMP in 6.12.
- 4/4: context conflict in dl_server_start(), which still
initializes the fair server in 6.12.
2/4 applies as is. The series builds and boots on v6.12.118 with the
Debian 6.12 rt config (PREEMPT_RT).
Tests, KVM guest, reproducer from the parent thread (3 ms spin),
sleep 1.00, 1.02 and 1.03 s, 90 s per run, late = FIFO wake-up later
than 500 us:
v6.12.118 8 late wake-ups in 270 s, ~2900 us
v6.12.118 + this series 0 in 270 s, max 15 us
With the v6.12-rt queue on top (as Debian ships it), which makes the
window much easier to hit, an equivalent backport (same code, the
idle_rq() helper added without moving available_idle_cpu()) went from
14 to 15 late wake-ups per 30 s to 0.
Starvation check (SCHED_OTHER task on the CPU of a SCHED_FIFO 50 busy
loop, 4.5 s window): 4.9% of the CPU with this series, 4.7% without,
0% with the fair_server runtime at 0.
Thanks,
Florent
Gabriele Monaco (1):
sched/deadline: Fix server stopping with runnable tasks
Peter Zijlstra (3):
sched/deadline: Fix dl_server time accounting
sched/deadline: Fix dl_server stop condition
sched: Provide idle_rq() helper
include/linux/sched.h | 16 ++++----
kernel/sched/deadline.c | 89 +++++++++++++++++++++++++++--------------
kernel/sched/fair.c | 9 +----
kernel/sched/idle.c | 16 +++++++-
kernel/sched/sched.h | 31 +++++++++++++-
kernel/sched/syscalls.c | 32 +--------------
6 files changed, 116 insertions(+), 77 deletions(-)
base-commit: b869a5313cbfe7102873d3de318ddb68675146d0
--
2.39.3 (Apple Git-146)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 2/4] sched/deadline: Fix dl_server stop condition Florent Carli
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: stable; +Cc: Juri Lelli, Peter Zijlstra, Gabriele Monaco, linux-rt-users
From: Peter Zijlstra <peterz@infradead.org>
commit e636ffb9e31b4f7dde7fef5358669266b9ce02ec upstream.
The dl_server time accounting code is a little odd. The normal scheduler
pattern is to update curr before doing something, such that the old state is
fully accounted before changing state.
Notably, the dl_server_timer() needs to propagate the current time accounting
since the current task could be ran by dl_server and thus this can affect
dl_se->runtime. Similarly for dl_server_start().
And since the (deferred) dl_server wants idle time accounted, rework
sched_idle_class time accounting to be more like all the others.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251020141130.GJ3245006@noisy.programming.kicks-ass.net
[ Florent: rq->donor does not exist in 6.12, use rq->curr ]
Signed-off-by: Florent Carli <fcarli@gmail.com>
---
kernel/sched/deadline.c | 40 +++++++++++++++-------------------------
kernel/sched/fair.c | 9 ++-------
kernel/sched/idle.c | 16 +++++++++++++++-
kernel/sched/sched.h | 3 +--
4 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index f5c64d1a0..2e3bd43af 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1216,8 +1216,12 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_
sched_clock_tick();
update_rq_clock(rq);
- if (!dl_se->dl_runtime)
- return HRTIMER_NORESTART;
+ /*
+ * Make sure current has propagated its pending runtime into
+ * any relevant server through calling dl_server_update() and
+ * friends.
+ */
+ rq->curr->sched_class->update_curr(rq);
if (dl_se->dl_defer_armed) {
/*
@@ -1594,35 +1598,16 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64
* as time available for the fair server, avoiding a penalty for the
* rt scheduler that did not consumed that time.
*/
-void dl_server_update_idle_time(struct rq *rq, struct task_struct *p)
+void dl_server_update_idle(struct sched_dl_entity *dl_se, s64 delta_exec)
{
- s64 delta_exec;
-
- if (!rq->fair_server.dl_defer)
- return;
-
- /* no need to discount more */
- if (rq->fair_server.runtime < 0)
- return;
-
- delta_exec = rq_clock_task(rq) - p->se.exec_start;
- if (delta_exec < 0)
- return;
-
- rq->fair_server.runtime -= delta_exec;
-
- if (rq->fair_server.runtime < 0) {
- rq->fair_server.dl_defer_running = 0;
- rq->fair_server.runtime = 0;
- }
-
- p->se.exec_start = rq_clock_task(rq);
+ if (dl_se->dl_server_active && dl_se->dl_runtime && dl_se->dl_defer)
+ update_curr_dl_se(dl_se->rq, dl_se, delta_exec);
}
void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
{
/* 0 runtime = fair server disabled */
- if (dl_se->dl_runtime)
+ if (dl_se->dl_server_active && dl_se->dl_runtime)
update_curr_dl_se(dl_se->rq, dl_se, delta_exec);
}
@@ -1849,6 +1834,11 @@ void dl_server_start(struct sched_dl_entity *dl_se)
if (!dl_se->dl_runtime || dl_se->dl_server_active)
return;
+ /*
+ * Update the current task to 'now'.
+ */
+ rq->curr->sched_class->update_curr(rq);
+
if (WARN_ON_ONCE(!cpu_online(cpu_of(rq))))
return;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 020a39fe0..7e5179189 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1259,8 +1259,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
* against fair_server such that it can account for this time
* and possibly avoid running this period.
*/
- if (dl_server_active(&rq->fair_server))
- dl_server_update(&rq->fair_server, delta_exec);
+ dl_server_update(&rq->fair_server, delta_exec);
}
account_cfs_rq_runtime(cfs_rq, delta_exec);
@@ -7114,12 +7113,8 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
goto enqueue_throttle;
}
- if (!rq_h_nr_queued && rq->cfs.h_nr_queued) {
- /* Account for idle runtime */
- if (!rq->nr_running)
- dl_server_update_idle_time(rq, rq->curr);
+ if (!rq_h_nr_queued && rq->cfs.h_nr_queued)
dl_server_start(&rq->fair_server);
- }
/* At this point se is NULL and we are at root level*/
add_nr_running(rq, 1);
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 1f0f0d9a5..a2ab252e7 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -471,9 +471,11 @@ static void wakeup_preempt_idle(struct rq *rq, struct task_struct *p, int flags)
resched_curr(rq);
}
+static void update_curr_idle(struct rq *rq);
+
static void put_prev_task_idle(struct rq *rq, struct task_struct *prev, struct task_struct *next)
{
- dl_server_update_idle_time(rq, prev);
+ update_curr_idle(rq);
scx_update_idle(rq, false, true);
}
@@ -521,6 +523,7 @@ dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags)
*/
static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
{
+ update_curr_idle(rq);
}
static void switched_to_idle(struct rq *rq, struct task_struct *p)
@@ -536,6 +539,17 @@ prio_changed_idle(struct rq *rq, struct task_struct *p, int oldprio)
static void update_curr_idle(struct rq *rq)
{
+ struct sched_entity *se = &rq->idle->se;
+ u64 now = rq_clock_task(rq);
+ s64 delta_exec;
+
+ delta_exec = now - se->exec_start;
+ if (unlikely(delta_exec <= 0))
+ return;
+
+ se->exec_start = now;
+
+ dl_server_update_idle(&rq->fair_server, delta_exec);
}
/*
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 5e788dc39..598dd26fe 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -411,14 +411,13 @@ extern s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, s6
* naturally thottled to once per period, avoiding high context switch
* workloads from spamming the hrtimer program/cancel paths.
*/
+extern void dl_server_update_idle(struct sched_dl_entity *dl_se, s64 delta_exec);
extern void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec);
extern void dl_server_start(struct sched_dl_entity *dl_se);
extern void dl_server_stop(struct sched_dl_entity *dl_se);
extern void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq,
dl_server_pick_f pick_task);
-extern void dl_server_update_idle_time(struct rq *rq,
- struct task_struct *p);
extern void fair_server_init(struct rq *rq);
extern void __dl_server_attach_root(struct sched_dl_entity *dl_se, struct rq *rq);
extern int dl_server_apply_params(struct sched_dl_entity *dl_se,
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6.12.y 2/4] sched/deadline: Fix dl_server stop condition
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting Florent Carli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 3/4] sched: Provide idle_rq() helper Florent Carli
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: stable; +Cc: Juri Lelli, Peter Zijlstra, Gabriele Monaco, linux-rt-users
From: Peter Zijlstra <peterz@infradead.org>
commit f5a538c07df26f5c601e41f7b9c7ade3e1e75803 upstream.
Gabriel reported that the dl_server doesn't stop as expected.
The problem was found to be the fact that idle time and fair runtime are
treated equally. Both will count towards dl_server runtime and push the
activation forwards when it is in the zero-laxity wait state.
Notably:
dl_server_update_idle()
update_curr_dl_se()
if (dl_defer && dl_throttled && dl_runtime_exceeded())
hrtimer_try_to_cancel(); // stop timer
replenish_dl_new_period()
deadline = now + dl_deadline; // fwd period
runtime = dl_runtime;
start_dl_timer(); // restart timer
And while we do want idle time accounted towards the *current* activation of
the dl_server -- after all, a fair task could've ran if we had any -- we don't
necessarily want idle time to cause or push forward an activation.
Introduce dl_defer_idle to make this distinction. It will be set once idle time
pushed the activation forward, once set idle time will only be allowed to
consume any runtime but not push the activation. This will then cause
dl_server_timer() to fire, which will stop the dl_server.
Any non-idle time accounting during this phase will clear dl_defer_idle, so
only a full period of idle will cause the dl_server to stop.
Reported-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251101000057.GA2184199@noisy.programming.kicks-ass.net
Signed-off-by: Florent Carli <fcarli@gmail.com>
---
include/linux/sched.h | 15 +++++++++------
kernel/sched/deadline.c | 40 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 1c584a1f0..7f0fb62df 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -650,20 +650,22 @@ struct sched_dl_entity {
*
* @dl_server tells if this is a server entity.
*
- * @dl_defer tells if this is a deferred or regular server. For
- * now only defer server exists.
- *
- * @dl_defer_armed tells if the deferrable server is waiting
- * for the replenishment timer to activate it.
- *
* @dl_server_active tells if the dlserver is active(started).
* dlserver is started on first cfs enqueue on an idle runqueue
* and is stopped when a dequeue results in 0 cfs tasks on the
* runqueue. In other words, dlserver is active only when cpu's
* runqueue has atleast one cfs task.
*
+ * @dl_defer tells if this is a deferred or regular server. For
+ * now only defer server exists.
+ *
+ * @dl_defer_armed tells if the deferrable server is waiting
+ * for the replenishment timer to activate it.
+ *
* @dl_defer_running tells if the deferrable server is actually
* running, skipping the defer phase.
+ *
+ * @dl_defer_idle tracks idle state
*/
unsigned int dl_throttled : 1;
unsigned int dl_yielded : 1;
@@ -674,6 +676,7 @@ struct sched_dl_entity {
unsigned int dl_defer : 1;
unsigned int dl_defer_armed : 1;
unsigned int dl_defer_running : 1;
+ unsigned int dl_defer_idle : 1;
/*
* Bandwidth enforcement timer. Each -deadline task has its
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 2e3bd43af..ea64ab436 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1223,6 +1223,11 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_
*/
rq->curr->sched_class->update_curr(rq);
+ if (dl_se->dl_defer_idle) {
+ dl_server_stop(dl_se);
+ return HRTIMER_NORESTART;
+ }
+
if (dl_se->dl_defer_armed) {
/*
* First check if the server could consume runtime in background.
@@ -1473,10 +1478,11 @@ s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, s64 delta
}
static inline void
-update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se,
- int flags);
+update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se, int flags);
+
static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64 delta_exec)
{
+ bool idle = rq->curr == rq->idle;
s64 scaled_delta_exec;
if (unlikely(delta_exec <= 0)) {
@@ -1497,6 +1503,9 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64
dl_se->runtime -= scaled_delta_exec;
+ if (dl_se->dl_defer_idle && !idle)
+ dl_se->dl_defer_idle = 0;
+
/*
* The fair server can consume its runtime while throttled (not queued/
* running as regular CFS).
@@ -1506,6 +1515,29 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64
* starting a new period, pushing the activation.
*/
if (dl_se->dl_defer && dl_se->dl_throttled && dl_runtime_exceeded(dl_se)) {
+ /*
+ * Non-servers would never get time accounted while throttled.
+ */
+ WARN_ON_ONCE(!dl_server(dl_se));
+
+ /*
+ * While the server is marked idle, do not push out the
+ * activation further, instead wait for the period timer
+ * to lapse and stop the server.
+ */
+ if (dl_se->dl_defer_idle && idle) {
+ /*
+ * The timer is at the zero-laxity point, this means
+ * dl_server_stop() / dl_server_start() can happen
+ * while now < deadline. This means update_dl_entity()
+ * will not replenish. Additionally start_dl_timer()
+ * will be set for 'deadline - runtime'. Negative
+ * runtime will not do.
+ */
+ dl_se->runtime = 0;
+ return;
+ }
+
/*
* If the server was previously activated - the starving condition
* took place, it this point it went away because the fair scheduler
@@ -1518,6 +1550,9 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64
replenish_dl_new_period(dl_se, dl_se->rq);
+ if (idle)
+ dl_se->dl_defer_idle = 1;
+
/*
* Not being able to start the timer seems problematic. If it could not
* be started for whatever reason, we need to "unthrottle" the DL server
@@ -1857,6 +1892,7 @@ void dl_server_stop(struct sched_dl_entity *dl_se)
hrtimer_try_to_cancel(&dl_se->dl_timer);
dl_se->dl_defer_armed = 0;
dl_se->dl_throttled = 0;
+ dl_se->dl_defer_idle = 0;
dl_se->dl_server_active = 0;
}
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6.12.y 3/4] sched: Provide idle_rq() helper
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 2/4] sched/deadline: Fix dl_server stop condition Florent Carli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 4/4] sched/deadline: Fix server stopping with runnable tasks Florent Carli
2026-11-21 15:27 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Sasha Levin
4 siblings, 0 replies; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: stable; +Cc: Juri Lelli, Peter Zijlstra, Gabriele Monaco, linux-rt-users
From: Peter Zijlstra <peterz@infradead.org>
commit 1e0a2ba7afb1b60f02599093d84b72ce62ad11c0 upstream.
A fix for the dl_server 'requires' idle_cpu() usage, which made me
note that it and available_idle_cpu() are extern function calls.
And while idle_cpu() is used outside of kernel/sched/,
available_idle_cpu() is not.
This makes it hard to make idle_cpu() an inline helper, so provide
idle_rq() and implement idle_cpu() and available_idle_cpu() using
that.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
[ Florent: rq->ttwu_pending only exists with CONFIG_SMP in 6.12 ]
Signed-off-by: Florent Carli <fcarli@gmail.com>
---
include/linux/sched.h | 1 -
kernel/sched/sched.h | 28 ++++++++++++++++++++++++++++
kernel/sched/syscalls.c | 32 +-------------------------------
3 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7f0fb62df..efee6139c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1895,7 +1895,6 @@ static inline int task_nice(const struct task_struct *p)
extern int can_nice(const struct task_struct *p, const int nice);
extern int task_curr(const struct task_struct *p);
extern int idle_cpu(int cpu);
-extern int available_idle_cpu(int cpu);
extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
extern void sched_set_fifo(struct task_struct *p);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 598dd26fe..27de92902 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1390,6 +1390,34 @@ static inline u32 sched_rng(void)
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
#define raw_rq() raw_cpu_ptr(&runqueues)
+static inline bool idle_rq(struct rq *rq)
+{
+ if (rq->curr != rq->idle || rq->nr_running)
+ return false;
+#ifdef CONFIG_SMP
+ if (rq->ttwu_pending)
+ return false;
+#endif
+ return true;
+}
+
+/**
+ * available_idle_cpu - is a given CPU idle for enqueuing work.
+ * @cpu: the CPU in question.
+ *
+ * Return: 1 if the CPU is currently idle. 0 otherwise.
+ */
+static inline bool available_idle_cpu(int cpu)
+{
+ if (!idle_rq(cpu_rq(cpu)))
+ return 0;
+
+ if (vcpu_is_preempted(cpu))
+ return 0;
+
+ return 1;
+}
+
#ifdef CONFIG_SCHED_CORE
static inline struct cpumask *sched_group_span(struct sched_group *sg);
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index b51b39a10..f31fcdcfe 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -201,37 +201,7 @@ int task_prio(const struct task_struct *p)
*/
int idle_cpu(int cpu)
{
- struct rq *rq = cpu_rq(cpu);
-
- if (rq->curr != rq->idle)
- return 0;
-
- if (rq->nr_running)
- return 0;
-
-#ifdef CONFIG_SMP
- if (rq->ttwu_pending)
- return 0;
-#endif
-
- return 1;
-}
-
-/**
- * available_idle_cpu - is a given CPU idle for enqueuing work.
- * @cpu: the CPU in question.
- *
- * Return: 1 if the CPU is currently idle. 0 otherwise.
- */
-int available_idle_cpu(int cpu)
-{
- if (!idle_cpu(cpu))
- return 0;
-
- if (vcpu_is_preempted(cpu))
- return 0;
-
- return 1;
+ return idle_rq(cpu_rq(cpu));
}
/**
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6.12.y 4/4] sched/deadline: Fix server stopping with runnable tasks
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
` (2 preceding siblings ...)
2026-11-20 18:19 ` [PATCH 6.12.y 3/4] sched: Provide idle_rq() helper Florent Carli
@ 2026-11-20 18:19 ` Florent Carli
2026-11-21 15:27 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Sasha Levin
4 siblings, 0 replies; 10+ messages in thread
From: Florent Carli @ 2026-11-20 18:19 UTC (permalink / raw)
To: stable; +Cc: Juri Lelli, Peter Zijlstra, Gabriele Monaco, linux-rt-users
From: Gabriele Monaco <gmonaco@redhat.com>
commit ca1e8eede4fc68ce85a9fdce1a6c13ad64933318 upstream.
The deadline server can currently stop due to idle although fair tasks
are runnable. This happens essentially when:
* the server is set to idle, a task wakes up, the server stops
* a task wakes up, the server sets itself to idle and stops right away
Address both cases by clearing the server idle flag whenever a fair task
wakes up and accounting also for pending tasks in the definition of idle.
Fixes: f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260113085159.114226-3-gmonaco@redhat.com
[ Florent: context conflict in dl_server_start(), which still
initializes the fair server in 6.12 ]
Signed-off-by: Florent Carli <fcarli@gmail.com>
---
kernel/sched/deadline.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index ea64ab436..2da68de70 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1482,7 +1482,7 @@ update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se, int
static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64 delta_exec)
{
- bool idle = rq->curr == rq->idle;
+ bool idle = idle_rq(rq);
s64 scaled_delta_exec;
if (unlikely(delta_exec <= 0)) {
@@ -1663,8 +1663,8 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
* | 8 | B:zero_laxity-wait | | |
* | | | <---+ |
* | +--------------------------------+ |
- * | | ^ ^ 2 |
- * | | 7 | 2 +--------------------+
+ * | | ^ ^ 2 |
+ * | | 7 | 2, 1 +----------------+
* | v |
* | +-------------+ |
* +-- | C:idle-wait | -+
@@ -1709,8 +1709,11 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
* dl_defer_idle = 0
*
*
- * [1] A->B, A->D
+ * [1] A->B, A->D, C->B
* dl_server_start()
+ * dl_defer_idle = 0;
+ * if (dl_server_active)
+ * return; // [B]
* dl_server_active = 1;
* enqueue_dl_entity()
* update_dl_entity(WAKEUP)
@@ -1825,6 +1828,7 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
* "B:zero_laxity-wait" -> "C:idle-wait" [label="7:dl_server_update_idle"]
* "B:zero_laxity-wait" -> "D:running" [label="3:dl_server_timer"]
* "C:idle-wait" -> "A:init" [label="8:dl_server_timer"]
+ * "C:idle-wait" -> "B:zero_laxity-wait" [label="1:dl_server_start"]
* "C:idle-wait" -> "B:zero_laxity-wait" [label="2:dl_server_update"]
* "C:idle-wait" -> "C:idle-wait" [label="7:dl_server_update_idle"]
* "D:running" -> "A:init" [label="4:pick_task_dl"]
@@ -1850,6 +1854,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)
{
struct rq *rq = dl_se->rq;
+ dl_se->dl_defer_idle = 0;
/*
* XXX: the apply do not work fine at the init phase for the
* fair server because things are not yet set. We need to improve
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19)
2026-11-20 18:19 ` Florent Carli
@ 2026-11-21 15:27 ` Sasha Levin
0 siblings, 0 replies; 10+ messages in thread
From: Sasha Levin @ 2026-11-21 15:27 UTC (permalink / raw)
To: Juri Lelli
Cc: Sasha Levin, stable, Peter Zijlstra, Vincent Guittot,
linux-rt-users, Gabriele Monaco, Florent Carli
> Stable team: please pick the following for 6.18.y, in this order. They
> cherry-pick cleanly on v6.18.64:
>
> e636ffb9e31b ("sched/deadline: Fix dl_server time accounting")
> f5a538c07df2 ("sched/deadline: Fix dl_server stop condition")
> 1e0a2ba7afb1 ("sched: Provide idle_rq() helper")
> ca1e8eede4fc ("sched/deadline: Fix server stopping with runnable tasks")
Queued for 6.18, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
` (3 preceding siblings ...)
2026-11-20 18:19 ` [PATCH 6.12.y 4/4] sched/deadline: Fix server stopping with runnable tasks Florent Carli
@ 2026-11-21 15:27 ` Sasha Levin
4 siblings, 0 replies; 10+ messages in thread
From: Sasha Levin @ 2026-11-21 15:27 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Juri Lelli, Peter Zijlstra, Gabriele Monaco,
linux-rt-users, Florent Carli
> This is the 6.12.y backport of the dl_server fixes discussed in the
> parent thread: on 6.12.y, the deferred fair server can run a
> SCHED_OTHER task ahead of SCHED_FIFO tasks on an almost idle CPU.
Queued the series for 6.12, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-21 15:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:09 [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19) Florent Carli
2026-11-20 17:09 ` Juri Lelli
2026-11-20 18:19 ` Florent Carli
2026-11-21 15:27 ` Sasha Levin
2026-11-20 18:19 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 2/4] sched/deadline: Fix dl_server stop condition Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 3/4] sched: Provide idle_rq() helper Florent Carli
2026-11-20 18:19 ` [PATCH 6.12.y 4/4] sched/deadline: Fix server stopping with runnable tasks Florent Carli
2026-11-21 15:27 ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Sasha Levin
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.