perf: riscv: Fix selecting counters in legacy mode
Dmitry Shifrin
dmitry.shifrin at syntacore.com
Tue Jul 30 01:47:47 PDT 2024
Hi Alexandre,
On Mon, 2024-07-29 at 20:17 +0200, Alexandre Ghiti wrote:
> Hi Dmitry,
>
> On 29/07/2024 20:05, Atish Patra wrote:
> > > 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 at syntacore.com>
> > > ---
> > > drivers/perf/riscv_pmu_sbi.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> > > index 36d128ff166f..bf14ab282e11 100644
> > > --- a/drivers/perf/riscv_pmu_sbi.c
> > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > @@ -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;
> > >
> > Nice catch.
> > Reviewed-by: Atish Patra <atishp at rivosinc.com>
>
>
> Can you add a Fixes tag? No need to send another version, just reply
> with the corresponding tag and b4 will grab it.
>
Fixes: cc4c07c89aad ("drivers: perf: Implement perf event mmap support in the SBI backend")
Thanks, Dmitry
> Thanks!
>
> Alex
>
>
> >
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
More information about the linux-riscv
mailing list