Skip to content

perf tools: Fix thread cache race, stat per-pkg delta bug, and memory leaks

Ian Rogers linux-perf-users lkml 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 0 repliesNew
  2. v14 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Rebase onto perf-tools-next (419442c00c66).
- Patch 2: Return 0 immediately from process_counter_values() when skip is true (after computing interval deltas before check_per_pkg()) instead of falling through with a zeroed count struct, which caused evsel__count_has_error() in non-global aggregation modes (e.g. --per-socket, --per-die) to wipe out the primary CPU's package count, mark ps_aggr->failed, and increment ps_aggr->nr (Sashiko).

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4perf threads: Don't resurrect removed threads in last_matchtools/perf/util/threads.c+11 -50 replies
2/4perf stat: Skip per-pkg secondary CPUs after computing deltastools/perf/util/stat.c+4 -50 replies
3/4perf metricgroup: Fix realloc() leaks in resolve_metric() and __add_metric()tools/perf/util/metricgroup.c+13 -60 replies
4/4perf pmu: Free alias on error paths in perf_pmu__new_alias()tools/perf/util/pmu.c+4 -10 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 0/4] perf tools: Fix thread cache race, stat per-pkg delta bug, and memory leaks

Four standalone bug fixes for pre-existing issues in perf tools uncovered during Sashiko review:

1. util/threads.c: Fix a race between threads__find() and threads__remove() where dropping table->lock between lookup and updating table->last_match could resurrect a removed thread in last_match (and avoid taking down_write(&table->lock) on last_match cache hits).
2. util/stat.c: Fix process_counter_values() on skipped per-pkg secondary
CPUs: compute interval deltas before check_per_pkg() so prev_raw_counts and interval ena/run are accurate, remove the static zero struct, and return 0 when skip is true so non-global aggregation modes (such as --per-socket and --per-die) do not mark ps_aggr failed (<not counted>) or inflate ps_aggr->nr.
3. util/metricgroup.c: Fix realloc() failure memory leaks of pending in resolve_metric() and root_metric->metric_refs in __add_metric().
4. util/pmu.c: Free alias on parse_double() and io__getline() error returns in perf_pmu__new_alias().

Changes in v2:
- Rebase onto perf-tools-next (419442c00c66).
- Patch 2: Return 0 immediately from process_counter_values() when skip is true (after computing interval deltas before check_per_pkg()) instead of falling through with a zeroed count struct, which caused evsel__count_has_error() in non-global aggregation modes (e.g. --per-socket, --per-die) to wipe out the primary CPU's package count, mark ps_aggr->failed, and increment ps_aggr->nr (Sashiko).

v1: https://lore.kernel.org/linux-perf-users/[email protected]/

AI Assistance Disclosure (per Documentation/process/coding-assistants.rst and Documentation/process/generated-content.rst):
- Tools used: Sashiko automated patch review (sashiko.dev) for bug detection, and Google Antigravity / Jetski coding assistant for root cause verification and patch drafting.
- Summary of prompts and assistance: Verified pre-existing issues flagged by Sashiko during review of the perf generic hashmap series and prepared standalone fixes with Fixes tags against perf-tools-next.
- Testing performed: Built on perf-tools-next (419442c00c66) with GCC (-DREFCNT_CHECKING=1) and Clang (BUILD_NONDISTRO=1, including -Wthread-safety context analysis); verified per-pkg aggregation and interval deltas across AGGR_GLOBAL and AGGR_SOCKET; ran perf test and scripts/checkpatch.pl.

Ian Rogers (4):
perf threads: Don't resurrect removed threads in last_match perf stat: Skip per-pkg secondary CPUs after computing deltas perf metricgroup: Fix realloc() leaks in resolve_metric() and

    __add_metric()

perf pmu: Free alias on error paths in perf_pmu__new_alias()

 tools/perf/util/metricgroup.c | 19 +++++++++++++------
 tools/perf/util/pmu.c         |  5 ++++-
 tools/perf/util/stat.c        |  9 ++++-----
 tools/perf/util/threads.c     | 16 +++++++++++-----
 4 files changed, 32 insertions(+), 17 deletions(-)

base-commit: 419442c00c667d33e27db4fef9733fa966e6a149

Signature · 1 line
2.56.1.839.g22a8290db9-goog