Skip to content

bpftool: Fix sparse CPU IDs

Hui Su bpf lkml 3 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 0 repliesApplied 2/2
  2. v22 patches 3 repliesSuperseded
  3. v12 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- 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.

Patches in v3 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpftool: Fix CPU IDs in per-CPU map outputtools/bpf/bpftool/common.c tools/bpf/bpftool/main.h tools/bpf/bpftool/map.c+103 -330 repliesApplied
2/2bpftool: Fix sparse CPU IDs in prog profiletools/bpf/bpftool/prog.c tools/bpf/bpftool/skeleton/profiler.bpf.c+37 -220 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/2] bpftool: Fix sparse CPU IDs

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/[email protected]/

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

Signature · 1 line
2.55.0