[PATCH v8 00/17] perf symbol/env: ELF machine clean up and lazy idle computation

Ian Rogers
2026-05-02T06:59:53Z

Add a helper to perf_env to compute the e_machine if it is EM_NONE.
Derive the value from the arch string if available. Similarly derive
the arch string from the ELF machine if available, for
consistency. This means perf's arch (machine type) is no longer
determined by uname but set to match that of the perf ELF executable.

Switch the idle computation to the point of use and lazily compute it,
rather than computing it for every symbol. The current only user is
`perf top`. At the point of use the perf_env is available and this can
be used to make sure the idle function computation is machine and
kernel version dependent.

To avoid concurrent update issues with bitfields sharing a byte in
`struct symbol` due to the lazy computation, introduce a global lock
for updates to these fields and use setter functions. The reads remain
lockless.

v8:
- Address Sashiko AI review feedback for Patch 1:
- Switch all code dependent on the arch string to use `e_machine`
instead (e.g., in `perf c2c`, `perf lock-contention`, `perf
header`, `perf arch common`, `tests/topology.c`,
`perf_env__init_kernel_mode`).
- Update `machine__is` and `machine__normalized_is` to take
`e_machine` integers instead of strings.
- Refactor `arch_syscalls__strerrno_function` (generated via
`arch_errno_names.sh`) to take an `e_machine` instead of an arch
string.
- Avoid premature caching of the host architecture in
`perf_session__e_machine` by using a non-caching helper when
threads are not yet available.

v7:
- Address better handling of strdup failures with arch in the
header/env.
- Address concurrent update issues in `struct symbol` bitfields by
introducing a global lock for writes.
https://lore.kernel.org/linux-perf-users/20260501182021.3651851-1-irogers@google.com/

v6: Ensure arch is canonical by going to e_machine and back (Sashiko)
https://lore.kernel.org/linux-perf-users/20260409230620.4176210-1-irogers@google.com/

v5: Add perf_env os_release helper (Namhyung/Sashiko)
https://lore.kernel.org/lkml/20260406170905.2614260-1-irogers@google.com/

v4: Fix Sashiko issues where an array element wasn't sorted properly,
the e_flags weren't returned properly, the idle type is change to
a u8 rather than an enum value and the s390 version check for
psw_idle is slightly reordered and tweaked.
https://lore.kernel.org/lkml/20260327045025.2276517-1-irogers@google.com/

v3: Properly set up the e_machine coming from the perf_env as reported
by Honglei Wang.
https://lore.kernel.org/lkml/20260326174521.1829203-1-irogers@google.com/

v2: Some minor white space clean up:
https://lore.kernel.org/lkml/20260325161836.1029457-1-irogers@google.com/

v1: https://lore.kernel.org/lkml/20260302234343.564937-1-irogers@google.com/

Ian Rogers (17):
perf env: Add perf_env__e_machine helper and use in perf_env__arch
perf tests topology: Switch env->arch use to env->e_machine
perf capstone: Determine architecture from e_machine
perf print_insn: Use e_machine for fallback IP length check
perf machine: Use perf_env e_machine rather than arch
perf sample-raw: Use perf_env e_machine rather than arch
perf sort: Use perf_env e_machine rather than arch
perf symbol: Avoid use of machine__is
perf arch common: Use perf_env e_machine rather than arch
perf header: In print_pmu_caps use perf_env e_machine
perf c2c: Use perf_env e_machine rather than arch
perf lock-contention: Use perf_env e_machine rather than arch
perf env: Refactor perf_env__arch_strerrno
perf env: Remove unused perf_env__raw_arch
perf env: Add helper to lazily compute the os_release
perf symbol: Add setters for bitfields sharing a byte to avoid
concurrent update issues
perf symbol: Lazily compute idle and use a global lock for updates

tools/perf/arch/common.c | 55 ++--
tools/perf/builtin-c2c.c | 2 +-
tools/perf/builtin-kwork.c | 2 +-
tools/perf/builtin-sched.c | 2 +-
tools/perf/builtin-trace.c | 5 +-
tools/perf/tests/topology.c | 8 +-
tools/perf/trace/beauty/arch_errno_names.sh | 40 ++-
tools/perf/util/annotate.c | 2 +-
tools/perf/util/capstone.c | 115 +++++---
tools/perf/util/data-convert-bt.c | 2 +-
tools/perf/util/env.c | 283 +++++++++++++++-----
tools/perf/util/env.h | 11 +-
tools/perf/util/header.c | 70 +++--
tools/perf/util/lock-contention.c | 6 +-
tools/perf/util/machine.c | 25 +-
tools/perf/util/machine.h | 2 -
tools/perf/util/print_insn.c | 8 +-
tools/perf/util/sample-raw.c | 18 +-
tools/perf/util/session.c | 26 +-
tools/perf/util/sort.c | 12 +-
tools/perf/util/symbol-elf.c | 2 +-
tools/perf/util/symbol.c | 163 +++++++----
tools/perf/util/symbol.h | 17 +-
23 files changed, 612 insertions(+), 264 deletions(-)

--
2.54.0.545.g6539524ca2-goog