Michal Suchanek fb3d24
From 0dcad700bb2776e3886fe0a645a4bf13b1e747cd Mon Sep 17 00:00:00 2001
Michal Suchanek fb3d24
From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Michal Suchanek fb3d24
Date: Tue, 19 Apr 2022 17:18:27 +0530
Michal Suchanek fb3d24
Subject: [PATCH] powerpc/perf: Fix power9 event alternatives
Michal Suchanek fb3d24
Michal Suchanek fb3d24
References: bsc#1137728, LTC#178106, git-fixes
Michal Suchanek fb3d24
Patch-mainline: v5.18-rc4
Michal Suchanek fb3d24
Git-commit: 0dcad700bb2776e3886fe0a645a4bf13b1e747cd
Michal Suchanek fb3d24
Michal Suchanek fb3d24
When scheduling a group of events, there are constraint checks done to
Michal Suchanek fb3d24
make sure all events can go in a group. Example, one of the criteria is
Michal Suchanek fb3d24
that events in a group cannot use the same PMC. But platform specific
Michal Suchanek fb3d24
PMU supports alternative event for some of the event codes. During
Michal Suchanek fb3d24
perf_event_open(), if any event group doesn't match constraint check
Michal Suchanek fb3d24
criteria, further lookup is done to find alternative event.
Michal Suchanek fb3d24
Michal Suchanek fb3d24
By current design, the array of alternatives events in PMU code is
Michal Suchanek fb3d24
expected to be sorted by column 0. This is because in
Michal Suchanek fb3d24
find_alternative() the return criteria is based on event code
Michal Suchanek fb3d24
comparison. ie. "event < ev_alt[i][0])". This optimisation is there
Michal Suchanek fb3d24
since find_alternative() can be called multiple times. In power9 PMU
Michal Suchanek fb3d24
code, the alternative event array is not sorted properly and hence there
Michal Suchanek fb3d24
is breakage in finding alternative events.
Michal Suchanek fb3d24
Michal Suchanek fb3d24
To work with existing logic, fix the alternative event array to be
Michal Suchanek fb3d24
sorted by column 0 for power9-pmu.c
Michal Suchanek fb3d24
Michal Suchanek fb3d24
Results:
Michal Suchanek fb3d24
Michal Suchanek fb3d24
With alternative events, multiplexing can be avoided. That is, for
Michal Suchanek fb3d24
example, in power9 PM_LD_MISS_L1 (0x3e054) has alternative event,
Michal Suchanek fb3d24
PM_LD_MISS_L1_ALT (0x400f0). This is an identical event which can be
Michal Suchanek fb3d24
programmed in a different PMC.
Michal Suchanek fb3d24
Michal Suchanek fb3d24
Before:
Michal Suchanek fb3d24
Michal Suchanek fb3d24
 # perf stat -e r3e054,r300fc
Michal Suchanek fb3d24
Michal Suchanek fb3d24
 Performance counter stats for 'system wide':
Michal Suchanek fb3d24
Michal Suchanek fb3d24
           1057860      r3e054              (50.21%)
Michal Suchanek fb3d24
               379      r300fc              (49.79%)
Michal Suchanek fb3d24
Michal Suchanek fb3d24
       0.944329741 seconds time elapsed
Michal Suchanek fb3d24
Michal Suchanek fb3d24
Since both the events are using PMC3 in this case, they are
Michal Suchanek fb3d24
multiplexed here.
Michal Suchanek fb3d24
Michal Suchanek fb3d24
After:
Michal Suchanek fb3d24
Michal Suchanek fb3d24
 # perf stat -e r3e054,r300fc
Michal Suchanek fb3d24
Michal Suchanek fb3d24
 Performance counter stats for 'system wide':
Michal Suchanek fb3d24
Michal Suchanek fb3d24
           1006948      r3e054
Michal Suchanek fb3d24
               182      r300fc
Michal Suchanek fb3d24
Michal Suchanek fb3d24
Fixes: 91e0bd1e6251 ("powerpc/perf: Add PM_LD_MISS_L1 and PM_BR_2PATH to power9 event list")
Michal Suchanek fb3d24
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Michal Suchanek fb3d24
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Michal Suchanek fb3d24
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek fb3d24
Link: https://lore.kernel.org/r/20220419114828.89843-1-atrajeev@linux.vnet.ibm.com
Michal Suchanek fb3d24
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek fb3d24
---
Michal Suchanek fb3d24
 arch/powerpc/perf/power9-pmu.c | 8 ++++----
Michal Suchanek fb3d24
 1 file changed, 4 insertions(+), 4 deletions(-)
Michal Suchanek fb3d24
Michal Suchanek fb3d24
diff --git a/arch/powerpc/perf/power9-pmu.c b/arch/powerpc/perf/power9-pmu.c
Michal Suchanek fb3d24
index c9eb5232e68b..c393e837648e 100644
Michal Suchanek fb3d24
--- a/arch/powerpc/perf/power9-pmu.c
Michal Suchanek fb3d24
+++ b/arch/powerpc/perf/power9-pmu.c
Michal Suchanek fb3d24
@@ -133,11 +133,11 @@ int p9_dd22_bl_ev[] = {
Michal Suchanek fb3d24
 
Michal Suchanek fb3d24
 /* Table of alternatives, sorted by column 0 */
Michal Suchanek fb3d24
 static const unsigned int power9_event_alternatives[][MAX_ALT] = {
Michal Suchanek fb3d24
-	{ PM_INST_DISP,			PM_INST_DISP_ALT },
Michal Suchanek fb3d24
-	{ PM_RUN_CYC_ALT,		PM_RUN_CYC },
Michal Suchanek fb3d24
-	{ PM_RUN_INST_CMPL_ALT,		PM_RUN_INST_CMPL },
Michal Suchanek fb3d24
-	{ PM_LD_MISS_L1,		PM_LD_MISS_L1_ALT },
Michal Suchanek fb3d24
 	{ PM_BR_2PATH,			PM_BR_2PATH_ALT },
Michal Suchanek fb3d24
+	{ PM_INST_DISP,			PM_INST_DISP_ALT },
Michal Suchanek fb3d24
+	{ PM_RUN_CYC_ALT,               PM_RUN_CYC },
Michal Suchanek fb3d24
+	{ PM_LD_MISS_L1,                PM_LD_MISS_L1_ALT },
Michal Suchanek fb3d24
+	{ PM_RUN_INST_CMPL_ALT,         PM_RUN_INST_CMPL },
Michal Suchanek fb3d24
 };
Michal Suchanek fb3d24
 
Michal Suchanek fb3d24
 static int power9_get_alternatives(u64 event, unsigned int flags, u64 alt[])
Michal Suchanek fb3d24
-- 
Michal Suchanek fb3d24
2.34.1
Michal Suchanek fb3d24