Skip to contentSkip to conversation

drivers/perf: riscv: handle legacy fallback in event check

PATCH In review Sergey Matyukevich 2 participants 2 messages Jul 10 – Jul 31

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/perf: riscv: handle legacy fallback in event check

Common events PERF_COUNT_HW_CPU_CYCLES and PERF_COUNT_HW_INSTRUCTIONS can fall back to the legacy counters. So do not mark them as invalid if OpenSBI reports that they are not mapped to sampling counters in PMU DT node.

---
 drivers/perf/riscv_pmu_sbi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/perf/riscv_pmu_sbi.c +2 -1
index dfc886dee5ad..8f7aa71dc96f 100644
@@ -335,7 +335,8 @@ static int pmu_sbi_check_event_info(void)
 		goto free_mem;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) {
+	/* skip check for cycles and instructions as they can fall back to legacy counters */
+	for (i = 2; i < ARRAY_SIZE(pmu_hw_event_map); i++) {
 		if (!(event_info_shmem[i].output & RISCV_PMU_EVENT_INFO_OUTPUT_MASK))
 			pmu_hw_event_map[i].event_idx = -ENOENT;
 	}

base-commit: a635d6748234582ea287c5ffeae28b9b23f91c7e

Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 15 lines · Sergey Matyukevich

Common events PERF_COUNT_HW_CPU_CYCLES and PERF_COUNT_HW_INSTRUCTIONS can fall back to the legacy counters. So do not mark them as invalid if OpenSBI reports that they are not mapped to sampling counters in PMU DT node.

---
 drivers/perf/riscv_pmu_sbi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/perf/riscv_pmu_sbi.c +0 -0
index dfc886dee5ad..8f7aa71dc96f 100644

drivers/perf/riscv_pmu_sbi.c static int pmu_sbi_check_event_info(void) · line 342

Quoted 9 lines
drivers/perf/riscv_pmu_sbi.c +2 -1
@@ -335,7 +335,8 @@ static int pmu_sbi_check_event_info(void)
 		goto free_mem;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) {
+	/* skip check for cycles and instructions as they can fall back to legacy counters */
+	for (i = 2; i < ARRAY_SIZE(pmu_hw_event_map); i++) {
 		if (!(event_info_shmem[i].output & RISCV_PMU_EVENT_INFO_OUTPUT_MASK))
 			pmu_hw_event_map[i].event_idx = -ENOENT;
 	}

I'm assuming the riscv tree are handling perf patches to the riscv driver, but please shout if not.

Will