From 8668e586e4bef556d5fe779282c6acbc8c1ad944 Mon Sep 17 00:00:00 2001 From: Zeng Heng Date: Thu, 11 Sep 2025 15:18:45 +0800 Subject: [PATCH] arm64/mpam: Add quirk for L3 CSU counters hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICXIBU -------------------------------- On certain platforms, the Cache Storage Usage monitor statistics need to half. Due to the L3 cache compression feature on some hisi chips, the L3 CSU counter shows a value twice the actual usage, which does not reflect the real occupancy. To mitigate this effect as much as possible, the statistic method needs to half the statistic. With L3 compression disabled, the halved value matches the real L3 usage. However, with L3 compression enabled, it becomes slightly lower than the real L3 occupancy. Fixes: bb66b4d115e5 ("arm_mpam: Add mpam_msmon_read() to read monitor value") Signed-off-by: Zeng Heng --- drivers/platform/mpam/mpam_devices.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index ba15ce4492f9..516ffc4b4a3d 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -936,6 +936,23 @@ static bool mpam_ris_has_nrdy_bit(struct mpam_msc_ris *ris) return true; } +static u64 mpam_csu_hisi_need_halved(struct mpam_msc_ris *ris, u64 now) +{ + static const struct midr_range cpus[] = { + MIDR_ALL_VERSIONS(MIDR_HISI_HIP12), + { /* sentinel */ } + }; + + if (!is_midr_in_range_list(read_cpuid_id(), cpus)) + return now; + + if (ris->comp->class->type != MPAM_CLASS_CACHE || + ris->comp->class->level != 3) + return now; + + return now >> 1; +} + static void __ris_msmon_read(void *arg) { bool nrdy = false; @@ -991,6 +1008,7 @@ static void __ris_msmon_read(void *arg) now = mpam_read_monsel_reg(msc, CSU); nrdy = now & MSMON___NRDY; now = FIELD_GET(MSMON___VALUE, now); + now = mpam_csu_hisi_need_halved(ris, now); break; case mpam_feat_msmon_mbwu: /* -- Gitee