Skip to contentSkip to conversation

perf, x86: Add Nehelem PMU programming errata workaround

PATCH In review Peter Zijlstra 3 participants 6 messages Mar 26, 2010 – Mar 28, 2010

Subsystems (2)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

PATCH 1/1 perf, x86: Add Nehelem PMU programming errata workaround

Subject: perf, x86: Add Nehelem PMU programming errata workaround
From: Peter Zijlstra <[email protected]>
Date: Fri Mar 26 13:59:41 CET 2010

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

---
(compile tested only, since I don't actually have an affected chip)

 arch/x86/kernel/cpu/perf_event.c       |    8 +++---
 arch/x86/kernel/cpu/perf_event_intel.c |   43 +++++++++++++++++++++++++++++----
 arch/x86/kernel/cpu/perf_event_p4.c    |    2 -
 arch/x86/kernel/cpu/perf_event_p6.c    |    2 -
 4 files changed, 45 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/perf_event.c +4 -4
Index: linux-2.6/arch/x86/kernel/cpu/perf_event.c
===================================================================
@@ -185,7 +185,7 @@ struct x86_pmu {
 	int		version;
 	int		(*handle_irq)(struct pt_regs *);
 	void		(*disable_all)(void);
-	void		(*enable_all)(void);
+	void		(*enable_all)(int added);
 	void		(*enable)(struct perf_event *);
 	void		(*disable)(struct perf_event *);
 	int		(*hw_config)(struct perf_event_attr *attr, struct hw_perf_event *hwc);
@@ -577,7 +577,7 @@ void hw_perf_disable(void)
 	x86_pmu.disable_all();
 }
 
-static void x86_pmu_enable_all(void)
+static void x86_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
@@ -785,7 +785,7 @@ void hw_perf_enable(void)
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	struct perf_event *event;
 	struct hw_perf_event *hwc;
-	int i;
+	int i, added = cpuc->n_added;
 
 	if (!x86_pmu_initialized())
 		return;
@@ -837,7 +837,7 @@ void hw_perf_enable(void)
 	cpuc->enabled = 1;
 	barrier();
 
-	x86_pmu.enable_all();
+	x86_pmu.enable_all(added);
 }
 
 static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc)
arch/x86/kernel/cpu/perf_event_intel.c +39 -4

73 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_p4.c +1 -1
Index: linux-2.6/arch/x86/kernel/cpu/perf_event_p4.c
===================================================================
@@ -423,7 +423,7 @@ static void p4_pmu_enable_event(struct p
 		(u64)(p4_config_unpack_cccr(hwc->config)) | P4_CCCR_ENABLE);
 }
 
-static void p4_pmu_enable_all(void)
+static void p4_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
arch/x86/kernel/cpu/perf_event_p6.c +1 -1
Index: linux-2.6/arch/x86/kernel/cpu/perf_event_p6.c
===================================================================
@@ -66,7 +66,7 @@ static void p6_pmu_disable_all(void)
 	wrmsrl(MSR_P6_EVNTSEL0, val);
 }
 
-static void p6_pmu_enable_all(void)
+static void p6_pmu_enable_all(int added)
 {
 	unsigned long val;
 
author maintainer
#1 lore raw
Commit-ID:  1ac62cfff252fb668405ef3398a1fa7f4a0d6d15
Gitweb:     http://git.kernel.org/tip/1ac62cfff252fb668405ef3398a1fa7f4a0d6d15
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Fri, 26 Mar 2010 14:08:44 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 26 Mar 2010 14:12:44 +0100

perf, x86: Add Nehelem PMU programming errata workaround

workaround From: Peter Zijlstra <[email protected]>
Date: Fri Mar 26 13:59:41 CET 2010

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

Cc Stephane Eranian <[email protected]>

LKML-Reference: <1269608924.12097.147.camel@laptop>

---
 arch/x86/kernel/cpu/perf_event.c       |    8 +++---
 arch/x86/kernel/cpu/perf_event_intel.c |   43 +++++++++++++++++++++++++++++---
 arch/x86/kernel/cpu/perf_event_p4.c    |    2 +-
 arch/x86/kernel/cpu/perf_event_p6.c    |    2 +-
 4 files changed, 45 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/perf_event.c +4 -4
index f571f51..6f66d4a 100644
@@ -184,7 +184,7 @@ struct x86_pmu {
 	int		version;
 	int		(*handle_irq)(struct pt_regs *);
 	void		(*disable_all)(void);
-	void		(*enable_all)(void);
+	void		(*enable_all)(int added);
 	void		(*enable)(struct perf_event *);
 	void		(*disable)(struct perf_event *);
 	int		(*hw_config)(struct perf_event_attr *attr, struct hw_perf_event *hwc);
@@ -576,7 +576,7 @@ void hw_perf_disable(void)
 	x86_pmu.disable_all();
 }
 
-static void x86_pmu_enable_all(void)
+static void x86_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
@@ -784,7 +784,7 @@ void hw_perf_enable(void)
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	struct perf_event *event;
 	struct hw_perf_event *hwc;
-	int i;
+	int i, added = cpuc->n_added;
 
 	if (!x86_pmu_initialized())
 		return;
@@ -836,7 +836,7 @@ void hw_perf_enable(void)
 	cpuc->enabled = 1;
 	barrier();
 
-	x86_pmu.enable_all();
+	x86_pmu.enable_all(added);
 }
 
 static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc)
arch/x86/kernel/cpu/perf_event_intel.c +39 -4

73 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_p4.c +1 -1
index f8fe069..0d1be36 100644
@@ -535,7 +535,7 @@ static void p4_pmu_enable_event(struct perf_event *event)
 				(cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE);
 }
 
-static void p4_pmu_enable_all(void)
+static void p4_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
arch/x86/kernel/cpu/perf_event_p6.c +1 -1
index 6ff4d01..877182c 100644
@@ -66,7 +66,7 @@ static void p6_pmu_disable_all(void)
 	wrmsrl(MSR_P6_EVNTSEL0, val);
 }
 
-static void p6_pmu_enable_all(void)
+static void p6_pmu_enable_all(int added)
 {
 	unsigned long val;
 
author maintainer
#2 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra

Subject: perf, x86: Add Nehelem PMU programming errata workaround
From: Peter Zijlstra <[email protected]>
Date: Fri Mar 26 13:59:41 CET 2010

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

*sigh* it appears the westmere chips suffer this too according to the new Xeon 5600 docs (BD53) .. I'll update the patch.

author maintainer
#3 lore raw
In reply to Peter Zijlstra
Commit-ID:  11164cd4f6dab326a88bdf27f2f8f7c11977e91a
Gitweb:     http://git.kernel.org/tip/11164cd4f6dab326a88bdf27f2f8f7c11977e91a
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Fri, 26 Mar 2010 14:08:44 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 26 Mar 2010 15:47:24 +0100

perf, x86: Add Nehelem PMU programming errata workaround

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

Cc Stephane Eranian <[email protected]>

LKML-Reference: <1269608924.12097.147.camel@laptop>

---
 arch/x86/kernel/cpu/perf_event.c       |    8 +++---
 arch/x86/kernel/cpu/perf_event_intel.c |   43 +++++++++++++++++++++++++++++---
 arch/x86/kernel/cpu/perf_event_p4.c    |    2 +-
 arch/x86/kernel/cpu/perf_event_p6.c    |    2 +-
 4 files changed, 45 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/perf_event.c +4 -4
index f571f51..6f66d4a 100644
@@ -184,7 +184,7 @@ struct x86_pmu {
 	int		version;
 	int		(*handle_irq)(struct pt_regs *);
 	void		(*disable_all)(void);
-	void		(*enable_all)(void);
+	void		(*enable_all)(int added);
 	void		(*enable)(struct perf_event *);
 	void		(*disable)(struct perf_event *);
 	int		(*hw_config)(struct perf_event_attr *attr, struct hw_perf_event *hwc);
@@ -576,7 +576,7 @@ void hw_perf_disable(void)
 	x86_pmu.disable_all();
 }
 
-static void x86_pmu_enable_all(void)
+static void x86_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
@@ -784,7 +784,7 @@ void hw_perf_enable(void)
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	struct perf_event *event;
 	struct hw_perf_event *hwc;
-	int i;
+	int i, added = cpuc->n_added;
 
 	if (!x86_pmu_initialized())
 		return;
@@ -836,7 +836,7 @@ void hw_perf_enable(void)
 	cpuc->enabled = 1;
 	barrier();
 
-	x86_pmu.enable_all();
+	x86_pmu.enable_all(added);
 }
 
 static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc)
arch/x86/kernel/cpu/perf_event_intel.c +39 -4

73 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_p4.c +1 -1
index f8fe069..0d1be36 100644
@@ -535,7 +535,7 @@ static void p4_pmu_enable_event(struct perf_event *event)
 				(cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE);
 }
 
-static void p4_pmu_enable_all(void)
+static void p4_pmu_enable_all(int added)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 	int idx;
arch/x86/kernel/cpu/perf_event_p6.c +1 -1
index 6ff4d01..877182c 100644
@@ -66,7 +66,7 @@ static void p6_pmu_disable_all(void)
 	wrmsrl(MSR_P6_EVNTSEL0, val);
 }
 
-static void p6_pmu_enable_all(void)
+static void p6_pmu_enable_all(int added)
 {
 	unsigned long val;
 
#4 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra

Subject: perf, x86: Add Nehelem PMU programming errata workaround
From: Peter Zijlstra <[email protected]>
Date: Fri Mar 26 13:59:41 CET 2010

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

Did you actually see this happen?

It looks like this will make the context switch into a perf enabled process _MUCH_ more expensive, MSR writes are very slow.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#5 lore raw
Quoted 6 lines · Andi Kleen
Quoted 4 lines · Peter Zijlstra

Subject: perf, x86: Add Nehelem PMU programming errata workaround
From: Peter Zijlstra <[email protected]>
Date: Fri Mar 26 13:59:41 CET 2010

Quoted 7 lines
Quoted 4 lines

Implement the workaround for Intel Errata AAK100 and AAP53.

Also, remove the Core-i7 name for Nehalem events since there are also Westmere based i7 chips.

Did you actually see this happen?

This is the same as AAJ91. At the time, I created a test program and it was moderately easy to reproduce.

Quoted 3 lines

It looks like this will make the context switch into a perf enabled process _MUCH_ more expensive, MSR writes are very slow.

Yes, but there is no alternative, I suspect.