From: Hui Su <sh_def@163.com>
To: bpf@vger.kernel.org
Cc: qmo@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
Hui Su <sh_def@163.com>
Subject: [PATCH bpf 0/2] bpftool: fix sparse logical CPU handling
Date: Tue, 8 Sep 2026 00:57:33 +0900 [thread overview]
Message-ID: <20260907155735.2929529-1-sh_def@163.com> (raw)
Per-CPU map values are stored in dense slots, while the slots correspond
to logical CPU IDs from the kernel's possible CPU mask. On sparse CPU
topologies, bpftool currently reports dense slot numbers as CPU IDs when
dumping per-CPU maps.
The prog profile command has the same assumption in a different form: it
uses the compact possible CPU count as the logical CPU range and as the
stride of its PERF_EVENT_ARRAY. This produces incorrect event keys when
logical CPU IDs are sparse.
The first patch adds a helper to enumerate logical CPU IDs from the
possible CPU mask and uses it in the map output paths. The second patch
reuses the helper for perf-event setup and uses a logical-ID span for
multi-metric event-array keys, while retaining compact userspace result
storage.
The series was tested in an arm64 QEMU guest with possible, present, and
online CPUs set to 0,2-3. Map output, including a BTF-described per-CPU
array, reports CPU IDs 0,2,3. The QEMU PMU does not provide usable
hardware profile counts; the profile test nevertheless reaches perf-event
setup in the fixed version, while the pre-fix version faults in
perf_event_alloc().
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 | 37 +++++++++++
tools/bpf/bpftool/main.h | 1 +
tools/bpf/bpftool/map.c | 77 ++++++++++++++++-------
tools/bpf/bpftool/prog.c | 35 +++++++----
tools/bpf/bpftool/skeleton/profiler.bpf.c | 7 ++-
5 files changed, 121 insertions(+), 36 deletions(-)
--
2.54.0
next reply other threads:[~2026-09-07 15:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 15:57 Hui Su [this message]
2026-09-07 15:57 ` [PATCH bpf 1/2] bpftool: Fix CPU IDs in per-CPU map output Hui Su
2026-09-07 15:57 ` [PATCH bpf 2/2] bpftool: Fix sparse CPU IDs in prog profile Hui Su
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=20260907155735.2929529-1-sh_def@163.com \
--to=sh_def@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
/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