Perf may let users override PMU events without rebuilding
Ian Rogers' series stacks user directories, compiled JSON, and kernel sysfs so events and metrics can be patched at runtime.
Linux perf may soon let developers and fleet administrators override CPU performance-monitoring events and metrics from ordinary directories, instead of editing JSON and rebuilding the tool.
Ian Rogers posted an 11-patch series that puts event aliases, metrics, and metric-group descriptions behind one layered lookup. Today perf draws event names from two fixed places: kernel sysfs under each PMU, and tables compiled into the binary. Metrics are read only from those built-in tables and are not tied to a PMU object. Adding or testing an encoding, a description, or a metric means a rebuild. Metrics cannot be supplied or overridden at runtime. Looking up a single event, such as cycles, also walks the whole sysfs events directory rather than opening that event on demand.
The proposed stack, set with a new pmu-events.dir option in perf's config, searches from highest to lowest priority: colon-separated user or system directories, compiled CPUID and system tables, kernel sysfs, then generic compiled fallbacks. That order keeps today's rules. Architecture-specific JSON can still replace a sysfs encoding, which matters on platforms such as RISC-V that map old event names to CPU-specific encodings without enlarging the kernel driver. Sysfs events still beat generic legacy fallbacks.
A single-event lookup would open only the named file and its sidecar attributes (scale, unit, description, and similar) instead of scanning every event. When the config option is unset, the user layer is skipped so there is no extra syscall cost.
Overlay trees can be host-local files or portable layouts keyed by CPUID, with symlinks from exact and stepping-stripped identifiers to model directories. Heterogeneous cores resolve against their own CPUID. Rogers also adds exporters: perf list can write the running machine's events and metrics to disk, and a new export option can dump compiled-in tables for another CPUID, model, or architecture straight from the perf binary, without the kernel's JSON sources. Edited files can be pointed back at perf through the same config option, so a stepping-specific description or a local metric sits above the built-in data.