Skip to contentSkip to conversation

perf_counter, x86: Implement generalized cache event types, add AMD support

tip:perfcounters/core tip-bot for Thomas Gleixner 3 participants 3 messages Jun 8, 2009 – Jun 9, 2009 x86

lore
Share & tools
lore
#0 lore raw
Commit-ID:  d3ad70660a0bf6d1a3692093939d238fe8add498
Gitweb:     http://git.kernel.org/tip/d3ad70660a0bf6d1a3692093939d238fe8add498
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Mon, 8 Jun 2009 22:33:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 8 Jun 2009 22:33:10 +0200

perf_counter, x86: Implement generalized cache event types, add AMD support

Fill in amd_hw_cache_event_id[] with the AMD CPU specific events, for family 0x0f, 0x10 and 0x11.

There's apparently no distinction between load and store events, so we only fill in the load events.

Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <new-submission>

---
 arch/x86/kernel/cpu/perf_counter.c |  102 ++++++++++++++++++++++++++++++++++++
 1 files changed, 102 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_counter.c +102 -0
index 0339d19..0c2136b 100644
@@ -389,6 +389,97 @@ static u64 intel_pmu_raw_event(u64 event)
 	return event & CORE_EVNTSEL_MASK;
 }
 
+static const u64 amd_0f_hw_cache_event_ids
+				[PERF_COUNT_HW_CACHE_MAX]
+				[PERF_COUNT_HW_CACHE_OP_MAX]
+				[PERF_COUNT_HW_CACHE_RESULT_MAX] =
+{
+ [ C(L1D) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(L1I ) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction cache fetches  */
+		[ C(RESULT_MISS)   ] = 0x0081, /* Instruction cache misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(L2  ) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(DTLB) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(ITLB) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes        */
+		[ C(RESULT_MISS)   ] = 0x0085, /* Instr. fetch ITLB misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+ },
+ [ C(BPU ) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x00c2, /* Retired Branch Instr.      */
+		[ C(RESULT_MISS)   ] = 0x00c3, /* Retired Mispredicted BI    */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+ },
+};
+
 /*
  * AMD Performance Monitor K7 and later.
  */
@@ -1345,6 +1436,17 @@ static int intel_pmu_init(void)
 static int amd_pmu_init(void)
 {
 	x86_pmu = amd_pmu;
+
+	switch (boot_cpu_data.x86 >= 0x0f) {
+	case 0x0f:
+	case 0x10:
+	case 0x11:
+		memcpy(hw_cache_event_ids, amd_0f_hw_cache_event_ids,
+		       sizeof(hw_cache_event_ids));
+
+		pr_cont("AMD Family 0f/10/11 events, ");
+		break;
+	}
 	return 0;
 }
 
#1 lore raw
Quoted 7 lines · tip-bot for Thomas Gleixner
Commit-ID:  d3ad70660a0bf6d1a3692093939d238fe8add498
Gitweb:     http://git.kernel.org/tip/d3ad70660a0bf6d1a3692093939d238fe8add498
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Mon, 8 Jun 2009 22:33:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 8 Jun 2009 22:33:10 +0200
Quoted 7 lines

perf_counter, x86: Implement generalized cache event types, add AMD support

Fill in amd_hw_cache_event_id[] with the AMD CPU specific events, for family 0x0f, 0x10 and 0x11.

There's apparently no distinction between load and store events, so we only fill in the load events.

Ah, that's what you did.. :-)

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 400

Quoted 9 lines
arch/x86/kernel/cpu/perf_counter.c +9 -0
+static const u64 amd_0f_hw_cache_event_ids
+				[PERF_COUNT_HW_CACHE_MAX]
+				[PERF_COUNT_HW_CACHE_OP_MAX]
+				[PERF_COUNT_HW_CACHE_RESULT_MAX] =
+{
+ [ C(L1D) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,

0x40 - Data Cache Access
0x41 - Data Cache Misses

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 408

Quoted 8 lines
arch/x86/kernel/cpu/perf_counter.c +8 -0
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,

0x4B - unit 0x3 (load+store) Prefetch Dispatched

Quoted 5 lines
arch/x86/kernel/cpu/perf_counter.c +5 -0
+	},
+ },
+ [ C(L1I ) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction cache fetches  */

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 423

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0x0081, /* Instruction cache misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x81 L1I Miss
0x82 L1I Miss, L2 Hit
0x83 L1I Miss, L2 Miss

Quoted 4 lines

+ },
+ [ C(L2 ) ] = {

arch/x86/kernel/cpu/perf_counter.c +2 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 409

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x42 unit 0x1e (shared|exclusive|owned|mod) L1 Miss L2 Hit
0x43 unit 0x1e L2 Miss

0x7d unit 0x3 (IC|DC) L2 Hit 0x7e unit 0x3 (IC|DC) L2 Miss

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 401

Quoted 6 lines

+ },
+ [ C(DTLB) ] = {

arch/x86/kernel/cpu/perf_counter.c +4 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x4D - unit 0x1 4k DTLB L1 Hit 0x45 - unit 0x1 4k DTLB L1 Miss L2 Hit 0x46 - unit 0x1 4k DTLB L1 Miss L2 Miss

Quoted 12 lines
arch/x86/kernel/cpu/perf_counter.c +12 -0
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(ITLB) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes        */

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 465

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0x0085, /* Instr. fetch ITLB misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},

0x84 L1 ITLB Miss, L2 ITLB Hit
0x85 Unit 0x1 (4k) L1 ITLB Miss, L2 Miss

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 470

Quoted 5 lines

+ },
+ [ C(BPU ) ] = {

arch/x86/kernel/cpu/perf_counter.c +3 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x00c2, /* Retired Branch Instr.      */
+		[ C(RESULT_MISS)   ] = 0x00c3, /* Retired Mispredicted BI    */

There's also Retired Taken in C4 and C5

Quoted 11 lines
arch/x86/kernel/cpu/perf_counter.c +11 -0
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+ },
+};
#2 lore raw
Quoted 120 lines · Peter Zijlstra
Quoted 7 lines · tip-bot for Thomas Gleixner
Commit-ID:  d3ad70660a0bf6d1a3692093939d238fe8add498
Gitweb:     http://git.kernel.org/tip/d3ad70660a0bf6d1a3692093939d238fe8add498
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Mon, 8 Jun 2009 22:33:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 8 Jun 2009 22:33:10 +0200
Quoted 7 lines

perf_counter, x86: Implement generalized cache event types, add AMD support

Fill in amd_hw_cache_event_id[] with the AMD CPU specific events, for family 0x0f, 0x10 and 0x11.

There's apparently no distinction between load and store events, so we only fill in the load events.

Ah, that's what you did.. :-)

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 400

Quoted 9 lines
arch/x86/kernel/cpu/perf_counter.c +9 -0
+static const u64 amd_0f_hw_cache_event_ids
+				[PERF_COUNT_HW_CACHE_MAX]
+				[PERF_COUNT_HW_CACHE_OP_MAX]
+				[PERF_COUNT_HW_CACHE_RESULT_MAX] =
+{
+ [ C(L1D) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,

0x40 - Data Cache Access
0x41 - Data Cache Misses

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 408

Quoted 8 lines
arch/x86/kernel/cpu/perf_counter.c +8 -0
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,

0x4B - unit 0x3 (load+store) Prefetch Dispatched

Quoted 5 lines
arch/x86/kernel/cpu/perf_counter.c +5 -0
+	},
+ },
+ [ C(L1I ) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction cache fetches  */

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 423

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0x0081, /* Instruction cache misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x81 L1I Miss
0x82 L1I Miss, L2 Hit
0x83 L1I Miss, L2 Miss

Quoted 4 lines

+ },
+ [ C(L2 ) ] = {

arch/x86/kernel/cpu/perf_counter.c +2 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 409

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x42 unit 0x1e (shared|exclusive|owned|mod) L1 Miss L2 Hit
0x43 unit 0x1e L2 Miss

0x7d unit 0x3 (IC|DC) L2 Hit 0x7e unit 0x3 (IC|DC) L2 Miss

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 401

Quoted 6 lines

+ },
+ [ C(DTLB) ] = {

arch/x86/kernel/cpu/perf_counter.c +4 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},

0x4D - unit 0x1 4k DTLB L1 Hit 0x45 - unit 0x1 4k DTLB L1 Miss L2 Hit 0x46 - unit 0x1 4k DTLB L1 Miss L2 Miss

Quoted 12 lines
arch/x86/kernel/cpu/perf_counter.c +12 -0
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = 0,
+		[ C(RESULT_MISS)   ] = 0,
+	},
+ },
+ [ C(ITLB) ] = {
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes        */

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 465

Quoted 10 lines
arch/x86/kernel/cpu/perf_counter.c +10 -0
+		[ C(RESULT_MISS)   ] = 0x0085, /* Instr. fetch ITLB misses   */
+	},
+	[ C(OP_WRITE) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},
+	[ C(OP_PREFETCH) ] = {
+		[ C(RESULT_ACCESS) ] = -1,
+		[ C(RESULT_MISS)   ] = -1,
+	},

0x84 L1 ITLB Miss, L2 ITLB Hit
0x85 Unit 0x1 (4k) L1 ITLB Miss, L2 Miss

Quoted 7 lines

arch/x86/kernel/cpu/perf_counter.c static u64 intel_pmu_raw_event(u64 event) · line 470

Quoted 5 lines

+ },
+ [ C(BPU ) ] = {

arch/x86/kernel/cpu/perf_counter.c +3 -0
+	[ C(OP_READ) ] = {
+		[ C(RESULT_ACCESS) ] = 0x00c2, /* Retired Branch Instr.      */
+		[ C(RESULT_MISS)   ] = 0x00c3, /* Retired Mispredicted BI    */

There's also Retired Taken in C4 and C5

Mind turning this into a patch? You did the hard work already :-)

Ingo