[PATCH v10 12/15] arm_mpam: Map resctrl RMIDs onto the request PARTIDs
From: Jinjie Ruan
Date: Mon Oct 19 2026 - 03:36:28 EST
From: Zeng Heng <zengheng4@xxxxxxxxxx>
The current resctrl RMID allocation assumes a rigid 2D encoding, which
limits the total number of monitoring groups to the hardware CLOSID count.
To decouple control and monitoring, redefine resctrl_arch_rmid_idx_encode()
as a flat, global monitoring index. When extra request PARTIDs are active,
the task's hardware PARTID and PMG are derived directly from this global
RMID via modulo division. Otherwise, legacy 1:1 behavior is preserved.
CDP and PARTID narrowing can now coexist through a two-phase mapping:
when both features are active, extract reqPARTID from rmid first, then
apply CDP's even/odd split on that reqPARTID.
No functional change for now as resctrl_using_extra_partids
remains false.
Cc: James Morse <james.morse@xxxxxxx>
Cc: Ben Horgan <ben.horgan@xxxxxxx>
Cc: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Cc: Fenghua Yu <fenghuay@xxxxxxxxxx>
Suggested-by: James Morse <james.morse@xxxxxxx>
Link: https://lore.kernel.org/all/2944b506-a462-42f8-95cf-404241fb27f0@xxxxxxx/
Signed-off-by: Zeng Heng <zengheng4@xxxxxxxxxx>
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
v9->v10:
- Remove CDP + narrowing mutual exclusion check
- Add narrowing path in resctrl_closid_rmid_to_partid_pmg() for CDP case
- Handle CDP in resctrl_partid_in_closid()
- Add consistent NULL checks in legacy path
- Remove the dead WARN_ON_ONCE(partid > U16_MAX)
---
drivers/resctrl/mpam_resctrl.c | 76 ++++++++++++++++++++++++++++------
1 file changed, 64 insertions(+), 12 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 332388a092ce..d60dea846486 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -62,6 +62,9 @@ static DEFINE_MUTEX(domain_list_lock);
*/
static bool cdp_enabled;
+/* If resctrl is leveraging extra request PARTIDs for monitoring. */
+static bool resctrl_using_extra_partids;
+
/*
* We use cacheinfo to discover the size of the caches and their id. cacheinfo
* populates this from a device_initcall(). mpam_resctrl_setup() must wait.
@@ -274,8 +277,28 @@ u32 resctrl_arch_system_num_rmid_idx(void)
return (mpam_pmg_max + 1) * (mpam_partid_max + 1);
}
+/* The request PARTID and PMG a resctrl RMID maps onto. */
+static u16 resctrl_rmid_to_partid(u32 rmid)
+{
+ return rmid / (mpam_pmg_max + 1);
+}
+
+static u8 resctrl_rmid_to_pmg(u32 rmid)
+{
+ return rmid % (mpam_pmg_max + 1);
+}
+
+/* The control group that owns a request PARTID. */
+static u16 resctrl_partid_to_closid(u16 partid)
+{
+ return mpam_partid_to_intpartid(partid);
+}
+
u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid)
{
+ if (resctrl_using_extra_partids)
+ return rmid;
+
return closid * (mpam_pmg_max + 1) + rmid;
}
@@ -287,8 +310,18 @@ bool resctrl_arch_rmid_idx_match(u32 closid, u32 rmid_closid)
void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid)
{
- *closid = idx / (mpam_pmg_max + 1);
- *rmid = idx % (mpam_pmg_max + 1);
+ if (resctrl_using_extra_partids) {
+ if (rmid)
+ *rmid = idx;
+ if (closid)
+ *closid = resctrl_partid_to_closid(resctrl_rmid_to_partid(idx));
+ return;
+ }
+
+ if (closid)
+ *closid = idx / (mpam_pmg_max + 1);
+ if (rmid)
+ *rmid = idx % (mpam_pmg_max + 1);
}
void resctrl_arch_sched_in(struct task_struct *tsk)
@@ -303,19 +336,35 @@ static void resctrl_closid_rmid_to_partid_pmg(u32 closid, u32 rmid,
u8 *pmg_d, u8 *pmg_i)
{
WARN_ON_ONCE(closid > U16_MAX);
- WARN_ON_ONCE(rmid > U8_MAX);
+ WARN_ON_ONCE(!resctrl_using_extra_partids && rmid > U8_MAX);
if (!cdp_enabled) {
- *partid_d = *partid_i = closid;
- *pmg_d = *pmg_i = rmid;
+ u16 partid;
+ u8 pmg;
+
+ if (resctrl_using_extra_partids) {
+ partid = resctrl_rmid_to_partid(rmid);
+ pmg = resctrl_rmid_to_pmg(rmid);
+ } else {
+ partid = closid;
+ pmg = rmid;
+ }
+
+ *partid_d = *partid_i = partid;
+ *pmg_d = *pmg_i = pmg;
} else {
- /*
- * When CDP is enabled, resctrl halves the closid range and we
- * use odd/even partid for one closid.
- */
- *partid_d = resctrl_get_config_index(closid, CDP_DATA);
- *partid_i = resctrl_get_config_index(closid, CDP_CODE);
- *pmg_d = *pmg_i = rmid;
+ if (resctrl_using_extra_partids) {
+ u16 req_partid = resctrl_rmid_to_partid(rmid);
+ u8 pmg = resctrl_rmid_to_pmg(rmid);
+
+ *partid_d = resctrl_get_config_index(req_partid, CDP_DATA);
+ *partid_i = resctrl_get_config_index(req_partid, CDP_CODE);
+ *pmg_d = *pmg_i = pmg;
+ } else {
+ *partid_d = resctrl_get_config_index(closid, CDP_DATA);
+ *partid_i = resctrl_get_config_index(closid, CDP_CODE);
+ *pmg_d = *pmg_i = rmid;
+ }
}
}
@@ -359,6 +408,9 @@ static bool resctrl_partid_in_closid(u16 partid, u32 closid)
if (cdp_enabled)
partid >>= 1;
+ if (resctrl_using_extra_partids)
+ partid = resctrl_partid_to_closid(partid);
+
return partid == closid;
}
--
2.43.0