[PATCH 0/3] perf: Fix libdw addr2line fallback, pr_debugN overhead, and cumulative hist decay

From: Ian Rogers

Date: Mon Oct 26 2026 - 02:52:01 EST


Three standalone fixes found while profiling `perf top` and DSO symbol/DWARF
resolution:

1. **perf libdw: Optimize fallback logic for missing DWARF**:
`libdw__addr2line()` previously returned `-1` when `dwfl_module_getdwarf()`
or `dwfl_module_getsrc()` returned `NULL`, while `addr2line()` in
`srcline.c` only stopped its fallback loop on `ret > 0`. This caused
`perf` to fall back through `llvm`, `libbfd`, and the external
`addr2line` subprocess on every stripped DSO or unmapped address, and
kept the `Dwfl` ELF mmap open on stripped binaries. Standardize backend
return values so `0` denotes conclusively missing DWARF/line info
(stopping the fallback loop and freeing the `Dwfl` session when no
DWARF exists), `< 0` denotes backend/initialization error, and `> 0`
denotes resolved source line info.
An earlier version of this patch was posted at:
https://lore.kernel.org/linux-perf-users/20260824062841.1529489-3-irogers@xxxxxxxxxx/
This version addresses the review feedback from that thread.

2. **perf debug: Avoid calling eprintf() in pr_debugN() when verbose < n**:
`pr_debugN()` unconditionally evaluated its arguments and called
`eprintf()` -> `veprintf()` before checking `verbose >= n`, accounting
for ~15% of total CPU time in `perf top` during ELF symbol loading even
at default `verbose == 0`. Guard `eprintf()` with `unlikely(verbose >= (n))`.

3. **perf hist: Do not delete cumulative caller entries before stat_acc decays**:
When `symbol_conf.cumulate_callchain` is enabled (`perf top -g`),
callchain caller entries with `he->stat.period == 0` were deleted on the
first `hists__decay_entries()` pass even while `he->stat_acc->period > 0`.
Require `he->stat_acc->period == 0` before deleting entries in
cumulative mode.

Assisted-by: Antigravity:gemini-3.1-pro

Ian Rogers (3):
perf libdw: Optimize fallback logic for missing DWARF
perf debug: Avoid calling eprintf() in pr_debugN() when verbose < n
perf hist: Do not delete cumulative caller entries before stat_acc
decays

tools/perf/tests/pmu-events.c | 5 ++-
tools/perf/util/addr2line.c | 28 ++++++++++---
tools/perf/util/debug.h | 5 +--
tools/perf/util/dso.h | 2 +-
tools/perf/util/hist.c | 6 ++-
tools/perf/util/libbfd.c | 6 +--
tools/perf/util/libdw.c | 25 ++++++++---
tools/perf/util/libdw.h | 5 ++-
tools/perf/util/llvm-c-helpers.cpp | 66 +++++++++++++++++++-----------
tools/perf/util/llvm.c | 12 ++++--
tools/perf/util/srcline.c | 21 +++++++---
11 files changed, 125 insertions(+), 56 deletions(-)

--
2.56.0.307.g5fe7bd680c-goog