diff mbox series

[v2,20/21] tools/perf: Pass the Counter constraint values in the pmu events

Message ID 20250114-counter_delegation-v2-20-8ba74cdb851b@rivosinc.com (mailing list archive)
State Superseded
Headers show
Series Add Counter delegation ISA extension support | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR fail merge-conflict
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-20-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 106.54s
conchuod/patch-20-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 1031.25s
conchuod/patch-20-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 1207.91s
conchuod/patch-20-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 16.30s
conchuod/patch-20-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 18.08s
conchuod/patch-20-test-6 success .github/scripts/patches/tests/checkpatch.sh took 0.35s
conchuod/patch-20-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 37.30s
conchuod/patch-20-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.00s
conchuod/patch-20-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.50s
conchuod/patch-20-test-10 success .github/scripts/patches/tests/module_param.sh took 0.01s
conchuod/patch-20-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-20-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.03s

Commit Message

Atish Kumar Patra Jan. 14, 2025, 10:57 p.m. UTC
RISC-V doesn't have any standard event to counter mapping discovery
mechanism in the ISA. The ISA defines 29 programmable counters and
platforms can choose to implement any number of them and map any
events to any counters. Thus, the perf tool need to inform the driver
about the counter mapping of each events.

The current perf infrastructure only parses the 'Counter' constraints
in metrics. This patch extends that to pass in the pmu events so that
any driver can retrieve those values via perf attributes if defined
accordingly.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 tools/perf/pmu-events/jevents.py | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 28acd598dd7c..c21945238469 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -274,6 +274,11 @@  class JsonEvent:
         return fixed[name.lower()]
       return event
 
+    def counter_list_to_bitmask(counterlist):
+      counter_ids = list(map(int, counterlist.split(',')))
+      bitmask = sum(1 << pos for pos in counter_ids)
+      return bitmask
+
     def unit_to_pmu(unit: str) -> Optional[str]:
       """Convert a JSON Unit to Linux PMU name."""
       if not unit or unit == "core":
@@ -427,6 +432,10 @@  class JsonEvent:
       else:
         raise argparse.ArgumentTypeError('Cannot find arch std event:', arch_std)
 
+    if self.counters['list']:
+      bitmask = counter_list_to_bitmask(self.counters['list'])
+      event += f',counterid_mask={bitmask:#x}'
+
     self.event = real_event(self.name, event)
 
   def __repr__(self) -> str: