From: Ziyang Men <ziyang.meme@gmail.com>
To: "Shuah Khan" <shuah@kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jiri Kosina" <jikos@kernel.org>,
"Benjamin Tissoires" <bentiss@kernel.org>,
"David Vernet" <void@manifault.com>,
"Eduard Zingerman" <eddyz87@gmail.com>
Cc: Viktor Malik <vmalik@redhat.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
JP Kobryn <inwardvessel@gmail.com>,
Mykola Lysenko <mykolal@meta.com>,
Nathan Chancellor <nathan@kernel.org>,
Ziyang Men <ziyang.meme@gmail.com>,
kernel-team@meta.com, linux-kselftest@vger.kernel.org,
cgroups@vger.kernel.org, linux-input@vger.kernel.org,
sched-ext@lists.linux.dev, linux-mm@kvack.org,
bpf@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 0/4] selftests: add shared Makefile for BPF selftests and new memcg test
Date: Tue, 8 Sep 2026 16:55:48 -0700 [thread overview]
Message-ID: <20260908235552.2610256-1-ziyang.meme@gmail.com> (raw)
This series refactors the BPF-related build machinery that is currently
duplicated across selftests/{bpf,sched_ext,hid}/. It adds the shared
tools/testing/selftests/lib.bpf.mk fragment and wires up three consumers,
simplifying both existing BPF selftests and future additions.
The series also adds a cgroup memory-controller selftest that complements
the existing coverage.
Patch 1 adds lib.bpf.mk.
Patch 2 adds selftests/cgroup/test_memcg_stat_cross_cpu, which verifies a
cgroup flush by comparing values read through BPF memcg kfuncs with the
corresponding cgroupfs values. The existing bpf/cgroup_iter_memcg test only
checks whether selected values are non-zero.
Patches 3 and 4 replace the duplicated BPF build machinery in
selftests/{hid,sched_ext} with lib.bpf.mk.
===
Changes since v3:
For shared Makefile:
- Track in-tree libbpf headers directly so a single make invocation rebuilds
BPF objects and skeletons after a header change.
- Restore the target definitions needed by LoongArch and MIPS cross builds.
- Validate output directories and skeleton suffixes, and reject dotted or
hyphenated source stems before they reach build and cleanup rules.
- Add stamp tracking for vmlinux.h generation while preserving content-based
header updates.
- Make skeletons and subskeletons explicit outputs, so a missing subskeleton is
regenerated and both sets participate in the all target.
- Namespace private variables, expand the caller-visible contract, track a
supplied VMLINUX_H, and remove unnecessary include search paths.
For cgroup selftest:
- Add CONFIG_BPF_EVENTS and probe every required kfunc plus the sleepable
cgroup iterator before running.
- Bound CPU fanout, cgroup/process count, and total memory use; skip a case
when the flush threshold would require more than 256 MiB.
- Check CPU discovery, polling, iterator creation, and BPF errors, with clearer
diagnostics.
- Compare each BPF statistic against two following memory.stat samples, keeping
exact equality on a quiet subtree while tolerating values that move between
the two samples.
For hid and sched_ext:
- Remove unused HID locals instead of suppressing warnings, drop obsolete
variables and comments, tighten cleanup, and correct the generated-output
description.
===
Changes since v2:
For shared Makefile:
- Use USERCFLAGS and USERLDFLAGS to extend CFLAGS and LDFLAGS.
- Pass OPT_FLAGS/RELEASE and EXTRA_CFLAGS to the libbpf and bpftool sub-makes.
- Use one rule per BPF source instead of a global vpath that also affected the
caller's normal %.c rules.
- Take HOSTCC/HOSTLD from lib.mk instead of including Makefile.include, which
also rewrote the caller's AR, LD, and CFLAGS.
- Report a missing vmlinux from the recipe rather than at parse time, so
"make clean" still works without BTF.
For cgroup selftest:
- Create one cgroup tree, perform one flush, then read through BPF and
cgroupfs.
- Use common cgroup helpers such as cg_read_key_long() and values_close().
- Use cpu_set_t rather than manually allocated CPU lists.
- Move test_memcontrol.c's anonymous-memory allocator into cgroup_util.
- Address the remaining review feedback.
===
Changes since v1:
- Generalize lib.bpf.mk for source layouts and suffixes, extra headers and
flags, skeleton suffixes, subskeletons, and configurable output directories.
- Add patch 3 (hid) and patch 4 (sched_ext), converting those directories to
the shared fragment.
Ziyang Men (4):
selftests: add shared lib.bpf.mk to build BPF progs and skeletons
selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush
selftests/hid: build the BPF program via the shared lib.bpf.mk
selftests/sched_ext: build BPF schedulers via the shared lib.bpf.mk
tools/testing/selftests/cgroup/.gitignore | 8 +
tools/testing/selftests/cgroup/Makefile | 46 ++
tools/testing/selftests/cgroup/config | 5 +
.../selftests/cgroup/lib/cgroup_util.c | 82 ++
.../cgroup/lib/include/cgroup_util.h | 3 +
.../cgroup/memcg_stat_cross_cpu.bpf.c | 95 +++
.../selftests/cgroup/memcg_stat_cross_cpu.h | 18 +
.../cgroup/test_memcg_stat_cross_cpu.c | 755 ++++++++++++++++++
.../selftests/cgroup/test_memcontrol.c | 29 +-
tools/testing/selftests/hid/.gitignore | 1 +
tools/testing/selftests/hid/Makefile | 179 +----
tools/testing/selftests/hid/progs/hid.c | 7 +-
tools/testing/selftests/lib.bpf.mk | 321 ++++++++
tools/testing/selftests/sched_ext/Makefile | 149 +---
14 files changed, 1382 insertions(+), 316 deletions(-)
create mode 100644 tools/testing/selftests/cgroup/memcg_stat_cross_cpu.bpf.c
create mode 100644 tools/testing/selftests/cgroup/memcg_stat_cross_cpu.h
create mode 100644 tools/testing/selftests/cgroup/test_memcg_stat_cross_cpu.c
create mode 100644 tools/testing/selftests/lib.bpf.mk
--
2.53.0-Meta
next reply other threads:[~2026-09-08 23:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 23:55 Ziyang Men [this message]
2026-09-08 23:55 ` [PATCH v4 1/4] selftests: add shared lib.bpf.mk to build BPF progs and skeletons Ziyang Men
2026-09-09 18:26 ` Tejun Heo
2026-09-08 23:55 ` [PATCH v4 2/4] selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush Ziyang Men
2026-09-08 23:55 ` [PATCH v4 3/4] selftests/hid: build the BPF program via the shared lib.bpf.mk Ziyang Men
2026-09-08 23:55 ` [PATCH v4 4/4] selftests/sched_ext: build BPF schedulers " Ziyang Men
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=20260908235552.2610256-1-ziyang.meme@gmail.com \
--to=ziyang.meme@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arighi@nvidia.com \
--cc=bentiss@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=eddyz87@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=inwardvessel@gmail.com \
--cc=jikos@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=mykolal@meta.com \
--cc=nathan@kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=tj@kernel.org \
--cc=vmalik@redhat.com \
--cc=void@manifault.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