]> www.infradead.org Git - users/willy/xarray.git/commitdiff
perf: riscv: Fix selecting counters in legacy mode
authorShifrin Dmitry <dmitry.shifrin@syntacore.com>
Mon, 29 Jul 2024 12:58:58 +0000 (15:58 +0300)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 1 Aug 2024 14:15:13 +0000 (07:15 -0700)
It is required to check event type before checking event config.
Events with the different types can have the same config.
This check is missed for legacy mode code

For such perf usage:
    sysctl -w kernel.perf_user_access=2
    perf stat -e cycles,L1-dcache-loads --
driver will try to force both events to CYCLE counter.

This commit implements event type check before forcing
events on the special counters.

Signed-off-by: Shifrin Dmitry <dmitry.shifrin@syntacore.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Fixes: cc4c07c89aad ("drivers: perf: Implement perf event mmap support in the SBI backend")
Link: https://lore.kernel.org/r/20240729125858.630653-1-dmitry.shifrin@syntacore.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
drivers/perf/riscv_pmu_sbi.c

index 44d3951d009fb09a21fba1d92827598e5a76f6c4..31a17a56eb3bba1b2d70e6443f37197ef3d78554 100644 (file)
@@ -416,7 +416,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
         * but not in the user access mode as we want to use the other counters
         * that support sampling/filtering.
         */
-       if (hwc->flags & PERF_EVENT_FLAG_LEGACY) {
+       if ((hwc->flags & PERF_EVENT_FLAG_LEGACY) && (event->attr.type == PERF_TYPE_HARDWARE)) {
                if (event->attr.config == PERF_COUNT_HW_CPU_CYCLES) {
                        cflags |= SBI_PMU_CFG_FLAG_SKIP_MATCH;
                        cmask = 1;