Michal Suchanek 2fb7ad
From c6cc9a852f123301d5271f1484df8e961b2b64f1 Mon Sep 17 00:00:00 2001
Michal Suchanek 2fb7ad
From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Michal Suchanek 2fb7ad
Date: Tue, 19 Apr 2022 17:18:28 +0530
Michal Suchanek 2fb7ad
Subject: [PATCH] powerpc/perf: Fix power10 event alternatives
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
References: jsc#SLE-13513 git-fixes
Michal Suchanek 2fb7ad
Patch-mainline: v5.18-rc4
Michal Suchanek 2fb7ad
Git-commit: c6cc9a852f123301d5271f1484df8e961b2b64f1
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
When scheduling a group of events, there are constraint checks done to
Michal Suchanek 2fb7ad
make sure all events can go in a group. Example, one of the criteria is
Michal Suchanek 2fb7ad
that events in a group cannot use the same PMC. But platform specific
Michal Suchanek 2fb7ad
PMU supports alternative event for some of the event codes. During
Michal Suchanek 2fb7ad
perf_event_open(), if any event group doesn't match constraint check
Michal Suchanek 2fb7ad
criteria, further lookup is done to find alternative event.
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
By current design, the array of alternatives events in PMU code is
Michal Suchanek 2fb7ad
expected to be sorted by column 0. This is because in
Michal Suchanek 2fb7ad
find_alternative() the return criteria is based on event code
Michal Suchanek 2fb7ad
comparison. ie. "event < ev_alt[i][0])". This optimisation is there
Michal Suchanek 2fb7ad
since find_alternative() can be called multiple times. In power10 PMU
Michal Suchanek 2fb7ad
code, the alternative event array is not sorted properly and hence there
Michal Suchanek 2fb7ad
is breakage in finding alternative event.
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
To work with existing logic, fix the alternative event array to be
Michal Suchanek 2fb7ad
sorted by column 0 for power10-pmu.c
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
Results:
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
In case where an alternative event is not chosen when we could, events
Michal Suchanek 2fb7ad
will be multiplexed. ie, time sliced where it could actually run
Michal Suchanek 2fb7ad
concurrently.
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
Example, in power10 PM_INST_CMPL_ALT(0x00002) has alternative event,
Michal Suchanek 2fb7ad
PM_INST_CMPL(0x500fa). Without the fix, if a group of events with PMC1
Michal Suchanek 2fb7ad
to PMC4 is used along with PM_INST_CMPL_ALT, it will be time sliced
Michal Suchanek 2fb7ad
since all programmable PMC's are consumed already. But with the fix,
Michal Suchanek 2fb7ad
when it picks alternative event on PMC5, all events will run
Michal Suchanek 2fb7ad
concurrently.
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
Before:
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
 # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
 Performance counter stats for 'system wide':
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
         328668935      r00002               (79.94%)
Michal Suchanek 2fb7ad
          56501024      r100fc               (79.95%)
Michal Suchanek 2fb7ad
          49564238      r200fa               (79.95%)
Michal Suchanek 2fb7ad
               376      r300fc               (80.19%)
Michal Suchanek 2fb7ad
               660      r400fc               (79.97%)
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
       4.039150522 seconds time elapsed
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
With the fix, since alternative event is chosen to run on PMC6, events
Michal Suchanek 2fb7ad
will be run concurrently.
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
After:
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
 # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
 Performance counter stats for 'system wide':
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
          23596607      r00002
Michal Suchanek 2fb7ad
           4907738      r100fc
Michal Suchanek 2fb7ad
           2283608      r200fa
Michal Suchanek 2fb7ad
               135      r300fc
Michal Suchanek 2fb7ad
               248      r400fc
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
       1.664671390 seconds time elapsed
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
Fixes: a64e697cef23 ("powerpc/perf: power10 Performance Monitoring support")
Michal Suchanek 2fb7ad
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Michal Suchanek 2fb7ad
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Michal Suchanek 2fb7ad
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek 2fb7ad
Link: https://lore.kernel.org/r/20220419114828.89843-2-atrajeev@linux.vnet.ibm.com
Michal Suchanek 2fb7ad
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 2fb7ad
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 2fb7ad
---
Michal Suchanek 2fb7ad
 arch/powerpc/perf/power10-pmu.c | 2 +-
Michal Suchanek 2fb7ad
 1 file changed, 1 insertion(+), 1 deletion(-)
Michal Suchanek 2fb7ad
Michal Suchanek 2fb7ad
diff --git a/arch/powerpc/perf/power10-pmu.c b/arch/powerpc/perf/power10-pmu.c
Michal Suchanek 2fb7ad
index d3398100a60f..c6d51e7093cf 100644
Michal Suchanek 2fb7ad
--- a/arch/powerpc/perf/power10-pmu.c
Michal Suchanek 2fb7ad
+++ b/arch/powerpc/perf/power10-pmu.c
Michal Suchanek 2fb7ad
@@ -91,8 +91,8 @@ extern u64 PERF_REG_EXTENDED_MASK;
Michal Suchanek 2fb7ad
 
Michal Suchanek 2fb7ad
 /* Table of alternatives, sorted by column 0 */
Michal Suchanek 2fb7ad
 static const unsigned int power10_event_alternatives[][MAX_ALT] = {
Michal Suchanek 2fb7ad
-	{ PM_CYC_ALT,			PM_CYC },
Michal Suchanek 2fb7ad
 	{ PM_INST_CMPL_ALT,		PM_INST_CMPL },
Michal Suchanek 2fb7ad
+	{ PM_CYC_ALT,			PM_CYC },
Michal Suchanek 2fb7ad
 };
Michal Suchanek 2fb7ad
 
Michal Suchanek 2fb7ad
 static int power10_get_alternatives(u64 event, unsigned int flags, u64 alt[])
Michal Suchanek 2fb7ad
-- 
Michal Suchanek 2fb7ad
2.34.1
Michal Suchanek 2fb7ad