mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hui Su <sh_def@163.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, juri.lelli@redhat.com, mingo@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, kprateek.nayak@amd.com, jstultz@google.com,
	connoro@google.com, Hui Su <sh_def@163.com>
Subject: [PATCH] sched/rt: Fix RT watchdog accounting for proxy execution
Date: Thu,  3 Sep 2026 19:12:47 +0800	[thread overview]
Message-ID: <20260903111247.3538976-1-sh_def@163.com> (raw)

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@163.com>
---
 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


             reply	other threads:[~2026-09-03 11:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 11:12 Hui Su [this message]
2026-09-09  9:38 ` Hui Su

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260903111247.3538976-1-sh_def@163.com \
    --to=sh_def@163.com \
    --cc=bsegall@google.com \
    --cc=connoro@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®