From: Ziyang Men <ziyang.meme@gmail.com>
To: "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"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>
Cc: Ben Segall <bsegall@google.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.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>,
Shuah Khan <shuah@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
JP Kobryn <inwardvessel@gmail.com>,
Mykola Lysenko <mykolal@meta.com>,
Ziyang Men <ziyang.meme@gmail.com>,
kernel-team@meta.com, bpf@vger.kernel.org,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] cgroup, sched: add bpf for cgroup cpu controller
Date: Thu, 13 Aug 2026 11:58:44 -0700 [thread overview]
Message-ID: <20260813185846.1216892-1-ziyang.meme@gmail.com> (raw)
As the title suggests, this series adds bpf kfuncs for the cgroup CPU
controller.
Motivation:
Collecting cgroup statistics is expensive: the existing
method is to open and parse a cgroup file. memcg already has an
efficient alternative through BPF; this series extends that idea to cpu.
Design:
- Leave reading the CFS bandwidth counters to the BPF program. They are
plain fields of tg->cfs_bandwidth, so they need no kernel code.
- Add one kfunc to compute the throttled time. This is necessary because
it is a sum over every possible cpu, which a user cannot do itself.
The only part it touches the scheduler part is to discard the static for
throttled_time_self() in order to use externally.
Patch 1 adds the kfuncs (kernel/cgroup/bpf_cpu.c); patch 2 adds a
test_progs selftest.
Tested on VM with v7.2-rc5.
Ziyang Men (2):
cgroup, sched: add BPF kfuncs to read a cpu cgroup's stats
selftests/bpf: add cgroup_iter_cpu test for cpu cgroup kfuncs
include/linux/cgroup.h | 15 +
kernel/cgroup/Makefile | 2 +
kernel/cgroup/bpf_cpu.c | 80 ++++++
kernel/cgroup/cgroup-internal.h | 3 +
kernel/cgroup/rstat.c | 42 +++
kernel/sched/core.c | 2 +-
tools/testing/selftests/bpf/cgroup_iter_cpu.h | 22 ++
tools/testing/selftests/bpf/config | 3 +
.../bpf/prog_tests/cgroup_iter_cpu.c | 259 ++++++++++++++++++
.../selftests/bpf/progs/cgroup_iter_cpu.c | 53 ++++
10 files changed, 480 insertions(+), 1 deletion(-)
create mode 100644 kernel/cgroup/bpf_cpu.c
create mode 100644 tools/testing/selftests/bpf/cgroup_iter_cpu.h
create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_cpu.c
create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_cpu.c
--
2.53.0-Meta
next reply other threads:[~2026-08-13 18:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 18:58 Ziyang Men [this message]
2026-08-13 18:58 ` [PATCH 1/2] cgroup, sched: add BPF kfuncs to read a cpu cgroup's stats Ziyang Men
2026-08-13 20:24 ` bot+bpf-ci
2026-08-13 18:58 ` [PATCH 2/2] selftests/bpf: add cgroup_iter_cpu test for cpu cgroup kfuncs Ziyang Men
2026-08-13 20:23 ` 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=20260813185846.1216892-1-ziyang.meme@gmail.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=juri.lelli@redhat.com \
--cc=kernel-team@meta.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=mykolal@meta.com \
--cc=peterz@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--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