Skip to content

Commit e48667b

Browse files
kimphillamdsuryasaimadhu
authored andcommitted
perf/amd/uncore: Add support for Family 19h L3 PMU
Family 19h introduces change in slice, core and thread specification in its L3 Performance Event Select (ChL3PmcCfg) h/w register. The change is incompatible with Family 17h's version of the register. Introduce a new path in l3_thread_slice_mask() to do things differently for Family 19h vs. Family 17h, otherwise the new hardware doesn't get programmed correctly. Instead of a linear core--thread bitmask, Family 19h takes an encoded core number, and a separate thread mask. There are new bits that are set for all cores and all slices, of which only the latter is used, since the driver counts events for all slices on behalf of the specified CPU. Also update amd_uncore_init() to base its L2/NB vs. L3/Data Fabric mode decision based on Family 17h or above, not just 17h and 18h: the Family 19h Data Fabric PMC is compatible with the Family 17h DF PMC. [ bp: Touchups. ] Signed-off-by: Kim Phillips <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9689dbb commit e48667b

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

arch/x86/events/amd/uncore.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,18 @@ static u64 l3_thread_slice_mask(int cpu)
191191
if (topology_smt_supported() && !topology_is_primary_thread(cpu))
192192
thread = 1;
193193

194-
shift = AMD64_L3_THREAD_SHIFT + 2 * (core % 4) + thread;
194+
if (boot_cpu_data.x86 <= 0x18) {
195+
shift = AMD64_L3_THREAD_SHIFT + 2 * (core % 4) + thread;
196+
thread_mask = BIT_ULL(shift);
197+
198+
return AMD64_L3_SLICE_MASK | thread_mask;
199+
}
200+
201+
core = (core << AMD64_L3_COREID_SHIFT) & AMD64_L3_COREID_MASK;
202+
shift = AMD64_L3_THREAD_SHIFT + thread;
195203
thread_mask = BIT_ULL(shift);
196204

197-
return AMD64_L3_SLICE_MASK | thread_mask;
205+
return AMD64_L3_EN_ALL_SLICES | core | thread_mask;
198206
}
199207

200208
static int amd_uncore_event_init(struct perf_event *event)
@@ -223,8 +231,8 @@ static int amd_uncore_event_init(struct perf_event *event)
223231
return -EINVAL;
224232

225233
/*
226-
* SliceMask and ThreadMask need to be set for certain L3 events in
227-
* Family 17h. For other events, the two fields do not affect the count.
234+
* SliceMask and ThreadMask need to be set for certain L3 events.
235+
* For other events, the two fields do not affect the count.
228236
*/
229237
if (l3_mask && is_llc_event(event))
230238
hwc->config |= l3_thread_slice_mask(event->cpu);
@@ -533,9 +541,9 @@ static int __init amd_uncore_init(void)
533541
if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
534542
return -ENODEV;
535543

536-
if (boot_cpu_data.x86 == 0x17 || boot_cpu_data.x86 == 0x18) {
544+
if (boot_cpu_data.x86 >= 0x17) {
537545
/*
538-
* For F17h or F18h, the Northbridge counters are
546+
* For F17h and above, the Northbridge counters are
539547
* repurposed as Data Fabric counters. Also, L3
540548
* counters are supported too. The PMUs are exported
541549
* based on family as either L2 or L3 and NB or DF.

arch/x86/include/asm/perf_event.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,22 @@
5050

5151
#define AMD64_L3_SLICE_SHIFT 48
5252
#define AMD64_L3_SLICE_MASK \
53-
((0xFULL) << AMD64_L3_SLICE_SHIFT)
53+
(0xFULL << AMD64_L3_SLICE_SHIFT)
54+
#define AMD64_L3_SLICEID_MASK \
55+
(0x7ULL << AMD64_L3_SLICE_SHIFT)
5456

5557
#define AMD64_L3_THREAD_SHIFT 56
5658
#define AMD64_L3_THREAD_MASK \
57-
((0xFFULL) << AMD64_L3_THREAD_SHIFT)
59+
(0xFFULL << AMD64_L3_THREAD_SHIFT)
60+
#define AMD64_L3_F19H_THREAD_MASK \
61+
(0x3ULL << AMD64_L3_THREAD_SHIFT)
62+
63+
#define AMD64_L3_EN_ALL_CORES BIT_ULL(47)
64+
#define AMD64_L3_EN_ALL_SLICES BIT_ULL(46)
65+
66+
#define AMD64_L3_COREID_SHIFT 42
67+
#define AMD64_L3_COREID_MASK \
68+
(0x7ULL << AMD64_L3_COREID_SHIFT)
5869

5970
#define X86_RAW_EVENT_MASK \
6071
(ARCH_PERFMON_EVENTSEL_EVENT | \

0 commit comments

Comments
 (0)