sched/deadline: Fix stale dl_defer_running in dl_server else-branch
PATCH 1/1 sched/deadline: Fix stale dl_defer_running in dl_server else-branch
From: Zhidao Su <[email protected]>
Peter's fix (115135422562) cleared dl_defer_running in the if-branch of update_dl_entity() (deadline expired/overflow). This ensures replenish_dl_new_period() always arms the zero-laxity timer. However, with PROXY_WAKING, re-activation hits the else-branch (same-period, deadline not expired), where dl_defer_running from a prior starvation episode can be stale.
During PROXY_WAKING CPU return-migration, proxy_force_return() migrates the task to a new CPU via deactivate_task()+attach_one_task(). The enqueue path on the new CPU triggers enqueue_task_fair() which calls dl_server_start() for the fair_server. Crucially, this re-activation does NOT call dl_server_stop() first, so dl_defer_running retains its prior value. If a prior starvation episode left dl_defer_running=1, and the server is re-activated within the same period:
[4] D->A: dl_server_stop() clears flags but may be skipped when dl_server_active=0 (server was already stopped before return-migration triggered dl_server_start())
[1] A->B: dl_server_start() -> enqueue_dl_entity(WAKEUP)
-> update_dl_entity() enters else-branch
-> 'if (!dl_defer_running)' guard fires, skips
dl_defer_armed=1 / dl_throttled=1
-> server enqueued into [D] state directly
-> update_curr_dl_se() consumes runtime
-> start_dl_timer() with dl_defer_armed=0 (slow path)
-> boot time increases ~72%Fix: in the else-branch, unconditionally clear dl_defer_running and always set dl_defer_armed=1 / dl_throttled=1. This ensures every same-period re-activation properly re-arms the zero-laxity timer, regardless of whether a prior starvation episode had set dl_defer_running.
The if-branch (deadline expired) is left untouched:replenish_dl_new_period() contains its own guard ('if (!dl_defer_running)') that arms the zero-laxity timer only when dl_defer_running=0. With PROXY_WAKING, dl_defer_running=1 in the deadline-expired path means a genuine starvation episode is ongoing, so the server can skip the zero-laxity wait and enter [D] directly. Clearing dl_defer_running here (as Peter's fix did) forces every PROXY_WAKING deadline-expired re-activation through the ~950ms zero-laxity wait.
Measured boot time to first ksched_football event (4 CPUs, 4G):
This fix: ~15-20s
Without fix (stale dl_defer_running): ~43-62s (+72-200%)
Note: Andrea Righi's v2 patch addresses the same symptom by clearing dl_defer_running in dl_server_stop(). However, dl_server_stop() is not called during PROXY_WAKING return-migration (proxy_force_return() calls dl_server_start() directly without dl_server_stop()). This fix targets the correct location: the else-branch of update_dl_entity().
--- kernel/sched/deadline.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
kernel/sched/deadline.c +12 -12
@@ -1034,22 +1034,22 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)return ; } -/* -* When [4] D->A is followed by [1] A->B, dl_defer_running -* needs to be cleared, otherwise it will fail to properly -* start the zero-laxity timer. -*/ - dl_se->dl_defer_running =0 ;replenish_dl_new_period (dl_se, rq); }else if (dl_server (dl_se) && dl_se->dl_defer) {/* -* The server can still use its previous deadline, so check if -* it left the dl_defer_running state. +* The server can still use its previous deadline. Clear +* dl_defer_running unconditionally: a stale dl_defer_running=1 +* from a prior starvation episode (set in dl_server_timer() when +* the zero-laxity timer fires) must not carry over to the next +* activation. PROXY_WAKING return-migration (proxy_force_return) +* re-activates the server via attach_one_task()->enqueue_task_fair() +* without calling dl_server_stop() first, so the flag is not +* cleared in the [4] D->A path for that case. +* Always re-arm the zero-laxity timer on each re-activation. */ -if (!dl_se->dl_defer_running) { - dl_se->dl_defer_armed =1 ; - dl_se->dl_throttled =1 ; - } + dl_se->dl_defer_running =0 ; + dl_se->dl_defer_armed =1 ; + dl_se->dl_throttled =1 ; } }
Signature · 1 line
2.43.0
Quoted 48 lines · On Thu, Apr 2, 2026 at 6:30 AM <[email protected]> wrote:
From: Zhidao Su <[email protected]>
Peter's fix (115135422562) cleared
dl_defer_runningin the if-branch ofupdate_dl_entity()(deadline expired/overflow). This ensuresreplenish_dl_new_period()always arms the zero-laxity timer. However, withPROXY_WAKING, re-activation hits the else-branch (same-period, deadline not expired), wheredl_defer_runningfrom a prior starvation episode can be stale.During
PROXY_WAKINGCPU return-migration,proxy_force_return()migrates the task to a new CPU via deactivate_task()+attach_one_task(). The enqueue path on the new CPU triggersenqueue_task_fair()which callsdl_server_start()for thefair_server. Crucially, this re-activation does NOT calldl_server_stop()first, sodl_defer_runningretains its prior value. If a prior starvation episode left dl_defer_running=1, and the server is re-activated within the same period:[4]
D->A:dl_server_stop()clears flags but may be skipped when dl_server_active=0 (server was already stopped before return-migration triggereddl_server_start())
[1]A->B:dl_server_start()->enqueue_dl_entity(WAKEUP)-> update_dl_entity() enters else-branch -> 'if (!dl_defer_running)' guard fires, skips dl_defer_armed=1 / dl_throttled=1 -> server enqueued into [D] state directly -> update_curr_dl_se() consumes runtime -> start_dl_timer() with dl_defer_armed=0 (slow path) -> boot time increases ~72%Fix: in the else-branch, unconditionally clear
dl_defer_runningand always set dl_defer_armed=1 / dl_throttled=1. This ensures every same-period re-activation properly re-arms the zero-laxity timer, regardless of whether a prior starvation episode had setdl_defer_running.The if-branch (deadline expired) is left untouched:
replenish_dl_new_period()contains its own guard ('if (!dl_defer_running)') that arms the zero-laxity timer only when dl_defer_running=0. WithPROXY_WAKING, dl_defer_running=1 in the deadline-expired path means a genuine starvation episode is ongoing, so the server can skip the zero-laxity wait and enter [D] directly. Clearingdl_defer_runninghere (as Peter's fix did) forces everyPROXY_WAKINGdeadline-expired re-activation through the ~950ms zero-laxity wait.Measured boot time to first
ksched_footballevent (4 CPUs, 4G):
This fix: ~15-20s
Without fix (staledl_defer_running): ~43-62s (+72-200%)
Quoted 7 lines
Note: Andrea Righi's v2 patch addresses the same symptom by clearing
dl_defer_runningindl_server_stop(). However,dl_server_stop()is not called duringPROXY_WAKINGreturn-migration (proxy_force_return()callsdl_server_start()directly withoutdl_server_stop()). This fix targets the correct location: the else-branch ofupdate_dl_entity().Signed-off-by Zhidao Su <[email protected]>
Oh, this is perfect! I've noticed the performance regression previously and narrowed it down to commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server"), but I hadn't quite gotten my head around the issue. In testing, your patch seems to resolve the regression as well as the revert I was doing previously.
I've included your patch in the series I'm hoping to send out soon here.
Thanks so much!
-john
Quoted 55 lines · John Stultz
Quoted 54 lines · On Thu, Apr 2, 2026 at 6:30 AM <[email protected]> wrote:
From: Zhidao Su <[email protected]>
Peter's fix (115135422562) cleared
dl_defer_runningin the if-branch ofupdate_dl_entity()(deadline expired/overflow). This ensuresreplenish_dl_new_period()always arms the zero-laxity timer. However, withPROXY_WAKING, re-activation hits the else-branch (same-period, deadline not expired), wheredl_defer_runningfrom a prior starvation episode can be stale.During
PROXY_WAKINGCPU return-migration,proxy_force_return()migrates the task to a new CPU via deactivate_task()+attach_one_task(). The enqueue path on the new CPU triggersenqueue_task_fair()which callsdl_server_start()for thefair_server. Crucially, this re-activation does NOT calldl_server_stop()first, sodl_defer_runningretains its prior value. If a prior starvation episode left dl_defer_running=1, and the server is re-activated within the same period:[4]
D->A:dl_server_stop()clears flags but may be skipped when dl_server_active=0 (server was already stopped before return-migration triggereddl_server_start())
[1]A->B:dl_server_start()->enqueue_dl_entity(WAKEUP)-> update_dl_entity() enters else-branch -> 'if (!dl_defer_running)' guard fires, skips dl_defer_armed=1 / dl_throttled=1 -> server enqueued into [D] state directly -> update_curr_dl_se() consumes runtime -> start_dl_timer() with dl_defer_armed=0 (slow path) -> boot time increases ~72%Fix: in the else-branch, unconditionally clear
dl_defer_runningand always set dl_defer_armed=1 / dl_throttled=1. This ensures every same-period re-activation properly re-arms the zero-laxity timer, regardless of whether a prior starvation episode had setdl_defer_running.The if-branch (deadline expired) is left untouched:
replenish_dl_new_period()contains its own guard ('if (!dl_defer_running)') that arms the zero-laxity timer only when dl_defer_running=0. WithPROXY_WAKING, dl_defer_running=1 in the deadline-expired path means a genuine starvation episode is ongoing, so the server can skip the zero-laxity wait and enter [D] directly. Clearingdl_defer_runninghere (as Peter's fix did) forces everyPROXY_WAKINGdeadline-expired re-activation through the ~950ms zero-laxity wait.Measured boot time to first
ksched_footballevent (4 CPUs, 4G):
This fix: ~15-20s
Without fix (staledl_defer_running): ~43-62s (+72-200%)Note: Andrea Righi's v2 patch addresses the same symptom by clearing
dl_defer_runningindl_server_stop(). However,dl_server_stop()is not called duringPROXY_WAKINGreturn-migration (proxy_force_return()callsdl_server_start()directly withoutdl_server_stop()). This fix targets the correct location: the else-branch ofupdate_dl_entity().
Quoted 7 lines
Quoted 1 line
Signed-off-by Zhidao Su <[email protected]>Oh, this is perfect! I've noticed the performance regression previously and narrowed it down to commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server"), but I hadn't quite gotten my head around the issue. In testing, your patch seems to resolve the regression as well as the revert I was doing previously.
Oh drat, unfortunately I was testing without the ksched_football test applied, and unfortunately this change isn't resolving the issue (basically see the ksched_football test seemingly stop making progress on boot, seemingly hanging the system).
So it doesn't seem this is sufficient. I'll continue working to understand the issue and will use your hint about calling dl_server_stop() maybe in the return migration path.
thanks
-john
PATCH 1/1 sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
From: zhidao su <[email protected]>
commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server") added a dl_defer_running = 0 reset in the if-branch of update_dl_entity() to handle the case where [4] D->A is followed by [1] A->B (lapsed deadline). The intent was to ensure the server re-enters the zero-laxity wait when restarted after the deadline has passed.
With Proxy Execution (PE), RT tasks proxied through the scheduler appear to trigger frequent dl_server_start() calls with expired deadlines. When this happens with dl_defer_running=1 (from a prior starvation episode), Peter's fix forces the fair_server back through the ~950ms zero-laxity wait each time.
In our testing (virtme-ng, 4 CPUs, 4G RAM, ksched_football):
With this fix: ~1s for all players to check in
Without this fix: ~28s for all players to check in
The issue appears to be that the clearing in update_dl_entity()'s if-branch is too aggressive for the PE use case. replenish_dl_new_period() already handles this via its internal guard:
if (dl_se->dl_defer && !dl_se->dl_defer_running) {
dl_se->dl_throttled = 1;
dl_se->dl_defer_armed = 1;
}When dl_defer_running=1 (starvation previously confirmed by the zero-laxity timer), replenish_dl_new_period() skips arming the zero-laxity timer, allowing the server to run directly. This seems
correct: once starvation has been confirmed, subsequent start/stop cycles triggered by PE should not re-introduce the deferral delay.
Note: this is the same change as the HACK revert in John's PE series (679ede58445 "HACK: Revert 'sched/deadline: Fix stuck dl_server'"), but with the rationale documented.
The state machine comment is updated to reflect the actual behavior of replenish_dl_new_period() when dl_defer_running=1.
--- kernel/sched/deadline.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/sched/deadline.c +3 -9
@@ -1034,12 +1034,6 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)return ; } -/* -* When [4] D->A is followed by [1] A->B, dl_defer_running -* needs to be cleared, otherwise it will fail to properly -* start the zero-laxity timer. -*/ - dl_se->dl_defer_running =0 ;replenish_dl_new_period (dl_se, rq); }else if (dl_server (dl_se) && dl_se->dl_defer) {/*
@@ -1662,11 +1656,11 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)* enqueue_dl_entity() * update_dl_entity(WAKEUP) * if (dl_time_before() || dl_entity_overflow()) -* dl_defer_running = 0; * replenish_dl_new_period(); * // fwd period -* dl_throttled = 1; -* dl_defer_armed = 1; +* if (!dl_defer_running) +* dl_throttled = 1; +* dl_defer_armed = 1; * if (!dl_defer_running) * dl_defer_armed = 1; * dl_throttled = 1;
Signature · 1 line
2.43.0
Peter Zijlstra
maintainerRe: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 52 lines · On Fri, Apr 03, 2026 at 04:12:15PM +0800, [email protected] wrote:
From: zhidao su <[email protected]>
commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") added adl_defer_running= 0 reset in the if-branch ofupdate_dl_entity()to handle the case where [4]D->Ais followed by [1]A->B(lapsed deadline). The intent was to ensure the server re-enters the zero-laxity wait when restarted after the deadline has passed.With Proxy Execution (PE), RT tasks proxied through the scheduler appear to trigger frequent
dl_server_start()calls with expired deadlines. When this happens with dl_defer_running=1 (from a prior starvation episode), Peter's fix forces thefair_serverback through the ~950ms zero-laxity wait each time.In our testing (virtme-ng, 4 CPUs, 4G RAM,
ksched_football):
With this fix: ~1s for all players to check in
Without this fix: ~28s for all players to check inThe issue appears to be that the clearing in update_dl_entity()'s if-branch is too aggressive for the PE use case.
replenish_dl_new_period()already handles this via its internal guard:if (dl_se->dl_defer && !dl_se->dl_defer_running) { dl_se->dl_throttled = 1; dl_se->dl_defer_armed = 1; }When dl_defer_running=1 (starvation previously confirmed by the zero-laxity timer),
replenish_dl_new_period()skips arming the zero-laxity timer, allowing the server to run directly. This seems
correct: once starvation has been confirmed, subsequent start/stop cycles triggered by PE should not re-introduce the deferral delay.Note: this is the same change as the HACK revert in John's PE series (
679ede58445"HACK: Revert 'sched/deadline: Fix stuckdl_server'"), but with the rationale documented.The state machine comment is updated to reflect the actual behavior of
replenish_dl_new_period()when dl_defer_running=1.Signed-off-by zhidao su <[email protected]>--- kernel/sched/deadline.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)kernel/sched/deadline.c +0
-0@@ -1034,12 +1034,6 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)return ; }
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1039
Quoted 10 lines
kernel/sched/deadline.c +0
-6-/* -* When [4] D->A is followed by [1] A->B, dl_defer_running -* needs to be cleared, otherwise it will fail to properly -* start the zero-laxity timer. -*/ - dl_se->dl_defer_running =0 ;replenish_dl_new_period (dl_se, rq); }else if (dl_server (dl_se) && dl_se->dl_defer) {/*
This cannot be right; it will insta break Andrea's test case again.
And I cannot make sense of your explanation; how does PE cause what to happen? You mention PROXY_WAKING, this then means proxy_force_return().
I suspect whatever it is you're seeing will go away once we delete that thing, see this discussion:
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Hello,
Quoted 54 lines · Peter Zijlstra
Quoted 53 lines · On Fri, Apr 03, 2026 at 04:12:15PM +0800, [email protected] wrote:
From: zhidao su <[email protected]>
commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") added adl_defer_running= 0 reset in the if-branch ofupdate_dl_entity()to handle the case where [4]D->Ais followed by [1]A->B(lapsed deadline). The intent was to ensure the server re-enters the zero-laxity wait when restarted after the deadline has passed.With Proxy Execution (PE), RT tasks proxied through the scheduler appear to trigger frequent
dl_server_start()calls with expired deadlines. When this happens with dl_defer_running=1 (from a prior starvation episode), Peter's fix forces thefair_serverback through the ~950ms zero-laxity wait each time.In our testing (virtme-ng, 4 CPUs, 4G RAM,
ksched_football):
With this fix: ~1s for all players to check in
Without this fix: ~28s for all players to check inThe issue appears to be that the clearing in update_dl_entity()'s if-branch is too aggressive for the PE use case.
replenish_dl_new_period()already handles this via its internal guard:if (dl_se->dl_defer && !dl_se->dl_defer_running) { dl_se->dl_throttled = 1; dl_se->dl_defer_armed = 1; }When dl_defer_running=1 (starvation previously confirmed by the zero-laxity timer),
replenish_dl_new_period()skips arming the zero-laxity timer, allowing the server to run directly. This seems
correct: once starvation has been confirmed, subsequent start/stop cycles triggered by PE should not re-introduce the deferral delay.Note: this is the same change as the HACK revert in John's PE series (
679ede58445"HACK: Revert 'sched/deadline: Fix stuckdl_server'"), but with the rationale documented.The state machine comment is updated to reflect the actual behavior of
replenish_dl_new_period()when dl_defer_running=1.Signed-off-by zhidao su <[email protected]>--- kernel/sched/deadline.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)kernel/sched/deadline.c +0
-0@@ -1034,12 +1034,6 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)return ; }
Quoted 11 lines
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1039
Quoted 9 lines
kernel/sched/deadline.c +0
-6-/* -* When [4] D->A is followed by [1] A->B, dl_defer_running -* needs to be cleared, otherwise it will fail to properly -* start the zero-laxity timer. -*/ - dl_se->dl_defer_running =0 ;replenish_dl_new_period (dl_se, rq); }else if (dl_server (dl_se) && dl_se->dl_defer) {/* This cannot be right; it will insta break Andrea's test case again.
I confirm that with this applied the sched_ext rt_stall selftest starts failing:
$ sudo ./runner -t rt_stall ... # Runtime of EXT task (PID 2260) is 0.010000 seconds # Runtime of RT task (PID 2261) is 5.000000 seconds # EXT task got 0.20% of total runtime not ok 4 FAIL: EXT task got less than 4.00% of runtime [ 218.923834] sched_ext: BPF scheduler "rt_stall" disabled (unregistered from user space) # Planned tests != run tests (1 != 4)
Quoted 9 lines
And I cannot make sense of your explanation; how does PE cause what to happen? You mention
PROXY_WAKING, this then meansproxy_force_return().I suspect whatever it is you're seeing will go away once we delete that thing, see this discussion:
Thanks,
-Andrea
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
In reply to Peter ZijlstraQuoted 66 lines · Peter Zijlstra
Quoted 52 lines · On Fri, Apr 03, 2026 at 04:12:15PM +0800, [email protected] wrote:
From: zhidao su <[email protected]>
commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") added adl_defer_running= 0 reset in the if-branch ofupdate_dl_entity()to handle the case where [4]D->Ais followed by [1]A->B(lapsed deadline). The intent was to ensure the server re-enters the zero-laxity wait when restarted after the deadline has passed.With Proxy Execution (PE), RT tasks proxied through the scheduler appear to trigger frequent
dl_server_start()calls with expired deadlines. When this happens with dl_defer_running=1 (from a prior starvation episode), Peter's fix forces thefair_serverback through the ~950ms zero-laxity wait each time.In our testing (virtme-ng, 4 CPUs, 4G RAM,
ksched_football):
With this fix: ~1s for all players to check in
Without this fix: ~28s for all players to check inThe issue appears to be that the clearing in update_dl_entity()'s if-branch is too aggressive for the PE use case.
replenish_dl_new_period()already handles this via its internal guard:if (dl_se->dl_defer && !dl_se->dl_defer_running) { dl_se->dl_throttled = 1; dl_se->dl_defer_armed = 1; }When dl_defer_running=1 (starvation previously confirmed by the zero-laxity timer),
replenish_dl_new_period()skips arming the zero-laxity timer, allowing the server to run directly. This seems
correct: once starvation has been confirmed, subsequent start/stop cycles triggered by PE should not re-introduce the deferral delay.Note: this is the same change as the HACK revert in John's PE series (
679ede58445"HACK: Revert 'sched/deadline: Fix stuckdl_server'"), but with the rationale documented.The state machine comment is updated to reflect the actual behavior of
replenish_dl_new_period()when dl_defer_running=1.Signed-off-by zhidao su <[email protected]>--- kernel/sched/deadline.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)kernel/sched/deadline.c +0
-0@@ -1034,12 +1034,6 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)return ; }kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1039
Quoted 10 lines
kernel/sched/deadline.c +0
-6-/* -* When [4] D->A is followed by [1] A->B, dl_defer_running -* needs to be cleared, otherwise it will fail to properly -* start the zero-laxity timer. -*/ - dl_se->dl_defer_running =0 ;replenish_dl_new_period (dl_se, rq); }else if (dl_server (dl_se) && dl_se->dl_defer) {/* This cannot be right; it will insta break Andrea's test case again.
Quoted 8 lines
And I cannot make sense of your explanation; how does PE cause what to happen? You mention
PROXY_WAKING, this then meansproxy_force_return().I suspect whatever it is you're seeing will go away once we delete that thing, see this discussion:
So unfortunately, this doesn't seem to be proxy-exec related at all.
It's almost identical to the issue I had awhile back with the dl_server, when spawning RT spinner threads threads (as kthreadd doesn't run as RT).
https://lore.kernel.org/lkml/CANDhNCqK3VBAxxWMsDez8xkX0vcTStWjRMR95pksUM6Q26Ctyw@mail.gmail.com/
Now, this is with my out-of-tree ksched_football test, which is a bit quirky. I've updated a branch with my test here against 7.0-rc5:
https://github.com/johnstultz-work/linux-dev/commits/ksched-football-dl_server-issue/
It runs at boot, but you can also re-run it via "echo 10 > /sys/kernel/ksched_football/start_game"
The idea in the test is there is a high priority "Ref" thread that spawns players from low priority to high that just spin on the cpu. The issue is once NR_CPU low-prio players start, they starve additional higher-prio players from starting (despite the highest priority Ref spawning them) because kthreadd is not RT. So the test effectively relies on the dl_server to kick in and let the rest of the players spawn. This isn't actually what the test is testing, but just how it gets ready to run the test.
Using a 8 cpu VM with CONFIG_SCHED_PROXY_EXEC disabled:
With commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, then dl_server allows all the threads to spawn right away, and then the test runs for 10 seconds.
See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)
With commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server") applied, it seems the dl_server boosting the kthreadd spawning is much more staggered. Again we spin up NR_CPU low priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.
Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4
With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
I haven't really diagnosed the issue, but it feels a little like the dl_server is boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the next dl_server period? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at the dl_server logic some more.
thanks
-john
Peter Zijlstra
maintainerRe: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 28 lines · John Stultz
Using a 8 cpu VM with
CONFIG_SCHED_PROXY_EXECdisabled:With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, thendl_serverallows all the threads to spawn right away, and then the test runs for 10 seconds.See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") applied, it seems thedl_serverboosting the kthreadd spawning is much more staggered. Again we spin upNR_CPUlow priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
Quoted 7 lines
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.
I'm getting a sense of deja-vu here. Didn't we cure this once before?
I'll go stare at this somewhere next week I suppose -- we have a long weekend here.
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · John Stultz
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.I'm getting a sense of deja-vu here. Didn't we cure this once before?
thanks
-john
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 11 lines · John Stultz
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · John Stultz
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.
Quoted 4 lines
Quoted 1 line
I'm getting a sense of deja-vu here. Didn't we cure this once before?
Oops, sorry, that was the other one. This was the previous fix for a similar issue with the same test:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a3a70caf7906708bf9bbc80018752a6b36543808
thanks
-john
Peter Zijlstra
maintainerRe: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
In reply to Peter ZijlstraQuoted 38 lines · Peter Zijlstra
Quoted 28 lines · John Stultz
Using a 8 cpu VM with
CONFIG_SCHED_PROXY_EXECdisabled:With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, thendl_serverallows all the threads to spawn right away, and then the test runs for 10 seconds.See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") applied, it seems thedl_serverboosting the kthreadd spawning is much more staggered. Again we spin upNR_CPUlow priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
Quoted 7 lines
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.
Quoted 4 lines
I'm getting a sense of deja-vu here. Didn't we cure this once before?
I'll go stare at this somewhere next week I suppose -- we have a long weekend here.
Random brain wave...
Since the dl_server is LLF (deferred), it will pretty much always trip the dl_entity_overflow() when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?
---
kernel/sched/deadline.c +1 -1
@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) { -if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 5 lines · Peter Zijlstra
Random brain wave...
Since the
dl_serveris LLF (deferred), it will pretty much always trip thedl_entity_overflow()when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?
Thanks for the brain wave!
Tested your diff — locktorture boot time drops to ~13s (vs ~37-52s with the hack revert) and ksched_football ball_pos stays at 0.
I traced update_dl_entity() and found the else-branch hits all show dl_defer_running=1 with dl_throttled=0 and dl_defer_armed=0 — that's the [D:running] state, so the guard there is correct. The actual stale case is in the if-branch (overflow=1, deadline not past, dl_defer_running=1), which your diff handles via revised wakeup.
That also means our original else-branch fix was wrong — unconditionally clearing dl_defer_running in [D:running] would corrupt a legitimately running server's state.
Is your revised wakeup diff the intended replacement for 115135422562? If so, happy to test further or help draft it into a proper patch.
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
In reply to Peter ZijlstraQuoted 56 lines · Peter Zijlstra
Quoted 38 lines · Peter Zijlstra
Quoted 28 lines · John Stultz
Using a 8 cpu VM with
CONFIG_SCHED_PROXY_EXECdisabled:With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, thendl_serverallows all the threads to spawn right away, and then the test runs for 10 seconds.See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") applied, it seems thedl_serverboosting the kthreadd spawning is much more staggered. Again we spin upNR_CPUlow priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
Quoted 7 lines
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.Quoted 4 lines
I'm getting a sense of deja-vu here. Didn't we cure this once before?
I'll go stare at this somewhere next week I suppose -- we have a long weekend here.
Random brain wave...
Since the
dl_serveris LLF (deferred), it will pretty much always trip thedl_entity_overflow()when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?---
kernel/sched/deadline.c +0
-0
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1033
Quoted 8 lines
kernel/sched/deadline.c +1
-1@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) { -if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);
Hey Peter!
So yeah, this does seem to resolve the main issue with the test.
After ~1second of the initial low-priority RT tasks starving the CPU, all the other threads spawn in quick succession, and it doesnt' delay us getting to run the test.
The only detail I might mention, is that looking at perfetto charts, comparing this fix vs reverting 115135422562 ("sched/deadline: Fix 'stuck' dl_server"), is that during the ksched_football test (where we have a lot of RT spinners running), other very short-running non-RT kworker threads seem to have more 1 second delays where they are runnable with this solution:
https://ui.perfetto.dev/#!/?s=fbc54ab8b823fc3d906eb16b9bcfb5b1fcbadf09
With 115135422562 reverted, they seem to get to run fairly quickly despite the RT spinners.
https://ui.perfetto.dev/#!/?s=35aa5b8e395ee5cf6fe22cc7f8c7e0cd8f4fcec5
This may be in fact the issue being fixed with 115135422562 (I still find the details opaque), and I don't see any delays much larger than a second. So it probably isn't an issue, but just wanted to highlight it.
thanks
-john
John Stultz
Tested-byRe: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 61 lines · John Stultz
Quoted 59 lines · Peter Zijlstra
Quoted 38 lines · Peter Zijlstra
Quoted 28 lines · John Stultz
Using a 8 cpu VM with
CONFIG_SCHED_PROXY_EXECdisabled:With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, thendl_serverallows all the threads to spawn right away, and then the test runs for 10 seconds.See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") applied, it seems thedl_serverboosting the kthreadd spawning is much more staggered. Again we spin upNR_CPUlow priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
Quoted 7 lines
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.Quoted 4 lines
I'm getting a sense of deja-vu here. Didn't we cure this once before?
I'll go stare at this somewhere next week I suppose -- we have a long weekend here.
Random brain wave...
Since the
dl_serveris LLF (deferred), it will pretty much always trip thedl_entity_overflow()when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?---
kernel/sched/deadline.c +0
-0@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) {
Quoted 11 lines
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1033
Quoted 5 lines
kernel/sched/deadline.c +1
-1-if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);Hey Peter!
So yeah, this does seem to resolve the main issue with the test.
After ~1second of the initial low-priority RT tasks starving the CPU, all the other threads spawn in quick succession, and it doesnt' delay us getting to run the test.
Forgot to add:
Juri Lelli
maintainerRe: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
In reply to Peter ZijlstraQuoted 57 lines · Peter Zijlstra
Quoted 38 lines · Peter Zijlstra
Quoted 28 lines · John Stultz
Using a 8 cpu VM with
CONFIG_SCHED_PROXY_EXECdisabled:With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") reverted, I see the (expected, maybe) behavior where the starvation lasts ~1second, thendl_serverallows all the threads to spawn right away, and then the test runs for 10 seconds.See perfetto chart:
https://ui.perfetto.dev/#!/?s=a729fd2dd4b224d6335c5b2e727dc1a1c302c11a
(click the Kernel-threads track and scroll down to see the test threads named referee/defense/offense/crazy-fan)With commit 115135422562 ("sched/deadline: Fix 'stuck'
dl_server") applied, it seems thedl_serverboosting the kthreadd spawning is much more staggered. Again we spin upNR_CPUlow priority threads, and there's ~1second of starvation, then we spawn one of the mid threads, and another second delay, then there's a two second delay befofe we get the third running, then we get a small burst of 5 threads at once, then it falls back to 1 second or more per thread as it spawns off the rest. All in all it takes ~44 seconds just to spawn the threads before running the test.Perfetto chart:
https://ui.perfetto.dev/#!/?s=ab8e487375d0c82ceea478ee4534a7189269c0d4With higher cpu counts (64), the test effectively prevents the system from booting (trips the hung task watchdog).
Quoted 7 lines
I haven't really diagnosed the issue, but it feels a little like the
dl_serveris boosting until the fair rq is empty but then giving up the rest of its time, so if a fair task runs repeatedly but for a very short period of time, it won't get to run again until the nextdl_serverperiod? Causing this rate-limiting one-task-per-second effect for thread spawning? I still need to stare at thedl_serverlogic some more.Quoted 4 lines
I'm getting a sense of deja-vu here. Didn't we cure this once before?
I'll go stare at this somewhere next week I suppose -- we have a long weekend here.
Random brain wave...
Since the
dl_serveris LLF (deferred), it will pretty much always trip thedl_entity_overflow()when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?---
kernel/sched/deadline.c +0
-0
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1033
Quoted 8 lines
kernel/sched/deadline.c +1
-1@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) { -if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);
So to keep boosting, by reducing runtime appropriately, until the end of the current dl-server period. Makes sense to me.
Thanks!
Juri
Re: [PATCH] sched/deadline: Fix stale dl_defer_running in update_dl_entity() if-branch
Quoted 15 lines · Juri Lelli
Quoted 15 lines
Random brain wave...
Since the
dl_serveris LLF (deferred), it will pretty much always trip thedl_entity_overflow()when interrupted, right? Does it make sense to use the revised wake-up rule for it, when appropriate?---
kernel/sched/deadline.c +0
-0@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) {
Quoted 9 lines
kernel/sched/deadline.c static void update_dl_entity(struct sched_dl_entity *dl_se) · line 1033
Quoted 6 lines
kernel/sched/deadline.c +1
-1-if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);So to keep boosting, by reducing runtime appropriately, until the end of the current dl-server period. Makes sense to me.
OK, like so then.
---
Subject: sched/deadline: Use revised wakeup rule for dl_server
From: Peter Zijlstra <[email protected]>
Date: Sat, 4 Apr 2026 12:22:44 +0200
John noted that commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server") unfixed the issue from commit a3a70caf7906 ("sched/deadline: Fix dl_server behaviour").
The issue in commit 115135422562 was for wakeups of the server after the deadline; in which case you *have* to start a new period. The case for a3a70caf7906 is wakeups before the deadline.
Now, because the server is effectively running a least-laxity policy, it means that any wakeup during the runnable phase means dl_entity_overflow() will be true. This means we need to adjust the runtime to allow it to still run until the existing deadline expires.
Use the revised wakeup rule for dl_defer entities.
--- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/deadline.c +1 -1
@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct scheif (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) { -if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);
[tip: sched/urgent] sched/deadline: Use revised wakeup rule for dl_server
In reply to Peter ZijlstraThe following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 14a857056466be9d3d907a94e92a704ac1be149b Gitweb: https://git.kernel.org/tip/14a857056466be9d3d907a94e92a704ac1be149b Author: Peter Zijlstra <[email protected]> AuthorDate: Sat, 04 Apr 2026 12:22:44 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 08 Apr 2026 13:11:43 +02:00
sched/deadline: Use revised wakeup rule for dl_server
John noted that commit 115135422562 ("sched/deadline: Fix 'stuck' dl_server") unfixed the issue from commit a3a70caf7906 ("sched/deadline: Fix dl_server behaviour").
The issue in commit 115135422562 was for wakeups of the server after the deadline; in which case you *have* to start a new period. The case for a3a70caf7906 is wakeups before the deadline.
Now, because the server is effectively running a least-laxity policy, it means that any wakeup during the runnable phase means dl_entity_overflow() will be true. This means we need to adjust the runtime to allow it to still run until the existing deadline expires.
Use the revised wakeup rule for dl_defer entities.
--- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/deadline.c +1 -1
@@ -1027,7 +1027,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq)) ||dl_entity_overflow (dl_se,rq_clock (rq))) { -if (unlikely (!dl_is_implicit (dl_se) && +if (unlikely ((!dl_is_implicit (dl_se) || dl_se->dl_defer) && !dl_time_before (dl_se->deadline,rq_clock (rq)) && !is_dl_boosted (dl_se))) {update_dl_revised_wakeup (dl_se, rq);