BPF List
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] bpftool: fix sparse logical CPU handling
@ 2026-09-07 15:57 Hui Su
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Su @ 2026-09-07 15:57 UTC (permalink / raw)
  To: bpf; +Cc: qmo, ast, daniel, andrii, eddyz87, memxor, Hui Su

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-07 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 15:57 [PATCH bpf 0/2] bpftool: fix sparse logical CPU handling Hui Su
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox