perf gains runtime overlays for PMU events and metrics
Ian Rogers' series lets users override event encodings and metrics from directories, without rebuilding perf or rescanning every sysfs event.
Linux perf is set to stop treating PMU event aliases and metrics as something you can change only by editing JSON and rebuilding the tool. Ian Rogers has posted an 11-patch series that puts events, metrics, and metric-group descriptions behind a layered directory stack on each PMU, so a developer or fleet administrator can override them at runtime.
Today perf draws event aliases from two fixed places: the kernel's sysfs event files and tables compiled into the binary. Metrics and metric-group text come only from those compiled-in tables, and they are not tied to a particular PMU. Adding or testing an encoding, a description, or a metric means a rebuild. Looking up a single event, as in a simple perf stat -e cycles, also walks the whole sysfs events directory instead of opening the one file it needs. Metrics cannot be supplied or overridden from a directory tree at all.
The series, which sits on earlier work that stores compiled-in event and metric strings in independently compressed blocks, resolves names through four layers, highest priority first: user or system directories named in a new pmu-events.dir perf config setting; compiled-in tables matched to the CPU or system PMU; kernel sysfs; and compiled-in generic fallbacks. That order keeps today's rule that architecture JSON can override a sysfs encoding, which matters for cases such as RISC-V mapping legacy event names to CPU-specific encodings without enlarging the kernel driver, while sysfs still beats generic legacy-hardware and legacy-cache fallbacks.
Directories can be colon-separated, with home-directory expansion, and support both host-local files and portable trees keyed by CPUID or uncore identifier via ordinary symlinks. No runtime map file or regular-expression engine is required. Stepping-specific names are tried before a stripped base CPUID, and heterogeneous core PMUs resolve against their own CPU. If the config option is unset, the user layer is omitted and adds no extra syscalls. Attribute files are opened on demand; the first non-empty value wins, so a stepping fixup can replace a description without replacing the encoding underneath.
Two exporters make the same layout writable. perf list --export-dir dumps the running machine's events and metrics as files that can be edited and layered back. A companion option can materialize any compiled-in CPUID, model, or architecture from the perf binary itself, without a kernel source tree. The JSON generator can also emit a multi-architecture tree of model directories and CPUID symlinks.