Skip to contentSkip to conversation

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

PATCH RESEND In review Jacob Shin 6 participants 16 messages Apr 9, 2013 – Apr 10, 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   |  235 +++++++++++++++++++++++++-------
 arch/x86/kernel/cpu/perf_event_intel.c |    2 +-
 7 files changed, 207 insertions(+), 58 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH RESEND 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 ba9aadf..f092dfe 100644
@@ -68,8 +68,8 @@ struct event_constraint {
 #define PERF_X86_EVENT_PEBS_LDLAT	0x1 /* ld+ldlat data address sampling */
 #define PERF_X86_EVENT_PEBS_ST		0x2 /* st data address sampling */
 
-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];
@@ -170,7 +170,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 RESEND 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 5ed7a4c..62516cf 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 f092dfe..9751201 100644
@@ -118,6 +118,7 @@ struct intel_shared_regs {
 };
 
 #define MAX_LBR_ENTRIES		16
+#define MAX_KFREE_ON_ONLINE	4
 
 struct cpu_hw_events {
 	/*
@@ -174,7 +175,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, f) {\
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 e84c4ba..ef709d3 100644
@@ -1741,7 +1741,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 RESEND 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 that 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  |  167 +++++++++++++++++++++++++++++----
 5 files changed, 162 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 bf7bb68..b575788 100644
@@ -196,6 +196,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 9751201..9297110 100644
@@ -172,6 +172,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 +150 -17

306 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#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.

If they're separate counters -- not shared with the regular cpu counters like the 10h NB counters are, then they should have their own PMU driver.

Similar to the 15h NB counters; which are a separate set of counters and no longer overlay the normal counters.

maintainer
#5 lore raw
Quoted 8 lines · Peter Zijlstra
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.

Quoted 6 lines

If they're separate counters -- not shared with the regular cpu counters like the 10h NB counters are, then they should have their own PMU driver.

Similar to the 15h NB counters; which are a separate set of counters and no longer overlay the normal counters.

Related; where's the 16h BKDG?

#6 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
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.

Quoted 7 lines

If they're separate counters -- not shared with the regular cpu counters like the 10h NB counters are, then they should have their own PMU driver.

Similar to the 15h NB counters; which are a separate set of counters and no longer overlay the normal counters.

Well, that's how this was suggested but that's not how it's implemented currently
and committed if I recall.

#7 lore raw
Quoted 14 lines · Stephane Eranian
Quoted 13 lines · Peter Zijlstra
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.

If they're separate counters -- not shared with the regular cpu counters like the 10h NB counters are, then they should have their own PMU driver.

Quoted 6 lines
Quoted 3 lines

Similar to the 15h NB counters; which are a separate set of counters and no longer overlay the normal counters.

Well, that's how this was suggested but that's not how it's implemented currently
and committed if I recall.

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

#8 lore raw
Quoted 18 lines · Peter Zijlstra
Quoted 17 lines · Stephane Eranian
Quoted 16 lines · Peter Zijlstra
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.

If they're separate counters -- not shared with the regular cpu counters like the 10h NB counters are, then they should have their own PMU driver.

Similar to the 15h NB counters; which are a separate set of counters and no longer overlay the normal counters.

Quoted 8 lines
Quoted 3 lines

Well, that's how this was suggested but that's not how it's implemented currently
and committed if I recall.

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

I remember. I agreed with you on this. I don't recall the details as to why Robert did not like that but I think it had to do with code duplication from the perf_event_amd.c.

maintainer
#9 lore raw
In reply to Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

#10 lore raw
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Quoted 6 lines

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

I think we can - if there's a functional replacement.

Thanks,

Ingo

#11 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Quoted 9 lines
Quoted 6 lines

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

I think we can - if there's a functional replacement.

Does the existing code expose a type in sysfs? If not then you cannot do this transparently, I am afraid because the syntax would be different, i.e., not cpu/...

I reviewed the code and tested it. But at the time, I thought you had agreed on the approach used.

#12 lore raw
Quoted 15 lines · Stephane Eranian
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I don't suppose we can deprecate it and remove this stuff?

I think we can - if there's a functional replacement.

Does the existing code expose a type in sysfs? If not then you cannot do this transparently, I am afraid because the syntax would be different, i.e., not cpu/...

That could be compatibility-bridged over in tooling?

I doubt these events are in heavy use.

Quoted 2 lines

I reviewed the code and tested it. But at the time, I thought you had agreed on the approach used.

I did - but PeterZ has a point, so it would be nice if we could improve on that.

Thanks,

Ingo

#13 lore raw
Quoted 22 lines · Ingo Molnar
Quoted 19 lines · Stephane Eranian
Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Quoted 6 lines

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

I think we can - if there's a functional replacement.

Quoted 8 lines
Quoted 3 lines

Does the existing code expose a type in sysfs? If not then you cannot do this transparently, I am afraid because the syntax would be different, i.e., not cpu/...

That could be compatibility-bridged over in tooling?

I doubt these events are in heavy use.

I agree.

Quoted 5 lines
Quoted 2 lines

I reviewed the code and tested it. But at the time, I thought you had agreed on the approach used.

I did - but PeterZ has a point, so it would be nice if we could improve on that.

I think it is doable by cloning some of the functions into an amd_unc.c file.

author
#14 lore raw
Quoted 17 lines · Stephane Eranian
Quoted 16 lines · Ingo Molnar
Quoted 13 lines · Stephane Eranian
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Hmm.. the 15h old interface bits got merged? I thought I kept telling that should be done like the intel uncore stuff since the hardware interface wasn't retarded anymore.

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

I think we can - if there's a functional replacement.

Does the existing code expose a type in sysfs?

It does not.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

If not then you cannot do this transparently, I am afraid because the syntax would be different, i.e., not cpu/...

That could be compatibility-bridged over in tooling?

I doubt these events are in heavy use.

I agree.

Right, I don't think they are.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I reviewed the code and tested it. But at the time, I thought you had agreed on the approach used.

I did - but PeterZ has a point, so it would be nice if we could improve on that.

I think it is doable by cloning some of the functions into an amd_unc.c file.

Sigh .. okay ....

maintainer
#15 lore raw
In reply to Stephane Eranian
Quoted 7 lines · Stephane Eranian
Quoted 7 lines
Quoted 6 lines

Ah well, that crap seems to have slipped in in Feb when I was still a near vegetable and not paying much attention.

/me curses a bit.

I don't suppose we can deprecate it and remove this stuff?

Quoted 8 lines
Quoted 2 lines

I think we can - if there's a functional replacement.

Does the existing code expose a type in sysfs? If not then you cannot do this transparently, I am afraid because the syntax would be different, i.e., not cpu/...

I reviewed the code and tested it. But at the time, I thought you had agreed on the approach used.

Btw, Robert is away this week. I'll CC him - he might still read email.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--