Re: perf failed with kernel 2.6.35-rc

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Zhang, Yanmin
Date: Wednesday, July 14, 2010 - 1:15 am

On Wed, 2010-07-14 at 08:49 +0800, Zhang, Yanmin wrote:
It doesn't work.

I copied the PMU dumping of logical processor 0.

Besides status register's bit0 is equal to 0, PMC0 count is small. So it takes
a long time to overflow.


CPU#0: ctrl:       000000070000000f
CPU#0: status:     0000000000000001
CPU#0: overflow:   0000000000000000
CPU#0: fixed:      0000000000000000
CPU#0: pebs:       0000000000000000
CPU#0: active:     0000000000000001
CPU#0:   gen-PMC0 ctrl:  000000000053003c
CPU#0:   gen-PMC0 count: 00000000549bffd9
CPU#0:   gen-PMC0 left:  0000000000000002
CPU#0:   gen-PMC1 ctrl:  00000000004300b1
CPU#0:   gen-PMC1 count: 0000000000000000
CPU#0:   gen-PMC1 left:  0000000000000000
CPU#0:   gen-PMC2 ctrl:  00000000004300b5
CPU#0:   gen-PMC2 count: 0000000000000000
CPU#0:   gen-PMC2 left:  0000000000000000
CPU#0:   gen-PMC3 ctrl:  0000000000000000
CPU#0:   gen-PMC3 count: 0000000000000000
CPU#0:   gen-PMC3 left:  0000000000000000
CPU#0: fixed-PMC0 count: 0000000000000000
CPU#0: fixed-PMC1 count: 0000000000000000
CPU#0: fixed-PMC2 count: 0000000000000000
SysRq : Show Regs


I instrumented function intel_pmu_nhm_enable_all to check
PMC0 count register before the workaround and after disabling
the 3 bits of MSR_CORE_PERF_GLOBAL_CTRL. It's changed unexpectedly.
below is a debug output about processor 0.

PMU register counter is changed. before[281474976710654] after[1]

So I think the event 0x4300D2 overflows. We need do a save and restore.
Below patch fixes it.

Yanmin

---

--- linux-2.6.35-rc5/arch/x86/kernel/cpu/perf_event_intel.c	2005-01-01 13:19:50.800000253 +0800
+++ linux-2.6.35-rc5_perf/arch/x86/kernel/cpu/perf_event_intel.c	2005-01-01 16:01:35.324000300 +0800
@@ -499,21 +499,34 @@ static void intel_pmu_nhm_enable_all(int
 {
 	if (added) {
 		struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+		struct perf_event *event;
 		int i;
 
+		for (i = 0; i < 3; i++) {
+			event = cpuc->events[i];
+			if (!event)
+				continue;
+			x86_perf_event_update(event);
+		}
 		wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 0, 0x4300D2);
 		wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x4300B1);
 		wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x4300B5);
 
-		wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x3);
+		wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x7);
 		wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
+		/*
+		 * Reset the last 3 bits of global status register in case
+		 * previous enabling causes overflows.
+		 */
+		wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, 0x7);
 
 		for (i = 0; i < 3; i++) {
-			struct perf_event *event = cpuc->events[i];
+			event = cpuc->events[i];
 
 			if (!event)
 				continue;
 
+			x86_perf_event_set_period(event);
 			__x86_pmu_enable_event(&event->hw,
 					       ARCH_PERFMON_EVENTSEL_ENABLE);
 		}


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Tue Jul 13, 1:14 am)
Re: perf failed with kernel 2.6.35-rc, Ingo Molnar, (Tue Jul 13, 1:50 am)
Re: perf failed with kernel 2.6.35-rc, Stephane Eranian, (Tue Jul 13, 8:16 am)
Re: perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Tue Jul 13, 5:13 pm)
Re: perf failed with kernel 2.6.35-rc, Stephane Eranian, (Tue Jul 13, 5:36 pm)
Re: perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Tue Jul 13, 5:49 pm)
Re: perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Tue Jul 13, 7:22 pm)
Re: perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Wed Jul 14, 1:15 am)
Re: perf failed with kernel 2.6.35-rc, Peter Zijlstra, (Tue Aug 3, 5:20 am)
Re: perf failed with kernel 2.6.35-rc, Stephane Eranian, (Wed Aug 4, 8:48 am)
Re: perf failed with kernel 2.6.35-rc, Zhang, Yanmin, (Thu Aug 5, 10:39 pm)
[tip:perf/urgent] perf, x86: Fix Intel-nhm PMU programming ..., tip-bot for Zhang, Y ..., (Wed Aug 18, 3:27 am)