Skip to contentSkip to conversation

x86/perf: Enable free running pebs for REGS_USER/INTR

PATCH New Andi Kleen 1 participant 1 message Sep 5, 2017

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH v2 1/1 x86/perf: Enable free running pebs for REGS_USER/INTR

From: Andi Kleen <[email protected]>

Currently free running PEBS is disabled when user or interrupt registers are requested. Most of the registers are actually available in the PEBS record and can be supported.

So we just need to check for the supported registers and then allow it: it is all except for the segment register.

For user registers this only works when the counter is limited to ring 3 only, so this also needs to be checked.

v2: Correctly check intr regs too.

---
 arch/x86/events/intel/core.c |  5 +++++
 arch/x86/events/perf_event.h | 24 +++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +5 -0
index 829e89cfcee2..146595217051 100644
@@ -2958,6 +2958,11 @@ static unsigned long intel_pmu_free_running_flags(struct perf_event *event)
 
 	if (event->attr.use_clockid)
 		flags &= ~PERF_SAMPLE_TIME;
+	if (!event->attr.exclude_kernel)
+		flags &= ~PERF_SAMPLE_REGS_USER;
+	if ((event->attr.sample_regs_user | event->attr.sample_regs_intr)
+			& ~PEBS_REGS)
+		flags &= ~(PERF_SAMPLE_REGS_USER | PERF_SAMPLE_REGS_INTR);
 	return flags;
 }
 
arch/x86/events/perf_event.h +23 -1
index 4196f81ec0e1..f7aaadf9331f 100644
@@ -85,13 +85,15 @@ struct amd_nb {
  * Flags PEBS can handle without an PMI.
  *
  * TID can only be handled by flushing at context switch.
+ * REGS_USER can be handled for events limited to ring 3.
  *
  */
 #define PEBS_FREERUNNING_FLAGS \
 	(PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | \
 	PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | \
 	PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | \
-	PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR)
+	PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR | \
+	PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER)
 
 /*
  * A debug store configuration.
@@ -110,6 +112,26 @@ struct debug_store {
 	u64	pebs_event_reset[MAX_PEBS_EVENTS];
 };
 
+#define PEBS_REGS \
+	(PERF_REG_X86_AX | \
+	 PERF_REG_X86_BX | \
+	 PERF_REG_X86_CX | \
+	 PERF_REG_X86_DX | \
+	 PERF_REG_X86_DI | \
+	 PERF_REG_X86_SI | \
+	 PERF_REG_X86_SP | \
+	 PERF_REG_X86_BP | \
+	 PERF_REG_X86_IP | \
+	 PERF_REG_X86_FLAGS | \
+	 PERF_REG_X86_R8 | \
+	 PERF_REG_X86_R9 | \
+	 PERF_REG_X86_R10 | \
+	 PERF_REG_X86_R11 | \
+	 PERF_REG_X86_R12 | \
+	 PERF_REG_X86_R13 | \
+	 PERF_REG_X86_R14 | \
+	 PERF_REG_X86_R15)
+
 /*
  * Per register state.
  */
Signature · 1 line
2.9.5