perf/x86/intel: Support RDPMC metrics clear mode
authorKan Liang <kan.liang@linux.intel.com>
Wed, 11 Dec 2024 16:03:17 +0000 (08:03 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 20 Dec 2024 14:31:22 +0000 (15:31 +0100)
commit0e45818ec1896c2b4aee0ec6721022ad625ea531
treeef65131c6b6dee47bdd5fa62f14e225f9faf4623
parent02c56362a7d3eccc209d5c00d73a06513d2504d5
perf/x86/intel: Support RDPMC metrics clear mode

The new RDPMC enhancement, metrics clear mode, is to clear the
PERF_METRICS-related resources as well as the fixed-function performance
monitoring counter 3 after the read is performed. It is available for
ring 3. The feature is enumerated by the
IA32_PERF_CAPABILITIES.RDPMC_CLEAR_METRICS[bit 19]. To enable the
feature, the IA32_FIXED_CTR_CTRL.METRICS_CLEAR_EN[bit 14] must be set.

Two ways were considered to enable the feature.
- Expose a knob in the sysfs globally. One user may affect the
  measurement of other users when changing the knob. The solution is
  dropped.
- Introduce a new event format, metrics_clear, for the slots event to
  disable/enable the feature only for the current process. Users can
  utilize the feature as needed.
The latter solution is implemented in the patch.

The current KVM doesn't support the perf metrics yet. For
virtualization, the feature can be enabled later separately.

Suggested-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lkml.kernel.org/r/20241211160318.235056-1-kan.liang@linux.intel.com
arch/x86/events/intel/core.c
arch/x86/events/perf_event.h
arch/x86/include/asm/perf_event.h