Skip to contentSkip to conversation

x86,fs/resctrl: Pave the way for MPAM counter assignment

PATCH Superseded Ben Horgan 2 participants 19 messages Apr 28 – May 5

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Ben Horgan

author
#0 lore raw

v5 cover x86,fs/resctrl: Pave the way for MPAM counter assignment

Some small changes from v4 addressing the comments there. Changelogs in patches.

Description from a previous version's cover letter:

A little bit of preparatory work to get ready for MPAM counter assignment. Resctrl gained support last year for counter assignment for AMD machines supporting ABMC. Tighten a few things up, that weren't needed for AMD, so that the MPAM driver can emulate ABMC and hence support counter assignment.

Based on v7.1-rc1

v1:
https://lore.kernel.org/lkml/[email protected]/
v2:
https://lore.kernel.org/lkml/[email protected]/
v3:
https://lore.kernel.org/lkml/[email protected]/
v4:
https://lore.kernel.org/lkml/[email protected]/

Ben Horgan (7):
fs/resctrl: Tidy up the error path in resctrl_mkdir_event_configs() x86,fs/resctrl: Create 'event_filter' files read only if they're not
configurable
fs/resctrl: Disallow the software controller when MBM counters are
assignable
fs/resctrl: Add monitor property 'mbm_cntr_assign_fixed' fs/resctrl: Continue counter allocation after failure fs/resctrl: Document that automatic counter assignment is best effort fs/resctrl: Document tasks file behaviour for task id 0 and idle tasks

 Documentation/filesystems/resctrl.rst | 22 ++++++++++++++------
 arch/x86/kernel/cpu/resctrl/monitor.c |  1 +
 fs/resctrl/internal.h                 |  2 ++
 fs/resctrl/monitor.c                  | 30 ++++++++++++++++++++-------
 fs/resctrl/rdtgroup.c                 | 25 +++++++++++++++-------
 include/linux/resctrl.h               | 18 +++++++++-------
 6 files changed, 70 insertions(+), 28 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v5 1/7 fs/resctrl: Tidy up the error path in resctrl_mkdir_event_configs()

The error path in resctrl_mkdir_event_configs() is unnecessarily complicated. Simplify it to just return directly on error.

---
 fs/resctrl/rdtgroup.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/resctrl/rdtgroup.c +4 -5
index 5dfdaa6f9d8f..fb6999178fe2 100644
@@ -2333,20 +2333,19 @@ static int resctrl_mkdir_event_configs(struct rdt_resource *r, struct kernfs_nod
 		kn_subdir2 = kernfs_create_dir(kn_subdir, mevt->name, kn_subdir->mode, mevt);
 		if (IS_ERR(kn_subdir2)) {
 			ret = PTR_ERR(kn_subdir2);
-			goto out;
+			return ret;
 		}
 
 		ret = rdtgroup_kn_set_ugid(kn_subdir2);
 		if (ret)
-			goto out;
+			return ret;
 
 		ret = rdtgroup_add_files(kn_subdir2, RFTYPE_ASSIGN_CONFIG);
 		if (ret)
-			break;
+			return ret;
 	}
 
-out:
-	return ret;
+	return 0;
 }
 
 static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v5 1/7] fs/resctrl: Tidy up the error path in resctrl_mkdir_event_configs()

Hi Ben,

Quoted 5 lines · Ben Horgan

The error path in resctrl_mkdir_event_configs() is unnecessarily complicated. Simplify it to just return directly on error.

resctrl's MAINTAINERS entry recently received a "Subsystem Profile" entry to make it clear that resctrl follows the rules in the tip tree handbook. This is required since resctrl fs patches flow via the tip tree.

For a smooth merge we should thus aim to follow the tip rules and for commit tag ordering this means the "Reviewed-by" tag follows the "Signed-off-by" tag. For reference, "Ordering of commit tags" in Documentation/process/maintainer-tip.rst

Reinette

author
#3 lore raw

PATCH v5 2/7 x86,fs/resctrl: Create 'event_filter' files read only if they're not configurable

In reply to Ben Horgan

When the counter assignment mode is mbm_event resctrl assumes the MBM events are configurable and exposes the 'event_filter' files. These files live at info/L3_MON/event_configs/<event>/event_filter and are used to display and set the event configuration.

The MPAM architecture has support for configuring the memory bandwidth utilization (MBWU) counters to only count reads or only count writes. However, In MPAM, this event filtering support is optional in the hardware (and not yet implemented in the MPAM driver) but MBM counter assignment is always possible for MPAM MBWU counters.

In order to support mbm_event mode with MPAM, create the 'event_filter' files read only if the event configuration can't be changed. A user can still chmod the file and so also return early with an error from event_filter_write().

Introduce a new monitor property, mbm_cntr_configurable, to indicate whether or not assignable MBM counters are configurable. On x86, set this to true whenever mbm_cntr_assignable is true to keep existing behaviour.

---
Changes since v2:
Use property, mbm_cntr_configurable, rather than arch hook Change the event_filter mode to read only in res_common_files[] Add resctrl_file_mode_init() and use in resctrl_l3_mon_resource_init() set mbm_cntr_configurable for x86 ABMC and mention in commit message

Changes since v4:
Add documentation
make -> create in commit message

---
 Documentation/filesystems/resctrl.rst | 11 +++++------
 arch/x86/kernel/cpu/resctrl/monitor.c |  1 +
 fs/resctrl/internal.h                 |  2 ++
 fs/resctrl/monitor.c                  |  7 +++++++
 fs/resctrl/rdtgroup.c                 | 11 ++++++++++-
 include/linux/resctrl.h               | 16 +++++++++-------
 6 files changed, 34 insertions(+), 14 deletions(-)
Documentation/filesystems/resctrl.rst +5 -6
index b003bed339fd..2898a51e6f4b 100644
@@ -427,9 +427,9 @@ with the following files:
 
 	Two MBM events are supported by default: mbm_local_bytes and mbm_total_bytes.
 	Each MBM event's sub-directory contains a file named "event_filter" that is
-	used to view and modify which memory transactions the MBM event is configured
-	with. The file is accessible only when "mbm_event" counter assignment mode is
-	enabled.
+	used to view and (if writable) modify which memory transactions the MBM event
+	is configured with. The file is accessible only when "mbm_event" counter
+	assignment mode is enabled.
 
 	List of memory transaction types supported:
 
@@ -454,9 +454,8 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
 	  local_reads,local_non_temporal_writes,local_reads_slow_memory
 
-	Modify the event configuration by writing to the "event_filter" file within
-	the "event_configs" directory. The read/write "event_filter" file contains the
-	configuration of the event that reflects which memory transactions are counted by it.
+	The memory transactions the MBM event is configured with can be changed
+	if "event_filter" is writable.
 
 	For example::
 
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
index 9bd87bae4983..794a6fb175e4 100644
@@ -454,6 +454,7 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r)
 	    (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) ||
 	     rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL))) {
 		r->mon.mbm_cntr_assignable = true;
+		r->mon.mbm_cntr_configurable = true;
 		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
 		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
 		hw_res->mbm_cntr_assign_enabled = true;
fs/resctrl/internal.h +2 -0
index 1a9b29119f88..48af75b9dc85 100644
@@ -408,6 +408,8 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free);
 
 void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 
+void resctrl_file_mode_init(const char *config, umode_t mode);
+
 void rdt_staged_configs_clear(void);
 
 bool closid_allocated(unsigned int closid);
fs/resctrl/monitor.c +7 -0
index 9fd901c78dc6..916f7a9d5658 100644
@@ -1422,6 +1422,11 @@ ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes
 		ret = -EINVAL;
 		goto out_unlock;
 	}
+	if (!r->mon.mbm_cntr_configurable) {
+		rdt_last_cmd_puts("event_filter is not configurable\n");
+		ret = -EPERM;
+		goto out_unlock;
+	}
 
 	ret = resctrl_parse_mem_transactions(buf, &evt_cfg);
 	if (!ret && mevt->evt_cfg != evt_cfg) {
@@ -1886,6 +1891,8 @@ int resctrl_l3_mon_resource_init(void)
 		resctrl_file_fflags_init("available_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
+		if (r->mon.mbm_cntr_configurable)
+			resctrl_file_mode_init("event_filter", 0644);
 		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
 					 RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
fs/resctrl/rdtgroup.c +10 -1
index fb6999178fe2..b382a348dd79 100644
@@ -2022,7 +2022,7 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "event_filter",
-		.mode		= 0644,
+		.mode		= 0444,
 		.kf_ops		= &rdtgroup_kf_single_ops,
 		.seq_show	= event_filter_show,
 		.write		= event_filter_write,
@@ -2215,6 +2215,15 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags)
 		rft->fflags = fflags;
 }
 
+void resctrl_file_mode_init(const char *config, umode_t mode)
+{
+	struct rftype *rft;
+
+	rft = rdtgroup_get_rftype_by_name(config);
+	if (rft)
+		rft->mode = mode;
+}
+
 /**
  * rdtgroup_kn_mode_restrict - Restrict user access to named resctrl file
  * @r: The resource group with which the file is associated.
include/linux/resctrl.h +9 -7
index 006e57fd7ca5..06e8c72e8660 100644
@@ -286,13 +286,14 @@ enum resctrl_schema_fmt {
 
 /**
  * struct resctrl_mon - Monitoring related data of a resctrl resource.
- * @num_rmid:		Number of RMIDs available.
- * @mbm_cfg_mask:	Memory transactions that can be tracked when bandwidth
- *			monitoring events can be configured.
- * @num_mbm_cntrs:	Number of assignable counters.
- * @mbm_cntr_assignable:Is system capable of supporting counter assignment?
- * @mbm_assign_on_mkdir:True if counters should automatically be assigned to MBM
- *			events of monitor groups created via mkdir.
+ * @num_rmid:			Number of RMIDs available.
+ * @mbm_cfg_mask:		Memory transactions that can be tracked when
+ *				bandwidth monitoring events can be configured.
+ * @num_mbm_cntrs:		Number of assignable counters.
+ * @mbm_cntr_assignable:	Is system capable of supporting counter assignment?
+ * @mbm_assign_on_mkdir:	True if counters should automatically be assigned to MBM
+ *				events of monitor groups created via mkdir.
+ * @mbm_cntr_configurable:	True if assignable counters are configurable.
  */
 struct resctrl_mon {
 	u32			num_rmid;
@@ -300,6 +301,7 @@ struct resctrl_mon {
 	int			num_mbm_cntrs;
 	bool			mbm_cntr_assignable;
 	bool			mbm_assign_on_mkdir;
+	bool			mbm_cntr_configurable;
 };
 
 /**
Signature · 1 line
2.43.0
maintainer Reviewed-by on v5 2/7
#4 lore raw

Re: [PATCH v5 2/7] x86,fs/resctrl: Create 'event_filter' files read only if they're not configurable

Hi Ben,

Quoted 8 lines · Ben Horgan

When the counter assignment mode is mbm_event resctrl assumes the MBM events are configurable and exposes the 'event_filter' files. These files live at info/L3_MON/event_configs/<event>/event_filter and are used to display and set the event configuration.

The MPAM architecture has support for configuring the memory bandwidth utilization (MBWU) counters to only count reads or only count writes. However, In MPAM, this event filtering support is optional in the

nit: In -> in

Quoted 8 lines

hardware (and not yet implemented in the MPAM driver) but MBM counter assignment is always possible for MPAM MBWU counters.

In order to support mbm_event mode with MPAM, create the 'event_filter' files read only if the event configuration can't be changed. A user can still chmod the file and so also return early with an error from event_filter_write().

Quoted 6 lines

Introduce a new monitor property, mbm_cntr_configurable, to indicate whether or not assignable MBM counters are configurable. On x86, set this to true whenever mbm_cntr_assignable is true to keep existing behaviour.

---

Reinette

author
#5 lore raw

PATCH v5 3/7 fs/resctrl: Disallow the software controller when MBM counters are assignable

In reply to Ben Horgan

The software controller requires that there is one MBM counter per monitor group that is assigned to the event backing the software controller, as per mba_MBps_event. When mbm_event mode is in use, it is not guaranteed that any particular event will have an assigned counter.

Currently, only AMD systems support counter assignment, but the MBA delay is non-linear and so the software controller is never supported anyway. On MPAM systems, the MBA delay is linear and so the software controller could be supported. The MPAM driver, unless a need arises, will not support the 'default' mbm_assign_mode and will always use the 'mbm_event' mode for memory bandwidth monitoring.

Rather than develop a way to guarantee the counter assignment requirements needed by the software controller, take the pragmatic approach. Don't allow the software controller to be used at the same time as 'mbm_event' mode. As MPAM is the only relevant architecture and it will use 'mbm_event' mode whenever there are assignable MBM counters, for simplicity's sake, don't allow the software controller when the MBM counters are assignable.

Implement this by failing the mount if the user requests the software controller, the mba_MBps option, and the MBM counters are assignable.

---
Changes since v4:
Remove "for each MBA control" from commit message
Update last_cmd_status message

---
 fs/resctrl/rdtgroup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/resctrl/rdtgroup.c +3 -2
index b382a348dd79..be84bb210e3a 100644
@@ -2530,7 +2530,8 @@ static bool supports_mba_mbps(void)
 
 	return (resctrl_is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
-		r->ctrl_scope == rmbm->mon_scope);
+		r->ctrl_scope == rmbm->mon_scope &&
+		!rmbm->mon.mbm_cntr_assignable);
 }
 
 /*
@@ -2945,7 +2946,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM (mbm_event mode not supported) and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;
Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [PATCH v5 3/7] fs/resctrl: Disallow the software controller when MBM counters are assignable

Hi Ben,

fs/resctrl/rdtgroup.c static bool supports_mba_mbps(void) · line 2535

Quoted 12 lines · Ben Horgan
fs/resctrl/rdtgroup.c +2 -1
index b382a348dd79..be84bb210e3a 100644
@@ -2530,7 +2530,8 @@ static bool supports_mba_mbps(void)
 
 	return (resctrl_is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
-		r->ctrl_scope == rmbm->mon_scope);
+		r->ctrl_scope == rmbm->mon_scope &&
+		!rmbm->mon.mbm_cntr_assignable);
 }

For better or worse supports_mba_mbps() has a function description that documents the above tests. Updating the tests but not the accompanying description creates an inconsistency. How about something like below?

fs/resctrl/rdtgroup.c +6 -4
index 36d21652616e..b456a67b2c24 100644
@@ -2536,10 +2536,12 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
 }
 
 /*
- * MBA software controller is supported only if
- * MBM is supported and MBA is in linear scale,
- * and the MBM monitor scope is the same as MBA
- * control scope.
+ * MBA software controller is supported only if MBM is supported and MBA is in
+ * linear scale, and the MBM monitor scope is the same as MBA control scope.
+ *
+ * Software controller cannot be supported when the MBM counters are assignable.
+ * There is no guarantee that MBM counters are assigned to the event backing
+ * the software controller in all monitoring domains of all monitoring groups.
  */
 static bool supports_mba_mbps(void)
 {

fs/resctrl/rdtgroup.c static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 2952

Quoted 11 lines
fs/resctrl/rdtgroup.c +1 -1
 /*
@@ -2945,7 +2946,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM (mbm_event mode not supported) and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;

Reinette

author
#7 lore raw

Re: [PATCH v5 3/7] fs/resctrl: Disallow the software controller when MBM counters are assignable

Hi Reinette,

Quoted 29 lines · Reinette Chatre

Hi Ben,

fs/resctrl/rdtgroup.c static bool supports_mba_mbps(void) · line 2535

Quoted 12 lines · Ben Horgan
fs/resctrl/rdtgroup.c +2 -1
index b382a348dd79..be84bb210e3a 100644
@@ -2530,7 +2530,8 @@ static bool supports_mba_mbps(void)
 
 	return (resctrl_is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
-		r->ctrl_scope == rmbm->mon_scope);
+		r->ctrl_scope == rmbm->mon_scope &&
+		!rmbm->mon.mbm_cntr_assignable);
 }

For better or worse supports_mba_mbps() has a function description that documents the above tests. Updating the tests but not the accompanying description creates an inconsistency. How about something like below?

fs/resctrl/rdtgroup.c +0 -0
index 36d21652616e..b456a67b2c24 100644
@@ -2536,10 +2536,12 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
 }
 
 /*

fs/resctrl/rdtgroup.c static void mba_sc_domain_destroy(struct rdt_resource *r, · line 2544

Quoted 10 lines
fs/resctrl/rdtgroup.c +6 -4
- * MBA software controller is supported only if
- * MBM is supported and MBA is in linear scale,
- * and the MBM monitor scope is the same as MBA
- * control scope.
+ * MBA software controller is supported only if MBM is supported and MBA is in
+ * linear scale, and the MBM monitor scope is the same as MBA control scope.
+ *
+ * Software controller cannot be supported when the MBM counters are assignable.
+ * There is no guarantee that MBM counters are assigned to the event backing
+ * the software controller in all monitoring domains of all monitoring groups.

Yes, that makes sense to me. I'll use that.

Thanks,

Ben

Quoted 17 lines
fs/resctrl/rdtgroup.c +0 -0
  */
 static bool supports_mba_mbps(void)
 {

fs/resctrl/rdtgroup.c static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 2952

Quoted 12 lines
fs/resctrl/rdtgroup.c +1 -1
 /*
@@ -2945,7 +2946,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM (mbm_event mode not supported) and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;

Reinette

author
#8 lore raw

Re: [PATCH v5 3/7] fs/resctrl: Disallow the software controller when MBM counters are assignable

Quoted 31 lines · Ben Horgan

Hi Reinette,

Quoted 28 lines · Reinette Chatre

Hi Ben,

fs/resctrl/rdtgroup.c static bool supports_mba_mbps(void) · line 2535

Quoted 12 lines · Ben Horgan
fs/resctrl/rdtgroup.c +2 -1
index b382a348dd79..be84bb210e3a 100644
@@ -2530,7 +2530,8 @@ static bool supports_mba_mbps(void)
 
 	return (resctrl_is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
-		r->ctrl_scope == rmbm->mon_scope);
+		r->ctrl_scope == rmbm->mon_scope &&
+		!rmbm->mon.mbm_cntr_assignable);
 }

For better or worse supports_mba_mbps() has a function description that documents the above tests. Updating the tests but not the accompanying description creates an inconsistency. How about something like below?

fs/resctrl/rdtgroup.c +0 -0
index 36d21652616e..b456a67b2c24 100644
@@ -2536,10 +2536,12 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
 }
 
Quoted 13 lines

fs/resctrl/rdtgroup.c static void mba_sc_domain_destroy(struct rdt_resource *r, · line 2544

Quoted 11 lines
fs/resctrl/rdtgroup.c +6 -4
 /*
- * MBA software controller is supported only if
- * MBM is supported and MBA is in linear scale,
- * and the MBM monitor scope is the same as MBA
- * control scope.
+ * MBA software controller is supported only if MBM is supported and MBA is in
+ * linear scale, and the MBM monitor scope is the same as MBA control scope.
+ *
+ * Software controller cannot be supported when the MBM counters are assignable.
+ * There is no guarantee that MBM counters are assigned to the event backing
+ * the software controller in all monitoring domains of all monitoring groups.

Yes, that makes sense to me. I'll use that.

I've add 'The' to the start of the first two sentences as that makes it read a bit better to me.

That ends up as:

/*
* The MBA software controller is supported only if MBM is supported and MBA is
* in linear scale, and the MBM monitor scope is the same as MBA control scope. *
* The software controller cannot be supported when the MBM counters are
* assignable. There is no guarantee that MBM counters are assigned to the
* event backing the software controller in all monitoring domains of all
* monitoring groups.
*/

Thanks,

Ben

Quoted 23 lines

Thanks,

Ben

Quoted 17 lines
fs/resctrl/rdtgroup.c +0 -0
  */
 static bool supports_mba_mbps(void)
 {

fs/resctrl/rdtgroup.c static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 2952

Quoted 12 lines
fs/resctrl/rdtgroup.c +1 -1
 /*
@@ -2945,7 +2946,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM (mbm_event mode not supported) and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;

Reinette

maintainer
#9 lore raw

Re: [PATCH v5 3/7] fs/resctrl: Disallow the software controller when MBM counters are assignable

Hi Ben,

Quoted 11 lines · Ben Horgan

/*
* The MBA software controller is supported only if MBM is supported and MBA is
* in linear scale, and the MBM monitor scope is the same as MBA control scope. *
* The software controller cannot be supported when the MBM counters are
* assignable. There is no guarantee that MBM counters are assigned to the
* event backing the software controller in all monitoring domains of all
* monitoring groups.
*/

Thank you very much. For this patch with above added:

| Reviewed-by: Reinette Chatre <[email protected]>

Reinette

author
#10 lore raw

Re: [PATCH v5 3/7] fs/resctrl: Disallow the software controller when MBM counters are assignable

Hi Reinette,

Quoted 15 lines · Reinette Chatre

Hi Ben,

Quoted 11 lines · Ben Horgan

/*
* The MBA software controller is supported only if MBM is supported and MBA is
* in linear scale, and the MBM monitor scope is the same as MBA control scope. *
* The software controller cannot be supported when the MBM counters are
* assignable. There is no guarantee that MBM counters are assigned to the
* event backing the software controller in all monitoring domains of all
* monitoring groups.
*/

Quoted 3 lines

Thank you very much. For this patch with above added:

| Reviewed-by: Reinette Chatre <[email protected]>

Thanks for all the reviews. I'll send out a v6 today.

Ben

Quoted 2 lines

Reinette

author
#11 lore raw

PATCH v5 4/7 fs/resctrl: Add monitor property 'mbm_cntr_assign_fixed'

In reply to Ben Horgan

Commit

3b497c3f4f04 ("fs/resctrl: Introduce the interface to display monitoring modes")

introduced CONFIG_RESCTRL_ASSIGN_FIXED but left adding the Kconfig entry until it was necessary. The counter assignment mode is fixed in MPAM, even when there are assignable counters, and so addressing this is needed to support MPAM.

To avoid the burden of another Kconfig entry, replace CONFIG_RESCTRL_ASSIGN_FIXED with a new property in 'struct resctrl_mon', 'mbm_cntr_assign_fixed' to be set by the architecture.

Do not request the architecture to change the counter assignment mode if it does not support doing so. Provide insight to user space about why such a request fails.

---
Changes since v2:
Change to a resctrl_mon property rather than a arch hook Update the commit message to mention the property

Changes since v4:
fix -> fixed in comment
commit message drop x86
In commit message add "to be set by the architecture" and update last paragraph.

---
 fs/resctrl/monitor.c    | 8 +++++++-
 include/linux/resctrl.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)
fs/resctrl/monitor.c +7 -1
index 916f7a9d5658..5fbcc64e50ce 100644
@@ -1456,7 +1456,7 @@ int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 		else
 			seq_puts(s, "[default]\n");
 
-		if (!IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED)) {
+		if (!r->mon.mbm_cntr_assign_fixed) {
 			if (enabled)
 				seq_puts(s, "default\n");
 			else
@@ -1507,6 +1507,12 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,
 	}
 
 	if (enable != resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		if (r->mon.mbm_cntr_assign_fixed) {
+			ret = -EINVAL;
+			rdt_last_cmd_puts("Counter assignment mode is not configurable\n");
+			goto out_unlock;
+		}
+
 		ret = resctrl_arch_mbm_cntr_assign_set(r, enable);
 		if (ret)
 			goto out_unlock;
include/linux/resctrl.h +2 -0
index 06e8c72e8660..73ff522448a0 100644
@@ -294,6 +294,7 @@ enum resctrl_schema_fmt {
  * @mbm_assign_on_mkdir:	True if counters should automatically be assigned to MBM
  *				events of monitor groups created via mkdir.
  * @mbm_cntr_configurable:	True if assignable counters are configurable.
+ * @mbm_cntr_assign_fixed:	True if the counter assignment mode is fixed.
  */
 struct resctrl_mon {
 	u32			num_rmid;
@@ -302,6 +303,7 @@ struct resctrl_mon {
 	bool			mbm_cntr_assignable;
 	bool			mbm_assign_on_mkdir;
 	bool			mbm_cntr_configurable;
+	bool			mbm_cntr_assign_fixed;
 };
 
 /**
Signature · 1 line
2.43.0
maintainer Reviewed-by on v5 4/7
#12 lore raw

Re: [PATCH v5 4/7] fs/resctrl: Add monitor property 'mbm_cntr_assign_fixed'

Hi Ben,

Quoted 13 lines · Ben Horgan

Commit

3b497c3f4f04 ("fs/resctrl: Introduce the interface to display monitoring modes")

introduced CONFIG_RESCTRL_ASSIGN_FIXED but left adding the Kconfig entry until it was necessary. The counter assignment mode is fixed in MPAM, even when there are assignable counters, and so addressing this is needed to support MPAM.

To avoid the burden of another Kconfig entry, replace CONFIG_RESCTRL_ASSIGN_FIXED with a new property in 'struct resctrl_mon', 'mbm_cntr_assign_fixed' to be set by the architecture.

Quoted 6 lines

Do not request the architecture to change the counter assignment mode if it does not support doing so. Provide insight to user space about why such a request fails.

---

Reinette

author
#13 lore raw

PATCH v5 5/7 fs/resctrl: Continue counter allocation after failure

In reply to Ben Horgan

In mbm_event mode, with mbm_assign_on_mkdir set to 1, when a user creates a new CTRL_MON or MON group resctrl attempts to allocate counters for each of the supported MBM events on each resctrl domain. As counters are limited, such allocation may fail and when it does counter allocations for the remaining domains are skipped even if the domains have available counters.

Since a counter allocation failure may result in counter allocation being skipped on other domains the user needs to view the resource group's mbm_L3_assignments files to get an accurate view of counter assignment in a new resource group and then manually create counters in the skipped domains with available counters.

Writes to mbm_L3_assignments using the wildcard format, <event>:*=e, also skip counter allocation in other domains after a counter allocation failure.

When handling a request to create counters in all domains it is unnecessary for a counter allocation in one domain to prevent counter allocation in other domains. Always attempt to allocate all the counters requested.

---
Changes since v4:
Update commit message (Reinette)

---
 fs/resctrl/monitor.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
fs/resctrl/monitor.c +9 -6
index 5fbcc64e50ce..0e6a389a16bf 100644
@@ -1211,9 +1211,10 @@ static int rdtgroup_alloc_assign_cntr(struct rdt_resource *r, struct rdt_l3_mon_
  * NULL; otherwise, assign the counter to the specified domain @d.
  *
  * If all counters in a domain are already in use, rdtgroup_alloc_assign_cntr()
- * will fail. The assignment process will abort at the first failure encountered
- * during domain traversal, which may result in the event being only partially
- * assigned.
+ * will fail. When attempting to assign counters to all domains, carry on trying
+ * to assign counters after a failure since only some domains may have counters
+ * and the goal is to assign counters where possible. If any counter assignment
+ * fails, return the error from the last failing assignment.
  *
  * Return:
  * 0 on success, < 0 on failure.
@@ -1226,9 +1227,11 @@ static int rdtgroup_assign_cntr_event(struct rdt_l3_mon_domain *d, struct rdtgro
 
 	if (!d) {
 		list_for_each_entry(d, &r->mon_domains, hdr.list) {
-			ret = rdtgroup_alloc_assign_cntr(r, d, rdtgrp, mevt);
-			if (ret)
-				return ret;
+			int err;
+
+			err = rdtgroup_alloc_assign_cntr(r, d, rdtgrp, mevt);
+			if (err)
+				ret = err;
 		}
 	} else {
 		ret = rdtgroup_alloc_assign_cntr(r, d, rdtgrp, mevt);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v5 5/7
#14 lore raw

Re: [PATCH v5 5/7] fs/resctrl: Continue counter allocation after failure

Hi Ben,

Quoted 9 lines · Ben Horgan

In mbm_event mode, with mbm_assign_on_mkdir set to 1, when a user creates a new CTRL_MON or MON group resctrl attempts to allocate counters for each of the supported MBM events on each resctrl domain. As counters are limited, such allocation may fail and when it does counter allocations for the remaining domains are skipped even if the domains have available counters.

Since a counter allocation failure may result in counter allocation being skipped on other domains the user needs to view the resource group's mbm_L3_assignments files to get an accurate view of counter assignment in a

nit: files -> file

Quoted 7 lines

new resource group and then manually create counters in the skipped domains with available counters.

Writes to mbm_L3_assignments using the wildcard format, <event>:*=e, also skip counter allocation in other domains after a counter allocation failure.

Quoted 6 lines

When handling a request to create counters in all domains it is unnecessary for a counter allocation in one domain to prevent counter allocation in other domains. Always attempt to allocate all the counters requested.

---

Reinette

author
#15 lore raw

PATCH v5 6/7 fs/resctrl: Document that automatic counter assignment is best effort

In reply to Ben Horgan

When using automatic counter assignment it's useful for a user to know which counters they can expect to be assigned on group creation.

Document that automatic counter assignment is best effort and how to discover any assignment failures.

---
Changes since v4:
Point user to mbm_L3_assignments rather than last_cmd_status (Reinette) Add "in all domains" (Reinette)

---
 Documentation/filesystems/resctrl.rst | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/filesystems/resctrl.rst +6 -0
index 2898a51e6f4b..b388e9193896 100644
@@ -479,6 +479,12 @@ with the following files:
 	"1":
 		Auto assignment is enabled.
 
+	Automatic counter assignment is done with best effort. If auto
+	assignment is enabled but there are not enough available counters then
+	monitor group creation could succeed while one or more events belonging
+	to the group may not have a counter assigned in all domains. Consult
+	mbm_L3_assignments for counter assignment states of the new groups.
+
 	Example::
 
 	  # echo 0 > /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
Signature · 1 line
2.43.0
maintainer Reviewed-by on v5 6/7
#16 lore raw

Re: [PATCH v5 6/7] fs/resctrl: Document that automatic counter assignment is best effort

Hi Ben,

Quoted 9 lines · Ben Horgan

When using automatic counter assignment it's useful for a user to know which counters they can expect to be assigned on group creation.

Document that automatic counter assignment is best effort and how to discover any assignment failures.

---

Reinette

author
#17 lore raw

PATCH v5 7/7 fs/resctrl: Document tasks file behaviour for task id 0 and idle tasks

In reply to Ben Horgan

When 0 is written to the tasks file it is interpreted as the current task in rdtgroup_move_task(). Each CPU's idle task has task_struct::pid set to 0 and, on x86, task_struct::closid to RESCTRL_RESERVED_CLOSID and task_struct::rmid to RESCTRL_RESERVED_RMID. Equivalently, on MPAM platforms, thread_info::mpam_partid_pmg is encoded with PARTID and PMG set to RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID, respectively. As there is no interface to change these from the default, the resctrl configuration for the idle tasks is fixed and they always behave equivalently to a task in the default tasks file and so take their configuration from the cpus/cpus_list files.

On read of the tasks file, show_rdt_tasks() filters out any 0 PID. Hence, a task id of 0 is never shown in the tasks file and the idle tasks are not represented either.

Document the user visible behaviour.

---
I have confirmed this experimentally on an MPAM platform.

Changes since v4:
Clean up the commit message (Reinette)

---
 Documentation/filesystems/resctrl.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/filesystems/resctrl.rst +5 -0
index b388e9193896..e4b66af55ffb 100644
@@ -575,6 +575,11 @@ All groups contain the following files:
 	then the task must already belong to the CTRL_MON parent of this
 	group. The task is removed from any previous MON group.
 
+	When writing to this file, a task id of 0 is interpreted as the
+	task id of the currently running task. On reading the file, a task
+	id of 0 will never be shown and there is no representation of the
+	idle tasks. Instead, a CPU's idle task is always considered as a
+	member of the group owning the CPU.
 
 "cpus":
 	Reading this file shows a bitmask of the logical CPUs owned by
Signature · 1 line
2.43.0
maintainer Reviewed-by on v5 7/7
#18 lore raw

Re: [PATCH v5 7/7] fs/resctrl: Document tasks file behaviour for task id 0 and idle tasks

Hi Ben,

Quoted 11 lines · Ben Horgan

When 0 is written to the tasks file it is interpreted as the current task in rdtgroup_move_task(). Each CPU's idle task has task_struct::pid set to 0 and, on x86, task_struct::closid to RESCTRL_RESERVED_CLOSID and task_struct::rmid to RESCTRL_RESERVED_RMID. Equivalently, on MPAM platforms, thread_info::mpam_partid_pmg is encoded with PARTID and PMG set to RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID, respectively. As there is no interface to change these from the default, the resctrl configuration for the idle tasks is fixed and they always behave equivalently to a task in the default tasks file and so take their configuration from the cpus/cpus_list files.

Quoted 8 lines

On read of the tasks file, show_rdt_tasks() filters out any 0 PID. Hence, a task id of 0 is never shown in the tasks file and the idle tasks are not represented either.

Document the user visible behaviour.

---

Thank you very much for adding this.

Reinette