Skip to contentSkip to conversation

ARM DSU PMU: 32-bit counter assumption and handling of 64-bit event counters

QUESTION feng.zhou 3 participants 3 messages Feb 6 – Mar 12

lore
Share & tools
lore

feng.zhou

author
#0 lore raw

Hi Will and Mark,

I have a question regarding the ARM DSU PMU driver implementation in drivers/perf/arm_dsu_pmu.c, specifically about the counter width assumptions.

Current Implementation:
======================
The driver currently assumes all event counters are 32-bit wide, with only the cycle counter being 64-bit (lines 69-71):

/* All event counters are 32bit, with a 64bit Cycle counter */

#define DSU_PMU_COUNTER_WIDTH(idx)	\
	(((idx) == DSU_PMU_IDX_CYCLE_COUNTER) ? 64 : 32)

This assumption is used throughout the code for handling counter overflow and calculating deltas (e.g., line 344 in dsu_pmu_event_update).

Issue Observed:
===============
I've encountered overflow issues when using perf tools on newer ARM CPUs where the event counters appear to be 64-bit rather than 32-bit. The current implementation causes incorrect event counting and potential data loss due to premature overflow handling based on the 32-bit mask.

Questions:
==========
1. Is the 32-bit event counter assumption based on the ARMv8 PMU specification or DSU-specific hardware documentation?

2. Are there known ARM CPU implementations where DSU event counters exceed 32 bits? If so, how should the driver handle this variation?

3. Would it be appropriate to detect the actual counter width at runtime (similar to how num_counters is probed in dsu_pmu_probe_pmu), or should this be handled through device tree / ACPI properties?

4. Should there be a mechanism to query the hardware for the actual counter width to ensure compatibility with future implementations?

Thank you for your time and any insights you can provide.

Best regards,
Feng

#1 lore raw

[+Robin and Suzuki]

Quoted 18 lines · feng.zhou

Hi Will and Mark,

I have a question regarding the ARM DSU PMU driver implementation in drivers/perf/arm_dsu_pmu.c, specifically about the counter width assumptions.

Current Implementation:
======================
The driver currently assumes all event counters are 32-bit wide, with only the cycle counter being 64-bit (lines 69-71):

/* All event counters are 32bit, with a 64bit Cycle counter */

#define DSU_PMU_COUNTER_WIDTH(idx)	\
	(((idx) == DSU_PMU_IDX_CYCLE_COUNTER) ? 64 : 32)

This assumption is used throughout the code for handling counter overflow and calculating deltas (e.g., line 344 in dsu_pmu_event_update).

Quoted 6 lines

Issue Observed:
===============
I've encountered overflow issues when using perf tools on newer ARM CPUs where the event counters appear to be 64-bit rather than 32-bit. The current implementation causes incorrect event counting and potential data loss due to premature overflow handling based on the 32-bit mask.

I suspect either the hardware or the architecture have evolved since the driver was initially written, possibly in a non-backwards-compatible way which is why you see problems.

Quoted 8 lines

Questions:
==========
1. Is the 32-bit event counter assumption based on the ARMv8 PMU specification or DSU-specific hardware documentation?

2. Are there known ARM CPU implementations where DSU event counters exceed 32 bits? If so, how should the driver handle this variation?

Quoted 8 lines

3. Would it be appropriate to detect the actual counter width at runtime (similar to how num_counters is probed in dsu_pmu_probe_pmu), or should this be handled through device tree / ACPI properties?

4. Should there be a mechanism to query the hardware for the actual counter width to ensure compatibility with future implementations?

Thank you for your time and any insights you can provide.

Suzuki and Robin should be able to help with these...

Will

#2 lore raw
Quoted 44 lines · Will Deacon

[+Robin and Suzuki]

Quoted 18 lines · feng.zhou

Hi Will and Mark,

I have a question regarding the ARM DSU PMU driver implementation in drivers/perf/arm_dsu_pmu.c, specifically about the counter width assumptions.

Current Implementation:
======================
The driver currently assumes all event counters are 32-bit wide, with only the cycle counter being 64-bit (lines 69-71):

/* All event counters are 32bit, with a 64bit Cycle counter */

#define DSU_PMU_COUNTER_WIDTH(idx)	\
	(((idx) == DSU_PMU_IDX_CYCLE_COUNTER) ? 64 : 32)

This assumption is used throughout the code for handling counter overflow and calculating deltas (e.g., line 344 in dsu_pmu_event_update).

Quoted 6 lines

Issue Observed:
===============
I've encountered overflow issues when using perf tools on newer ARM CPUs where the event counters appear to be 64-bit rather than 32-bit. The current implementation causes incorrect event counting and potential data loss due to premature overflow handling based on the 32-bit mask.

I suspect either the hardware or the architecture have evolved since the driver was initially written, possibly in a non-backwards-compatible way which is why you see problems.

Quoted 12 lines

Questions:
==========
1. Is the 32-bit event counter assumption based on the ARMv8 PMU specification or DSU-specific hardware documentation?

2. Are there known ARM CPU implementations where DSU event counters exceed 32 bits? If so, how should the driver handle this variation?

3. Would it be appropriate to detect the actual counter width at runtime (similar to how num_counters is probed in dsu_pmu_probe_pmu), or should this be handled through device tree / ACPI properties?

Quoted 6 lines
Quoted 4 lines

4. Should there be a mechanism to query the hardware for the actual counter width to ensure compatibility with future implementations?

Thank you for your time and any insights you can provide.

Suzuki and Robin should be able to help with these...

Yup, indeed newer DSUs subtly evolved, and the patches are already in 7.0-rc ;)

Cheers,
Robin.