Skip to contentSkip to conversation

perf, amd: Support for Family 16h L2I Performance Counters

PATCH Superseded Jacob Shin 1 participant 5 messages Mar 27, 2013 – Apr 2, 2013

Subsystems (2)
lore
Share & tools
lore

Jacob Shin

author
#0 lore raw

cover perf, amd: Support for Family 16h L2I Performance Counters

Upcoming AMD Family 16h Processors provide 4 new performance counters to count L2 related events. Similar to northbridge counters, these new counters are shared across multiple CPUs that share the same L2 cache. This patchset adds support for these new counters and enforces sharing by leveraging the existing sharing logic used for the northbridge counters.

Jacob Shin (3):
perf, amd: Further generalize NB event constraints handling logic perf, x86: Allow for multiple kfree_on_online pointers perf, amd: Enable L2I performance counters on AMD Family 16h

 arch/x86/include/asm/cpufeature.h      |    2 +
 arch/x86/include/asm/perf_event.h      |    4 +
 arch/x86/include/uapi/asm/msr-index.h  |    4 +
 arch/x86/kernel/cpu/perf_event.c       |    7 +-
 arch/x86/kernel/cpu/perf_event.h       |   11 +-
 arch/x86/kernel/cpu/perf_event_amd.c   |  227 +++++++++++++++++++++++++-------
 arch/x86/kernel/cpu/perf_event_intel.c |    2 +-
 7 files changed, 199 insertions(+), 58 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/3 perf, amd: Further generalize NB event constraints handling logic

In preparation for enabling AMD L2I performance counters, we will further generalize NB event constraints handling logic to now allow any type of shared counters. This is just a code rework, there are no functional changes.

---
 arch/x86/kernel/cpu/perf_event.h     |    6 +--
 arch/x86/kernel/cpu/perf_event_amd.c |   70 +++++++++++++++++-----------------
 2 files changed, 38 insertions(+), 38 deletions(-)
arch/x86/kernel/cpu/perf_event.h +3 -3
index 7f5c75c..fdaac69 100644
@@ -61,8 +61,8 @@ struct event_constraint {
 	int	overlap;
 };
 
-struct amd_nb {
-	int nb_id;  /* NorthBridge id */
+struct amd_shared_regs {
+	int id;
 	int refcnt; /* reference count */
 	struct perf_event *owners[X86_PMC_IDX_MAX];
 	struct event_constraint event_constraints[X86_PMC_IDX_MAX];
@@ -163,7 +163,7 @@ struct cpu_hw_events {
 	/*
 	 * AMD specific bits
 	 */
-	struct amd_nb			*amd_nb;
+	struct amd_shared_regs		*amd_nb;
 	/* Inverted mask of bits to clear in the perf_ctr ctrl registers */
 	u64				perf_ctr_virt_mask;
 
arch/x86/kernel/cpu/perf_event_amd.c +35 -35

181 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/3 perf, x86: Allow for multiple kfree_on_online pointers

In reply to Jacob Shin

Currently only 1 pointer can be freed using kfree_on_online mechanism, allow for multiple.

---
 arch/x86/kernel/cpu/perf_event.c       |    7 +++++--
 arch/x86/kernel/cpu/perf_event.h       |    3 ++-
 arch/x86/kernel/cpu/perf_event_amd.c   |    2 +-
 arch/x86/kernel/cpu/perf_event_intel.c |    2 +-
 4 files changed, 9 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event.c +5 -2
index bf0f01a..64c4b7a 100644
@@ -1258,10 +1258,12 @@ x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
 	unsigned int cpu = (long)hcpu;
 	struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
 	int ret = NOTIFY_OK;
+	int i;
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 	case CPU_UP_PREPARE:
-		cpuc->kfree_on_online = NULL;
+		for (i = 0; i < MAX_KFREE_ON_ONLINE; i++)
+			cpuc->kfree_on_online[i] = NULL;
 		if (x86_pmu.cpu_prepare)
 			ret = x86_pmu.cpu_prepare(cpu);
 		break;
@@ -1274,7 +1276,8 @@ x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
 		break;
 
 	case CPU_ONLINE:
-		kfree(cpuc->kfree_on_online);
+		for (i = 0; i < MAX_KFREE_ON_ONLINE; i++)
+			kfree(cpuc->kfree_on_online[i]);
 		break;
 
 	case CPU_DYING:
arch/x86/kernel/cpu/perf_event.h +2 -1
index fdaac69..770f3b99 100644
@@ -111,6 +111,7 @@ struct intel_shared_regs {
 };
 
 #define MAX_LBR_ENTRIES		16
+#define MAX_KFREE_ON_ONLINE	4
 
 struct cpu_hw_events {
 	/*
@@ -167,7 +168,7 @@ struct cpu_hw_events {
 	/* Inverted mask of bits to clear in the perf_ctr ctrl registers */
 	u64				perf_ctr_virt_mask;
 
-	void				*kfree_on_online;
+	void				*kfree_on_online[MAX_KFREE_ON_ONLINE];
 };
 
 #define __EVENT_CONSTRAINT(c, n, m, w, o) {\
arch/x86/kernel/cpu/perf_event_amd.c +1 -1
index 23964a6..36b5162 100644
@@ -505,7 +505,7 @@ static void amd_pmu_cpu_starting(int cpu)
 			continue;
 
 		if (nb->id == nb_id) {
-			cpuc->kfree_on_online = cpuc->amd_nb;
+			cpuc->kfree_on_online[0] = cpuc->amd_nb;
 			cpuc->amd_nb = nb;
 			break;
 		}
arch/x86/kernel/cpu/perf_event_intel.c +1 -1
index dab7580..f79a0c5 100644
@@ -1719,7 +1719,7 @@ static void intel_pmu_cpu_starting(int cpu)
 
 			pc = per_cpu(cpu_hw_events, i).shared_regs;
 			if (pc && pc->core_id == core_id) {
-				cpuc->kfree_on_online = cpuc->shared_regs;
+				cpuc->kfree_on_online[0] = cpuc->shared_regs;
 				cpuc->shared_regs = pc;
 				break;
 			}
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH 3/3 perf, amd: Enable L2I performance counters on AMD Family 16h

In reply to Jacob Shin

AMD Family 16h processors provide 4 new performance counters (in addition to 4 legacy core counters, and 4 northbridge counters) for monitoring L2 cache specific events (i.e. L2 cache misses). These 4 counters are shared between all CPUs in a "compute unit" (they share the same L2 cache). We will use the same existing event constraints handling logic to enforce this sharing.

---
 arch/x86/include/asm/cpufeature.h     |    2 +
 arch/x86/include/asm/perf_event.h     |    4 +
 arch/x86/include/uapi/asm/msr-index.h |    4 +
 arch/x86/kernel/cpu/perf_event.h      |    2 +
 arch/x86/kernel/cpu/perf_event_amd.c  |  159 +++++++++++++++++++++++++++++----
 5 files changed, 154 insertions(+), 17 deletions(-)
arch/x86/include/asm/cpufeature.h +2 -0
index 93fe929..0f534af 100644
@@ -168,6 +168,7 @@
 #define X86_FEATURE_TOPOEXT	(6*32+22) /* topology extensions CPUID leafs */
 #define X86_FEATURE_PERFCTR_CORE (6*32+23) /* core performance counter extensions */
 #define X86_FEATURE_PERFCTR_NB  (6*32+24) /* NB performance counter extensions */
+#define X86_FEATURE_PERFCTR_L2I (6*32+28) /* L2I performance counter extensions */
 
 /*
  * Auxiliary flags: Linux defined - For features scattered in various
@@ -311,6 +312,7 @@ extern const char * const x86_power_flags[32];
 #define cpu_has_pclmulqdq	boot_cpu_has(X86_FEATURE_PCLMULQDQ)
 #define cpu_has_perfctr_core	boot_cpu_has(X86_FEATURE_PERFCTR_CORE)
 #define cpu_has_perfctr_nb	boot_cpu_has(X86_FEATURE_PERFCTR_NB)
+#define cpu_has_perfctr_l2i	boot_cpu_has(X86_FEATURE_PERFCTR_L2I)
 #define cpu_has_cx8		boot_cpu_has(X86_FEATURE_CX8)
 #define cpu_has_cx16		boot_cpu_has(X86_FEATURE_CX16)
 #define cpu_has_eager_fpu	boot_cpu_has(X86_FEATURE_EAGER_FPU)
arch/x86/include/asm/perf_event.h +4 -0
index 57cb634..ed430ea 100644
@@ -36,6 +36,9 @@
 #define AMD64_EVENTSEL_INT_CORE_SEL_SHIFT		37
 #define AMD64_EVENTSEL_INT_CORE_SEL_MASK		\
 	(0xFULL << AMD64_EVENTSEL_INT_CORE_SEL_SHIFT)
+#define AMD64_EVENTSEL_THREAD_MASK_SHIFT		56
+#define AMD64_EVENTSEL_THREAD_MASK_MASK			\
+	(0xFULL << AMD64_EVENTSEL_THREAD_MASK_SHIFT)
 
 #define AMD64_EVENTSEL_EVENT	\
 	(ARCH_PERFMON_EVENTSEL_EVENT | (0x0FULL << 32))
@@ -57,6 +60,7 @@
 #define AMD64_NUM_COUNTERS				4
 #define AMD64_NUM_COUNTERS_CORE				6
 #define AMD64_NUM_COUNTERS_NB				4
+#define AMD64_NUM_COUNTERS_L2I				4
 
 #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL		0x3c
 #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK		(0x00 << 8)
arch/x86/include/uapi/asm/msr-index.h +4 -0
index 892ce40..9c54104 100644
@@ -194,6 +194,10 @@
 #define MSR_AMD64_IBSBRTARGET		0xc001103b
 #define MSR_AMD64_IBS_REG_COUNT_MAX	8 /* includes MSR_AMD64_IBSBRTARGET */
 
+/* Fam 16h MSRs */
+#define MSR_F16H_L2I_PERF_CTL		0xc0010230
+#define MSR_F16H_L2I_PERF_CTR		0xc0010231
+
 /* Fam 15h MSRs */
 #define MSR_F15H_PERF_CTL		0xc0010200
 #define MSR_F15H_PERF_CTR		0xc0010201
arch/x86/kernel/cpu/perf_event.h +2 -0
index 770f3b99..79b65ac 100644
@@ -165,6 +165,8 @@ struct cpu_hw_events {
 	 * AMD specific bits
 	 */
 	struct amd_shared_regs		*amd_nb;
+	struct amd_shared_regs		*amd_l2i;
+
 	/* Inverted mask of bits to clear in the perf_ctr ctrl registers */
 	u64				perf_ctr_virt_mask;
 
arch/x86/kernel/cpu/perf_event_amd.c +142 -17

298 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#4 lore raw
In reply to Jacob Shin
Quoted 6 lines · Jacob Shin

Upcoming AMD Family 16h Processors provide 4 new performance counters to count L2 related events. Similar to northbridge counters, these new counters are shared across multiple CPUs that share the same L2 cache. This patchset adds support for these new counters and enforces sharing by leveraging the existing sharing logic used for the northbridge counters.

Ingo, please consider commiting to perf/core for 3.10. This patchset is very similar to our northbridge counter support that went into 3.9:
https://lkml.org/lkml/2013/2/18/81

This series adds support for yet another set of new counters.

Thank you,

Quoted 18 lines

Jacob Shin (3):
perf, amd: Further generalize NB event constraints handling logic perf, x86: Allow for multiple kfree_on_online pointers perf, amd: Enable L2I performance counters on AMD Family 16h

 arch/x86/include/asm/cpufeature.h      |    2 +
 arch/x86/include/asm/perf_event.h      |    4 +
 arch/x86/include/uapi/asm/msr-index.h  |    4 +
 arch/x86/kernel/cpu/perf_event.c       |    7 +-
 arch/x86/kernel/cpu/perf_event.h       |   11 +-
 arch/x86/kernel/cpu/perf_event_amd.c   |  227 +++++++++++++++++++++++++-------
 arch/x86/kernel/cpu/perf_event_intel.c |    2 +-
 7 files changed, 199 insertions(+), 58 deletions(-)
Signature · 1 line
1.7.9.5