mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinjie Ruan <2118537295@qq.com>
To: babu.moger@amd.com, ben.horgan@arm.com, bp@alien8.de,
	catalin.marinas@arm.com, dave.hansen@linux.intel.com,
	Dave.Martin@arm.com, fenghuay@nvidia.com, gshan@redhat.com,
	hpa@zytor.com, james.morse@arm.com, jic23@kernel.org,
	mingo@redhat.com, reinette.chatre@intel.com,
	ruanjinjie@huawei.com, tan.shaopeng@fujitsu.com, tglx@kernel.org,
	tony.luck@intel.com, zengheng4@huawei.com, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v10 12/15] arm_mpam: Map resctrl RMIDs onto the request PARTIDs
Date: Mon, 19 Oct 2026 15:33:38 +0800	[thread overview]
Message-ID: <tencent_8162C8AD8CD4DF0CD931E28A6C1AEA840406@qq.com> (raw)
In-Reply-To: <20261019073453.2142856-1-2118537295@qq.com>

From: Zeng Heng <zengheng4@huawei.com>

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@arm.com>
Cc: Ben Horgan <ben.horgan@arm.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Fenghua Yu <fenghuay@nvidia.com>
Suggested-by: James Morse <james.morse@arm.com>
Link: https://lore.kernel.org/all/2944b506-a462-42f8-95cf-404241fb27f0@arm.com/
Signed-off-by: Zeng Heng <zengheng4@huawei.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
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


      parent reply	other threads:[~2026-10-19  7:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261019073453.2142856-1-2118537295@qq.com>
2026-10-19  7:33 ` [PATCH v10 01/15] fs/resctrl: Return -EBUSY when per-CLOSID RMIDs are in limbo Jinjie Ruan
2026-10-19  8:27   ` Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 02/15] fs/resctrl: Skip monitor context allocation when force-freeing RMIDs Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 03/15] arm_mpam: Fix error return in resctrl_arch_mon_ctx_alloc() Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 04/15] arm_mpam: Fix infinite PARTID reset loop when 65536 PARTIDs are supported Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 05/15] arm_mpam: Don't stall MPAM enable when an MSC fails to probe Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 06/15] fs/resctrl: Unmount resctrl with the CDP state it was mounted with Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 07/15] fs/resctrl: Add resctrl_arch_rmid_idx_match() helper Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 08/15] arm_mpam: resctrl: Add resctrl_closid_rmid_to_partid_pmg() helper Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 09/15] arm_mpam: Add a helper to check a PARTID is in a CLOSID Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 10/15] arm_mpam: Track the PARTID and internal PARTID limits per class Jinjie Ruan
2026-10-19  7:33 ` [PATCH v10 11/15] arm_mpam: Divide the PARTIDs between the control groups Jinjie Ruan
2026-10-19  7:33 ` Jinjie Ruan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_8162C8AD8CD4DF0CD931E28A6C1AEA840406@qq.com \
    --to=2118537295@qq.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghuay@nvidia.com \
    --cc=gshan@redhat.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=jic23@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=reinette.chatre@intel.com \
    --cc=ruanjinjie@huawei.com \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tglx@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=zengheng4@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®