[RFC PATCH 07/10] arm_mpam: Generalize the fixed-point conversion helpers
From: Jinjie Ruan
Date: Thu Oct 22 2026 - 22:55:06 EST
mbw_max_to_percent() and percent_to_mbw_max() open-code the width in
cprops->bwa_wd. Split the conversion into a helper that takes the width
and keep the mbw wrappers, so the CMAX/CMIN controls, which use the
same fixed-point format but are cmax_wd bits wide, can reuse it.
No functional change.
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
drivers/resctrl/mpam_resctrl.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 9d223057953a..dcdbf0404f07 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -739,18 +739,23 @@ static u32 get_mba_granularity(struct mpam_props *cprops)
*
* Find the nearest percentage value to the upper bound of the selected band:
*/
-static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops)
+static u32 __mbw_max_to_percent(u16 mbw_max, u8 wd)
{
u32 val = mbw_max;
- val >>= 16 - cprops->bwa_wd;
+ val >>= 16 - wd;
val += 1;
val *= MAX_MBA_BW;
- val = DIV_ROUND_CLOSEST(val, 1 << cprops->bwa_wd);
+ val = DIV_ROUND_CLOSEST(val, 1 << wd);
return val;
}
+static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops)
+{
+ return __mbw_max_to_percent(mbw_max, cprops->bwa_wd);
+}
+
/*
* Find the band whose upper bound is closest to the specified percentage.
*
@@ -761,18 +766,23 @@ static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops)
* percentages) and over-commit (where the total of the converted
* allocations is greater than expected).
*/
-static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops)
+static u16 __percent_to_mbw_max(u8 pc, u8 wd)
{
u32 val = pc;
- val <<= cprops->bwa_wd;
+ val <<= wd;
val = DIV_ROUND_CLOSEST(val, MAX_MBA_BW);
val = max(val, 1) - 1;
- val <<= 16 - cprops->bwa_wd;
+ val <<= 16 - wd;
return val;
}
+static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops)
+{
+ return __percent_to_mbw_max(pc, cprops->bwa_wd);
+}
+
static u32 get_mba_min(struct mpam_props *cprops)
{
if (!mba_class_use_mbw_max(cprops)) {
--
2.34.1