Skip to contentSkip to conversation

perf: ampere: Add support for Ampere SoC PMUs

PATCH In review Ilkka Koskinen 3 participants 12 messages Jun 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf: ampere: Add support for Ampere SoC PMUs

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         | 232 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |  28 ++-
 drivers/perf/arm_cspmu/arm_cspmu.h            |   6 +
 6 files changed, 309 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 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
Reviewed-by on v1 1/4
#2 lore raw

RE: [PATCH 1/4] perf: arm_cspmu: Split 64-bit write to 32-bit writes

Quoted 12 lines

-----Original Message-----
From: Ilkka Koskinen <[email protected]>
Sent: Thursday, June 22, 2023 8:12 AM
To: Will Deacon <[email protected]>; Robin Murphy <[email protected]>; Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Mark Rutland <[email protected]>
Cc: Ilkka Koskinen <[email protected]>; linux-arm- [email protected]; [email protected]
Subject: [PATCH 1/4] perf: arm_cspmu: Split 64-bit write to 32-bit writes

Quoted 7 lines

External email: Use caution opening links or attachments

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

Thanks,
Besar

Quoted 24 lines
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +4 -2
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);
 
--

2.40.1

#3 lore raw

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

In reply to Ilkka Koskinen

Generic filters aren't used in all the platforms. Instead, the platforms may use different means to filter events. Add support for implementation specific filters.

---
 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
#4 lore raw

Re: [PATCH 2/4] perf: arm_cspmu: Support implementation specific filters

Quoted 3 lines · On Wed, 21 Jun 2023 18:11:39 -0700 Ilkka Koskinen…

Generic filters aren't used in all the platforms. Instead, the platforms may use different means to filter events. Add support for implementation specific filters.

If the specification allows explicitly for non standard ways of controlling filters it would be good to add a specification reference to this.

Otherwise one question inline.

Quoted 40 lines
---
 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 +5 -1
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)
 {

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_start(struct perf_event *event, int pmu_flags) · line 833

Quoted 5 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
@@ -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);

Optional callback so don't you need either provide a default, or check it isn't null?

Quoted 17 lines
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
 	}
 
 	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);
#5 lore raw

RE: [PATCH 2/4] perf: arm_cspmu: Support implementation specific filters

Quoted 17 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Thursday, June 22, 2023 3:34 PM
To: Ilkka Koskinen <[email protected]>
Cc: Will Deacon <[email protected]>; Robin Murphy <[email protected]>; Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Mark Rutland <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/4] perf: arm_cspmu: Support implementation specific filters

External email: Use caution opening links or attachments

On Wed, 21 Jun 2023 18:11:39 -0700
Ilkka Koskinen <[email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

Generic filters aren't used in all the platforms. Instead, the platforms may use different means to filter events. Add support for implementation specific filters.

If the specification allows explicitly for non standard ways of controlling filters it would be good to add a specification reference to this.

Want to point out that the spec considers PMEVTYPER and PMEVFILTR* registers as optional, please refer to section 2.1 in the spec. The spec also defines PMIMPDEF registers (starting from offset 0xD80), which is intended for implementation defined extension. My interpretation to this is implementer can have other methods to configure event selection and filtering, although maybe not clear of how much freedom is given to the implementer.

Quoted 45 lines

Otherwise one question inline.

Review

Quoted 9 lines
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 8 ++++++--
 drivers/perf/arm_cspmu/arm_cspmu.h | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/perf/arm_cspmu/arm_cspmu.c

drivers/perf/arm_cspmu/arm_cspmu.c static int arm_cspmu_init_impl_ops(struct

Quoted 14 lines

index 0f517152cb4e..fafd734c3218 100644

drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
@@ -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)

drivers/perf/arm_cspmu/arm_cspmu.c static inline void arm_cspmu_set_event(struct

Quoted 8 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
      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,

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_start(struct perf_event

Quoted 9 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
      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)

Quoted 9 lines

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_start(struct perf_event *event, int pmu_flags) · line 833

Quoted 5 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
              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);

Optional callback so don't you need either provide a default, or check it isn't null?

Right, the CHECK_DEFAULT_IMPL_OPS(impl_ops, set_ev_filter) above will fallback to default if ops.set_ev_filter is null.

Regards,
Besar

Quoted 18 lines

Review

Quoted 4 lines
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
      }
 
      hwc->state = 0;
(quoted diff) +0 -0

b/drivers/perf/arm_cspmu/arm_cspmu.h

Quoted 13 lines

index 83df53d1c132..d6d88c246a23 100644

drivers/perf/arm_cspmu/arm_cspmu.h +3 -0
@@ -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);
#6 lore raw

RE: [PATCH 2/4] perf: arm_cspmu: Support implementation specific filters

Quoted 25 lines · Besar Wicaksono
Quoted 17 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Thursday, June 22, 2023 3:34 PM
To: Ilkka Koskinen <[email protected]>
Cc: Will Deacon <[email protected]>; Robin Murphy <[email protected]>; Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Mark Rutland <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/4] perf: arm_cspmu: Support implementation specific filters

External email: Use caution opening links or attachments

On Wed, 21 Jun 2023 18:11:39 -0700
Ilkka Koskinen <[email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

Generic filters aren't used in all the platforms. Instead, the platforms may use different means to filter events. Add support for implementation specific filters.

If the specification allows explicitly for non standard ways of controlling filters it would be good to add a specification reference to this.

Quoted 5 lines

Want to point out that the spec considers PMEVTYPER and PMEVFILTR* registers as optional, please refer to section 2.1 in the spec. The spec also defines PMIMPDEF registers (starting from offset 0xD80), which is intended for implementation defined extension. My interpretation to this is implementer can have other methods to configure event selection and filtering, although maybe not clear of how much freedom is given to the implementer.

That's a good idea. I do that.

Cheers, Ilkka

Quoted 82 lines
Quoted 46 lines

Otherwise one question inline.

Review

Quoted 9 lines
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 8 ++++++--
 drivers/perf/arm_cspmu/arm_cspmu.h | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/perf/arm_cspmu/arm_cspmu.c

drivers/perf/arm_cspmu/arm_cspmu.c static int arm_cspmu_init_impl_ops(struct

Quoted 14 lines

index 0f517152cb4e..fafd734c3218 100644

drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
@@ -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)

drivers/perf/arm_cspmu/arm_cspmu.c static inline void arm_cspmu_set_event(struct

Quoted 8 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
      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,

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_start(struct perf_event

Quoted 9 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
      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)

Quoted 9 lines

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_start(struct perf_event *event, int pmu_flags) · line 833

Quoted 5 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
              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);

Optional callback so don't you need either provide a default, or check it isn't null?

Right, the CHECK_DEFAULT_IMPL_OPS(impl_ops, set_ev_filter) above will fallback to default if ops.set_ev_filter is null.

Regards,
Besar

Quoted 18 lines

Review

Quoted 4 lines
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
      }
 
      hwc->state = 0;
(quoted diff) +0 -0

b/drivers/perf/arm_cspmu/arm_cspmu.h

Quoted 13 lines

index 83df53d1c132..d6d88c246a23 100644

drivers/perf/arm_cspmu/arm_cspmu.h +3 -0
@@ -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);
#7 lore raw

PATCH 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
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] perf: arm_cspmu: Support implementation specific validation

Quoted 4 lines · On Wed, 21 Jun 2023 18:11:40 -0700 Ilkka Koskinen…

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

FWIW given it's so simple...

Quoted 45 lines
---
 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);
#9 lore raw

PATCH 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         | 232 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |   7 +
 5 files changed, 286 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..bf86bffeef63
@@ -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,filter_enable=3,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 +232 -0

232 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 +7 -0
index 471d6d7ac81a..587515eea0b4 100644
@@ -29,6 +29,7 @@
 #include <linux/perf_event.h>
 #include <linux/platform_device.h>
 
+#include "ampere_cspmu.h"
 #include "arm_cspmu.h"
 #include "nvidia_cspmu.h"
 
@@ -114,6 +115,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 +390,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
#10 lore raw

Re: [PATCH 4/4] perf: arm_cspmu: ampere_cspmu: Add support for Ampere SoC PMU

Quoted 4 lines · On Wed, 21 Jun 2023 18:11:41 -0700 Ilkka Koskinen…

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

Hi Ilkka,

Drive by review so not super detailed (I was curious) but a few questions/comments inline.

Jonathan

Quoted 20 lines
---
 .../admin-guide/perf/ampere_cspmu.rst         |  29 +++
 drivers/perf/arm_cspmu/Makefile               |   2 +-
 drivers/perf/arm_cspmu/ampere_cspmu.c         | 232 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |   7 +
 5 files changed, 286 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 +2 -0
new file mode 100644
index 000000000000..bf86bffeef63
@@ -0,0 +1,29 @@
 
+
+Example for perf tool use::

Documentation/admin-guide/perf/ampere_cspmu.rst line 29

Quoted 10 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +10 -0
+
+  / # 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,filter_enable=3,bank=5,rank=3,threshold=2/,ampere_mcu_pmu_1/rd_sent/ \
+        sleep 1

Why filter_enable=3?

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 2 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +2 -0
+static u32 ampere_cspmu_event_filter(const struct perf_event *event)
+{

Whilst lots of other comments on this - perhaps add another one here to why this is a noop.

Quoted 46 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +46 -0
+	return 0;
+}
+
+static void ampere_cspmu_set_ev_filter(struct arm_cspmu *cspmu,
+				       struct hw_perf_event *hwc,
+				       u32 filter)
+{
+	struct perf_event *event;
+	unsigned int idx;
+	u32 threshold, rank, bank;
+
+	/*
+	 * At this point, all the events have the same filter settings.
+	 * Therefore, take the first event and use its configuration.
+	 */
+	idx = find_first_bit(cspmu->hw_events.used_ctrs,
+			     cspmu->cycle_counter_logical_idx);
+
+	event = cspmu->hw_events.events[idx];
+
+	threshold	= get_threshold(event);
+	rank		= get_rank(event);
+	bank		= get_bank(event);
+
+	writel(threshold, cspmu->base0 + PMAUXR0);
+	writel(rank, cspmu->base0 + PMAUXR1);
+	writel(bank, cspmu->base0 + PMAUXR2);
+}
+
+static int ampere_cspmu_validate_configs(struct perf_event *event,
+					 struct perf_event *event2)
+{
+	if (get_threshold(event) != get_threshold(event2) ||
+	    get_rank(event) != get_rank(event2) ||
+	    get_bank(event) != get_bank(event2))
+		return -EINVAL;
+
+	return 0;
+}
+
+static int ampere_cspmu_validate_event(struct arm_cspmu *cspmu,
+				       struct perf_event *new)
+{
+	struct perf_event *curr, *leader = new->group_leader;
+	unsigned int idx;
+	int ret;

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 10 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +10 -0
+
+	ret = ampere_cspmu_validate_configs(new, leader);
+	if (ret)
+		return ret;
+
+	/* We compare the global filter settings to existing events */
+	idx = find_first_bit(cspmu->hw_events.used_ctrs,
+			     cspmu->cycle_counter_logical_idx);
+
+	/* This is the first event */

Maybe add why that matters to the comment?

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 13 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +13 -0
+	if (idx == cspmu->cycle_counter_logical_idx)
+		return 0;
+
+	curr = cspmu->hw_events.events[idx];
+
+	return ampere_cspmu_validate_configs(curr, new);
+}
+
+static char *ampere_cspmu_format_name(const struct arm_cspmu *cspmu,
+				      const char *name_pattern)
+{
+	struct device *dev = cspmu->dev;
+	static atomic_t pmu_generic_idx = {0};

Why not an ida?

If the pmu drivers ever become easy to unbind then you won't get ID reusage like this an eventually you will run into overflow problems.

Quoted 9 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +9 -0
+
+	return devm_kasprintf(dev, GFP_KERNEL, name_pattern,
+			      atomic_fetch_inc(&pmu_generic_idx));
+}
+
+int ampere_cspmu_init_ops(struct arm_cspmu *cspmu)
+{
+	struct device *dev = cspmu->dev;
+	struct ampere_cspmu_ctx *ctx;

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 10 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +10 -0
+	struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops;
+
+	ctx = devm_kzalloc(dev, sizeof(struct ampere_cspmu_ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	ctx->event_attr		= ampereone_mcu_pmu_event_attrs;
+	ctx->format_attr	= ampereone_mcu_format_attrs;
+	ctx->name		= ampere_cspmu_format_name(cspmu,
+							   "ampere_mcu_pmu_%u");

Long line and need to break avoided if you don't bother trying to align the = signs... Personally I don't like this style as it causes a lot of churn as drivers evolve, but meh, it's up to you.

Given the result is confusing if the allocation fails (name not what is expected) I would also check that allocation and error out if it fails. Obviously it won't under realistic circumstances, but a bit of paranoia never hurt anyone.

Quoted 13 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +13 -0
+	cspmu->impl.ctx = ctx;
+
+	impl_ops->event_filter		= ampere_cspmu_event_filter;
+	impl_ops->set_ev_filter		= ampere_cspmu_set_ev_filter;
+	impl_ops->validate_event	= ampere_cspmu_validate_event;
+	impl_ops->get_name		= ampere_cspmu_get_name;
+	impl_ops->get_event_attrs	= ampere_cspmu_get_event_attrs;
+	impl_ops->get_format_attrs	= ampere_cspmu_get_format_attrs;
+
+	return 0;
+}
+
+MODULE_LICENSE("GPL v2");

...

drivers/perf/arm_cspmu/arm_cspmu.c line 32

Quoted 9 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
index 471d6d7ac81a..587515eea0b4 100644
@@ -29,6 +29,7 @@
 #include <linux/perf_event.h>
 #include <linux/platform_device.h>
 
+#include "ampere_cspmu.h"

I'd be tempted to keep the generic header in a separate block then follow with the vendor ones. Not particularly important though.

Quoted 13 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
 #include "arm_cspmu.h"
 #include "nvidia_cspmu.h"
 
@@ -114,6 +115,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 +390,11 @@ static const struct impl_match impl_match[] = {
 	  .mask = ARM_CSPMU_PMIIDR_IMPLEMENTER,

drivers/perf/arm_cspmu/arm_cspmu.c static const struct impl_match impl_match[] = { · line 400

Quoted 10 lines
drivers/perf/arm_cspmu/arm_cspmu.c +5 -0
 	  .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
+	},
 	{}
 };
 

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

#11 lore raw

Re: [PATCH 4/4] perf: arm_cspmu: ampere_cspmu: Add support for Ampere SoC PMU

Hi Jonathan

Quoted 31 lines · Jonathan Cameron
Quoted 4 lines · On Wed, 21 Jun 2023 18:11:41 -0700 Ilkka Koskinen…

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

Hi Ilkka,

Drive by review so not super detailed (I was curious) but a few questions/comments inline.

Jonathan

Quoted 17 lines
---
 .../admin-guide/perf/ampere_cspmu.rst         |  29 +++
 drivers/perf/arm_cspmu/Makefile               |   2 +-
 drivers/perf/arm_cspmu/ampere_cspmu.c         | 232 ++++++++++++++++++
 drivers/perf/arm_cspmu/ampere_cspmu.h         |  17 ++
 drivers/perf/arm_cspmu/arm_cspmu.c            |   7 +
 5 files changed, 286 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 +0 -0
new file mode 100644
index 000000000000..bf86bffeef63
@@ -0,0 +1,29 @@
Quoted 14 lines

Documentation/admin-guide/perf/ampere_cspmu.rst line 29

Quoted 12 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +12 -0
+
+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,filter_enable=3,bank=5,rank=3,threshold=2/,ampere_mcu_pmu_1/rd_sent/ \
+        sleep 1

Why filter_enable=3?

Thanks for catching. That's from the first cspmu version and got accidentally back there. The rest of the patch looks like what it was supposed to be though.

Quoted 5 lines

Documentation/admin-guide/perf/ampere_cspmu.rst line 14

Quoted 2 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +2 -0
+static u32 ampere_cspmu_event_filter(const struct perf_event *event)
+{

Whilst lots of other comments on this - perhaps add another one here to why this is a noop.

Sure, makes sense.

Quoted 3 lines
Quoted 3 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +2 -0
+	return 0;
+}

...

Quoted 10 lines
Quoted 10 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +10 -0
+static int ampere_cspmu_validate_event(struct arm_cspmu *cspmu,
+				       struct perf_event *new)
+{
+	struct perf_event *curr, *leader = new->group_leader;
+	unsigned int idx;
+	int ret;
+
+	ret = ampere_cspmu_validate_configs(new, leader);
+	if (ret)
+		return ret;
Quoted 8 lines

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 6 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +6 -0
+
+	/* We compare the global filter settings to existing events */
+	idx = find_first_bit(cspmu->hw_events.used_ctrs,
+			     cspmu->cycle_counter_logical_idx);
+
+	/* This is the first event */

Maybe add why that matters to the comment?

Sure, I'll do that.

Quoted 17 lines
Quoted 4 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +3 -0
+	if (idx == cspmu->cycle_counter_logical_idx)
+		return 0;
+

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 10 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +10 -0
+	curr = cspmu->hw_events.events[idx];
+
+	return ampere_cspmu_validate_configs(curr, new);
+}
+
+static char *ampere_cspmu_format_name(const struct arm_cspmu *cspmu,
+				      const char *name_pattern)
+{
+	struct device *dev = cspmu->dev;
+	static atomic_t pmu_generic_idx = {0};

Why not an ida?

Quoted 2 lines

If the pmu drivers ever become easy to unbind then you won't get ID reusage like this an eventually you will run into overflow problems.

Didn't appear in my mind when I wrote the submodule. I'll change it.

Releasing devices would eventually require a release hook too to support reusing the IDs but we can add that later.

Quoted 16 lines
Quoted 16 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +15 -0
+
+	return devm_kasprintf(dev, GFP_KERNEL, name_pattern,
+			      atomic_fetch_inc(&pmu_generic_idx));
+}
+
+int ampere_cspmu_init_ops(struct arm_cspmu *cspmu)
+{
+	struct device *dev = cspmu->dev;
+	struct ampere_cspmu_ctx *ctx;
+	struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops;
+
+	ctx = devm_kzalloc(dev, sizeof(struct ampere_cspmu_ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
Quoted 8 lines

Documentation/admin-guide/perf/ampere_cspmu.rst

Quoted 4 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +4 -0
+	ctx->event_attr		= ampereone_mcu_pmu_event_attrs;
+	ctx->format_attr	= ampereone_mcu_format_attrs;
+	ctx->name		= ampere_cspmu_format_name(cspmu,
+							   "ampere_mcu_pmu_%u");

Long line and need to break avoided if you don't bother trying to align the = signs... Personally I don't like this style as it causes a lot of churn as drivers evolve, but meh, it's up to you.

I don't really have preference on either way. I remove the aligment and combine those two lines.

Quoted 4 lines

Given the result is confusing if the allocation fails (name not what is expected) I would also check that allocation and error out if it fails. Obviously it won't under realistic circumstances, but a bit of paranoia never hurt anyone.

I agree, I fix it.

Quoted 25 lines
Quoted 14 lines
Documentation/admin-guide/perf/ampere_cspmu.rst new file +13 -0
+	cspmu->impl.ctx = ctx;
+
+	impl_ops->event_filter		= ampere_cspmu_event_filter;
+	impl_ops->set_ev_filter		= ampere_cspmu_set_ev_filter;
+	impl_ops->validate_event	= ampere_cspmu_validate_event;
+	impl_ops->get_name		= ampere_cspmu_get_name;
+	impl_ops->get_event_attrs	= ampere_cspmu_get_event_attrs;
+	impl_ops->get_format_attrs	= ampere_cspmu_get_format_attrs;
+
+	return 0;
+}
+
+MODULE_LICENSE("GPL v2");

...

Quoted 8 lines
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
index 471d6d7ac81a..587515eea0b4 100644
@@ -29,6 +29,7 @@
 #include <linux/perf_event.h>
 #include <linux/platform_device.h>
 
Quoted 4 lines

drivers/perf/arm_cspmu/arm_cspmu.c line 32

Quoted 1 line
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
+#include "ampere_cspmu.h"

I'd be tempted to keep the generic header in a separate block then follow with the vendor ones. Not particularly important though.

I like your idea

Quoted 26 lines
Quoted 24 lines
drivers/perf/arm_cspmu/arm_cspmu.c +6 -0
 #include "arm_cspmu.h"
 #include "nvidia_cspmu.h"
 
@@ -114,6 +115,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 +390,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
+	},
 	{}
 };