[PATCH] sched/rt: Fix RT watchdog accounting for proxy execution
From: Hui Su
Date: Thu Sep 03 2026 - 07:17:49 EST
With proxy execution, task_tick_rt() is invoked for the scheduling
context in rq->donor, while rq->curr identifies the task that is
actually executing.
The RT watchdog looks up RLIMIT_RTTIME through its task argument and
updates that task's rt.timeout and posix_cputimers state. Runtime
accounting, however, charges execution time to rq->curr, and
run_posix_cpu_timers() checks current after the scheduler tick. Pass
rq->curr to watchdog() so these state updates follow the actual execution
context.
Reset rt.timeout when a non-RT execution task blocks while using an RT
donor, or resumes with a non-RT scheduling context. This ties the timeout
lifecycle to the execution and scheduling contexts, handles nested proxy
chains, and preserves the timeout across scheduler preemption. Native RT
tasks retain their existing behavior.
Tested with a proxy-execution reproducer using SCHED_FIFO and
SCHED_RR donors. The unpatched kernel charges rt.timeout to the donor,
while the patched kernel charges the execution task and delivers SIGXCPU
to it. Nested proxy chains, blocking and non-RT context transitions,
scheduler preemption, and donor cancellation were also exercised.
Fixes: 7de9d4f94638 ("sched: Start blocked_on chain processing in find_proxy_task()")
Signed-off-by: Hui Su <sh_def@xxxxxxx>
---
kernel/sched/core.c | 13 +++++++++++++
kernel/sched/rt.c | 2 +-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f78275192036..c429e410f6dc 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6746,6 +6746,11 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
return false;
}
+ /* End the current proxy execution episode when the owner blocks. */
+ if (sched_proxy_exec() && !rt_prio(p->prio) &&
+ rt_prio(rq->donor->prio))
+ p->rt.timeout = 0;
+
p->is_blocked = 1;
/*
@@ -7221,6 +7226,14 @@ static void __sched notrace __schedule(int sched_mode)
rq_set_donor(rq, next);
}
+ /*
+ * End a previous RT proxy interval when a non-RT execution task is
+ * selected with a non-RT scheduling context.
+ */
+ if (sched_proxy_exec() && !rt_prio(next->prio) &&
+ !rt_prio(rq->donor->prio) && next->rt.timeout)
+ next->rt.timeout = 0;
+
picked:
clear_tsk_need_resched(prev);
clear_preempt_need_resched();
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index e6e5f8a2caaf..bdcfc4fa8922 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2545,7 +2545,7 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
update_curr_rt(rq);
update_rt_rq_load_avg(rq_clock_pelt(rq), rq, 1);
- watchdog(rq, p);
+ watchdog(rq, rq->curr);
/*
* RR tasks need a special form of time-slice management.
--
2.54.0