mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jemmy Wong <jemmywong512@gmail.com>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Jemmy Wong <jemmywong512@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] sched/core: Flush pending runtime for the execution context
Date: Thu,  8 Oct 2026 21:26:03 +0800	[thread overview]
Message-ID: <20261008132604.98242-3-jemmywong512@gmail.com> (raw)
In-Reply-To: <20261008132604.98242-1-jemmywong512@gmail.com>

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@gmail.com>
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)


  parent reply	other threads:[~2026-10-08 13:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 13:26 [PATCH 0/3] sched: Fix proxy-exec use of curr and donor Jemmy Wong
2026-10-08 13:26 ` [PATCH 1/3] sched/fair: Drive NUMA and cache tick work from the execution context Jemmy Wong
2026-10-08 13:26 ` Jemmy Wong [this message]
2026-10-08 13:26 ` [PATCH 3/3] sched/core: Check CFS bandwidth against the donor for NOHZ Jemmy Wong
2026-10-08 15:33 ` [PATCH 0/3] sched: Fix proxy-exec use of curr and donor Kayra Cizmeci
2026-10-09  3:41   ` Jemmy Wong
2026-10-09  4:07     ` Hui Su
2026-10-09  5:46       ` Jemmy Wong

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=20261008132604.98242-3-jemmywong512@gmail.com \
    --to=jemmywong512@gmail.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.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=tim.c.chen@linux.intel.com \
    --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®