sched/core: Account PSI IRQ time to the execution context
PATCH 1/1 sched/core: Account PSI IRQ time to the execution context
psi_account_irqtime() has two callers which share rq->psi_irq_time, and they disagree about the context: __schedule() passes the outgoing rq->curr, sched_tick() passes rq->donor. Under proxy execution the donor is blocked on a mutex while rq->curr burns the CPU.
The tick charges PSI_IRQ_FULL to the donor's cgroup and advances the timestamp, so the call from __schedule() then finds delta <= 0 and charges nothing. The delta is not counted twice, it lands on the wrong cgroup.
Pass rq->curr, which is what the call read before commit af0c8b2bf67b ("sched: Split scheduler and execution contexts") renamed curr to donor across sched_tick(). Without CONFIG_SCHED_PROXY_EXEC the two rq members are a union, so this only changes anything where that option is set, and it depends on EXPERT.
---
Built and booted on x86_64 with CONFIG_SCHED_PROXY_EXEC=y, PSI and IRQ_TIME_ACCOUNTING enabled, under x86_debug.config and panic_on_warn. I did not construct a case where donor and curr differ.
kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -5791,7 +5791,7 @@ void sched_tick(void) curr = rq->curr; donor = rq->donor; -psi_account_irqtime (rq, donor,NULL ); +psi_account_irqtime (rq, curr,NULL );update_rq_clock (rq); hw_pressure =arch_scale_hw_pressure (cpu_of (rq));
base-commit: 5dd1818b15d98d4a20806cd00b1b40320b06004f
Signature · 1 line
2.43.0
Quoted 1 line
I did not construct a case where donor and curr differ.
I tested two proxy-execution processes in separate cgroup v2 cgroups. The owner held a CPU0 mutex for 20s; a SCHED_FIFO donor blocked on it. On x86_64 QEMU (4 vCPUs, 2 GiB), with PSI and IRQ time accounting enabled, the irq.pressure total deltas (us) were:
unpatched: owner 22,053, donor 401,127
patched: owner 552,740, donor 31,566
Both runs completed successfully, and attribution moved to execution context. This exercises the donor != curr case missing from the original test.
Quoted 10 lines · Zhan Xusheng
psi_account_irqtime()has two callers which sharerq->psi_irq_time, and they disagree about the context:__schedule()passes the outgoingrq->curr,sched_tick()passesrq->donor. Under proxy execution the donor is blocked on a mutex whilerq->currburns the CPU.The tick charges
PSI_IRQ_FULLto the donor's cgroup and advances the timestamp, so the call from__schedule()then finds delta <= 0 and charges nothing. The delta is not counted twice, it lands on the wrong cgroup.
Quoted 8 lines
Pass
rq->curr, which is what the call read before commitaf0c8b2bf67b("sched: Split scheduler and execution contexts") renamed curr to donor acrosssched_tick(). WithoutCONFIG_SCHED_PROXY_EXECthe two rq members are a union, so this only changes anything where that option is set, and it depends on EXPERT.Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")Signed-off-by Zhan Xusheng <[email protected]>
Thank you for finding this, and thank you to Hui Su for testing it!
thanks
-john
Peter Zijlstra
maintainerQuoted 29 lines · Zhan Xusheng
psi_account_irqtime()has two callers which sharerq->psi_irq_time, and they disagree about the context:__schedule()passes the outgoingrq->curr,sched_tick()passesrq->donor. Under proxy execution the donor is blocked on a mutex whilerq->currburns the CPU.The tick charges
PSI_IRQ_FULLto the donor's cgroup and advances the timestamp, so the call from__schedule()then finds delta <= 0 and charges nothing. The delta is not counted twice, it lands on the wrong cgroup.Pass
rq->curr, which is what the call read before commitaf0c8b2bf67b("sched: Split scheduler and execution contexts") renamed curr to donor acrosssched_tick(). WithoutCONFIG_SCHED_PROXY_EXECthe two rq members are a union, so this only changes anything where that option is set, and it depends on EXPERT.Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")Signed-off-by Zhan Xusheng <[email protected]>---
Built and booted onx86_64withCONFIG_SCHED_PROXY_EXEC=y, PSI andIRQ_TIME_ACCOUNTINGenabled, under x86_debug.config andpanic_on_warn. I did not construct a case where donor and curr differ.kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +0
-0
kernel/sched/core.c void sched_tick(void) · line 5797
Quoted 8 lines
kernel/sched/core.c +1
-1@@ -5791,7 +5791,7 @@ void sched_tick(void) curr = rq->curr; donor = rq->donor; -psi_account_irqtime (rq, donor,NULL ); +psi_account_irqtime (rq, curr,NULL );update_rq_clock (rq); hw_pressure =arch_scale_hw_pressure (cpu_of (rq));
Does not in fact apply. There is no curr in sched_tick anymore.
Quoted 1 line · Peter Zijlstra
Does not in fact apply. There is no curr in
sched_tickanymore.
It needs commit f5741d2b3451 ("sched/core: Call wq_worker_tick() for the execution context"), which added that local. That is in sched/urgent and master, not in sched/core, and the patch applies cleanly to the first two.
If you want it on sched/core instead, I will resend using rq->curr at the call site.
Peter Zijlstra
maintainerQuoted 9 lines · Zhan Xusheng
Quoted 1 line · Peter Zijlstra
Does not in fact apply. There is no curr in
sched_tickanymore.It needs commit
f5741d2b3451("sched/core: Callwq_worker_tick()for the execution context"), which added that local. That is in sched/urgent and master, not in sched/core, and the patch applies cleanly to the first two.If you want it on sched/core instead, I will resend using
rq->currat the call site.
Hmm, I thought I was on tip/master which should have /urgent on, but let me try again. Perhaps I fat-fingered something.
Peter Zijlstra
maintainerQuoted 8 lines · Peter Zijlstra
Quoted 7 lines · Zhan Xusheng
Quoted 1 line · Peter Zijlstra
Does not in fact apply. There is no curr in
sched_tickanymore.It needs commit
f5741d2b3451("sched/core: Callwq_worker_tick()for the execution context"), which added that local. That is in sched/urgent and master, not in sched/core, and the patch applies cleanly to the first two.
Quoted 5 lines
Quoted 2 lines
If you want it on sched/core instead, I will resend using
rq->currat the call site.Hmm, I thought I was on tip/master which should have /urgent on, but let me try again. Perhaps I fat-fingered something.
And indeed. I must've done something weird this morning. In it goes.
[tip: sched/urgent] sched/core: Account PSI IRQ time to the execution context, not the scheduling context
In reply to Zhan XushengThe 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: a0bb6fac53fa7cf1cadb487b43d4c9276a6b82e3 Gitweb: https://git.kernel.org/tip/a0bb6fac53fa7cf1cadb487b43d4c9276a6b82e3 Author: Zhan Xusheng <[email protected]> AuthorDate: Fri, 18 Sep 2026 21:29:15 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 24 Sep 2026 10:32:50 +02:00
sched/core: Account PSI IRQ time to the execution context, not the scheduling context
psi_account_irqtime() has two callers which share rq->psi_irq_time, and they disagree about the context: __schedule() passes the outgoing rq->curr, sched_tick() passes rq->donor. Under proxy execution the donor is blocked on a mutex while rq->curr burns the CPU.
The tick charges PSI_IRQ_FULL to the donor's cgroup and advances the timestamp, so the call from __schedule() then finds delta <= 0 and charges nothing. The delta is not counted twice, it lands on the wrong cgroup.
Pass rq->curr, which is what the call read before commit af0c8b2bf67b ("sched: Split scheduler and execution contexts") renamed 'curr' to 'donor' across sched_tick(). Without CONFIG_SCHED_PROXY_EXEC the two rq members are a union, so this only changes anything where that option is set, and it depends on EXPERT.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -5798,7 +5798,7 @@ void sched_tick(void) curr = rq->curr; donor = rq->donor; -psi_account_irqtime (rq, donor,NULL ); +psi_account_irqtime (rq, curr,NULL );update_rq_clock (rq); hw_pressure =arch_scale_hw_pressure (cpu_of (rq));