Skip to contentSkip to conversation

House keeping for the perf PMU dump/reset code

PATCH New Andi Kleen 2 participants 7 messages Feb 27, 2015 – Apr 2, 2015

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

The perf core PMU driver has functions to dump the PMU, and also reset it when something goes wrong. These code paths hadn't quite keep up with newer PMU features.

This patchkit fixes various issues.

Shouldn't make a difference unless something goes wrong with the PMU.

-Andi

author
#1 lore raw

PATCH 1/3 perf, x86: Reset more state in PMU reset

From: Andi Kleen <[email protected]>

The PMU reset code didn't quite keep up with newer PMU features. Improve it a bit to really reset a modern PMU:

- Clear all overflow status
- Clear LBRs and freezing state
- Disable fixed counters too

---
 arch/x86/kernel/cpu/perf_event_intel.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/kernel/cpu/perf_event_intel.c +11 -0
index 3c024ba..0a48094 100644
@@ -1596,6 +1596,17 @@ static void intel_pmu_reset(void)
 	if (ds)
 		ds->bts_index = ds->bts_buffer_base;
 
+	/* Ack all overflows and disable fixed counters */
+	if (x86_pmu.version >= 2) {
+		intel_pmu_ack_status(intel_pmu_get_status());
+		wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
+	}
+
+	/* Reset LBRs and LBR freezing */
+	if (x86_pmu.lbr_nr)
+		update_debugctlmsr(get_debugctlmsr() &
+			~(DEBUGCTLMSR_FREEZE_LBRS_ON_PMI|DEBUGCTLMSR_LBR));
+
 	local_irq_restore(flags);
 }
 
Signature · 1 line
1.9.3
#2 lore raw

[tip:perf/core] perf/x86/intel: Reset more state in PMU reset

perf/x86/intel: Reset more state in PMU reset
Commit-ID:  8882edf735738c949aba4b65d3ec3453066bab12
Gitweb:     http://git.kernel.org/tip/8882edf735738c949aba4b65d3ec3453066bab12
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 27 Feb 2015 09:48:30 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 2 Apr 2015 17:33:16 +0200

perf/x86/intel: Reset more state in PMU reset

The PMU reset code didn't quite keep up with newer PMU features. Improve it a bit to really reset a modern PMU:

- Clear all overflow status
- Clear LBRs and freezing state
- Disable fixed counters too

---
 arch/x86/kernel/cpu/perf_event_intel.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/x86/kernel/cpu/perf_event_intel.c +12 -0
index 6ea61a5..5999460 100644
@@ -1538,6 +1538,18 @@ static void intel_pmu_reset(void)
 	if (ds)
 		ds->bts_index = ds->bts_buffer_base;
 
+	/* Ack all overflows and disable fixed counters */
+	if (x86_pmu.version >= 2) {
+		intel_pmu_ack_status(intel_pmu_get_status());
+		wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
+	}
+
+	/* Reset LBRs and LBR freezing */
+	if (x86_pmu.lbr_nr) {
+		update_debugctlmsr(get_debugctlmsr() &
+			~(DEBUGCTLMSR_FREEZE_LBRS_ON_PMI|DEBUGCTLMSR_LBR));
+	}
+
 	local_irq_restore(flags);
 }
 
author
#3 lore raw

PATCH 2/3 perf, x86: Dump DEBUGCTL in pmu dump

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

LBRs and LBR freezing are controlled through DEBUGCTL. So dump the state of DEBUGCTL too when dumping the PMU state.

---
 arch/x86/kernel/cpu/perf_event.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +5 -1
index 01b6f3a..1579a46 100644
@@ -1105,7 +1105,7 @@ static void x86_pmu_start(struct perf_event *event, int flags)
 void perf_event_print_debug(void)
 {
 	u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed;
-	u64 pebs;
+	u64 pebs, debugctl;
 	struct cpu_hw_events *cpuc;
 	unsigned long flags;
 	int cpu, idx;
@@ -1131,6 +1131,10 @@ void perf_event_print_debug(void)
 		pr_info("CPU#%d: overflow:   %016llx\n", cpu, overflow);
 		pr_info("CPU#%d: fixed:      %016llx\n", cpu, fixed);
 		pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		if (x86_pmu.lbr_nr) {
+			rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+			pr_info("CPU#%d: debugctl:   %016llx\n", cpu, debugctl);
+		}
 	}
 	pr_info("CPU#%d: active:     %016llx\n", cpu, *(u64 *)cpuc->active_mask);
 
Signature · 1 line
1.9.3
#4 lore raw

[tip:perf/core] perf/x86: Dump DEBUGCTL in PMU dump

perf/x86: Dump DEBUGCTL in PMU dump
Commit-ID:  da3e606d885a17525eb18afd423f5c438860b833
Gitweb:     http://git.kernel.org/tip/da3e606d885a17525eb18afd423f5c438860b833
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 27 Feb 2015 09:48:31 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 2 Apr 2015 17:33:17 +0200

perf/x86: Dump DEBUGCTL in PMU dump

LBRs and LBR freezing are controlled through the DEBUGCTL MSR. So dump the state of DEBUGCTL too when dumping the PMU state.

---
 arch/x86/kernel/cpu/perf_event.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +5 -1
index b8b7a12..9947372 100644
@@ -1171,7 +1171,7 @@ static void x86_pmu_start(struct perf_event *event, int flags)
 void perf_event_print_debug(void)
 {
 	u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed;
-	u64 pebs;
+	u64 pebs, debugctl;
 	struct cpu_hw_events *cpuc;
 	unsigned long flags;
 	int cpu, idx;
@@ -1197,6 +1197,10 @@ void perf_event_print_debug(void)
 		pr_info("CPU#%d: overflow:   %016llx\n", cpu, overflow);
 		pr_info("CPU#%d: fixed:      %016llx\n", cpu, fixed);
 		pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		if (x86_pmu.lbr_nr) {
+			rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+			pr_info("CPU#%d: debugctl:   %016llx\n", cpu, debugctl);
+		}
 	}
 	pr_info("CPU#%d: active:     %016llx\n", cpu, *(u64 *)cpuc->active_mask);
 
author
#5 lore raw

PATCH 3/3 perf, x86: Only dump PEBS register when PEBS has been detected

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Technically PEBS_ENABLED is only guaranteed to exist when we detected PEBS. So add a check for this to the PMU dump function. I don't think it can happen on a real CPU, but could in a VM.

---
 arch/x86/kernel/cpu/perf_event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.c +4 -2
index 1579a46..bca85ca 100644
@@ -1123,14 +1123,16 @@ void perf_event_print_debug(void)
 		rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
 		rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow);
 		rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed);
-		rdmsrl(MSR_IA32_PEBS_ENABLE, pebs);
 
 		pr_info("\n");
 		pr_info("CPU#%d: ctrl:       %016llx\n", cpu, ctrl);
 		pr_info("CPU#%d: status:     %016llx\n", cpu, status);
 		pr_info("CPU#%d: overflow:   %016llx\n", cpu, overflow);
 		pr_info("CPU#%d: fixed:      %016llx\n", cpu, fixed);
-		pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		if (x86_pmu.pebs_constraints) {
+			rdmsrl(MSR_IA32_PEBS_ENABLE, pebs);
+			pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		}
 		if (x86_pmu.lbr_nr) {
 			rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
 			pr_info("CPU#%d: debugctl:   %016llx\n", cpu, debugctl);
Signature · 1 line
1.9.3
#6 lore raw

[tip:perf/core] perf/x86: Only dump PEBS register when PEBS has been detected

perf/x86: Only dump PEBS register when PEBS has been detected
Commit-ID:  15fde1101a1aed11958e0d86bc360f01866a74b1
Gitweb:     http://git.kernel.org/tip/15fde1101a1aed11958e0d86bc360f01866a74b1
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 27 Feb 2015 09:48:32 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 2 Apr 2015 17:33:17 +0200

perf/x86: Only dump PEBS register when PEBS has been detected

Technically PEBS_ENABLED is only guaranteed to exist when we detected PEBS. So add a check for this to the PMU dump function. I don't think it can happen on a real CPU, but could in a VM.

---
 arch/x86/kernel/cpu/perf_event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.c +4 -2
index 9947372..689e357 100644
@@ -1189,14 +1189,16 @@ void perf_event_print_debug(void)
 		rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
 		rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow);
 		rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed);
-		rdmsrl(MSR_IA32_PEBS_ENABLE, pebs);
 
 		pr_info("\n");
 		pr_info("CPU#%d: ctrl:       %016llx\n", cpu, ctrl);
 		pr_info("CPU#%d: status:     %016llx\n", cpu, status);
 		pr_info("CPU#%d: overflow:   %016llx\n", cpu, overflow);
 		pr_info("CPU#%d: fixed:      %016llx\n", cpu, fixed);
-		pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		if (x86_pmu.pebs_constraints) {
+			rdmsrl(MSR_IA32_PEBS_ENABLE, pebs);
+			pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
+		}
 		if (x86_pmu.lbr_nr) {
 			rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
 			pr_info("CPU#%d: debugctl:   %016llx\n", cpu, debugctl);