[PATCH v3 5/9] arm_mpam: Propagate control group config to sub-monitoring groups

Zeng Heng posted 9 patches 2 weeks, 6 days ago
[PATCH v3 5/9] arm_mpam: Propagate control group config to sub-monitoring groups
Posted by Zeng Heng 2 weeks, 6 days ago
With the narrow PARTID feature, each control group is assigned multiple
(req)PARTIDs to expand monitoring capacity. When a control group's
configuration is updated, all associated sub-monitoring groups (each
identified by a unique reqPARTID) should be synchronized.

In __write_config(), iterate over all reqPARTIDs belonging to the
control group and propagate the configuration to each sub-monitoring
group:

  * For MSCs supporting narrow PARTID, establish the reqPARTID to
    intPARTID mapping.
  * For MSCs without narrow PARTID support, synchronize the configuration
    to new PARTIDs directly.

Signed-off-by: Zeng Heng <zengheng4@huawei.com>
---
 drivers/resctrl/mpam_devices.c  | 33 +++++++++++++++++++++++++++------
 drivers/resctrl/mpam_internal.h |  2 ++
 drivers/resctrl/mpam_resctrl.c  |  2 +-
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 2634afc41c6a..d98f81621be1 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -1543,6 +1543,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
 {
 	u32 pri_val = 0;
 	u16 cmax = MPAMCFG_CMAX_CMAX;
+	u16 intpartid = req2intpartid(partid);
 	struct mpam_msc *msc = ris->vmsc->msc;
 	struct mpam_props *rprops = &ris->props;
 	u16 dspri = GENMASK(rprops->dspri_wd, 0);
@@ -1552,15 +1553,17 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
 	__mpam_part_sel(ris->ris_idx, partid, msc);
 
 	if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) {
-		/* Update the intpartid mapping */
 		mpam_write_partsel_reg(msc, INTPARTID,
-				       MPAMCFG_INTPARTID_INTERNAL | partid);
+				       MPAMCFG_INTPARTID_INTERNAL | intpartid);
 
 		/*
-		 * Then switch to the 'internal' partid to update the
-		 * configuration.
+		 * Mapping from reqpartid to intpartid already established.
+		 * Sub-monitoring groups share the parent's configuration.
 		 */
-		__mpam_intpart_sel(ris->ris_idx, partid, msc);
+		if (partid != intpartid)
+			goto out;
+
+		__mpam_intpart_sel(ris->ris_idx, intpartid, msc);
 	}
 
 	if (mpam_has_feature(mpam_feat_cpor_part, rprops) &&
@@ -1632,6 +1635,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
 
 	mpam_quirk_post_config_change(ris, partid, cfg);
 
+out:
 	mutex_unlock(&msc->part_sel_lock);
 }
 
@@ -1766,11 +1770,28 @@ struct mpam_write_config_arg {
 	u16 partid;
 };
 
+static u32 get_num_reqpartid_per_intpartid(void)
+{
+	return (mpam_partid_max + 1) / (mpam_intpartid_max + 1);
+}
+
 static int __write_config(void *arg)
 {
+	int closid_num = resctrl_arch_get_num_closid(NULL);
 	struct mpam_write_config_arg *c = arg;
+	u32 reqpartid, req_idx;
 
-	mpam_reprogram_ris_partid(c->ris, c->partid, &c->comp->cfg[c->partid]);
+	/* c->partid should be within the range of intPARTIDs */
+	WARN_ON_ONCE(c->partid >= closid_num);
+
+	/* Synchronize the configuration to each sub-monitoring group. */
+	for (req_idx = 0; req_idx < get_num_reqpartid_per_intpartid();
+	     req_idx++) {
+		reqpartid = req_idx * closid_num + c->partid;
+
+		mpam_reprogram_ris_partid(c->ris, reqpartid,
+					 &c->comp->cfg[c->partid]);
+	}
 
 	return 0;
 }
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index 2029a5b7283e..9069e2314d77 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -487,6 +487,8 @@ void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx);
 int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
 				   cpumask_t *affinity);
 
+u16 req2intpartid(u16 reqpartid);
+
 #ifdef CONFIG_RESCTRL_FS
 int mpam_resctrl_setup(void);
 void mpam_resctrl_exit(void);
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 15e8cf7d8f1f..725583d7bd07 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -296,7 +296,7 @@ static u8 rmid2pmg(u32 rmid)
 	return rmid % (mpam_pmg_max + 1);
 }
 
-static u16 req2intpartid(u16 reqpartid)
+u16 req2intpartid(u16 reqpartid)
 {
 	return reqpartid % (mpam_intpartid_max + 1);
 }
-- 
2.25.1