From: Kim Phillips <kim.phill...@amd.com>

commit 2f217d58a8a086d3399fecce39fb358848e799c4 upstream.

Fill in the L3 performance event select register ThreadMask
bitfield, to enable per hardware thread accounting.

Signed-off-by: Kim Phillips <kim.phill...@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>
Cc: <sta...@vger.kernel.org>
Cc: Alexander Shishkin <alexander.shish...@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Borislav Petkov <b...@alien8.de>
Cc: Gary Hook <gary.h...@amd.com>
Cc: H. Peter Anvin <h...@zytor.com>
Cc: Janakarajan Natarajan <janakarajan.natara...@amd.com>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Martin Liska <mli...@suse.cz>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Pu Wen <pu...@hygon.cn>
Cc: Stephane Eranian <eran...@google.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Vince Weaver <vincent.wea...@maine.edu>
Link: https://lkml.kernel.org/r/20190628215906.4276-2-kim.phill...@amd.com
Signed-off-by: Ingo Molnar <mi...@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 arch/x86/events/amd/uncore.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- a/arch/x86/events/amd/uncore.c
+++ b/arch/x86/events/amd/uncore.c
@@ -210,15 +210,22 @@ static int amd_uncore_event_init(struct
        hwc->config = event->attr.config & AMD64_RAW_EVENT_MASK_NB;
        hwc->idx = -1;
 
+       if (event->cpu < 0)
+               return -EINVAL;
+
        /*
         * SliceMask and ThreadMask need to be set for certain L3 events in
         * Family 17h. For other events, the two fields do not affect the count.
         */
-       if (l3_mask && is_llc_event(event))
-               hwc->config |= (AMD64_L3_SLICE_MASK | AMD64_L3_THREAD_MASK);
+       if (l3_mask && is_llc_event(event)) {
+               int thread = 2 * (cpu_data(event->cpu).cpu_core_id % 4);
 
-       if (event->cpu < 0)
-               return -EINVAL;
+               if (smp_num_siblings > 1)
+                       thread += cpu_data(event->cpu).apicid & 1;
+
+               hwc->config |= (1ULL << (AMD64_L3_THREAD_SHIFT + thread) &
+                               AMD64_L3_THREAD_MASK) | AMD64_L3_SLICE_MASK;
+       }
 
        uncore = event_to_amd_uncore(event);
        if (!uncore)


Reply via email to