Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Fenghua Yu <fenghuay@nvidia.com>
To: Reinette Chatre <reinette.chatre@intel.com>,
	Tony Luck <tony.luck@intel.com>, Ben Horgan <ben.horgan@arm.com>,
	James Morse <james.morse@arm.com>,
	Dave Martin <Dave.Martin@arm.com>,
	Shaopeng Tan <tan.shaopeng@fujitsu.com>,
	Chen Yu <yu.c.chen@intel.com>, Babu Moger <babu.moger@amd.com>,
	Drew Fustini <fustini@kernel.org>,
	Vikram Sethi <vsethi@nvidia.com>,
	Shanker Donthineni <sdonthineni@nvidia.com>,
	Newton Liu <newtonl@nvidia.com>, Gavin Shan <gshan@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Fenghua Yu <fenghuay@nvidia.com>
Subject: [PATCH 06/23] resctrl: Mirror schemata for controls without MBW hardware
Date: Thu, 16 Jul 2026 14:02:56 -0700	[thread overview]
Message-ID: <20260716210329.2914625-6-fenghuay@nvidia.com> (raw)
In-Reply-To: <cover.1784217438.git.fenghuay@nvidia.com>

When an emulated control has no MBW hardware of its own, redirect
schemata reads and writes to the backing control so both lines show
and update the same value.

Signed-off-by: Fenghua Yu <fenghuay@nvidia.com>
---
 fs/resctrl/ctrlmondata.c | 93 ++++++++++++++++++++++++++++++++++++----
 fs/resctrl/rdtgroup.c    |  1 +
 include/linux/resctrl.h  |  6 +++
 3 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 1f832a838115..ee7823cf9493 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -28,6 +28,13 @@ struct rdt_parse_data {
 	u32			closid;
 	enum rdtgrp_mode	mode;
 	char			*buf;
+	/*
+	 * The control whose schemata line is being parsed, before any
+	 * redirection to a backing control. Used to distinguish a real
+	 * duplicate domain from the mirrored write of an emulated control and
+	 * the control that backs it.
+	 */
+	struct resctrl_ctrl	*line_ctrl;
 };
 
 typedef int (ctrlval_parser_t)(struct rdt_parse_data *data,
@@ -105,7 +112,7 @@ static int parse_bw(struct rdt_parse_data *data, struct rdt_resource_final *f,
 	u32 bw_val;
 
 	cfg = &d->staged_config[f->conf_type];
-	if (cfg->have_new_ctrl) {
+	if (cfg->have_new_ctrl && cfg->staged_ctrl == data->line_ctrl) {
 		rdt_last_cmd_printf("Duplicate domain %d\n", d->hdr.id);
 		return -EINVAL;
 	}
@@ -118,8 +125,18 @@ static int parse_bw(struct rdt_parse_data *data, struct rdt_resource_final *f,
 		return 0;
 	}
 
+	if (cfg->have_new_ctrl) {
+		if (cfg->new_ctrl != bw_val) {
+			rdt_last_cmd_printf("Conflicting values for domain %d\n",
+					    d->hdr.id);
+			return -EINVAL;
+		}
+		return 0;
+	}
+
 	cfg->new_ctrl = bw_val;
 	cfg->have_new_ctrl = true;
+	cfg->staged_ctrl = data->line_ctrl;
 
 	return 0;
 }
@@ -185,7 +202,7 @@ static int parse_cbm(struct rdt_parse_data *data, struct rdt_resource_final *f,
 	u32 cbm_val;
 
 	cfg = &d->staged_config[f->conf_type];
-	if (cfg->have_new_ctrl) {
+	if (cfg->have_new_ctrl && cfg->staged_ctrl == data->line_ctrl) {
 		rdt_last_cmd_printf("Duplicate domain %d\n", d->hdr.id);
 		return -EINVAL;
 	}
@@ -228,6 +245,7 @@ static int parse_cbm(struct rdt_parse_data *data, struct rdt_resource_final *f,
 
 	cfg->new_ctrl = cbm_val;
 	cfg->have_new_ctrl = true;
+	cfg->staged_ctrl = data->line_ctrl;
 
 	return 0;
 }
@@ -238,11 +256,50 @@ static int parse_cbm(struct rdt_parse_data *data, struct rdt_resource_final *f,
  * separated by ";". The "id" is in decimal, and must match one of
  * the "id"s for this resource.
  */
+/*
+ * A control can be emulated by another control (for example the legacy,
+ * resource-wide MB control emulated by a node-scoped bandwidth control). When
+ * the control has no MBW hardware of its own (membw.no_mbw_hw), reads and writes
+ * are redirected to the control that emulates it (emulated_by) so both schemata
+ * lines show and update the same value.
+ *
+ * Emulation is only performed in legacy mode. In native mode
+ * (RESCTRL_CTRL_NATIVE) a control without hardware is left as-is, so a
+ * disabled control is not emulated by another control.
+ */
+static struct resctrl_ctrl *resctrl_ctrl_backing(struct rdt_resource *r,
+						 struct resctrl_ctrl *ctrl)
+{
+	if (r->mode == RESCTRL_CTRL_LEGACY &&
+	    ctrl->type == RESCTRL_CTRL_SCALAR &&
+	    ctrl->emulated_by && ctrl->membw.no_mbw_hw)
+		return ctrl->emulated_by;
+
+	return ctrl;
+}
+
+/*
+ * A control emulated by another control has no MBW hardware of its own, so it
+ * only has a schemata line while emulation is active. Emulation is performed
+ * in legacy mode only, so in native mode such a control is hidden from
+ * schemata rather than showing an empty or meaningless line.
+ */
+static bool resctrl_ctrl_schemata_hidden(struct rdt_resource *r,
+					 struct resctrl_ctrl *ctrl)
+{
+	if (ctrl->type != RESCTRL_CTRL_SCALAR ||
+	    !ctrl->emulated_by || !ctrl->membw.no_mbw_hw)
+		return false;
+
+	return r->mode != RESCTRL_CTRL_LEGACY;
+}
+
 static int parse_line(char *line, struct rdt_resource_final *f,
 		      struct resctrl_ctrl *ctrl, struct rdtgroup *rdtgrp)
 {
 	enum resctrl_conf_type t = f->conf_type;
 	ctrlval_parser_t *parse_ctrlval = NULL;
+	struct resctrl_ctrl *line_ctrl = ctrl;
 	struct resctrl_staged_config *cfg;
 	struct rdt_resource *r = f->res;
 	struct rdt_parse_data data;
@@ -253,6 +310,9 @@ static int parse_line(char *line, struct rdt_resource_final *f,
 	/* Walking r->domains, ensure it can't race with cpuhp */
 	lockdep_assert_cpus_held();
 
+	/* A control without MBW hardware mirrors the control that emulates it. */
+	ctrl = resctrl_ctrl_backing(r, ctrl);
+
 	parse_ctrlval = resctrl_ctrl_priv_all[ctrl->type].parser;
 
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
@@ -276,6 +336,7 @@ static int parse_line(char *line, struct rdt_resource_final *f,
 			data.buf = dom;
 			data.closid = rdtgrp->closid;
 			data.mode = rdtgrp->mode;
+			data.line_ctrl = line_ctrl;
 			if (parse_ctrlval(&data, f, d, ctrl))
 				return -EINVAL;
 			if (rdtgrp->mode ==  RDT_MODE_PSEUDO_LOCKSETUP) {
@@ -418,7 +479,7 @@ static int rdtgroup_parse_ctrl(char *ctrlname, char *tok,
 	list_for_each_entry(f, &rdt_resource_final_all, list) {
 		if (!strcmp(resname, f->name) && rdtgrp->closid < f->num_closid) {
 			ctrl = resctrl_resource_ctrl_get(f->res, ctrlname);
-			if (ctrl)
+			if (ctrl && !resctrl_ctrl_schemata_hidden(f->res, ctrl))
 				return parse_line(tok, f, ctrl, rdtgrp);
 			else
 				break;
@@ -511,6 +572,7 @@ static void show_doms(struct seq_file *s, struct rdt_resource_final *f,
 		      bool print_ctrl, int closid, struct resctrl_ctrl *ctrl)
 {
 	struct rdt_resource *r = f->res;
+	struct resctrl_ctrl *vctrl;
 	struct rdt_ctrl_domain *dom;
 	bool sep = false;
 	u32 ctrl_val;
@@ -523,17 +585,23 @@ static void show_doms(struct seq_file *s, struct rdt_resource_final *f,
 				resctrl_ctrl_is_default(ctrl) ? "" : "_",
 				resctrl_ctrl_is_default(ctrl) ?
 				 "" : resctrl_ctrl_name_str(ctrl->name));
-	list_for_each_entry(dom, &ctrl->domains, hdr.list) {
+
+	/*
+	 * A control without MBW hardware has no values of its own; show the
+	 * values of the control that emulates it so both schemata lines match.
+	 */
+	vctrl = resctrl_ctrl_backing(r, ctrl);
+	list_for_each_entry(dom, &vctrl->domains, hdr.list) {
 		if (sep)
 			seq_puts(s, ";");
 
-		if (is_mba_sc(r, ctrl))
+		if (is_mba_sc(r, vctrl))
 			ctrl_val = dom->mbps_val[closid];
 		else
-			ctrl_val = resctrl_arch_get_config(r, ctrl, dom, closid,
+			ctrl_val = resctrl_arch_get_config(r, vctrl, dom, closid,
 							   f->conf_type);
 
-		seq_printf(s, resctrl_ctrl_priv_all[ctrl->type].fmt_str,
+		seq_printf(s, resctrl_ctrl_priv_all[vctrl->type].fmt_str,
 			   dom->hdr.id, ctrl_val);
 		sep = true;
 	}
@@ -553,11 +621,14 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
 	if (rdtgrp) {
 		if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
 			list_for_each_entry(f, &rdt_resource_final_all, list) {
-				for_each_resource_ctrl(ctrl, f->res)
+				for_each_resource_ctrl(ctrl, f->res) {
+					if (resctrl_ctrl_schemata_hidden(f->res, ctrl))
+						continue;
 					seq_printf(s, "%s%s%s:uninitialized\n", f->name,
 						   resctrl_ctrl_is_default(ctrl) ? "" : "_",
 						   resctrl_ctrl_is_default(ctrl) ?
 						    "" : resctrl_ctrl_name_str(ctrl->name));
+				}
 			}
 		} else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
 			if (!rdtgrp->plr->d) {
@@ -574,8 +645,11 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			list_for_each_entry(f, &rdt_resource_final_all, list) {
 				if (closid >= f->num_closid)
 					continue;
-				for_each_resource_ctrl(ctrl, f->res)
+				for_each_resource_ctrl(ctrl, f->res) {
+					if (resctrl_ctrl_schemata_hidden(f->res, ctrl))
+						continue;
 					show_doms(s, f, true, closid, ctrl);
+				}
 			}
 		}
 	} else {
@@ -1147,6 +1221,7 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource_final *f,
 			data.buf = dom;
 			data.mode = RDT_MODE_SHAREABLE;
 			data.closid = closid;
+			data.line_ctrl = ctrl;
 			if (parse_cbm(&data, f, d, ctrl))
 				return -EINVAL;
 			/*
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 3bec23728847..a34c7ed8f874 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -4147,6 +4147,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, struct resctrl_ctrl *ctrl,
 		cfg = &d->staged_config[CDP_NONE];
 		cfg->new_ctrl = resctrl_get_default_ctrlval(ctrl);
 		cfg->have_new_ctrl = true;
+		cfg->staged_ctrl = ctrl;
 	}
 }
 
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 06482e766087..cfb4c17bcb53 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -121,10 +121,16 @@ struct pseudo_lock_region {
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
  * @have_new_ctrl:	whether the user provided new_ctrl is valid
+ * @staged_ctrl:	the control whose schemata line staged this config.
+ *			Used to tell a real duplicate domain in one schemata
+ *			line from the mirrored write of an emulated control
+ *			and the control that backs it, which share the same
+ *			staged config.
  */
 struct resctrl_staged_config {
 	u32			new_ctrl;
 	bool			have_new_ctrl;
+	struct resctrl_ctrl	*staged_ctrl;
 };
 
 enum resctrl_domain_type {
-- 
2.43.0



  parent reply	other threads:[~2026-07-16 21:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 21:02 [PATCH RFC 00/23] resctrl: MBA control emulation and ARM MPAM MB_NODE support Fenghua Yu
2026-07-16 21:02 ` [PATCH 01/23] resctrl: Fix ownership of resource_schemata control subdirectories Fenghua Yu
2026-07-16 21:02 ` [PATCH 02/23] arm_mpam: Fix NULL address access issue Fenghua Yu
2026-07-16 21:02 ` [PATCH 03/23] resctrl: Expose MBA resource_schemata mode sysfs Fenghua Yu
2026-07-16 21:02 ` [PATCH 04/23] resctrl: Expose per-control status in resource_schemata Fenghua Yu
2026-07-16 21:02 ` [PATCH 05/23] resctrl: Add nested resource_schemata support for emulated controls Fenghua Yu
2026-07-16 21:02 ` Fenghua Yu [this message]
2026-07-16 21:02 ` [PATCH 07/23] resctrl: Rebuild resource_schemata subdirs on MBA mode change Fenghua Yu
2026-07-16 21:02 ` [PATCH 08/23] Documentation: resctrl: document MBA control emulation Fenghua Yu
2026-07-16 21:02 ` [PATCH 09/23] resctrl: De-hardcode L3 monitor infrastructure Fenghua Yu
2026-07-16 21:03 ` [PATCH 10/23] resctrl: Expose MBA MBM counter assignment sysfs Fenghua Yu
2026-07-16 21:03 ` [PATCH 11/23] resctrl: name node-scoped monitor domains mon_NODE_<id> Fenghua Yu
2026-07-16 21:03 ` [PATCH 12/23] resctrl: Add node-scope MBM total event Fenghua Yu
2026-07-16 21:03 ` [PATCH 13/23] resctrl: Make MBM paths resource-aware Fenghua Yu
2026-07-16 21:03 ` [PATCH 14/23] arm_mpam: Support memory-level MSCs and ABMC per class Fenghua Yu
2026-07-16 21:03 ` [PATCH 15/23] arm_mpam: Refine L3 topology and class selection Fenghua Yu
2026-07-16 21:03 ` [PATCH 16/23] arm_mpam: Include all MSC components during domain setup Fenghua Yu
2026-07-16 21:03 ` [PATCH 17/23] arm_mpam: Handle CPU-less numa nodes Fenghua Yu
2026-07-16 21:03 ` [PATCH 18/23] arm_mpam: Emulate MB control with node-scoped MB_NODE control Fenghua Yu
2026-07-16 21:03 ` [PATCH 19/23] Documentation: arm64: mpam: document memory-level MB control and NUMA nodes Fenghua Yu
2026-07-16 21:03 ` [PATCH 20/23] Documentation: resctrl: document NODE-scoped MBA domains and mon_NODE monitoring Fenghua Yu
2026-07-16 21:03 ` [PATCH 21/23] Documentation: resctrl: document MB_NODE emulation example on ARM MPAM Fenghua Yu
2026-07-16 21:03 ` [PATCH 22/23] arm_mpam: Add KUnit test for CPU-less NUMA node affinity Fenghua Yu
2026-07-16 21:03 ` [PATCH 23/23] selftests/resctrl: Add MB emulation test for ARM MPAM Fenghua Yu

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=20260716210329.2914625-6-fenghuay@nvidia.com \
    --to=fenghuay@nvidia.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=fustini@kernel.org \
    --cc=gshan@redhat.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=newtonl@nvidia.com \
    --cc=reinette.chatre@intel.com \
    --cc=sdonthineni@nvidia.com \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tony.luck@intel.com \
    --cc=vsethi@nvidia.com \
    --cc=yu.c.chen@intel.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