Re: [PATCH] drivers: perf: arm_pmuv3: Update 'pmc_width' based on actual HW event width

From: Robin Murphy
Date: Tue Oct 10 2023 - 07:38:29 EST


On 09/10/2023 5:37 am, Anshuman Khandual wrote:
This updates 'perf_event_mmap_page->pmc_width' based on actual HW event's
width that are currently missing i.e ARMPMU_EVT_63BIT and ARMPMU_EVT_47BIT.

Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
---
This applies on v6.6-rc5.

drivers/perf/arm_pmuv3.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index fe4db1831662..94723d00548e 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -1375,6 +1375,10 @@ void arch_perf_update_userpage(struct perf_event *event,
if (userpg->cap_user_rdpmc) {
if (event->hw.flags & ARMPMU_EVT_64BIT)
userpg->pmc_width = 64;
+ else if (event->hw.flags & ARMPMU_EVT_63BIT)
+ userpg->pmc_width = 63;
+ else if (event->hw.flags & ARMPMU_EVT_47BIT)
+ userpg->pmc_width = 47;

I think this will give the wrong behaviour in at least some cases - if the user has not requested a "long" event which would lead to ARMPMU_EVT_64BIT being set, we will bias the values to only count 32 effective bits regardless of how wide the physical counters are. I believe this is what "the valid width of the counter" in the documentation is trying to refer to.

Thanks,
Robin.

else
userpg->pmc_width = 32;
}