perf/x86/amd: Add event map for AMD Family 17h

Family 17h differs from prior families by:

- Does not support an L2 cache miss event
- It has re-enumerated PMC counters for:
- L2 cache references
- front & back end stalled cycles

So we add a new amd_f17h_perfmon_event_map[] so that the generic
perf event names will resolve to the correct h/w events on
family 17h and above processors.

Reference sections 2.1.13.3.3 (stalls) and 2.1.13.3.6 (L2):

https://www.amd.com/system/files/TechDocs/54945_PPR_Family_17h_Models_00h-0Fh.pdf

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Cc: <stable@vger.kernel.org> # v4.9+
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Liška <mliska@suse.cz>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Pu Wen <puwen@hygon.cn>
Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Fixes: e40ed1542dd7 ("perf/x86: Add perf support for AMD family-17h processors")
[ Improved the formatting a bit. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by Kim Phillips and committed by Ingo Molnar 3fe3331b b24131eb

+26 -9
+26 -9
arch/x86/events/amd/core.c
··· 117 }; 118 119 /* 120 - * AMD Performance Monitor K7 and later. 121 */ 122 static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] = 123 { 124 - [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, 125 - [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, 126 - [PERF_COUNT_HW_CACHE_REFERENCES] = 0x077d, 127 - [PERF_COUNT_HW_CACHE_MISSES] = 0x077e, 128 - [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, 129 - [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, 130 - [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */ 131 - [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x00d1, /* "Dispatch stalls" event */ 132 }; 133 134 static u64 amd_pmu_event_map(int hw_event) 135 { 136 return amd_perfmon_event_map[hw_event]; 137 } 138
··· 117 }; 118 119 /* 120 + * AMD Performance Monitor K7 and later, up to and including Family 16h: 121 */ 122 static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] = 123 { 124 + [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, 125 + [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, 126 + [PERF_COUNT_HW_CACHE_REFERENCES] = 0x077d, 127 + [PERF_COUNT_HW_CACHE_MISSES] = 0x077e, 128 + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, 129 + [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, 130 + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */ 131 + [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x00d1, /* "Dispatch stalls" event */ 132 + }; 133 + 134 + /* 135 + * AMD Performance Monitor Family 17h and later: 136 + */ 137 + static const u64 amd_f17h_perfmon_event_map[PERF_COUNT_HW_MAX] = 138 + { 139 + [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, 140 + [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, 141 + [PERF_COUNT_HW_CACHE_REFERENCES] = 0xff60, 142 + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, 143 + [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, 144 + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x0287, 145 + [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x0187, 146 }; 147 148 static u64 amd_pmu_event_map(int hw_event) 149 { 150 + if (boot_cpu_data.x86 >= 0x17) 151 + return amd_f17h_perfmon_event_map[hw_event]; 152 + 153 return amd_perfmon_event_map[hw_event]; 154 } 155