[PATCH 0/2] perf/x86/amd/uncore: Drop redundant counter slot searches
From: Usama Arif
Date: Mon Sep 21 2026 - 13:15:32 EST
Both amd_uncore_add() and amd_uncore_del() search ctx->events[] for an
event whose counter slot is already recorded in event->hw.idx.
Perf serializes ->add() and ->del() for an event, and the driver never
moves an installed event between slots, so an installed event can only
be at the recorded index. Both searches are redundant.
Neither callback is normally hot. That changes once more events target
a PMU than it has counters. Perf then multiplexes them: every mux tick
deschedules the resident set and schedules the next one, so both callbacks
run for each rotated event on every tick.
Meta's fleet-wide profiles attribute 1.1% of kernel CPU time, excluding
do_idle(), to amd_uncore_add() and amd_uncore_del() combined. On the
host that exposed this, a workload holding 15,782 perf event file
descriptors drove 56,575 calls per second into each callback from mux
rotation, against a 16-counter DF PMU.
Patch 1 removes the scan in amd_uncore_add(). It walks every counter
before the free slot search, which is the common case once multiplexing
has scheduled the event out.
Patch 2 makes amd_uncore_del() free the recorded slot directly instead
of rescanning from slot zero. Deleting all events from a full PMU with
N counters drops from N * (N + 1) / 2 compare-exchanges to N.
No functional change intended.
Usama Arif (2):
perf/x86/amd/uncore: Remove redundant event slot scan
perf/x86/amd/uncore: Free counter slot by index
arch/x86/events/amd/uncore.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
--
2.53.0-Meta