Skip to contentSkip to conversation

sched/rt: Fix RT watchdog accounting for proxy execution

PATCH In review Hui Su 1 participant 2 messages Sep 3 – Sep 9 Scheduler

lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH 1/1 sched/rt: Fix RT watchdog accounting for proxy execution

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()")
---
 kernel/sched/core.c | 13 +++++++++++++
 kernel/sched/rt.c   |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
kernel/sched/core.c +13 -0
index f78275192036..c429e410f6dc 100644
@@ -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();
kernel/sched/rt.c +1 -1
index e6e5f8a2caaf..bdcfc4fa8922 100644
@@ -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.
Signature · 1 line
2.54.0
author
#1 lore raw
Quoted 6 lines · Hui Su

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.

Pass rq->curr to watchdog() so these state updates follow the actual execution context.

This standalone patch has been superseded by the v4 series. The scheduler task-tick framework has since been reworked to dispatch both the donor and execution classes, and the RT watchdog fix has been rebased and folded into patch 4/5.

The v4 series is available at:

https://lore.kernel.org/r/[email protected]

The task-tick framework redesign was discussed in Peter Zijlstra's review:

https://lore.kernel.org/r/[email protected]

Please consider this standalone patch superseded.

Thanks,
Hui