From: Ziyang Men <ziyang.meme@gmail.com>
To: Tejun Heo <tj@kernel.org>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
kernel-team@meta.com, "Ingo Molnar" <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Ben Segall" <bsegall@google.com>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"JP Kobryn" <inwardvessel@gmail.com>,
bpf@vger.kernel.org, cgroups@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] cgroup: add BPF kfuncs to read a cpu cgroup's stats
Date: Tue, 18 Aug 2026 15:44:36 -0700 [thread overview]
Message-ID: <aoTgVOTxsEbFXTp2@devvm16600.scu0.facebook.com> (raw)
In-Reply-To: <aoSTaFwsVEoNW01D@slm.duckdns.org>
Hi Tejun,
On Tue, Aug 18, 2026 at 07:16:24AM -1000, Tejun Heo wrote:
>On Mon, Aug 17, 2026 at 05:24:49PM -0700, Ziyang Men wrote:
>> +++ b/kernel/cgroup/bpf_cpu.c
>
>Probably not the best file name. bpf_cgroup.c or maybe just put it in
>cgroup.c?
>
bpf_cgroup.c sounds good, I will rename to it.
>> +/**
>> + * bpf_css_to_task_group - Cast a CPU controller css to its task group
>> + * @css: CPU controller css
>> + *
>> + * Must be called under RCU.
>> + * A C cast does not give the verifier a task_group pointer. This kfunc
>> + * preserves the task_group and per-CPU types needed to read cfs_rq.
>
>The fact that this is used for per-CPU types now probably won't age well if
>this grows more usages in the future.
>
Yes the major usage of this function is to enable the bpf side to compute the
throttled_time meanwhile not touch the codes in scheduler.
>> + *
>> + * Return: The task group, or NULL if @css belongs to another controller.
>> + */
>> +__bpf_kfunc struct task_group *
>> +bpf_css_to_task_group(struct cgroup_subsys_state *css)
>> +{
>> + if (css->ss != &cpu_cgrp_subsys)
>
>unlikely()?
>
Ok. Added.
>> + return NULL;
>> +
>> + /* task_group embeds css at offset zero. */
>> + return (struct task_group *)css;
>
>container_of()?
>
Ok. Added.
>> +/**
>> + * bpf_css_flush_rstat - Flush a cgroup subsystem's rstat data
>> + * @css: cgroup subsystem state to flush
>> + */
>> +__bpf_kfunc void bpf_css_flush_rstat(struct cgroup_subsys_state *css)
>> +{
>> + css_rstat_flush(css);
>> +}
>
>Why is this necessary? Isn't css_rstat_flush() already exposed as a kfunc?
>
Ok. Will remove it.
>> +/**
>> + * bpf_cgroup_base_stat - Read a cgroup's base statistics
>> + * @cgrp: cgroup to read from
>> + * @out: zero-initialized output in nanoseconds
>> + *
>> + * CPU time is adjusted as for cpu.stat.
>> + */
>> +__bpf_kfunc void bpf_cgroup_base_stat(struct cgroup *cgrp,
>> + struct cgroup_base_stat *out)
>> +{
>> + if (cgroup_parent(cgrp)) {
>> + __css_rstat_lock(&cgrp->self, -1);
>> + *out = cgrp->bstat;
>> + cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
>> + &out->cputime.utime, &out->cputime.stime);
>> + __css_rstat_unlock(&cgrp->self, -1);
>> + } else {
>> + root_cgroup_cputime(out);
>> + }
>> +}
>> +
>> +__bpf_kfunc_end_defs();
>> +
>> +BTF_KFUNCS_START(bpf_rstat_common_kfunc_ids)
>> +BTF_ID_FLAGS(func, bpf_css_flush_rstat, KF_SLEEPABLE)
>> +BTF_ID_FLAGS(func, bpf_cgroup_base_stat, KF_SLEEPABLE)
>
>Why are these SLEEPABLE?
>
The css_rstat_flush() calls might_sleep() and cond_resched().
The bpf_cgroup_base_stat() takes an rstat spinlock_t, which can sleep on
PREEMPT_RT.
So both marked as SLEEPABLE.
>Thanks.
>
>--
>tejun
Please let me know your concerns. Thanks!
Best,
Ziyang
next prev parent reply other threads:[~2026-08-18 22:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 0:24 [PATCH v2 0/2] cgroup: expose cpu.stat to BPF Ziyang Men
2026-08-18 0:24 ` [PATCH v2 1/2] cgroup: add BPF kfuncs to read a cpu cgroup's stats Ziyang Men
2026-08-18 1:28 ` bot+bpf-ci
2026-08-18 17:16 ` Tejun Heo
2026-08-18 22:44 ` Ziyang Men [this message]
2026-08-18 22:47 ` Tejun Heo
2026-08-18 23:59 ` Ziyang Men
2026-08-18 0:24 ` [PATCH v2 2/2] selftests/bpf: add cgroup_iter_cpu test for cpu cgroup kfuncs Ziyang Men
2026-08-18 1:28 ` bot+bpf-ci
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=aoTgVOTxsEbFXTp2@devvm16600.scu0.facebook.com \
--to=ziyang.meme@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dietmar.eggemann@arm.com \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hannes@cmpxchg.org \
--cc=inwardvessel@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=peterz@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=yonghong.song@linux.dev \
/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