Skip to contentSkip to conversation

perf: arm_spe: Relax period restriction

PATCH RESEND Superseded Leo Yan 2 participants 3 messages Jun 27, 2025 Arm PMU profiling and debugging

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH RESEND v2 1/1 perf: arm_spe: Relax period restriction

The minimum interval specified the PMSIDR_EL1.Interval field is a hardware recommendation. However, this value is set by hardware designer before the production. It may not accurately reflects actual hardware limitations, and tools currently have no way to test shorter periods.

This change relaxes the limitation by allowing any non-zero periods. This gives chance for experimenting smaller periods.

The downside is that small periods may increase the risk of AUX ring buffer overruns. When an overrun occurs, the perf core layer will trigger an irq work to disable the event and wake up the tool in user space to read the trace data. After the tool finishes reading, it will re-enable the AUX event.

---
 drivers/perf/arm_spe_pmu.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/perf/arm_spe_pmu.c +7 -3
index 3efed8839a4e..e40e5daa838d 100644
@@ -308,12 +308,16 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event)
 
 static void arm_spe_event_sanitise_period(struct perf_event *event)
 {
-	struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu);
 	u64 period = event->hw.sample_period;
 	u64 max_period = PMSIRR_EL1_INTERVAL_MASK;
 
-	if (period < spe_pmu->min_period)
-		period = spe_pmu->min_period;
+	/*
+	 * As per the Arm ARM (DDI 0487 L.a), section D24.7.12 PMSIRR_EL1,
+	 * Sampling Interval Reload Register, the INTERVAL field (bits [31:8])
+	 * states: "Software must set this to a nonzero value."
+	 */
+	if (period < FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1))
+		period = FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1);
 	else if (period > max_period)
 		period = max_period;
 	else
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Leo Yan

The minimum interval specified the PMSIDR_EL1.Interval field is a hardware recommendation. However, this value is set by hardware designer before the production. It may not accurately reflects actual hardware limitations, and tools currently have no way to test shorter periods.

This change relaxes the limitation by allowing any non-zero periods. This gives chance for experimenting smaller periods.

Is this going to be safe on all SPE implementations ?

Quoted 22 lines

The downside is that small periods may increase the risk of AUX ring buffer overruns. When an overrun occurs, the perf core layer will trigger an irq work to disable the event and wake up the tool in user space to read the trace data. After the tool finishes reading, it will re-enable the AUX event.

---
 drivers/perf/arm_spe_pmu.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/perf/arm_spe_pmu.c +0 -1
index 3efed8839a4e..e40e5daa838d 100644
@@ -308,12 +308,16 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event)
 
 static void arm_spe_event_sanitise_period(struct perf_event *event)
 {
-	struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu);

drivers/perf/arm_spe_pmu.c static u64 arm_spe_event_to_pmscr(struct perf_event *event) · line 318

Quoted 10 lines
drivers/perf/arm_spe_pmu.c +5 -2
 	u64 period = event->hw.sample_period;
 	u64 max_period = PMSIRR_EL1_INTERVAL_MASK;
 
-	if (period < spe_pmu->min_period)
-		period = spe_pmu->min_period;
+	/*
+	 * As per the Arm ARM (DDI 0487 L.a), section D24.7.12 PMSIRR_EL1,
+	 * Sampling Interval Reload Register, the INTERVAL field (bits [31:8])
+	 * states: "Software must set this to a nonzero value."
+	 */The motivation (as explained in the commit message) for using arch permitted

minimum value instead of the recommended (PMSIDR_EL1.Interval) value, should be explained in the comment here as well.

drivers/perf/arm_spe_pmu.c static u64 arm_spe_event_to_pmscr(struct perf_event *event) · line 320

Quoted 2 lines
drivers/perf/arm_spe_pmu.c +2 -0
+	if (period < FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1))
+		period = FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1);

Given that FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1) is a constant - should not it be defined as a macro e.g PMSIRR_EL1_MINIMUM_INTERVAL or something similar instead of deriving it twice.

Quoted 3 lines
drivers/perf/arm_spe_pmu.c +0 -0
 	else if (period > max_period)
 		period = max_period;
 	else
author
#2 lore raw
Quoted 10 lines · Anshuman Khandual
Quoted 7 lines · Leo Yan

The minimum interval specified the PMSIDR_EL1.Interval field is a hardware recommendation. However, this value is set by hardware designer before the production. It may not accurately reflects actual hardware limitations, and tools currently have no way to test shorter periods.

This change relaxes the limitation by allowing any non-zero periods. This gives chance for experimenting smaller periods.

Is this going to be safe on all SPE implementations ?

AFAIK, this change applies on all Arm SPE versions.

Quoted 24 lines
Quoted 24 lines

The downside is that small periods may increase the risk of AUX ring buffer overruns. When an overrun occurs, the perf core layer will trigger an irq work to disable the event and wake up the tool in user space to read the trace data. After the tool finishes reading, it will re-enable the AUX event.

---
 drivers/perf/arm_spe_pmu.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/perf/arm_spe_pmu.c +0 -1
index 3efed8839a4e..e40e5daa838d 100644
@@ -308,12 +308,16 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event)
 
 static void arm_spe_event_sanitise_period(struct perf_event *event)
 {
-	struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu);
 	u64 period = event->hw.sample_period;
 	u64 max_period = PMSIRR_EL1_INTERVAL_MASK;
 
Quoted 9 lines

drivers/perf/arm_spe_pmu.c static u64 arm_spe_event_to_pmscr(struct perf_event *event)

Quoted 7 lines
drivers/perf/arm_spe_pmu.c +5 -2
-	if (period < spe_pmu->min_period)
-		period = spe_pmu->min_period;
+	/*
+	 * As per the Arm ARM (DDI 0487 L.a), section D24.7.12 PMSIRR_EL1,
+	 * Sampling Interval Reload Register, the INTERVAL field (bits [31:8])
+	 * states: "Software must set this to a nonzero value."
+	 */The motivation (as explained in the commit message) for using arch permitted

minimum value instead of the recommended (PMSIDR_EL1.Interval) value, should be explained in the comment here as well.

Will update the comment to make it clear.

Quoted 5 lines

drivers/perf/arm_spe_pmu.c static u64 arm_spe_event_to_pmscr(struct perf_event *event) · line 320

Quoted 2 lines
drivers/perf/arm_spe_pmu.c +2 -0
+	if (period < FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1))
+		period = FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1);

Given that FIELD_PREP(PMSIRR_EL1_INTERVAL_MASK, 1) is a constant - should not it be defined as a macro e.g PMSIRR_EL1_MINIMUM_INTERVAL or something similar instead of deriving it twice.

I assume the compiler will evaluate the macro, so defining a new macro should make no difference.

For more readable, I will try to add the macro in next spin.

Thanks,
Leo

Quoted 4 lines
Quoted 3 lines
drivers/perf/arm_spe_pmu.c +0 -0
 	else if (period > max_period)
 		period = max_period;
 	else