sched: Fix DL server starvation under core scheduling
Subsystems (3)
cover sched: Fix DL server starvation under core scheduling
Under core scheduling the class a DL server reserves CPU time for gets almost nothing. With the default fair server (50 ms / 1 s), a CFS task spinning on one SMT sibling beside a cookied SCHED_FIFO task on the other measures 0.000% of its CPU instead of the reserved 5%. The ext server starves sched_ext tasks the same way.
Two independent mechanisms are at fault. The core-wide selection mishandles the rq->dl_server hand-off: a stale link is passed to idle (which then forces the siblings idle and trips the forced-idle WARN), a sibling's link is lost on the fast path, and picks are ranked before p->dl_server is set (patches 1-3, Fixes: bd9bbc96e835). Independently, a deferred server is charged its rq's forced-idle time, so its runtime runs out while it is still throttled, replenish_dl_new_period() pushes the activation a full period out, and the next period of forced idle pushes it again (patch 4, Fixes: a110a81c52a9). Either fix alone leaves the share at ~0%.
Patch 5 adds cs_dl_server_test to selftests/sched: a cookied FIFO spinner on one sibling, an uncookied CFS spinner on the other, and a check of the CFS share of that CPU against half the fair server's reservation, 2.5% by default. Run under QEMU with -smp 4,cores=2,threads=2.
Over a 5 s window, plain tip fails 10/10 at 0.000%, and with the whole series it passes 31/31 at 3.99-5.19%.
This series was prepared with the help of an AI coding assistant. I have reviewed and tested all of it.
Fernand Sieber (5):
sched/core: Clear stale rq->dl_server when core-sched replaces a pick sched/core: Keep a sibling's DL server link in the core-wide pick sched/core: Rank DL server picks as deadline in the core-wide pick sched/deadline: Don't charge core-sched forced idle to the DL servers selftests/sched: Add a core-sched forced-idle DL server test
kernel/sched/core.c | 59 ++- kernel/sched/idle.c | 7 + kernel/sched/sched.h | 15 + tools/testing/selftests/sched/.gitignore | 1 + tools/testing/selftests/sched/Makefile | 4 +- tools/testing/selftests/sched/config | 4 +- .../selftests/sched/cs_dl_server_test.c | 402 ++++++++++++++++++ 7 files changed, 471 insertions(+), 21 deletions(-) create mode 100644 tools/testing/selftests/sched/cs_dl_server_test.c
base-commit: d7e670601af6c564ccf6d3b2ddf70ee4f41a6d1c
Signature · 8 lines
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
PATCH 1/5 sched/core: Clear stale rq->dl_server when core-sched replaces a pick
With core scheduling and the fair server, the forced-idle accounting warns from an idle core:
WARNING: kernel/sched/core_sched.c:263 at __sched_core_account_forceidle+0x1d6/0x1f0, CPU#0: swapper/0/0
The core is in forced idle with no sibling running a task. The reason is a stale rq->dl_server causing the idle task to incorrectly be considered as carried by the deadline server. The idle task then wins over a runnable sibling task and the whole core is idle despite having runnable tasks.
The timeline below describes the issue:
Setup. CPU0 and CPU1 are SMT siblings.
- CPU1 runs R, a SCHED_FIFO task with cookie X.
- CPU0 has C, a CFS task with no cookie, which has been starved. So CPU0's fair server is due to step in.
t0, CPU0 picks for the core.
- pick_task(rq0) goes through the deadline class, which picks the fair server, which picks C. As a side effect it sets rq0->dl_server = &rq0->fair_server.
- pick_task(rq1) picks R.
t1, ranking. C->dl_server is only set once C is switched in, so C ranks as CFS. R (RT) beats C (CFS), so the core cookie becomes X.
t2, matching. CPU0's pick C has cookie 0, not X, so it is replaced. There is no cookie-X task on CPU0, so the replacement is idle, and CPU0 is forced idle.
- The code sets rq0->core_pick = idle and rq0->core_dl_server = NULL.
- The bug: it leaves rq0->dl_server pointing at CPU0's fair server, even though idle didn't come through any server.
t3, CPU0 switches. CPU0 is the selecting CPU, so next = idle, and put_prev_set_next_task() hands the stale rq0->dl_server to it. Now idle->dl_server is CPU0's fair server.
t4, C leaves. Load balancing moves C to another core, so CPU0 has nothing runnable. The stale link stays on idle.
t5, the next core-wide selection (when CPU1 reschedules, say on a wakeup).
- CPU0's pick is idle, and the ranking sees idle->dl_server set, so it ranks idle as a deadline task.
- idle now beats R, and the core cookie becomes idle's cookie, 0.
- CPU1's R has cookie X, not 0, so CPU1 is forced idle.
t6, result. The whole core is idle. R is runnable but can't run, and nothing runs on either CPU. That's the WARN in __sched_core_account_forceidle(): forced idle with no sibling running a task. It lasts until CPU0 goes through a full schedule that resets its server link.
With this patch, step t2 also does rq0->dl_server = NULL. At t3 idle gets no server, and at t5 it ranks as plain idle, so R wins and keeps running on CPU1.
--- kernel/sched/core.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/sched/core.c +6 -0
@@ -6453,6 +6453,12 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) p =sched_core_find (rq_i, cookie);if (!p) p = idle_sched_class.pick_task (rq_i, rf); + +/* +* Neither a core tree pick nor idle comes through a +* DL server; drop the one the replaced pick left. +*/ + rq_i->dl_server =NULL ; } rq_i->core_pick = p;
Signature · 8 lines
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
[tip: sched/urgent] sched/deadline: Clear stale rq->dl_server when core-sched replaces a pick
The 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: 5b65edb7f582803cda84552990779610ca22581c Gitweb: https://git.kernel.org/tip/5b65edb7f582803cda84552990779610ca22581c Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:44 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sun, 22 Nov 2026 16:16:27 +01:00
sched/deadline: Clear stale rq->dl_server when core-sched replaces a pick
With core scheduling and the fair server, the forced-idle accounting warns from an idle core:
WARNING: kernel/sched/core_sched.c:263 at __sched_core_account_forceidle+0x1d6/0x1f0, CPU#0: swapper/0/0
The core is in forced idle with no sibling running a task. The reason is a stale rq->dl_server causing the idle task to incorrectly be considered as carried by the deadline server. The idle task then wins over a runnable sibling task and the whole core is idle despite having runnable tasks.
The timeline below describes the issue:
Setup. CPU0 and CPU1 are SMT siblings.
- CPU1 runs R, a SCHED_FIFO task with cookie X.
- CPU0 has C, a CFS task with no cookie, which has been starved. So CPU0's fair server is due to step in.
t0, CPU0 picks for the core.
- pick_task(rq0) goes through the deadline class, which picks the fair server, which picks C. As a side effect it sets rq0->dl_server = &rq0->fair_server.
- pick_task(rq1) picks R.
t1, ranking. C->dl_server is only set once C is switched in, so C ranks as CFS. R (RT) beats C (CFS), so the core cookie becomes X.
t2, matching. CPU0's pick C has cookie 0, not X, so it is replaced. There is no cookie-X task on CPU0, so the replacement is idle, and CPU0 is forced idle.
- The code sets rq0->core_pick = idle and rq0->core_dl_server = NULL.
- The bug: it leaves rq0->dl_server pointing at CPU0's fair server, even though idle didn't come through any server.
t3, CPU0 switches. CPU0 is the selecting CPU, so next = idle, and put_prev_set_next_task() hands the stale rq0->dl_server to it. Now idle->dl_server is CPU0's fair server.
t4, C leaves. Load balancing moves C to another core, so CPU0 has nothing runnable. The stale link stays on idle.
t5, the next core-wide selection (when CPU1 reschedules, say on a wakeup).
- CPU0's pick is idle, and the ranking sees idle->dl_server set, so it ranks idle as a deadline task.
- idle now beats R, and the core cookie becomes idle's cookie, 0.
- CPU1's R has cookie X, not 0, so CPU1 is forced idle.
t6, result. The whole core is idle. R is runnable but can't run, and nothing runs on either CPU. That's the WARN in __sched_core_account_forceidle(): forced idle with no sibling running a task. It lasts until CPU0 goes through a full schedule that resets its server link.
With this patch, step t2 also does rq0->dl_server = NULL. At t3 idle gets no server, and at t5 it ranks as plain idle, so R wins and keeps running on CPU1.
--- kernel/sched/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/sched/core.c +6 -1
@@ -6453,10 +6453,15 @@ restart: p =sched_core_find (rq_i, cookie);if (!p) p = idle_sched_class.pick_task (rq_i, rf); + +/* +* Neither a core tree pick nor idle comes through a +* DL server; drop the one the replaced pick left. +*/ + rq_i->core_dl_server = rq_i->dl_server =NULL ; } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ;if (p == rq_i->idle) {if (rq_i->nr_running) {
[tip: sched/urgent] sched/deadline: Clear stale rq->dl_server when core-sched replaces a pick
In reply to Fernand SieberThe 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: d2583cb031135d3e2f6eeec9049fc2066fd3655c Gitweb: https://git.kernel.org/tip/d2583cb031135d3e2f6eeec9049fc2066fd3655c Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:44 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 23 Nov 2026 10:38:26 +01:00
sched/deadline: Clear stale rq->dl_server when core-sched replaces a pick
With core scheduling and the fair server, the forced-idle accounting warns from an idle core:
WARNING: kernel/sched/core_sched.c:263 at __sched_core_account_forceidle+0x1d6/0x1f0, CPU#0: swapper/0/0
The core is in forced idle with no sibling running a task. The reason is a stale rq->dl_server causing the idle task to incorrectly be considered as carried by the deadline server. The idle task then wins over a runnable sibling task and the whole core is idle despite having runnable tasks.
The timeline below describes the issue:
Setup. CPU0 and CPU1 are SMT siblings.
- CPU1 runs R, a SCHED_FIFO task with cookie X.
- CPU0 has C, a CFS task with no cookie, which has been starved. So CPU0's fair server is due to step in.
t0, CPU0 picks for the core.
- pick_task(rq0) goes through the deadline class, which picks the fair server, which picks C. As a side effect it sets rq0->dl_server = &rq0->fair_server.
- pick_task(rq1) picks R.
t1, ranking. C->dl_server is only set once C is switched in, so C ranks as CFS. R (RT) beats C (CFS), so the core cookie becomes X.
t2, matching. CPU0's pick C has cookie 0, not X, so it is replaced. There is no cookie-X task on CPU0, so the replacement is idle, and CPU0 is forced idle.
- The code sets rq0->core_pick = idle and rq0->core_dl_server = NULL.
- The bug: it leaves rq0->dl_server pointing at CPU0's fair server, even though idle didn't come through any server.
t3, CPU0 switches. CPU0 is the selecting CPU, so next = idle, and put_prev_set_next_task() hands the stale rq0->dl_server to it. Now idle->dl_server is CPU0's fair server.
t4, C leaves. Load balancing moves C to another core, so CPU0 has nothing runnable. The stale link stays on idle.
t5, the next core-wide selection (when CPU1 reschedules, say on a wakeup).
- CPU0's pick is idle, and the ranking sees idle->dl_server set, so it ranks idle as a deadline task.
- idle now beats R, and the core cookie becomes idle's cookie, 0.
- CPU1's R has cookie X, not 0, so CPU1 is forced idle.
t6, result. The whole core is idle. R is runnable but can't run, and nothing runs on either CPU. That's the WARN in __sched_core_account_forceidle(): forced idle with no sibling running a task. It lasts until CPU0 goes through a full schedule that resets its server link.
With this patch, step t2 also does rq0->dl_server = NULL. At t3 idle gets no server, and at t5 it ranks as plain idle, so R wins and keeps running on CPU1.
--- kernel/sched/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/sched/core.c +6 -1
@@ -6453,10 +6453,15 @@ restart: p =sched_core_find (rq_i, cookie);if (!p) p = idle_sched_class.pick_task (rq_i, rf); + +/* +* Neither a core tree pick nor idle comes through a +* DL server; drop the one the replaced pick left. +*/ + rq_i->core_dl_server = rq_i->dl_server =NULL ; } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ;if (p == rq_i->idle) {if (rq_i->nr_running) {
PATCH 2/5 sched/core: Keep a sibling's DL server link in the core-wide pick
In reply to Fernand SieberThe core-wide selection records in rq_i->core_dl_server the DL server each sibling's pick came through, then clears it for every sibling in the cookie matching loop, including when the pick is kept. The sibling takes the fast path, which sets rq->dl_server from rq->core_dl_server, and runs the task its server picked with p->dl_server NULL. Only the selecting CPU keeps the link, as its pick goes through rq->dl_server.
A running task is ranked for core scheduling by p->dl_server. While such a task runs on a sibling, each following core-wide selection ranks it as a plain fair or ext task rather than by its server's deadline, so a higher class task on another sibling takes the core back before the server's runtime is used. The RV nomiss monitor, which follows the server through next->dl_server at sched_switch, does not see the server run either.
Keep the server that pick_task() left in rq_i->dl_server. With the previous patch it is NULL when the class pick was replaced. Drop the assignment in the first loop, which the matching loop always overwrites.
--- kernel/sched/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/core.c +1 -2
@@ -6431,7 +6431,6 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server = rq_i->dl_server;if (!max ||prio_less (max, p, fi_before)) max = p;
@@ -6462,7 +6461,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ; + rq_i->core_dl_server = rq_i->dl_server;if (p == rq_i->idle) {if (rq_i->nr_running) {
Signature · 8 lines
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
Peter Zijlstra
maintainerRe: [PATCH 2/5] sched/core: Keep a sibling's DL server link in the core-wide pick
Quoted 39 lines · Fernand Sieber
The core-wide selection records in
rq_i->core_dl_serverthe DL server each sibling's pick came through, then clears it for every sibling in the cookie matching loop, including when the pick is kept. The sibling takes the fast path, which setsrq->dl_serverfromrq->core_dl_server, and runs the task its server picked withp->dl_serverNULL. Only the selecting CPU keeps the link, as its pick goes throughrq->dl_server.A running task is ranked for core scheduling by
p->dl_server. While such a task runs on a sibling, each following core-wide selection ranks it as a plain fair or ext task rather than by its server's deadline, so a higher class task on another sibling takes the core back before the server's runtime is used. The RV nomiss monitor, which follows the server throughnext->dl_serveratsched_switch, does not see the server run either.Keep the server that
pick_task()left inrq_i->dl_server. With the previous patch it is NULL when the class pick was replaced. Drop the assignment in the first loop, which the matching loop always overwrites.Fixes bd9bbc96e835 ("sched: Rework dl_server")Signed-off-by Fernand Sieber <[email protected]>--- kernel/sched/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/sched/core.c +0
-1@@ -6431,7 +6431,6 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server = rq_i->dl_server;if (!max ||prio_less (max, p, fi_before)) max = p;
kernel/sched/core.c pick_next_task(struct rq *rq, struct rq_flags *rf) · line 6467
Quoted 8 lines
kernel/sched/core.c +1
-1@@ -6462,7 +6461,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ; + rq_i->core_dl_server = rq_i->dl_server;if (p == rq_i->idle) {if (rq_i->nr_running) {
Isn't this broken in the face of a rq->lock drop through pick_task() ?
Consider this does:
SMT0: pick_task()
SMT1: pick_task()
drop rq->lock newidle
SMT0: rq_0->core_dl_server = rq_0->dl_server;
I am reworking all of that somewhere, but delaying saving rq->dl_server like this feels fragile.
Can't we fold the first two patches into something like so?
---
kernel/sched/core.c +7 -1
@@ -6453,10 +6453,16 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) p =sched_core_find (rq_i, cookie);if (!p) p = idle_sched_class.pick_task (rq_i, rf); + +/* +* Neither a core tree pick nor idle comes through a +* DL server; drop the one the replaced pick left. +*/ + rq_i->dl_server =NULL ; } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ; + rq_i->core_dl_server = rq_i->dl_server;if (p == rq_i->idle) {if (rq_i->nr_running) {
Peter Zijlstra
maintainerRe: [PATCH 2/5] sched/core: Keep a sibling's DL server link in the core-wide pick
Quoted 76 lines · Peter Zijlstra
Quoted 39 lines · Fernand Sieber
The core-wide selection records in
rq_i->core_dl_serverthe DL server each sibling's pick came through, then clears it for every sibling in the cookie matching loop, including when the pick is kept. The sibling takes the fast path, which setsrq->dl_serverfromrq->core_dl_server, and runs the task its server picked withp->dl_serverNULL. Only the selecting CPU keeps the link, as its pick goes throughrq->dl_server.A running task is ranked for core scheduling by
p->dl_server. While such a task runs on a sibling, each following core-wide selection ranks it as a plain fair or ext task rather than by its server's deadline, so a higher class task on another sibling takes the core back before the server's runtime is used. The RV nomiss monitor, which follows the server throughnext->dl_serveratsched_switch, does not see the server run either.Keep the server that
pick_task()left inrq_i->dl_server. With the previous patch it is NULL when the class pick was replaced. Drop the assignment in the first loop, which the matching loop always overwrites.Fixes bd9bbc96e835 ("sched: Rework dl_server")Signed-off-by Fernand Sieber <[email protected]>--- kernel/sched/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/sched/core.c +0
-1@@ -6431,7 +6431,6 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server = rq_i->dl_server;if (!max ||prio_less (max, p, fi_before)) max = p;kernel/sched/core.c pick_next_task(struct rq *rq, struct rq_flags *rf) · line 6467
Quoted 8 lines
kernel/sched/core.c +1
-1@@ -6462,7 +6461,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ; + rq_i->core_dl_server = rq_i->dl_server;if (p == rq_i->idle) {if (rq_i->nr_running) {Isn't this broken in the face of a
rq->lockdrop throughpick_task()?Consider this does:
SMT0:
pick_task()
SMT1:pick_task()drop rq->lock newidleSMT0: rq_0->core_dl_server = rq_0->dl_server;I am reworking all of that somewhere, but delaying saving
rq->dl_serverlike this feels fragile.Can't we fold the first two patches into something like so?
---
kernel/sched/core.c +1
-0@@ -6453,10 +6453,16 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) p =sched_core_find (rq_i, cookie);if (!p) p = idle_sched_class.pick_task (rq_i, rf); +
kernel/sched/core.c pick_next_task(struct rq *rq, struct rq_flags *rf) · line 6465
Quoted 10 lines
kernel/sched/core.c +6
-1+/* +* Neither a core tree pick nor idle comes through a +* DL server; drop the one the replaced pick left. +*/ + rq_i->dl_server =NULL ; } rq_i->core_pick = p; - rq_i->core_dl_server =NULL ; + rq_i->core_dl_server = rq_i->dl_server;
No that isn't quite right either, perhaps just make it:
rq_i->core_dl_server = rq_i->dl_server = NULL;
PATCH 3/5 sched/core: Rank DL server picks as deadline in the core-wide pick
In reply to Fernand SieberCommit 4b26cfdd3956 ("sched/core: Fix priority checking for DL server picks") made the core-wide selection rank a task picked through a DL server as deadline, so that a fair task competing with RT tasks under core scheduling still gets its server's bandwidth. It keys on p->dl_server, which pick_task() used to set.
Since commit bd9bbc96e835 ("sched: Rework dl_server"), pick_task() records the server in rq->dl_server and p->dl_server is only set once the task is switched in. The core-wide selection still ranks each sibling's pick with prio_less(), so a task the sibling's server has just picked ranks as a plain fair or ext task and loses to an RT task on another sibling. The server's CPU then runs a task with the RT task's cookie or is forced idle, and the fair task gets none of the server's bandwidth for as long as the RT task runs.
Rank each sibling's pick by the server it came through, rq_i->dl_server. prio_less() keeps using p->dl_server for the core tree, whose tasks are not being picked.
--- kernel/sched/core.c | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-)
kernel/sched/core.c +34 -16
@@ -196,12 +196,13 @@ __read_mostly int scheduler_running;DEFINE_STATIC_KEY_FALSE (__sched_core_enabled);/* kernel prio, less is more */ -static inline int __task_prio (const struct task_struct *p) +static inline int __task_prio (const struct task_struct *p, +const struct sched_dl_entity *dl_server) {if (p->sched_class == &stop_sched_class)/* trumps deadline */ return -2 ; -if (p->dl_server) +if (dl_server)return -1 ;/* deadline */ if (rt_or_dl_prio (p->prio))
@@ -223,12 +224,19 @@ static inline int __task_prio(const struct task_struct *p)* ge(a,b) := !l(a,b) */ -/* real prio, less is less */ -static inline bool prio_less (const struct task_struct *a, -const struct task_struct *b,bool in_fi) +/* +* real prio, less is less +* +* @a_dl_server and @b_dl_server are the DL servers @a and @b run on +* behalf of, if any. +*/ +static inline bool __prio_less (const struct task_struct *a, +const struct sched_dl_entity *a_dl_server, +const struct task_struct *b, +const struct sched_dl_entity *b_dl_server, +bool in_fi) { - -int pa =__task_prio (a), pb =__task_prio (b); +int pa =__task_prio (a, a_dl_server), pb =__task_prio (b, b_dl_server);if (-pa < -pb)return true;
@@ -239,18 +247,13 @@ static inline bool prio_less(const struct task_struct *a,if (pa ==-1 ) {/* dl_prio() doesn't work because of stop_class above */ const struct sched_dl_entity *a_dl, *b_dl; - a_dl = &a->dl;/* -* Since,'a' and 'b' can be CFS tasks served by DL server, +* Since 'a' and 'b' can be tasks served by a DL server, * __task_prio() can return -1 (for DL) even for those. In that * case, get to the dl_server's DL entity. */ -if (a->dl_server) - a_dl = a->dl_server; - - b_dl = &b->dl; -if (b->dl_server) - b_dl = b->dl_server; + a_dl = a_dl_server ?: &a->dl; + b_dl = b_dl_server ?: &b->dl;return !dl_time_before (a_dl->deadline, b_dl->deadline); }
@@ -266,6 +269,12 @@ static inline bool prio_less(const struct task_struct *a,return false; } +static inline bool prio_less (const struct task_struct *a, +const struct task_struct *b,bool in_fi) +{ +return __prio_less (a, a->dl_server, b, b->dl_server, in_fi); +} +static inline bool __sched_core_less (const struct task_struct *a,const struct task_struct *b) {
@@ -6297,6 +6306,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)__must_hold (__rq_lockp (rq )) {struct task_struct *next, *p, *max; +struct sched_dl_entity *max_dl_server;bool fi_before = false;bool core_clock_updated = (rq == rq->core);unsigned long cookie;
@@ -6410,6 +6420,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)* Tie-break prio towards the current CPU */ max =NULL ; + max_dl_server =NULL ;for_each_core_cpu_wrap (i, rq) { rq_i =cpu_rq (i);
@@ -6432,8 +6443,15 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) rq_i->core_pick = p; -if (!max ||prio_less (max, p, fi_before)) +/* +* p->dl_server is only set once @p runs; rank a pick that +* came through a DL server by that server. +*/ +if (!max ||__prio_less (max, max_dl_server, p, rq_i->dl_server, + fi_before)) { max = p; + max_dl_server = rq_i->dl_server; + } } cookie = rq->core->core_cookie = max->core_cookie;
Signature · 8 lines
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
Peter Zijlstra
maintainerRe: [PATCH 3/5] sched/core: Rank DL server picks as deadline in the core-wide pick
Quoted 15 lines · Fernand Sieber
Commit
4b26cfdd3956("sched/core: Fix priority checking for DL server picks") made the core-wide selection rank a task picked through a DL server as deadline, so that a fair task competing with RT tasks under core scheduling still gets its server's bandwidth. It keys onp->dl_server, whichpick_task()used to set.Since commit
bd9bbc96e835("sched: Reworkdl_server"),pick_task()records the server inrq->dl_serverandp->dl_serveris only set once the task is switched in. The core-wide selection still ranks each sibling's pick withprio_less(), so a task the sibling's server has just picked ranks as a plain fair or ext task and loses to an RT task on another sibling. The server's CPU then runs a task with the RT task's cookie or is forced idle, and the fair task gets none of the server's bandwidth for as long as the RT task runs.
Quoted 4 lines
Rank each sibling's pick by the server it came through,
rq_i->dl_server.prio_less()keeps usingp->dl_serverfor the core tree, whose tasks are not being picked.
I don't love this, but I don't see another way either, so yes.
[tip: sched/core] sched/core: Rank DL server picks as deadline in the core-wide pick
In reply to Fernand SieberThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 87a825f3c680474eeb5c2a28398ad625bb69319e Gitweb: https://git.kernel.org/tip/87a825f3c680474eeb5c2a28398ad625bb69319e Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:46 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 23 Nov 2026 10:45:41 +01:00
sched/core: Rank DL server picks as deadline in the core-wide pick
Commit 4b26cfdd3956 ("sched/core: Fix priority checking for DL server picks") made the core-wide selection rank a task picked through a DL server as deadline, so that a fair task competing with RT tasks under core scheduling still gets its server's bandwidth. It keys on p->dl_server, which pick_task() used to set.
Since commit bd9bbc96e835 ("sched: Rework dl_server"), pick_task() records the server in rq->dl_server and p->dl_server is only set once the task is switched in. The core-wide selection still ranks each sibling's pick with prio_less(), so a task the sibling's server has just picked ranks as a plain fair or ext task and loses to an RT task on another sibling. The server's CPU then runs a task with the RT task's cookie or is forced idle, and the fair task gets none of the server's bandwidth for as long as the RT task runs.
Rank each sibling's pick by the server it came through, rq_i->dl_server. prio_less() keeps using p->dl_server for the core tree, whose tasks are not being picked.
--- kernel/sched/core.c | 51 ++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-)
kernel/sched/core.c +35 -16
@@ -196,12 +196,13 @@ __read_mostly int scheduler_running;DEFINE_STATIC_KEY_FALSE (__sched_core_enabled);/* kernel prio, less is more */ -static inline int __task_prio (const struct task_struct *p) +static inline int __task_prio (const struct task_struct *p, +const struct sched_dl_entity *dl_server) {if (p->sched_class == &stop_sched_class)/* trumps deadline */ return -2 ; -if (p->dl_server) +if (dl_server)return -1 ;/* deadline */ if (rt_or_dl_prio (p->prio))
@@ -223,12 +224,19 @@ static inline int __task_prio(const struct task_struct *p)* ge(a,b) := !l(a,b) */ -/* real prio, less is less */ -static inline bool prio_less (const struct task_struct *a, -const struct task_struct *b,bool in_fi) +/* +* real prio, less is less +* +* @a_dl_server and @b_dl_server are the DL servers @a and @b run on +* behalf of, if any. +*/ +static inline bool __prio_less (const struct task_struct *a, +const struct sched_dl_entity *a_dl_server, +const struct task_struct *b, +const struct sched_dl_entity *b_dl_server, +bool in_fi) { - -int pa =__task_prio (a), pb =__task_prio (b); +int pa =__task_prio (a, a_dl_server), pb =__task_prio (b, b_dl_server);if (-pa < -pb)return true;
@@ -239,18 +247,13 @@ static inline bool prio_less(const struct task_struct *a,if (pa ==-1 ) {/* dl_prio() doesn't work because of stop_class above */ const struct sched_dl_entity *a_dl, *b_dl; - a_dl = &a->dl;/* -* Since,'a' and 'b' can be CFS tasks served by DL server, +* Since 'a' and 'b' can be tasks served by a DL server, * __task_prio() can return -1 (for DL) even for those. In that * case, get to the dl_server's DL entity. */ -if (a->dl_server) - a_dl = a->dl_server; - - b_dl = &b->dl; -if (b->dl_server) - b_dl = b->dl_server; + a_dl = a_dl_server ?: &a->dl; + b_dl = b_dl_server ?: &b->dl;return !dl_time_before (a_dl->deadline, b_dl->deadline); }
@@ -266,6 +269,12 @@ static inline bool prio_less(const struct task_struct *a,return false; } +static inline bool prio_less (const struct task_struct *a, +const struct task_struct *b,bool in_fi) +{ +return __prio_less (a, a->dl_server, b, b->dl_server, in_fi); +} +static inline bool __sched_core_less (const struct task_struct *a,const struct task_struct *b) {
@@ -6316,6 +6325,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)__must_hold (__rq_lockp (rq )) {struct task_struct *next, *p, *max; +struct sched_dl_entity *max_dl_server;bool fi_before = false;bool core_clock_updated = (rq == rq->core);unsigned long cookie;
@@ -6429,6 +6439,7 @@ restart:* Tie-break prio towards the current CPU */ max =NULL ; + max_dl_server =NULL ;for_each_core_cpu_wrap (i, rq) { rq_i =cpu_rq (i);
@@ -6452,8 +6463,16 @@ restart: rq_i->core_pick = p; rq_i->core_dl_server = rq_i->dl_server; -if (!max ||prio_less (max, p, fi_before)) +/* +* p->dl_server is only set once @p runs; rank a pick that +* came through a DL server by that server. +*/ +if (!max ||__prio_less (max, max_dl_server, + p, rq_i->dl_server, + fi_before)) { max = p; + max_dl_server = rq_i->dl_server; + } } cookie = rq->core->core_cookie = max->core_cookie;
PATCH 4/5 sched/deadline: Don't charge core-sched forced idle to the DL servers
In reply to Fernand SieberA deferred DL server is charged the idle time of its rq, on the premise that the time was available to the server's class and went unused. Core scheduling breaks that premise: a CPU is forced idle when a SMT sibling runs a task with an incompatible cookie, so that time was available to no class at all.
update_curr_dl_se() then runs the server's runtime out while it is throttled and calls replenish_dl_new_period(), pushing the activation a full period out. dl_defer_idle does not help, as idle_rq() is false on a forced-idle CPU: nr_running is not 0. Every period of forced idle pushes the activation again, the zero-laxity timer never fires, and the class the server reserves for gets nothing.
Reproduction on 2 cores x 2 threads with the default fair server (50 ms / 1 s): a SCHED_FIFO spinner with a core-sched cookie on CPU0 and an uncookied CFS spinner on CPU1 force-idle CPU1, and the CFS task gets under 0.1% of a CPU instead of the reserved 5%. The ext server starves sched_ext tasks the same way, and there a plain CFS spinner on the sibling is enough.
Don't charge forced idle. A server still only loses runtime to real execution or real idle, and one whose class has nothing to run still stops through dl_defer_idle once the rq is idle for real; with core scheduling off nothing changes. Getting the reserved bandwidth back also needs the server's pick to win the core-wide selection, which the preceding sched/core patches fix.
--- kernel/sched/idle.c | 7 +++++++ kernel/sched/sched.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+)
kernel/sched/idle.c +7 -0
@@ -573,6 +573,13 @@ 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)) +return ; +dl_server_update_idle (&rq->fair_server, delta_exec);#ifdef CONFIG_SCHED_CLASS_EXT dl_server_update_idle (&rq->ext_server, delta_exec);
kernel/sched/sched.h +15 -0
@@ -1525,6 +1525,16 @@ static inline bool sched_core_disabled(void)return !static_branch_unlikely (&__sched_core_enabled); } +/* +* True while core scheduling keeps @rq idle because a SMT sibling runs a task +* with an incompatible cookie, even though @rq has runnable tasks of its own. +*/ +static inline bool forced_idle_rq (struct rq *rq) +{ +return sched_core_enabled (rq) && rq->core->core_forceidle_count && + rq->nr_running; +} +/* * Be careful with this function; not for general use. The return value isn't * stable unless you actually hold a relevant rq->__lock.
@@ -1659,6 +1669,11 @@ static inline bool sched_core_disabled(void)return true; } +static inline bool forced_idle_rq (struct rq *rq) +{ +return false; +} +static inline raw_spinlock_t *rq_lockp (struct rq *rq) {return &rq->__lock;
Signature · 8 lines
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
[tip: sched/urgent] sched/deadline: Don't charge core-sched forced idle to the DL servers
The 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: 051820698aae32c571a66720327f793e2077c0fa Gitweb: https://git.kernel.org/tip/051820698aae32c571a66720327f793e2077c0fa Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:47 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sun, 22 Nov 2026 16:16:35 +01:00
sched/deadline: Don't charge core-sched forced idle to the DL servers
A deferred DL server is charged the idle time of its rq, on the premise that the time was available to the server's class and went unused. Core scheduling breaks that premise: a CPU is forced idle when a SMT sibling runs a task with an incompatible cookie, so that time was available to no class at all.
update_curr_dl_se() then runs the server's runtime out while it is throttled and calls replenish_dl_new_period(), pushing the activation a full period out. dl_defer_idle does not help, as idle_rq() is false on a forced-idle CPU: nr_running is not 0. Every period of forced idle pushes the activation again, the zero-laxity timer never fires, and the class the server reserves for gets nothing.
Reproduction on 2 cores x 2 threads with the default fair server (50 ms / 1 s): a SCHED_FIFO spinner with a core-sched cookie on CPU0 and an uncookied CFS spinner on CPU1 force-idle CPU1, and the CFS task gets under 0.1% of a CPU instead of the reserved 5%. The ext server starves sched_ext tasks the same way, and there a plain CFS spinner on the sibling is enough.
Don't charge forced idle. A server still only loses runtime to real execution or real idle, and one whose class has nothing to run still stops through dl_defer_idle once the rq is idle for real; with core scheduling off nothing changes. Getting the reserved bandwidth back also needs the server's pick to win the core-wide selection, which the preceding sched/core patches fix.
--- kernel/sched/idle.c | 7 +++++++ kernel/sched/sched.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+)
kernel/sched/idle.c +7 -0
@@ -573,6 +573,13 @@ 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)) +return ; +dl_server_update_idle (&rq->fair_server, delta_exec);#ifdef CONFIG_SCHED_CLASS_EXT dl_server_update_idle (&rq->ext_server, delta_exec);
kernel/sched/sched.h +15 -0
@@ -1522,6 +1522,16 @@ static inline bool sched_core_disabled(void) }/* +* True while core scheduling keeps @rq idle because a SMT sibling runs a task +* with an incompatible cookie, even though @rq has runnable tasks of its own. +*/ +static inline bool forced_idle_rq (struct rq *rq) +{ +return sched_core_enabled (rq) && rq->core->core_forceidle_count && + rq->nr_running; +} + +/* * Be careful with this function; not for general use. The return value isn't * stable unless you actually hold a relevant rq->__lock. */
@@ -1655,6 +1665,11 @@ static inline bool sched_core_disabled(void)return true; } +static inline bool forced_idle_rq (struct rq *rq) +{ +return false; +} +static inline raw_spinlock_t *rq_lockp (struct rq *rq) {return &rq->__lock;
[tip: sched/urgent] sched/deadline: Don't charge core-sched forced idle to the DL servers
In reply to Fernand SieberThe 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: f4626e1c3c14306453e89bfc7799bd295f38b402 Gitweb: https://git.kernel.org/tip/f4626e1c3c14306453e89bfc7799bd295f38b402 Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:47 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 23 Nov 2026 10:38:26 +01:00
sched/deadline: Don't charge core-sched forced idle to the DL servers
A deferred DL server is charged the idle time of its rq, on the premise that the time was available to the server's class and went unused. Core scheduling breaks that premise: a CPU is forced idle when a SMT sibling runs a task with an incompatible cookie, so that time was available to no class at all.
update_curr_dl_se() then runs the server's runtime out while it is throttled and calls replenish_dl_new_period(), pushing the activation a full period out. dl_defer_idle does not help, as idle_rq() is false on a forced-idle CPU: nr_running is not 0. Every period of forced idle pushes the activation again, the zero-laxity timer never fires, and the class the server reserves for gets nothing.
Reproduction on 2 cores x 2 threads with the default fair server (50 ms / 1 s): a SCHED_FIFO spinner with a core-sched cookie on CPU0 and an uncookied CFS spinner on CPU1 force-idle CPU1, and the CFS task gets under 0.1% of a CPU instead of the reserved 5%. The ext server starves sched_ext tasks the same way, and there a plain CFS spinner on the sibling is enough.
Don't charge forced idle. A server still only loses runtime to real execution or real idle, and one whose class has nothing to run still stops through dl_defer_idle once the rq is idle for real; with core scheduling off nothing changes. Getting the reserved bandwidth back also needs the server's pick to win the core-wide selection, which the preceding sched/core patches fix.
--- kernel/sched/idle.c | 7 +++++++ kernel/sched/sched.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+)
kernel/sched/idle.c +7 -0
@@ -573,6 +573,13 @@ 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)) +return ; +dl_server_update_idle (&rq->fair_server, delta_exec);#ifdef CONFIG_SCHED_CLASS_EXT dl_server_update_idle (&rq->ext_server, delta_exec);
kernel/sched/sched.h +15 -0
@@ -1522,6 +1522,16 @@ static inline bool sched_core_disabled(void) }/* +* True while core scheduling keeps @rq idle because a SMT sibling runs a task +* with an incompatible cookie, even though @rq has runnable tasks of its own. +*/ +static inline bool forced_idle_rq (struct rq *rq) +{ +return sched_core_enabled (rq) && rq->core->core_forceidle_count && + rq->nr_running; +} + +/* * Be careful with this function; not for general use. The return value isn't * stable unless you actually hold a relevant rq->__lock. */
@@ -1655,6 +1665,11 @@ static inline bool sched_core_disabled(void)return true; } +static inline bool forced_idle_rq (struct rq *rq) +{ +return false; +} +static inline raw_spinlock_t *rq_lockp (struct rq *rq) {return &rq->__lock;
PATCH 5/5 selftests/sched: Add a core-sched forced-idle DL server test
In reply to Fernand SieberNothing in selftests notices a deferred DL server that is charged for core-sched forced idle and so never activates: the fair server keeps its reservation in debugfs while the CFS tasks it reserves for get a few hundredths of a percent of a CPU.
Add cs_dl_server_test. It pins a SCHED_FIFO 50 spinner with its own core cookie to one SMT sibling and an uncookied CFS spinner to the other, so the second sibling is forced idle whenever the FIFO task runs, then checks the CFS task's share of that CPU over five seconds against the fair server's reservation under /sys/kernel/debug/sched/. The floor is half the reservation, 2.5% by default, since every slice the server gets costs a forced-idle hand-over. It skips without SMT, without core scheduling, or without the debugfs reservation.
At 2 cores x 2 threads the share measures 4.0-5.2% once both this idle charge and the core-wide DL server pick are fixed, and 0.0% with either missing, so it passes only with both.
--- tools/testing/selftests/sched/.gitignore | 1 + tools/testing/selftests/sched/Makefile | 4 +- tools/testing/selftests/sched/config | 4 +- .../selftests/sched/cs_dl_server_test.c | 402 ++++++++++++++++++ 4 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched/cs_dl_server_test.c
tools/testing/selftests/sched/.gitignore +1 -0
@@ -1 +1,2 @@ cs_prctl_test +cs_dl_server_test
tools/testing/selftests/sched/Makefile +2 -2
@@ -8,7 +8,7 @@ CFLAGS += -O2 -Wall -g -I./ $(KHDR_INCLUDES) -Wl,-rpath=./ \ $(CLANG_FLAGS) LDLIBS += -lpthread -TEST_GEN_FILES := cs_prctl_test -TEST_PROGS := cs_prctl_test +TEST_GEN_FILES := cs_prctl_test cs_dl_server_test +TEST_PROGS := cs_prctl_test cs_dl_server_test include ../lib.mk
tools/testing/selftests/sched/config +3 -1
@@ -1 +1,3 @@ -# empty +CONFIG_SCHED_CORE=y +CONFIG_SCHED_SMT=y +CONFIG_DEBUG_FS=y
tools/testing/selftests/sched/cs_dl_server_test.c new file +402 -0
402 lines not on this page · raw message
Signature · 8 lines
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
[tip: sched/urgent] selftests/sched: Add a core-sched forced-idle DL server test
The 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: 70f43730a814fcf4198960dcff5fadb2fc8b795d Gitweb: https://git.kernel.org/tip/70f43730a814fcf4198960dcff5fadb2fc8b795d Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:48 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sun, 22 Nov 2026 16:16:44 +01:00
selftests/sched: Add a core-sched forced-idle DL server test
Nothing in selftests notices a deferred DL server that is charged for core-sched forced idle and so never activates: the fair server keeps its reservation in debugfs while the CFS tasks it reserves for get a few hundredths of a percent of a CPU.
Add cs_dl_server_test. It pins a SCHED_FIFO 50 spinner with its own core cookie to one SMT sibling and an uncookied CFS spinner to the other, so the second sibling is forced idle whenever the FIFO task runs, then checks the CFS task's share of that CPU over five seconds against the fair server's reservation under /sys/kernel/debug/sched/. The floor is half the reservation, 2.5% by default, since every slice the server gets costs a forced-idle hand-over. It skips without SMT, without core scheduling, or without the debugfs reservation.
At 2 cores x 2 threads the share measures 4.0-5.2% once both this idle charge and the core-wide DL server pick are fixed, and 0.0% with either missing, so it passes only with both.
--- tools/testing/selftests/sched/.gitignore | 1 +- tools/testing/selftests/sched/Makefile | 4 +- tools/testing/selftests/sched/config | 4 +- tools/testing/selftests/sched/cs_dl_server_test.c | 402 +++++++++++++- 4 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched/cs_dl_server_test.c
tools/testing/selftests/sched/.gitignore +1 -0
@@ -1 +1,2 @@ cs_prctl_test +cs_dl_server_test
tools/testing/selftests/sched/Makefile +2 -2
@@ -8,7 +8,7 @@ CFLAGS += -O2 -Wall -g -I./ $(KHDR_INCLUDES) -Wl,-rpath=./ \ $(CLANG_FLAGS) LDLIBS += -lpthread -TEST_GEN_FILES := cs_prctl_test -TEST_PROGS := cs_prctl_test +TEST_GEN_FILES := cs_prctl_test cs_dl_server_test +TEST_PROGS := cs_prctl_test cs_dl_server_test include ../lib.mk
tools/testing/selftests/sched/config +3 -1
@@ -1 +1,3 @@ -# empty +CONFIG_SCHED_CORE=y +CONFIG_SCHED_SMT=y +CONFIG_DEBUG_FS=y
tools/testing/selftests/sched/cs_dl_server_test.c new file +402 -0
402 lines not on this page · raw message
Re: [tip: sched/urgent] selftests/sched: Add a core-sched forced-idle DL server test
Hi Peter,
Thanks for picking these up. I think there's an issue with the split:
sched/urgent has the two fixes and the new selftest:
d2583cb03113 ("sched/deadline: Clear stale rq->dl_server when core-sched replaces a pick") f4626e1c3c14 ("sched/deadline: Don't charge core-sched forced idle to the DL servers") 6d6fca38f51f ("selftests/sched: Add a core-sched forced-idle DL server test")
but the ranking patch went to sched/core:
87a825f3c680 ("sched/core: Rank DL server picks as deadline in the core-wide pick")
https://lore.kernel.org/all/179542773720.92412.4774760214632371644.tip-bot2@tip-bot2/
Without it the selftest fails on sched/urgent (8/8 in QEMU, the CFS task gets 0-1% against the 2.5% floor), and passes with it.
Could you move 87a825f3c680 to sched/urgent too? If you would rather keep it for the merge window, the selftest should go to sched/core with it.
Thanks,
Fernand
Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07
[tip: sched/urgent] selftests/sched: Add a core-sched forced-idle DL server test
In reply to Fernand SieberThe 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: 6d6fca38f51f414b75201d07b9ad4003f714551e Gitweb: https://git.kernel.org/tip/6d6fca38f51f414b75201d07b9ad4003f714551e Author: Fernand Sieber <[email protected]> AuthorDate: Thu, 12 Nov 2026 18:15:48 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 23 Nov 2026 10:38:26 +01:00
selftests/sched: Add a core-sched forced-idle DL server test
Nothing in selftests notices a deferred DL server that is charged for core-sched forced idle and so never activates: the fair server keeps its reservation in debugfs while the CFS tasks it reserves for get a few hundredths of a percent of a CPU.
Add cs_dl_server_test. It pins a SCHED_FIFO 50 spinner with its own core cookie to one SMT sibling and an uncookied CFS spinner to the other, so the second sibling is forced idle whenever the FIFO task runs, then checks the CFS task's share of that CPU over five seconds against the fair server's reservation under /sys/kernel/debug/sched/. The floor is half the reservation, 2.5% by default, since every slice the server gets costs a forced-idle hand-over. It skips without SMT, without core scheduling, or without the debugfs reservation.
At 2 cores x 2 threads the share measures 4.0-5.2% once both this idle charge and the core-wide DL server pick are fixed, and 0.0% with either missing, so it passes only with both.
--- tools/testing/selftests/sched/.gitignore | 1 +- tools/testing/selftests/sched/Makefile | 4 +- tools/testing/selftests/sched/config | 4 +- tools/testing/selftests/sched/cs_dl_server_test.c | 402 +++++++++++++- 4 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched/cs_dl_server_test.c
tools/testing/selftests/sched/.gitignore +1 -0
@@ -1 +1,2 @@ cs_prctl_test +cs_dl_server_test
tools/testing/selftests/sched/Makefile +2 -2
@@ -8,7 +8,7 @@ CFLAGS += -O2 -Wall -g -I./ $(KHDR_INCLUDES) -Wl,-rpath=./ \ $(CLANG_FLAGS) LDLIBS += -lpthread -TEST_GEN_FILES := cs_prctl_test -TEST_PROGS := cs_prctl_test +TEST_GEN_FILES := cs_prctl_test cs_dl_server_test +TEST_PROGS := cs_prctl_test cs_dl_server_test include ../lib.mk
tools/testing/selftests/sched/config +3 -1
@@ -1 +1,3 @@ -# empty +CONFIG_SCHED_CORE=y +CONFIG_SCHED_SMT=y +CONFIG_DEBUG_FS=y
tools/testing/selftests/sched/cs_dl_server_test.c new file +402 -0
402 lines not on this page · raw message