[PATCH 2/3] sched/core: Flush pending runtime for the execution context

From: Jemmy Wong

Date: Thu Oct 08 2026 - 09:33:19 EST


task_sched_runtime() reports sum_exec_runtime to getrusage() and
CLOCK_THREAD_CPUTIME_ID. It commits the open run interval first, but
only when @p is the donor, using @p->sched_class->update_curr().

The interval is not added to the donor. The donor class's update_curr()
reads the donor's exec_start, and update_se() charges that delta to
rq->curr. Under proxy execution those tasks differ: the lock holder is
on CPU as rq->curr, and the waiter blocked on the mutex is rq->donor.
A runtime read of the lock holder skipped the flush and dropped the
time since the last update.

Commit the interval when @p is rq->curr, through the donor class's
update_curr(). The delta is still taken from the donor's exec_start
and still applied to @p. Without CONFIG_SCHED_PROXY_EXEC, curr and
donor are a union and therefore the same task, so the condition is
unchanged.

Fixes: aa4f74dfd42b ("sched: Fix runtime accounting w/ split exec & sched contexts")
Signed-off-by: Jemmy Wong <jemmywong512@xxxxxxxxx>
Assisted-by: LLM
---
kernel/sched/core.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1fe40de6ebe3..b2005fafae59 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5715,14 +5715,18 @@ unsigned long long task_sched_runtime(struct task_struct *p)

rq = task_rq_lock(p, &rf);
/*
- * Must be ->curr _and_ ->on_rq. If dequeued, we would
- * project cycles that may never be accounted to this
+ * Must be the execution context _and_ ->on_rq. If dequeued, we
+ * would project cycles that may never be accounted to this
* thread, breaking clock_gettime().
+ *
+ * Pending time is charged to rq->curr by update_se(), not the
+ * donor. Under proxy execution those can differ; flush via the
+ * donor's update_curr() so the delta lands on p.
*/
- if (task_current_donor(rq, p) && task_on_rq_queued(p)) {
+ if (task_current(rq, p) && task_on_rq_queued(p)) {
prefetch_curr_exec_start(p);
update_rq_clock(rq);
- p->sched_class->update_curr(rq);
+ rq->donor->sched_class->update_curr(rq);
}
ns = p->se.sum_exec_runtime;
task_rq_unlock(rq, p, &rf);
--
2.54.0 (Apple Git-157)