perf/x86/intel: Support PEBS counters snapshotting
authorKan Liang <kan.liang@linux.intel.com>
Tue, 21 Jan 2025 15:23:03 +0000 (07:23 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 5 Feb 2025 09:29:45 +0000 (10:29 +0100)
commite02e9b0374c378aab016ae8ace60d9d98ab8caa6
tree4c59747dc3d42366e2506195310b8ca5c013c90c
parent8ce939a0fa194939cc1f92dbd8bc1a7806e7d40a
perf/x86/intel: Support PEBS counters snapshotting

The counters snapshotting is a new adaptive PEBS extension, which can
capture programmable counters, fixed-function counters, and performance
metrics in a PEBS record. The feature is available in the PEBS format
V6.

The target counters can be configured in the new fields of MSR_PEBS_CFG.
Then the PEBS HW will generate the bit mask of counters (Counters Group
Header) followed by the content of all the requested counters into a
PEBS record.

The current Linux perf sample read feature can read all events in the
group when any event in the group is overflowed. But the rdpmc in the
NMI/overflow handler has a small gap from overflow. Also, there is some
overhead for each rdpmc read. The counters snapshotting feature can be
used as an accurate and low-overhead replacement.

Extend intel_update_topdown_event() to accept the value from PEBS
records.

Add a new PEBS_CNTR flag to indicate a sample read group that utilizes
the counters snapshotting feature. When the group is scheduled, the
PEBS configure can be updated accordingly.

To prevent the case that a PEBS record value might be in the past
relative to what is already in the event, perf always stops the PMU and
drains the PEBS buffer before updating the corresponding event->count.

Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250121152303.3128733-4-kan.liang@linux.intel.com
arch/x86/events/core.c
arch/x86/events/intel/core.c
arch/x86/events/intel/ds.c
arch/x86/events/perf_event.h
arch/x86/events/perf_event_flags.h
arch/x86/include/asm/perf_event.h