From: Tejun Heo <tj@kernel.org>
To: Hui Su <sh_def@163.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Koutny <mkoutny@suse.com>,
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>,
John Stultz <jstultz@google.com>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched: Account cgroup CPU time to the execution context
Date: Thu, 3 Sep 2026 20:37:31 -1000 [thread overview]
Message-ID: <appnKwylGK3QUIJ3@slm.duckdns.org> (raw)
In-Reply-To: <20260904034707.268416-1-sh_def@163.com>
On Fri, Sep 04, 2026 at 11:47:07AM +0800, Hui Su wrote:
> Proxy execution separates the scheduling context from the execution
> context. Commit aa4f74dfd42b ("sched: Fix runtime accounting w/ split
> exec & sched contexts") made per-task and thread-group runtime
> accounting follow the task that actually executes, while cgroup CPU
> usage is charged to the donor.
>
> When the donor and execution task belong to different cgroups, this
> makes a task's execution time count against a different cgroup from the
> one the task belongs to.
>
> Cgroup CPU usage should follow the execution context, matching the
> per-task, thread-group, and cgroup user/system accounting. Keep
> scheduling state associated with the donor, but charge cgroup CPU
> usage to rq->curr.
>
> A reproducer with the donor and execution task in separate cgroups
> showed the execution task accumulating runtime while cgroup CPU usage
> was charged to the donor's cgroup. With this change, the execution
> task's cgroup accumulates the CPU usage instead. The same behavior was
> verified with an RT donor and with legacy cpuacct accounting.
>
> Fixes: aa4f74dfd42b ("sched: Fix runtime accounting w/ split exec & sched contexts")
> Suggested-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Hui Su <sh_def@163.com>
Provided John is okay with going this way:
Acked-by: Tejun Heo <tj@kernel.org>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 8dff37059faf..6fcf67d741e8 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1404,7 +1404,6 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
>
> se->exec_start = now;
> if (entity_is_task(se)) {
> - struct task_struct *donor = task_of(se);
> struct task_struct *running = rq->curr;
> /*
> * If se is a task, we account the time against the running
> @@ -1417,8 +1416,7 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
> account_group_exec_runtime(running, delta_exec);
> account_mm_sched(rq, running, delta_exec);
>
> - /* cgroup time is always accounted against the donor */
> - cgroup_account_cputime(donor, delta_exec);
> + cgroup_account_cputime(running, delta_exec);
The diff looks so much better.
Thanks.
--
tejun
next prev parent reply other threads:[~2026-09-04 6:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 3:47 [PATCH v2] sched: Account cgroup CPU time to the execution context Hui Su
2026-09-04 6:37 ` Tejun Heo [this message]
2026-09-09 5:17 ` John Stultz
2026-09-09 6:08 ` Hui Su
2026-09-09 17:48 ` Tejun Heo
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=appnKwylGK3QUIJ3@slm.duckdns.org \
--to=tj@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--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=mkoutny@suse.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sh_def@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.