Skip to content

perf: Fix libdw addr2line fallback, pr_debugN overhead, and cumulative hist decay

Ian Rogers linux-perf-users lkml 1 version Applied

Status from this message: Thanks, applied for v7.4.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 1 replyApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/3perf libdw: Optimize fallback logic for missing DWARFtools/perf/util/addr2line.c tools/perf/util/dso.h tools/perf/util/libbfd.c +5 more+115 -500 replies
2/3perf debug: Avoid calling eprintf() in pr_debugN() when verbose < ntools/perf/tests/pmu-events.c tools/perf/util/debug.h+6 -40 replies
3/3perf hist: Do not delete cumulative caller entries before stat_acc decaystools/perf/util/hist.c+4 -20 replies

Reviews trailers per patch

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

Read the v1 thread

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

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/[email protected]/
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(-)
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog