bpftool currently assumes that possible CPU IDs are dense. This is not
true when the possible CPU mask itself is sparse, such as 0,2-3. In that
case, per-CPU map output labels and prog profile event-array keys can
refer to the wrong logical CPUs.
The first patch keeps dense per-CPU buffer slots separate from logical CPU
IDs when printing per-CPU map values. The parsed CPU count is passed
together with the logical CPU IDs so that output labels and loop bounds use
the same possible-CPU mask.
The second patch applies the same distinction to prog profile. Userspace
keeps a compact CPU count for per-CPU result buffers, while perf events are
created for the actual logical CPU IDs and PERF_EVENT_ARRAY keys use the
logical CPU ID span. The current per-CPU perf event grouping in bpf-next is
preserved.
Changes in v3:
- Rebase the series onto bpf-next/master as requested by Andrii.
- Adapt the prog profile fix to current bpf-next while preserving its
per-CPU perf event grouping and scaled-value accounting.
- Pass the parsed CPU count through the per-CPU map output helpers.
- Match the existing bpftool memory-allocation error style.
- Pass profile_cpu_ids directly to get_possible_cpu_ids().
- Move testing details from individual patches to the cover letter.
Previous versions:
v2: https://lore.kernel.org/lkml/20260918102052.1247819-1-sh_def@163.com/
Testing:
- PASS: Host and ARM64 bpftool builds, bpftool Documentation build, bash
syntax, and diff checks.
- PASS: ARM64 QEMU with a synthetic possible/present/online mask of 0,2-3;
plain, JSON, and BTF per-CPU map output reported CPUs 0,2,3, and prog
profile reached perf_event_open for CPUs 0,2,3. QEMU did not provide
usable PMU counts.
Hui Su (2):
bpftool: Fix CPU IDs in per-CPU map output
bpftool: Fix sparse CPU IDs in prog profile
tools/bpf/bpftool/common.c | 40 ++++++++++
tools/bpf/bpftool/main.h | 1 +
tools/bpf/bpftool/map.c | 95 +++++++++++++++--------
tools/bpf/bpftool/prog.c | 51 +++++++-----
tools/bpf/bpftool/skeleton/profiler.bpf.c | 8 +-
5 files changed, 140 insertions(+), 55 deletions(-)
base-commit: 79dc258c9392051420a26f1504c647bd3d27c66a
--
2.55.0