Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism
@ 2026-12-06  2:11 Ian Rogers
  2026-12-06  2:11 ` [PATCH 1/8] perf pmu-events: Ignore backup and non-event JSON files in metric.py Ian Rogers
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Ian Rogers @ 2026-12-06  2:11 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim
  Cc: Jiri Olsa, Adrian Hunter, James Clark, linux-perf-users,
	linux-kernel, Ian Rogers

This series removes the copy of ~1,013 checked-in pmu-events JSON/CSV
files into $(OUTPUT) during out-of-tree builds, hardens pmu-events file
discovery against stray and backup files, and removes several
serialization bottlenecks in the perf build and build-test:

- Patches 1-3 (no-copy pmu-events overlay & hardening):
  * Ignore hidden, backup, non-list, and generated JSON files in
    metric.py and jevents.py.
  * Refactor jevents.py directory scanning and add --gen-dir,
    --gen-manifest, and --gen-file overlay options so generated JSONs
    live in $(OUTPUT)pmu-events/gen/ for both in-tree and out-of-tree
    builds without copying checked-in sources or polluting the source
    tree.
  * Track input file lists with write-if-changed manifests via GNU
    Make's $(file ...) built-in, derive model lists from mapfile.csv,
    and drop the 1,013 per-file COPY rules and orphan-pruning logic.
  * Preserves byte-for-byte identical pmu-events.c and
    pmu-events-string.c outputs (and Python-free NO_JEVENTS=1 builds).

- Patches 4-6 (pmu-events generation & test parallelism):
  * Scope LoadAllModelEvents() via mapfile.csv so AMD models do not
    parse Intel event JSONs and vice versa (and ARM stays scoped to its
    vendor), add --output-dir batch mode to amd_metrics.py,
    arm64_metrics.py, and intel_metrics.py, and add unit tests in
    metric_test.py.
  * Replace 136 per-model/per-file metric generation rules in
    pmu-events/Build with 3 parallel stamp-gated batch invocations
    (~0.5 s wall time for all 136 JSONs: 87 ms AMD, 121 ms ARM64,
    503 ms Intel).
  * Move EMPTY_PMU_EVENTS_TEST_LOG and METRIC_TEST_LOG off pmu-events.c
    onto pmu-events-in.o so tests run in parallel with jevents.py and C
    compilation.

- Patch 7 (header-only prepare dependencies):
  * Split phony lib{api,bpf,perf,subcmd,symbol}-headers targets running
    only install_headers out of the full archive rules in Makefile.perf
    (updating bpf_skel.mak to depend on bpf_helper_defs.h instead of
    libbpf.a).
  * Use those header targets in prepare and libperf-headers in
    LIBPMU_EVENTS_IN so library archive builds run in parallel with perf
    object compilation and pmu-events.

- Patch 8 (build-test linter deduplication):
  * Pass NO_SHELLCHECK=1 NO_MYPY=1 NO_PYLINT=1 to all targets in
    tools/perf/tests/make except make_pure and make_pure_O so static
    checks run once per suite instead of repeating ~291 linter
    invocations on every build configuration.

Build performance impact
------------------------
Measured on a 28-thread x86_64 host (clean out-of-tree builds from
identical worktrees, default JEVENTS_ARCH=all):
- Full default build (including shellcheck, mypy, pylint):
  * Wall time: 75.98 s -> 65.94 s (-13.2%, -10.04 s)
  * CPU time:  472.3 s -> 396.6 s (-16.0%, -75.8 CPU-s)
  * Log lines: 2,423 -> 1,165 (-51.9%)
- Full build without linters (NO_SHELLCHECK=1 NO_MYPY=1 NO_PYLINT=1):
  * Wall time: 57.83 s -> 44.70 s (-22.7%, -13.13 s)
  * CPU time:  222.5 s -> 142.0 s (-36.2%, -80.5 CPU-s)
  * Log lines: 2,125 -> 870 (-59.1%)
- Cold libpmu-events.a build: net wall time (excluding feature
  detection) drops from 9.22 s to 4.96 s (-46.2%; gross 13.95 s to
  8.80 s), COPY rules drop from 1,013 to 0, and build log lines drop
  from 1,330 to 60 (-95.5%).
- Metric JSON generation: 136 separate Python processes drop to 3
  parallel vendor-scoped invocations (~0.5 s wall time total: 87 ms
  AMD, 121 ms ARM64, 503 ms Intel).
- prepare / single-object builds: lib{api,bpf,perf,subcmd,symbol}.a
  no longer serialize perf object compilation or pmu-events (saving
  ~1 s of libperf.a compile latency before pmu-events starts, and
  eliminating all 5 archive builds for single-object targets like
  perf.o or util/symbol.o).
- build-test (tests/make): a single shellcheck + mypy + pylint pass
  (187 shell scripts and 52 Python files, 291 invocations) consumes
  ~272 CPU-seconds (241 s user + 32 s sys); running it once on
  make_pure_O instead of ~42 times across make build-test eliminates
  >11,000 CPU-seconds of redundant static analysis.

Tool-generated content disclosure
---------------------------------
Per Documentation/process/coding-assistants.rst and
Documentation/process/generated-content.rst, this series was developed
with AI assistance from Jetski. Across an interactive session guided by
the author, Jetski analyzed the pmu-events and prepare build
dependencies, drafted the Python, Makefile/Build, unit test, commit
message, and cover letter changes, and ran the build and regression
checks listed below.

Testing
-------
Tested on x86_64 Linux (GCC, Clang 21.1.8, bpf-gcc 16.1.0, 28 cores):
- Byte-for-byte comparison of all 137 generated JSONs, pmu-events.c,
  pmu-events-string.c, and standalone single-model CLI invocations of
  amd_metrics.py, arm64_metrics.py, and intel_metrics.py against
  pre-series baselines.
- metric_test.py (8/8 tests including test_MapfileVendorScoping),
  mypy-pmu-events, pylint-pmu-events, and
  tools/perf/tests/shell/jevents_bad_key.sh.
- Out-of-tree and in-tree builds, incremental no-op rebuilds,
  JEVENTS_ARCH={all,x86,arm64,nds32}, NO_JEVENTS=1 (including without
  python3 on PATH under NO_JEVENTS=1 NO_LIBBPF=1), NO_LIBBPF=1,
  LIBBPF_DYNAMIC=1 (with BPF skeletons), single-object builds (perf.o
  and util/symbol.o confirming no .a archives compile during prepare),
  clean, and tests/make make_minimal_O (plus command-expansion checks
  across tests/make targets).
- scripts/checkpatch.pl across all 8 patches (0 errors; only the
  expected "none none" positional args warning in pmu-events/Build).

Not tested:
- Native builds on non-x86 hosts (arm64, riscv, powerpc, s390) and
  cross-compilation builds.
- Full end-to-end "make build-test" on this branch (make_gen_vmlinux_h_O
  hit an unrelated bpf-gcc 16 C23 error on BTF-generated vmlinux.h,
  which is being fixed separately).
- Runtime execution of make_kernelsrc and make_kernelsrc_tools
  (verified by expanded command inspection only).

Ian Rogers (8):
  perf pmu-events: Ignore backup and non-event JSON files in metric.py
  perf jevents: Support --gen-dir/--gen-manifest overlay and ignore
    backups
  perf build: Avoid copying pmu-events JSON files into OUTPUT
  perf pmu-events: Batch metric generation and scope via mapfile.csv
  perf build: Batch metric JSON generation in pmu-events/Build
  perf build: Run pmu-events tests in parallel with jevents.py
  perf build: Depend on lib*-headers instead of archives in prepare
  perf tests make: Only run shellcheck, mypy and pylint in pure builds

 tools/perf/.gitignore                  |   7 +-
 tools/perf/Makefile.perf               |  81 ++++---
 tools/perf/bpf_skel.mak                |   2 +-
 tools/perf/pmu-events/Build            | 208 +++++++++---------
 tools/perf/pmu-events/amd_metrics.py   |  70 +++---
 tools/perf/pmu-events/arm64_metrics.py |  45 +++-
 tools/perf/pmu-events/intel_metrics.py |  87 +++++---
 tools/perf/pmu-events/jevents.py       | 290 +++++++++++++++++--------
 tools/perf/pmu-events/metric.py        | 185 +++++++++++++---
 tools/perf/pmu-events/metric_test.py   |  65 ++++++
 tools/perf/tests/make                  |  21 +-
 11 files changed, 718 insertions(+), 343 deletions(-)


base-commit: 114463420e8acafacaecc4f8caf15d544c3801c8
-- 
2.56.1.915.g69d5ec7298-goog

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

end of thread, other threads:[~2026-12-06  2:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  2:11 [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism Ian Rogers
2026-12-06  2:11 ` [PATCH 1/8] perf pmu-events: Ignore backup and non-event JSON files in metric.py Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 2/8] perf jevents: Support --gen-dir/--gen-manifest overlay and ignore backups Ian Rogers
2026-12-06  2:23   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 3/8] perf build: Avoid copying pmu-events JSON files into OUTPUT Ian Rogers
2026-12-06  2:26   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 4/8] perf pmu-events: Batch metric generation and scope via mapfile.csv Ian Rogers
2026-12-06  2:28   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 5/8] perf build: Batch metric JSON generation in pmu-events/Build Ian Rogers
2026-12-06  2:26   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 6/8] perf build: Run pmu-events tests in parallel with jevents.py Ian Rogers
2026-12-06  2:11 ` [PATCH 7/8] perf build: Depend on lib*-headers instead of archives in prepare Ian Rogers
2026-12-06  2:11 ` [PATCH 8/8] perf tests make: Only run shellcheck, mypy and pylint in pure builds Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:28 ` [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism sashiko-bot

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