perf/amd/uncore: Make L3 thread mask code more readable
authorKim Phillips <kim.phillips@amd.com>
Fri, 13 Mar 2020 23:10:23 +0000 (18:10 -0500)
committerBorislav Petkov <bp@suse.de>
Tue, 17 Mar 2020 12:00:49 +0000 (13:00 +0100)
Convert the l3_thread_slice_mask() function to use the more readable
topology_* helper functions, more intuitive variable names like shift
and thread_mask, and BIT_ULL().

No functional changes.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200313231024.17601-2-kim.phillips@amd.com
arch/x86/events/amd/uncore.c

index 2abcb1abd07c70a0afeba0b238b584e0ef9fc8a9..07af497b517fa68613a8e0bcdfe7775e81988d10 100644 (file)
@@ -185,13 +185,16 @@ static void amd_uncore_del(struct perf_event *event, int flags)
  */
 static u64 l3_thread_slice_mask(int cpu)
 {
-       int thread = 2 * (cpu_data(cpu).cpu_core_id % 4);
+       u64 thread_mask, core = topology_core_id(cpu);
+       unsigned int shift, thread = 0;
 
-       if (smp_num_siblings > 1)
-               thread += cpu_data(cpu).apicid & 1;
+       if (topology_smt_supported() && !topology_is_primary_thread(cpu))
+               thread = 1;
 
-       return (1ULL << (AMD64_L3_THREAD_SHIFT + thread) &
-               AMD64_L3_THREAD_MASK) | AMD64_L3_SLICE_MASK;
+       shift = AMD64_L3_THREAD_SHIFT + 2 * (core % 4) + thread;
+       thread_mask = BIT_ULL(shift);
+
+       return AMD64_L3_SLICE_MASK | thread_mask;
 }
 
 static int amd_uncore_event_init(struct perf_event *event)