Skip to contentSkip to conversation

perf: ampere: Add support for Ampere SoC PMUs

PATCH Superseded Ilkka Koskinen 3 participants 10 messages Jun 7, 2023 – Jun 21, 2023

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

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

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            |  33 ++-
 drivers/perf/arm_cspmu/arm_cspmu.h            |   8 +
 6 files changed, 327 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 v3 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 a3f1c410b417..f8b4a149eb88 100644
@@ -702,7 +702,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 (supports_64bit_atomics(cspmu))
+			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

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

Quoted 28 lines

-----Original Message-----
From: Ilkka Koskinen <[email protected]>
Sent: Wednesday, June 7, 2023 3:32 PM
To: Jonathan Corbet <[email protected]>; Will Deacon <[email protected]>; Mark Rutland <[email protected]>; Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Robin Murphy <[email protected]>
Cc: [email protected]; [email protected]; linux-arm- [email protected]; Ilkka Koskinen <[email protected]>
Subject: [PATCH v3 1/4] perf: arm_cspmu: Split 64-bit write to 32-bit writes

External email: Use caution opening links or attachments

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 +0 -0
index a3f1c410b417..f8b4a149eb88 100644

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_write_counter(struct · line 706

Quoted 6 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
@@ -702,7 +702,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 (supports_64bit_atomics(cspmu))

Looks good to me, but this function was recently replaced by arm_cspmu::has_atomic_dword. Please rebase the patch.

Thanks,
Besar

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

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

Hi Besar,

Quoted 32 lines · Besar Wicaksono
Quoted 32 lines

-----Original Message-----
From: Ilkka Koskinen <[email protected]>
Sent: Wednesday, June 7, 2023 3:32 PM
To: Jonathan Corbet <[email protected]>; Will Deacon <[email protected]>; Mark Rutland <[email protected]>; Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Robin Murphy <[email protected]>
Cc: [email protected]; [email protected]; linux-arm- [email protected]; Ilkka Koskinen <[email protected]>
Subject: [PATCH v3 1/4] perf: arm_cspmu: Split 64-bit write to 32-bit writes

External email: Use caution opening links or attachments

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 +0 -0
index a3f1c410b417..f8b4a149eb88 100644
@@ -702,7 +702,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);
 
Quoted 5 lines

drivers/perf/arm_cspmu/arm_cspmu.c static void arm_cspmu_write_counter(struct perf_event *event, u64 val) · line 705

Quoted 2 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
-               writeq(val, cspmu->base1 + offset);
+               if (supports_64bit_atomics(cspmu))

Looks good to me, but this function was recently replaced by arm_cspmu::has_atomic_dword. Please rebase the patch.

Sure, I do that.

Cheers, Ilkka

Quoted 14 lines

Thanks,
Besar

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

#4 lore raw

PATCH v3 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 | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/perf/arm_cspmu/arm_cspmu.c +6 -2
index f8b4a149eb88..72ca4f56347c 100644
@@ -122,6 +122,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);
+
 /*
  * In CoreSight PMU architecture, all of the MMIO registers are 32-bit except
  * counter register. The counter register can be implemented as 32-bit or 64-bit
@@ -432,6 +435,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;
 }
@@ -798,7 +802,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)
 {
@@ -832,7 +836,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 +4 -0
index 51323b175a4a..f89ae2077164 100644
@@ -102,6 +102,10 @@ 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
Reviewed-by on v3 2/4
#5 lore raw

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

Quoted 14 lines

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

Quoted 8 lines

External email: Use caution opening links or attachments

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.

Quoted 68 lines
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 8 ++++++--
 drivers/perf/arm_cspmu/arm_cspmu.h | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
index f8b4a149eb88..72ca4f56347c 100644
@@ -122,6 +122,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);
+
 /*
  * In CoreSight PMU architecture, all of the MMIO registers are 32-bit except
  * counter register. The counter register can be implemented as 32-bit or 64-

bit

drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
@@ -432,6 +435,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;

}

drivers/perf/arm_cspmu/arm_cspmu.c +1 -1
@@ -798,7 +802,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 +1 -1
@@ -832,7 +836,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 +4 -1
index 51323b175a4a..f89ae2077164 100644
@@ -102,6 +102,10 @@ 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);
--

2.40.1

#6 lore raw

PATCH v3 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 | 13 ++++++++++++-
 drivers/perf/arm_cspmu/arm_cspmu.h |  4 ++++
 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +12 -1
index 72ca4f56347c..9021d1878250 100644
@@ -559,7 +559,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)) {
@@ -593,6 +593,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;
@@ -618,6 +624,7 @@ static bool arm_cspmu_validate_event(struct pmu *pmu,
  */
 static bool arm_cspmu_validate_group(struct perf_event *event)
 {
+	struct arm_cspmu *cspmu = to_arm_cspmu(event->pmu);
 	struct perf_event *sibling, *leader = event->group_leader;
 	struct arm_cspmu_hw_events fake_hw_events;
 
@@ -635,6 +642,10 @@ static bool arm_cspmu_validate_group(struct perf_event *event)
 			return false;
 	}
 
+	if (cspmu->impl.ops.validate_group &&
+	    cspmu->impl.ops.validate_group(event))
+		return false;
+
 	return arm_cspmu_validate_event(event->pmu, &fake_hw_events, event);
 }
 
drivers/perf/arm_cspmu/arm_cspmu.h +4 -0
index f89ae2077164..291cedb196ea 100644
@@ -106,6 +106,10 @@ struct arm_cspmu_impl_ops {
 	void (*set_ev_filter)(struct arm_cspmu *cspmu,
 			      struct hw_perf_event *hwc,
 			      u32 filter);
+	/* Implementation specific group validation */
+	int (*validate_group)(struct perf_event *event);
+	/* Implementation specific event validation */
+	int (*validate_event)(struct arm_cspmu *cspmu, struct perf_event *new);
 	/* Hide/show unsupported events */
 	umode_t (*event_attr_is_visible)(struct kobject *kobj,
 					 struct attribute *attr, int unused);
Signature · 1 line
2.40.1
#7 lore raw

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

Quoted 44 lines · 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 | 13 ++++++++++++-
  drivers/perf/arm_cspmu/arm_cspmu.h |  4 ++++
  2 files changed, 16 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +8 -1
index 72ca4f56347c..9021d1878250 100644
@@ -559,7 +559,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)) {
@@ -593,6 +593,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;
@@ -618,6 +624,7 @@ static bool arm_cspmu_validate_event(struct pmu *pmu,
   */
  static bool arm_cspmu_validate_group(struct perf_event *event)
  {
+	struct arm_cspmu *cspmu = to_arm_cspmu(event->pmu);
  	struct perf_event *sibling, *leader = event->group_leader;
  	struct arm_cspmu_hw_events fake_hw_events;
 

drivers/perf/arm_cspmu/arm_cspmu.c static bool arm_cspmu_validate_group(struct perf_event *event) · line 647

Quoted 6 lines
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
@@ -635,6 +642,10 @@ static bool arm_cspmu_validate_group(struct perf_event *event)
  			return false;
  	}
 
+	if (cspmu->impl.ops.validate_group &&
+	    cspmu->impl.ops.validate_group(event))
+		return false;

Hmm, this means that any driver wanting to use it has to duplicate all the group iteration logic, which isn't ideal. More than that, though, the way you've implemented it in patch #4 I'm not sure even does anything, since it only appears to be repeating the same checks that already happen in this path:

arm_csmpu_validate_group()

    arm_cspmu_validate_event()
      arm_cspmu_get_event_idx()
        ops.validate_event() -> ampere_cspmu_validate_params()

so there's no need for the ops.validate_group hook to just call ampere_cspmu_validate_params() a second time when it's guaranteed to succeed (because otherwise we'd have bailed out already).

I think what we want overall is an "is this event config valid at all" hook from arm_cspmu_event_init() (which we don't really need to implement yet unless you want to start sanity-checking your actual rank/bank/threshold values), plus an "is this event schedulable in the given PMU context" hook from arm_cspmu_get_event_idx(), which should serve for both group validation via the fake context in event_init and actual scheduling in the real context in add.

Thanks,
Robin.

Quoted 19 lines
drivers/perf/arm_cspmu/arm_cspmu.c +1 -0
+
  	return arm_cspmu_validate_event(event->pmu, &fake_hw_events, event);
  }
 
drivers/perf/arm_cspmu/arm_cspmu.h +4 -0
index f89ae2077164..291cedb196ea 100644
@@ -106,6 +106,10 @@ struct arm_cspmu_impl_ops {
  	void (*set_ev_filter)(struct arm_cspmu *cspmu,
  			      struct hw_perf_event *hwc,
  			      u32 filter);
+	/* Implementation specific group validation */
+	int (*validate_group)(struct perf_event *event);
+	/* Implementation specific event validation */
+	int (*validate_event)(struct arm_cspmu *cspmu, struct perf_event *new);
  	/* Hide/show unsupported events */
  	umode_t (*event_attr_is_visible)(struct kobject *kobj,
  					 struct attribute *attr, int unused);
#8 lore raw

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

Hi Robin,

Quoted 51 lines · Robin Murphy
Quoted 45 lines · 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 | 13 ++++++++++++-
  drivers/perf/arm_cspmu/arm_cspmu.h |  4 ++++
  2 files changed, 16 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +7 -1
index 72ca4f56347c..9021d1878250 100644
@@ -559,7 +559,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)) {
@@ -593,6 +593,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;
@@ -618,6 +624,7 @@ static bool arm_cspmu_validate_event(struct pmu *pmu,
   */
  static bool arm_cspmu_validate_group(struct perf_event *event)
  {
+	struct arm_cspmu *cspmu = to_arm_cspmu(event->pmu);
  	struct perf_event *sibling, *leader = event->group_leader;
  	struct arm_cspmu_hw_events fake_hw_events;
  @@ -635,6 +642,10 @@ static bool arm_cspmu_validate_group(struct 

perf_event *event)
return false;
}
+ if (cspmu->impl.ops.validate_group &&

drivers/perf/arm_cspmu/arm_cspmu.c static bool arm_cspmu_validate_group(struct perf_event *event) · line 647

Quoted 2 lines
drivers/perf/arm_cspmu/arm_cspmu.c +2 -0
+	    cspmu->impl.ops.validate_group(event))
+		return false;

Hmm, this means that any driver wanting to use it has to duplicate all the group iteration logic, which isn't ideal. More than that, though, the way you've implemented it in patch #4 I'm not sure even does anything, since it only appears to be repeating the same checks that already happen in this path:

Quoted 6 lines

arm_csmpu_validate_group()
arm_cspmu_validate_event()

     arm_cspmu_get_event_idx()
       ops.validate_event() -> ampere_cspmu_validate_params()

so there's no need for the ops.validate_group hook to just call ampere_cspmu_validate_params() a second time when it's guaranteed to succeed (because otherwise we'd have bailed out already).

Yeah, I took another look how the framework really does it and you're absolutely correct, it's totally unnecessary.

Quoted 2 lines

I think what we want overall is an "is this event config valid at all" hook from arm_cspmu_event_init() (which we don't really need to implement yet unless you want to start sanity-checking your actual rank/bank/threshold values), plus an "is this event schedulable in the given PMU context" hook from arm_cspmu_get_event_idx(), which should serve for both group validation via the fake context in event_init and actual scheduling in the real context in add.

Ah, that's true. I can already verify the group event has the same rank/bank/threshold settings as the group leader in ops.validate_event(). Thus, one hook seems enough.

I fix and rebase the patchset.

Cheers, Ilkka

Quoted 24 lines

Thanks,
Robin.

Quoted 20 lines

+
return arm_cspmu_validate_event(event->pmu, &fake_hw_events, event);
}
diff --git a/drivers/perf/arm_cspmu/arm_cspmu.h
b/drivers/perf/arm_cspmu/arm_cspmu.h
index f89ae2077164..291cedb196ea 100644

drivers/perf/arm_cspmu/arm_cspmu.h +4 -0
@@ -106,6 +106,10 @@ struct arm_cspmu_impl_ops {
  	void (*set_ev_filter)(struct arm_cspmu *cspmu,
  			      struct hw_perf_event *hwc,
  			      u32 filter);
+	/* Implementation specific group validation */
+	int (*validate_group)(struct perf_event *event);
+	/* Implementation specific event validation */
+	int (*validate_event)(struct arm_cspmu *cspmu, struct perf_event 
 *new);
  	/* Hide/show unsupported events */
  	umode_t (*event_attr_is_visible)(struct kobject *kobj,

struct attribute *attr, int unused);

#9 lore raw

PATCH v3 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            |   7 +
 5 files changed, 297 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 +7 -0
index 9021d1878250..885393ed993e 100644
@@ -30,6 +30,7 @@
 #include <linux/platform_device.h>
 #include <acpi/processor.h>
 
+#include "ampere_cspmu.h"
 #include "arm_cspmu.h"
 #include "nvidia_cspmu.h"
 
@@ -119,6 +120,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;
 
@@ -394,6 +396,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 · 7 lines
2.40.1


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