Skip to contentSkip to conversation

perf: ampere: Add support for Ampere SoC PMUs

PATCH Superseded Ilkka Koskinen 2 participants 3 messages Apr 27, 2023 – May 1, 2023

Subsystems (2)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: ampere: Add support for Ampere SoC PMUs

Add support for Ampere SoC PMUs. This driver supports MCU PMU available in the AmpereOne SoC.

---
 .../admin-guide/perf/ampere-soc-pmu.rst       |  36 +
 Documentation/admin-guide/perf/index.rst      |   1 +
 drivers/perf/Kconfig                          |  10 +
 drivers/perf/Makefile                         |   1 +
 drivers/perf/ampere_soc_pmu.c                 | 724 ++++++++++++++++++
 5 files changed, 772 insertions(+)
 create mode 100644 Documentation/admin-guide/perf/ampere-soc-pmu.rst
 create mode 100644 drivers/perf/ampere_soc_pmu.c
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +36 -0
new file mode 100644
index 000000000000..5161fbd1c548
@@ -0,0 +1,36 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============================================
+Ampere SoC Performance Monitoring Unit (PMU)
+============================================
+
+Ampere SoC PMU is a generic PMU IP. At the first phase it's used for counting
+MCU events on AmpereOne.
+
+MCU PMU events
+--------------
+
+The PMU driver registers a PMU device for every supported PMU instance on each
+SoC. See /sys/devices/AMPC0100:<nn>/.
+
+The PMU driver supports setting filters for "rank", "bank", and "threshold". The
+filter settings are device specific and shared between all the relevant events.
+The default value for all the filters is zero. The filters can be modified by
+setting them with the last event of the particular device. All the previous
+settings are overwritten.
+
+
+Example for perf tool use::
+
+  / # perf list mcu
+    mcu0/cycle-count                                  [Kernel PMU event]
+  <...>
+    mcu16/cycle-count                                 [Kernel PMU event]
+  <...>
+
+  / # perf stat -a -e mcu0/cycle-count,bank=5/,mcu0/dfi-cmd,threshold=16,rank=8/,mcu1/dfi-cmd/ \
+        sleep 1
+
+Note, as none of the filters was set for mcu1, the default value is assigned to
+them. For mcu0, bank setting will be overwritten with the default value since
+it wasn't set with the last mcu0 event.
Documentation/admin-guide/perf/index.rst +1 -0
index 9de64a40adab..8de9d253ae81 100644
@@ -21,3 +21,4 @@ Performance monitor support
    alibaba_pmu
    nvidia-pmu
    meson-ddr-pmu
+   ampere-soc-pmu
drivers/perf/Kconfig +10 -0
index 711f82400086..6551005aaa04 100644
@@ -209,6 +209,16 @@ config MARVELL_CN10K_DDR_PMU
 	  Enable perf support for Marvell DDR Performance monitoring
 	  event on CN10K platform.
 
+config AMPERE_SOC_PMU
+	tristate "Ampere SoC PMU"
+	depends on ARM64 && ACPI
+	help
+	  Enable support for Ampere SoC performance counters used on
+	  Ampere SoCs.
+
+	  The SoC PMU can support multiple different PMU types. At the first
+	  phase it supports MCU PMU available on AmpereOne.
+
 source "drivers/perf/arm_cspmu/Kconfig"
 
 source "drivers/perf/amlogic/Kconfig"
drivers/perf/Makefile +1 -0
index dabc859540ce..17be9b0f75f8 100644
@@ -24,3 +24,4 @@ obj-$(CONFIG_APPLE_M1_CPU_PMU) += apple_m1_cpu_pmu.o
 obj-$(CONFIG_ALIBABA_UNCORE_DRW_PMU) += alibaba_uncore_drw_pmu.o
 obj-$(CONFIG_ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU) += arm_cspmu/
 obj-$(CONFIG_MESON_DDR_PMU) += amlogic/
+obj-$(CONFIG_AMPERE_SOC_PMU) += ampere_soc_pmu.o
drivers/perf/ampere_soc_pmu.c new file +724 -0

724 lines not on this page · raw message

Signature · 1 line
2.39.2
#1 lore raw
Quoted 30 lines · Ilkka Koskinen

Add support for Ampere SoC PMUs. This driver supports MCU PMU available in the AmpereOne SoC.

---
  .../admin-guide/perf/ampere-soc-pmu.rst       |  36 +
  Documentation/admin-guide/perf/index.rst      |   1 +
  drivers/perf/Kconfig                          |  10 +
  drivers/perf/Makefile                         |   1 +
  drivers/perf/ampere_soc_pmu.c                 | 724 ++++++++++++++++++
  5 files changed, 772 insertions(+)

create mode 100644 Documentation/admin-guide/perf/ampere-soc-pmu.rst create mode 100644 drivers/perf/ampere_soc_pmu.c

Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +10 -0
new file mode 100644
index 000000000000..5161fbd1c548
@@ -0,0 +1,36 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============================================
+Ampere SoC Performance Monitoring Unit (PMU)
+============================================
+
+Ampere SoC PMU is a generic PMU IP. At the first phase it's used for counting
+MCU events on AmpereOne.
+
+MCU PMU events

Documentation/admin-guide/perf/ampere-soc-pmu.rst line 20

Quoted 10 lines
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +10 -0
+--------------
+
+The PMU driver registers a PMU device for every supported PMU instance on each
+SoC. See /sys/devices/AMPC0100:<nn>/.
+
+The PMU driver supports setting filters for "rank", "bank", and "threshold". The
+filter settings are device specific and shared between all the relevant events.
+The default value for all the filters is zero. The filters can be modified by
+setting them with the last event of the particular device. All the previous
+settings are overwritten.

Yeah, that doesn't really work... what is the "last event" relative to? Order of arguments to arbitrary tools? Order of perf_event_open syscalls? Order in which events are actually scheduled on the PMU? (which users can't even control - think event rotation)

To be practical I think you'll have to handle this the same way as arm_smmuv3_pmu's global filtering, and only allow events with matching filter configs to be scheduled together.

[...]

Quoted 28 lines
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +28 -0
+#define SOC_PMEVCNTR0_LO	0x000
+#define SOC_PMEVCNTR0_HI	0x004
+#define SOC_PMCCNTR_LO		0x0F8
+#define SOC_PMCCNTR_HI		0x0FC
+
+#define SOC_PMEVTYPER0		0x400
+
+#define SOC_PMELCSR		0xA10
+
+#define SOC_PMCNTENSET		0xC00
+#define SOC_PMCNTENCLR		0xC20
+#define SOC_PMINTENSET		0xC40
+#define SOC_PMINTENCLR		0xC60
+#define SOC_PMOVSCLR		0xC80
+#define SOC_PMOVSSET		0xCC0
+
+#define SOC_PMAUXR0		0xD80
+#define SOC_PMAUXR1		0xD84
+#define SOC_PMAUXR2		0xD88
+#define SOC_PMAUXR3		0xD8C
+
+#define SOC_PMCFGR		0xE00
+#define SOC_PMCR		0xE04
+#define PMU_PMCR_E		BIT(0)
+#define PMU_PMCR_P		BIT(1)
+
+#define SOC_PMAUTHSTATUS	0xFB8
+#define SOC_PMDEVARCH		0xFBC

Documentation/admin-guide/perf/ampere-soc-pmu.rst

Quoted 10 lines
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +10 -0
+#define SOC_PMDEVTYPE		0xFCC
+#define SOC_PMPIDR4		0xFD0
+#define SOC_PMPIDR0		0xFE0
+#define SOC_PMPIDR1		0xFE4
+#define SOC_PMPIDR2		0xFE8
+#define SOC_PMPIDR3		0xFEC
+#define SOC_PMCIDR0		0xFF0
+#define SOC_PMCIDR1		0xFF4
+#define SOC_PMCIDR2		0xFF8
+#define SOC_PMCIDR3		0xFFC

This register map quite clearly follows the Arm CoreSight PMU architecture. Nice to see it being used, but would you mind having a go at hooking up your imp-def bits to the existing arm_cspmu driver?

Thanks,
Robin.

#2 lore raw

Hi Robin,

Quoted 50 lines · Robin Murphy
Quoted 38 lines · Ilkka Koskinen

Add support for Ampere SoC PMUs. This driver supports MCU PMU available in the AmpereOne SoC.

---
  .../admin-guide/perf/ampere-soc-pmu.rst       |  36 +
  Documentation/admin-guide/perf/index.rst      |   1 +
  drivers/perf/Kconfig                          |  10 +
  drivers/perf/Makefile                         |   1 +
  drivers/perf/ampere_soc_pmu.c                 | 724 ++++++++++++++++++
  5 files changed, 772 insertions(+)

create mode 100644 Documentation/admin-guide/perf/ampere-soc-pmu.rst create mode 100644 drivers/perf/ampere_soc_pmu.c

Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +7 -0
new file mode 100644
index 000000000000..5161fbd1c548
@@ -0,0 +1,36 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============================================
+Ampere SoC Performance Monitoring Unit (PMU)
+============================================
+
+Ampere SoC PMU is a generic PMU IP. At the first phase it's used for 

counting

Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +6 -0
+MCU events on AmpereOne.
+
+MCU PMU events
+--------------
+
+The PMU driver registers a PMU device for every supported PMU instance on 

each

Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +3 -0
+SoC. See /sys/devices/AMPC0100:<nn>/.
+
+The PMU driver supports setting filters for "rank", "bank", and 
Quoted 8 lines

"threshold". The
+filter settings are device specific and shared between all the relevant events.
+The default value for all the filters is zero. The filters can be modified by
+setting them with the last event of the particular device. All the previous
+settings are overwritten.

Yeah, that doesn't really work... what is the "last event" relative to? Order of arguments to arbitrary tools? Order of perf_event_open syscalls? Order in which events are actually scheduled on the PMU? (which users can't even control - think event rotation)

Quoted 1 line

To be practical I think you'll have to handle this the same way as arm_smmuv3_pmu's global filtering, and only allow events with matching filter configs to be scheduled together.

Thanks for pointing out that to me! I thought my implementation had an issue with the shared filters but when I tried to look, if any of the supported PMUs was using them the same way, I somehow missed arm_smmuv3_pmu. I fix the driver.

Quoted 34 lines

[...]

Quoted 32 lines
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +32 -0
+#define SOC_PMEVCNTR0_LO	0x000
+#define SOC_PMEVCNTR0_HI	0x004
+#define SOC_PMCCNTR_LO		0x0F8
+#define SOC_PMCCNTR_HI		0x0FC
+
+#define SOC_PMEVTYPER0		0x400
+
+#define SOC_PMELCSR		0xA10
+
+#define SOC_PMCNTENSET		0xC00
+#define SOC_PMCNTENCLR		0xC20
+#define SOC_PMINTENSET		0xC40
+#define SOC_PMINTENCLR		0xC60
+#define SOC_PMOVSCLR		0xC80
+#define SOC_PMOVSSET		0xCC0
+
+#define SOC_PMAUXR0		0xD80
+#define SOC_PMAUXR1		0xD84
+#define SOC_PMAUXR2		0xD88
+#define SOC_PMAUXR3		0xD8C
+
+#define SOC_PMCFGR		0xE00
+#define SOC_PMCR		0xE04
+#define PMU_PMCR_E		BIT(0)
+#define PMU_PMCR_P		BIT(1)
+
+#define SOC_PMAUTHSTATUS	0xFB8
+#define SOC_PMDEVARCH		0xFBC
+#define SOC_PMDEVTYPE		0xFCC
+#define SOC_PMPIDR4		0xFD0
+#define SOC_PMPIDR0		0xFE0
+#define SOC_PMPIDR1		0xFE4
Quoted 8 lines

Documentation/admin-guide/perf/ampere-soc-pmu.rst

Quoted 6 lines
Documentation/admin-guide/perf/ampere-soc-pmu.rst new file +6 -0
+#define SOC_PMPIDR2		0xFE8
+#define SOC_PMPIDR3		0xFEC
+#define SOC_PMCIDR0		0xFF0
+#define SOC_PMCIDR1		0xFF4
+#define SOC_PMCIDR2		0xFF8
+#define SOC_PMCIDR3		0xFFC

This register map quite clearly follows the Arm CoreSight PMU architecture. Nice to see it being used, but would you mind having a go at hooking up your imp-def bits to the existing arm_cspmu driver?

I didn't think about that. I'll take a look at the coresight pmu driver and see how I could do it properly.

Thanks, Ilkka