[RFC PATCH v2 9/9] arm_mpam: Cap the CLOSID/RMID space by the bandwidth counters for mba_MBps
From: Jinjie Ruan
Date: Thu Nov 12 2026 - 08:23:26 EST
MPAM assigns each monitor group a bandwidth counter from a shared pool
when the group is created, but the number of groups comes from the
PARTID and PMG spaces. Once the pool is empty, new groups get no
counter, their reads fail with -ENOENT, and the MBA software controller
cannot keep them below their target.
While the controller is enabled, cap the CLOSIDs and the RMIDs per
CLOSID to the number of counters, shrinking the RMIDs first and keeping
one per CLOSID for the default monitor group. CDP hides the MBA
resource, as MBW_MAX is configured per PARTID and the two PARTIDs of a
CLOSID would alias, so the controller cannot be enabled together with
CDP and the cap needs no CDP adjustment.
resctrl_arch_get_num_closid() reports the capped CLOSIDs,
resctrl_arch_rmid_valid() refuses the RMIDs above the cap, and
resctrl_arch_set_mba_sc() updates num_rmid and the limbo threshold.
Without mba_MBps nothing changes.
Suggested-by: Ben Horgan <ben.horgan@xxxxxxx>
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
drivers/resctrl/mpam_resctrl.c | 48 +++++++++++++++++++++++++++++++++-
include/linux/arm_mpam.h | 10 ++-----
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 53fcffb23984..1e23a9a41ea9 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -62,6 +62,14 @@ static DEFINE_MUTEX(domain_list_lock);
*/
static bool cdp_enabled;
+/*
+ * The CLOSIDs and the RMIDs per CLOSID resctrl may use while the MBA software
+ * controller is enabled. Set by resctrl_arch_set_mba_sc().
+ */
+static u32 mpam_capped_num_closid;
+static u32 mpam_capped_num_rmid;
+static bool mba_sc_enabled;
+
/*
* 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.
@@ -271,7 +279,7 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid)
*/
u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
{
- return mpam_partid_max + 1;
+ return mba_sc_enabled ? mpam_capped_num_closid : mpam_partid_max + 1;
}
u32 resctrl_arch_system_num_rmid_idx(void)
@@ -290,6 +298,12 @@ void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid)
*rmid = idx % (mpam_pmg_max + 1);
}
+/* The CLOSID is already capped by resctrl_arch_get_num_closid(). */
+bool resctrl_arch_rmid_valid(u32 closid, u32 rmid)
+{
+ return !mba_sc_enabled || rmid < mpam_capped_num_rmid;
+}
+
void resctrl_arch_sched_in(struct task_struct *tsk)
{
lockdep_assert_preemption_disabled();
@@ -1154,6 +1168,38 @@ static void mpam_resctrl_pick_counters(void)
}
}
+/*
+ * The controller needs a bandwidth counter for every monitor group, so while
+ * it is enabled cap the CLOSIDs and the RMIDs per CLOSID to the number of
+ * counters, shrinking the RMIDs first. The number of monitor groups changes,
+ * and so does the limbo threshold. CDP hides the MBA resource, so it cannot
+ * be enabled together with the controller and needs no adjustment here.
+ */
+void resctrl_arch_set_mba_sc(bool enable)
+{
+ struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[QOS_L3_MBM_TOTAL_EVENT_ID];
+ struct rdt_resource *l3 = &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res;
+ u32 num_closid = mpam_partid_max + 1;
+ u32 num_rmid = mpam_pmg_max + 1;
+
+ if (enable && mon->class) {
+ u32 num_mon = mon->class->props.num_mbwu_mon;
+
+ num_closid = min(num_closid, num_mon);
+ num_rmid = clamp(num_mon / num_closid, 1U, num_rmid);
+ }
+
+ mpam_capped_num_closid = num_closid;
+ mpam_capped_num_rmid = num_rmid;
+ mba_sc_enabled = enable;
+
+ l3->mon.num_rmid = num_closid * num_rmid;
+
+ if (resctrl_rmid_realloc_limit)
+ resctrl_rmid_realloc_threshold =
+ resctrl_rmid_realloc_limit / (num_closid * num_rmid);
+}
+
static void __config_cntr(struct mpam_resctrl_mon *mon, u32 cntr_id,
enum resctrl_conf_type cdp_type, u32 closid, u32 rmid,
bool assign)
diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
index 73a6277f688c..7c939a6f670b 100644
--- a/include/linux/arm_mpam.h
+++ b/include/linux/arm_mpam.h
@@ -62,14 +62,8 @@ bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid);
void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid);
u32 resctrl_arch_system_num_rmid_idx(void);
-
-/* MPAM does not limit the RMIDs for the MBA software controller yet. */
-static inline void resctrl_arch_set_mba_sc(bool enable) { }
-
-static inline bool resctrl_arch_rmid_valid(u32 closid, u32 rmid)
-{
- return true;
-}
+void resctrl_arch_set_mba_sc(bool enable);
+bool resctrl_arch_rmid_valid(u32 closid, u32 rmid);
struct rdt_resource;
void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
--
2.34.1