Skip to contentSkip to conversation

perf: ampere: Add support for Ampere SoC PMUs

PATCH Superseded Ilkka Koskinen 2 participants 7 messages Jul 14, 2023 – Jul 31, 2023

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover perf: ampere: Add support for Ampere SoC PMUs

Changes since v4:
* "Support implementation specific filters" patch:
- Added comment about filter and impdef registers and reference to the Coresight PMU specification to the commit message

* "Add support for Ampere SoC PMU" patch:
- Fixed the documentation and added more comments
- Changed the incrementing PMU index number to idr_alloc() (Needs a impdef release hook patch to release unused index)
- Fixed style in init_ops() to more reasonable
- Moved bank parameter to config1

Changes since v3:
* use_64b_counter_reg => has_atomic_dword (patch 1/4)
* Removed the unnecessary hook for group validation (patch 3/4)
* Added group config validation to ampere_cspmu_validate_event() (patch 4/4)
* Rebased the patchset

Changes since v2:
* Changed to use supports_64bits_atomics() and replaced the split writes with lo_hi_writeq()
* Added implementation specific group validation to patch 3
* Dropped shared interrupt patch
* Removed unnecessary filter_enable parameter from ampere module
* Added group validation to ampere module

Changes since v1:
* Rather than creating a completely new driver, implemented as a submodule of Arm CoreSight PMU driver
* Fixed shared filter handling

Ilkka Koskinen (4):
perf: arm_cspmu: Split 64-bit write to 32-bit writes
perf: arm_cspmu: Support implementation specific filters
perf: arm_cspmu: Support implementation specific validation
perf: arm_cspmu: ampere_cspmu: Add support for Ampere SoC PMU

 .../admin-guide/perf/ampere_cspmu.rst         |  29 +++
 drivers/perf/arm_cspmu/Makefile               |   2 +-
 drivers/perf/arm_cspmu/ampere_cspmu.c         | 243 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |  29 ++-
 drivers/perf/arm_cspmu/arm_cspmu.h            |   6 +
 6 files changed, 321 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/admin-guide/perf/ampere_cspmu.rst
 create mode 100644 drivers/perf/arm_cspmu/ampere_cspmu.c
 create mode 100644 drivers/perf/arm_cspmu/ampere_cspmu.h
Signature · 1 line
2.40.1
#1 lore raw

PATCH v5 1/4 perf: arm_cspmu: Split 64-bit write to 32-bit writes

Split the 64-bit register accesses if 64-bit access is not supported by the PMU.

---
 drivers/perf/arm_cspmu/arm_cspmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +4 -1
index e2b7827c4563..0f517152cb4e 100644
@@ -696,7 +696,10 @@ static void arm_cspmu_write_counter(struct perf_event *event, u64 val)
 	if (use_64b_counter_reg(cspmu)) {
 		offset = counter_offset(sizeof(u64), event->hw.idx);
 
-		writeq(val, cspmu->base1 + offset);
+		if (cspmu->has_atomic_dword)
+			writeq(val, cspmu->base1 + offset);
+		else
+			lo_hi_writeq(val, cspmu->base1 + offset);
 	} else {
 		offset = counter_offset(sizeof(u32), event->hw.idx);
 
Signature · 1 line
2.40.1
#2 lore raw

PATCH v5 2/4 perf: arm_cspmu: Support implementation specific filters

In reply to Ilkka Koskinen

ARM Coresight PMU architecture specification [1] defines PMEVTYPER and PMEVFILT* registers as optional in Chapter 2.1. Moreover, implementers may choose to use PMIMPDEF* registers (offset: 0xD80-> 0xDFF) to filter the events. Add support for those by adding implementation specific filter callback function.

[1] https://developer.arm.com/documentation/ihi0091/latest

---
 drivers/perf/arm_cspmu/arm_cspmu.c | 8 ++++++--
 drivers/perf/arm_cspmu/arm_cspmu.h | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/perf/arm_cspmu/arm_cspmu.c +6 -2
index 0f517152cb4e..fafd734c3218 100644
@@ -117,6 +117,9 @@
 
 static unsigned long arm_cspmu_cpuhp_state;
 
+static void arm_cspmu_set_ev_filter(struct arm_cspmu *cspmu,
+				    struct hw_perf_event *hwc, u32 filter);
+
 static struct acpi_apmt_node *arm_cspmu_apmt_node(struct device *dev)
 {
 	return *(struct acpi_apmt_node **)dev_get_platdata(dev);
@@ -426,6 +429,7 @@ static int arm_cspmu_init_impl_ops(struct arm_cspmu *cspmu)
 	CHECK_DEFAULT_IMPL_OPS(impl_ops, event_type);
 	CHECK_DEFAULT_IMPL_OPS(impl_ops, event_filter);
 	CHECK_DEFAULT_IMPL_OPS(impl_ops, event_attr_is_visible);
+	CHECK_DEFAULT_IMPL_OPS(impl_ops, set_ev_filter);
 
 	return 0;
 }
@@ -792,7 +796,7 @@ static inline void arm_cspmu_set_event(struct arm_cspmu *cspmu,
 	writel(hwc->config, cspmu->base0 + offset);
 }
 
-static inline void arm_cspmu_set_ev_filter(struct arm_cspmu *cspmu,
+static void arm_cspmu_set_ev_filter(struct arm_cspmu *cspmu,
 					   struct hw_perf_event *hwc,
 					   u32 filter)
 {
@@ -826,7 +830,7 @@ static void arm_cspmu_start(struct perf_event *event, int pmu_flags)
 		arm_cspmu_set_cc_filter(cspmu, filter);
 	} else {
 		arm_cspmu_set_event(cspmu, hwc);
-		arm_cspmu_set_ev_filter(cspmu, hwc, filter);
+		cspmu->impl.ops.set_ev_filter(cspmu, hwc, filter);
 	}
 
 	hwc->state = 0;
drivers/perf/arm_cspmu/arm_cspmu.h +3 -0
index 83df53d1c132..d6d88c246a23 100644
@@ -101,6 +101,9 @@ struct arm_cspmu_impl_ops {
 	u32 (*event_type)(const struct perf_event *event);
 	/* Decode filter value from configs */
 	u32 (*event_filter)(const struct perf_event *event);
+	/* Set event filter */
+	void (*set_ev_filter)(struct arm_cspmu *cspmu,
+			      struct hw_perf_event *hwc, u32 filter);
 	/* Hide/show unsupported events */
 	umode_t (*event_attr_is_visible)(struct kobject *kobj,
 					 struct attribute *attr, int unused);
Signature · 1 line
2.40.1
#3 lore raw

PATCH v5 3/4 perf: arm_cspmu: Support implementation specific validation

In reply to Ilkka Koskinen

Some platforms may use e.g. different filtering mechanism and, thus, may need different way to validate the events and group.

---
 drivers/perf/arm_cspmu/arm_cspmu.c | 8 +++++++-
 drivers/perf/arm_cspmu/arm_cspmu.h | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +7 -1
index fafd734c3218..471d6d7ac81a 100644
@@ -553,7 +553,7 @@ static void arm_cspmu_disable(struct pmu *pmu)
 static int arm_cspmu_get_event_idx(struct arm_cspmu_hw_events *hw_events,
 				struct perf_event *event)
 {
-	int idx;
+	int idx, ret;
 	struct arm_cspmu *cspmu = to_arm_cspmu(event->pmu);
 
 	if (supports_cycle_counter(cspmu)) {
@@ -587,6 +587,12 @@ static int arm_cspmu_get_event_idx(struct arm_cspmu_hw_events *hw_events,
 	if (idx >= cspmu->num_logical_ctrs)
 		return -EAGAIN;
 
+	if (cspmu->impl.ops.validate_event) {
+		ret = cspmu->impl.ops.validate_event(cspmu, event);
+		if (ret)
+			return ret;
+	}
+
 	set_bit(idx, hw_events->used_ctrs);
 
 	return idx;
drivers/perf/arm_cspmu/arm_cspmu.h +3 -0
index d6d88c246a23..5070d34c2285 100644
@@ -104,6 +104,9 @@ struct arm_cspmu_impl_ops {
 	/* Set event filter */
 	void (*set_ev_filter)(struct arm_cspmu *cspmu,
 			      struct hw_perf_event *hwc, u32 filter);
+	/* Implementation specific event validation */
+	int (*validate_event)(struct arm_cspmu *cspmu,
+			      struct perf_event *event);
 	/* Hide/show unsupported events */
 	umode_t (*event_attr_is_visible)(struct kobject *kobj,
 					 struct attribute *attr, int unused);
Signature · 1 line
2.40.1
#4 lore raw

PATCH v5 4/4 perf: arm_cspmu: ampere_cspmu: Add support for Ampere SoC PMU

In reply to Ilkka Koskinen

Ampere SoC PMU follows CoreSight PMU architecture. It uses implementation specific registers to filter events rather than PMEVFILTnR registers.

---
 .../admin-guide/perf/ampere_cspmu.rst         |  29 +++
 drivers/perf/arm_cspmu/Makefile               |   2 +-
 drivers/perf/arm_cspmu/ampere_cspmu.c         | 243 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |   8 +
 5 files changed, 298 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/admin-guide/perf/ampere_cspmu.rst
 create mode 100644 drivers/perf/arm_cspmu/ampere_cspmu.c
 create mode 100644 drivers/perf/arm_cspmu/ampere_cspmu.h
Documentation/admin-guide/perf/ampere_cspmu.rst new file +29 -0
new file mode 100644
index 000000000000..94f93f5aee6c
@@ -0,0 +1,29 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============================================
+Ampere SoC Performance Monitoring Unit (PMU)
+============================================
+
+Ampere SoC PMU is a generic PMU IP that follows Arm CoreSight PMU architecture.
+Therefore, the driver is implemented as a submodule of arm_cspmu driver. At the
+first phase it's used for counting MCU events on AmpereOne.
+
+
+MCU PMU events
+--------------
+
+The PMU driver supports setting filters for "rank", "bank", and "threshold".
+Note, that the filters are per PMU instance rather than per event.
+
+
+Example for perf tool use::
+
+  / # perf list ampere
+
+    ampere_mcu_pmu_0/act_sent/                         [Kernel PMU event]
+    <...>
+    ampere_mcu_pmu_1/rd_sent/                          [Kernel PMU event]
+    <...>
+
+  / # perf stat -a -e ampere_mcu_pmu_0/act_sent,bank=5,rank=3,threshold=2/,ampere_mcu_pmu_1/rd_sent/ \
+        sleep 1
drivers/perf/arm_cspmu/Makefile +1 -1
index fedb17df982d..b80a8bd8da54 100644
@@ -3,4 +3,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU) += arm_cspmu_module.o
-arm_cspmu_module-y := arm_cspmu.o nvidia_cspmu.o
+arm_cspmu_module-y := arm_cspmu.o nvidia_cspmu.o ampere_cspmu.o
drivers/perf/arm_cspmu/ampere_cspmu.c new file +243 -0

243 lines not on this page · raw message

drivers/perf/arm_cspmu/ampere_cspmu.h new file +17 -0
new file mode 100644
index 000000000000..9b3e1628d1d6
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Ampere SoC PMU (Performance Monitor Unit)
+ *
+ * Copyright (c) 2023, Ampere Computing LLC
+ */
+
+#ifndef __AMPERE_CSPMU_H__
+#define __AMPERE_CSPMU_H__
+
+#include "arm_cspmu.h"
+
+/* Allocate AMPERE descriptor. */
+int ampere_cspmu_init_ops(struct arm_cspmu *cspmu);
+
+#endif /* __AMPERE_CSPMU_H__ */
drivers/perf/arm_cspmu/arm_cspmu.c +8 -0
index 471d6d7ac81a..579f2697b419 100644
@@ -30,6 +30,8 @@
 #include <linux/platform_device.h>
 
 #include "arm_cspmu.h"
+
+#include "ampere_cspmu.h"
 #include "nvidia_cspmu.h"
 
 #define PMUNAME "arm_cspmu"
@@ -114,6 +116,7 @@
 
 /* JEDEC-assigned JEP106 identification code */
 #define ARM_CSPMU_IMPL_ID_NVIDIA		0x36B
+#define ARM_CSPMU_IMPL_ID_AMPERE		0xA16
 
 static unsigned long arm_cspmu_cpuhp_state;
 
@@ -388,6 +391,11 @@ static const struct impl_match impl_match[] = {
 	  .mask = ARM_CSPMU_PMIIDR_IMPLEMENTER,
 	  .impl_init_ops = nv_cspmu_init_ops
 	},
+	{
+	  .pmiidr = ARM_CSPMU_IMPL_ID_AMPERE,
+	  .mask = ARM_CSPMU_PMIIDR_IMPLEMENTER,
+	  .impl_init_ops = ampere_cspmu_init_ops
+	},
 	{}
 };
 
Signature · 1 line
2.40.1
maintainer
#5 lore raw
In reply to Ilkka Koskinen
Quoted 11 lines · Ilkka Koskinen

Changes since v4:
* "Support implementation specific filters" patch:
- Added comment about filter and impdef registers and reference to the Coresight PMU specification to the commit message

* "Add support for Ampere SoC PMU" patch:
- Fixed the documentation and added more comments
- Changed the incrementing PMU index number to idr_alloc() (Needs a impdef release hook patch to release unused index)
- Fixed style in init_ops() to more reasonable
- Moved bank parameter to config1

This looks pretty good to me, but I think we should merge the series reworking the backend registration first:

https://lore.kernel.org/all/[email protected]/

and then this should slot in quite nicely. I've left a minor comment over there and I'd like Suzuki's review, but then we're good to go.

Cheers,

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Hi Will,

Quoted 16 lines · Will Deacon
Quoted 11 lines · Ilkka Koskinen

Changes since v4:
* "Support implementation specific filters" patch:
- Added comment about filter and impdef registers and reference to the Coresight PMU specification to the commit message

* "Add support for Ampere SoC PMU" patch:
- Fixed the documentation and added more comments
- Changed the incrementing PMU index number to idr_alloc() (Needs a impdef release hook patch to release unused index)
- Fixed style in init_ops() to more reasonable
- Moved bank parameter to config1

This looks pretty good to me, but I think we should merge the series reworking the backend registration first:

Quoted 8 lines

https://lore.kernel.org/all/[email protected]/

and then this should slot in quite nicely. I've left a minor comment over there and I'd like Suzuki's review, but then we're good to go.

Cheers,

Will

Sounds good to me. I'll try to find some time to do the needed changes to my patches and rebase them on top of Besar's patchset.

Cheers, Ilkka