Re: [PATCH 9/9] perf: arm_pmuv3: Add support for Armv9.4 PMU instruction counter

From: Rob Herring
Date: Mon Jun 10 2024 - 10:16:06 EST


On Mon, Jun 10, 2024 at 5:55 AM Mark Rutland <mark.rutland@xxxxxxx> wrote:
>
> On Fri, Jun 07, 2024 at 02:31:34PM -0600, Rob Herring (Arm) wrote:
> > Armv9.4/8.9 PMU adds optional support for a fixed instruction counter
> > similar to the fixed cycle counter. Support for the feature is indicated
> > in the ID_AA64DFR1_EL1 register PMICNTR field. The counter is not
> > accessible in AArch32.
> >
> > Existing userspace using direct counter access won't know how to handle
> > the fixed instruction counter, so we have to avoid using the counter
> > when user access is requested.
> >
> > Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
> > ---
> > arch/arm/include/asm/arm_pmuv3.h | 21 +++++++++++++++++++++
> > arch/arm64/include/asm/arm_pmuv3.h | 29 +++++++++++++++++++++++++++++
> > arch/arm64/kvm/pmu.c | 8 ++++++--
> > arch/arm64/tools/sysreg | 25 +++++++++++++++++++++++++
> > drivers/perf/arm_pmuv3.c | 28 ++++++++++++++++++++++++++--
> > include/linux/perf/arm_pmu.h | 8 ++++++--
> > include/linux/perf/arm_pmuv3.h | 4 +++-
> > 7 files changed, 116 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/arm/include/asm/arm_pmuv3.h b/arch/arm/include/asm/arm_pmuv3.h
> > index ac2cf37b57e3..b836537ddfbf 100644
> > --- a/arch/arm/include/asm/arm_pmuv3.h
> > +++ b/arch/arm/include/asm/arm_pmuv3.h
> > @@ -10,6 +10,7 @@
> > #include <asm/cputype.h>
> >
> > #define ARMV8_PMU_CYCLE_IDX 31
> > +#define ARMV8_PMU_INSTR_IDX 32 /* Not accessible from AArch32 */
>
> As with ARMV8_PMU_CYCLE_IDX, I reckon this should live in
> <linux/perf/arm_pmuv3.h> (with the comment above) so that we don't need
> separate definitions for arm & arm64.

Sure. My only reasoning was to not pull in everything defined in
<linux/perf/arm_pmuv3.h> where it is not needed (KVM).

Of course, the normal pattern here is that linux/foo.h includes
asm/foo.h. We should probably do that here because the arm64 version
of arm_pmuv3.h depends on defines (e.g. PMEVN_SWITCH) in
perf/arm_pmuv3.h, but there is no explicit include. I'll add doing
that into the series.

> [...]
>
> > diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
> > index 231817a379b5..8ab6e09871de 100644
> > --- a/arch/arm64/tools/sysreg
> > +++ b/arch/arm64/tools/sysreg
> > @@ -2029,6 +2029,31 @@ Sysreg FAR_EL1 3 0 6 0 0
> > Field 63:0 ADDR
> > EndSysreg
> >
> > +Sysreg PMICNTR_EL0 3 3 9 4 0
> > +Field 63:0 ICNT
> > +EndSysreg
>
> LGTM per ARM DDI 0487K.a, section D23.5.15, pages 8989 to 8992.
>
> > +
> > +Sysreg PMICFILTR_EL0 3 3 9 6 0
> > +Res0 63:59
> > +Field 58 SYNC
> > +Field 57:56 VS
>
> The 'VS' field doesn't seem to be in the ARM ARM (ARM DDI 0487K.a); is
> that defined in a supplement?

It is in the A-profile Arch Registers doc:
https://developer.arm.com/documentation/ddi0601/2024-03/AArch64-Registers/PMICFILTR-EL0--Performance-Monitors-Instruction-Counter-Filter-Register?lang=en

> > +Res0 55:32
> > +Field 31 P
> > +Field 30 U
> > +Field 29 NSK
> > +Field 28 NSU
> > +Field 27 NSH
> > +Field 26 M
> > +Res0 25
> > +Field 24 SH
> > +Field 23 T
> > +Field 22 RLK
> > +Field 21 RLU
> > +Field 20 RLH
> > +Res0 19:16
> > +Field 15:0 evtCount
> > +EndSysreg
>
> Aside from 'VS', this LGTM per ARM DDI 0487K.a, section D23.5.14, pages
> 8981 to 8988.
>
> One important thing to note is that this doesn't have the threshold
> controls (TC, TE, TH); so if threshold events make sense for instruction
> events, we cannot place those in the dedicated isntruction counter.

Talking to James C, he thinks there could be. Counting cycles which
retired more than 1 instruction was what he came up with.

Also, looks like we need to handle thresholds for the cycle counter as
well. Either reject thresholds for cycles events or don't place cycles
on the fixed cycle counter if thresholds are used. While thresholds
with cycles doesn't make much sense, James prefers the latter as he
did do that for testing.

Rob