Skip to contentSkip to conversation

fs,x86/resctrl: Support AMD Assignable Bandwidth Monitoring Counters (ABMC)

PATCH Applied Babu Moger 5 participants 118 messages Jun 13, 2025 – Jul 8, 2025 Page 2 of 2

Subsystems (3)

v14 of 18 Applied Latest is v18 →

lore
Share & tools
lore
author reviewer
#111 lore raw

Re: [PATCH v14 31/32] fs/resctrl: Introduce the interface to switch between monitor modes

In reply to Reinette Chatre

Hi Reinette,

Quoted 9 lines · Reinette Chatre

Hi Babu,

Quoted 6 lines · Babu Moger

Resctrl subsystem can support two monitoring modes, "mbm_event" or "default". In mbm_event mode, monitoring event can only accumulate data while it is backed by a hardware counter. In "default" mode, resctrl assumes there is a hardware counter for each event within every CTRL_MON and MON group.

Quoted 4 lines
Quoted 1 line

Introduce interface to switch between mbm_event and default modes.

"Introduce interface" -> "Introduce mbm_assign_mode resctrl file"

Sure.

Quoted 36 lines
Quoted 20 lines

Example:
To list the MBM monitor modes supported:

$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
[mbm_event]
default

To enable the "mbm_event" monitoring mode:

$ echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode

To enable the "default" monitoring mode:

$ echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode

MBM event counters are automatically reset as part of changing the mode. Clear both architectural and non-architectural event states to prevent overflow conditions during the next event read. Also clear assignable counter configuration on all the domains.

---

...

Quoted 13 lines
---
 Documentation/filesystems/resctrl.rst | 23 +++++++-
 fs/resctrl/internal.h                 |  2 +
 fs/resctrl/monitor.c                  | 27 ++++++++++
 fs/resctrl/rdtgroup.c                 | 78 +++++++++++++++++++++++++--
 4 files changed, 126 insertions(+), 4 deletions(-)
Documentation/filesystems/resctrl.rst +0 -0
index cd82c2966ed7..7e62c7fdcefa 100644
@@ -259,7 +259,9 @@ with the following files:
 
Quoted 7 lines

Documentation/filesystems/resctrl.rst with the following files: · line 262

Quoted 4 lines
Documentation/filesystems/resctrl.rst +1 -1
 "mbm_assign_mode":
 	The supported monitoring modes. The enclosed brackets indicate which mode
-	is enabled.
+	is enabled. The MBM events (mbm_total_bytes and/or mbm_local_bytes) associated

Since there may be more events in future I think the "(mbm_total_bytes and/or mbm_local_bytes)" can be dropped.

Sure.

Quoted 5 lines
Quoted 5 lines
Documentation/filesystems/resctrl.rst +2 -0
+	with counters may reset when "mbm_assign_mode" is changed.
+
 	::
 
Quoted 8 lines

Documentation/filesystems/resctrl.rst with the following files: · line 284

Quoted 6 lines
Documentation/filesystems/resctrl.rst +1 -0
 	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
@@ -279,6 +281,15 @@ with the following files:
 	of counters available is described in the "num_mbm_cntrs" file. Changing the
 	mode may cause all counters on the resource to reset.
 
+	Moving to mbm_event mode require users to assign the counters to the events.

"Moving to mbm_event mode require" -> "mbm_event counter assignment mode requires"

Sure.

Quoted 62 lines
Quoted 62 lines
Documentation/filesystems/resctrl.rst +18 -0
+	Otherwise, the MBM event counters will return 'Unassigned' when read.
+
+	The mode is beneficial for AMD platforms that support more CTRL_MON
+	and MON groups than available hardware counters. By default, this
+	feature is enabled on AMD platforms with the ABMC (Assignable Bandwidth
+	Monitoring Counters) capability, ensuring counters remain assigned even
+	when the corresponding RMID is not actively used by any processor.
+
 	"default":
 
 	In default mode, resctrl assumes there is a hardware counter for each
@@ -288,6 +299,16 @@ with the following files:
 	result in misleading values or display "Unavailable" if no counter is assigned
 	to the event.
 
+	* To enable "mbm_event" monitoring mode:
+	  ::
+
+	    # echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+
+	* To enable "default" monitoring mode:
+	  ::
+
+	    # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+
 "num_mbm_cntrs":
 	The maximum number of counter IDs (total of available and assigned counters)
 	in each domain when the system supports mbm_event mode.
fs/resctrl/internal.h +2 -0
index 14d99c723ea5..adc9ff3efdfd 100644
@@ -414,6 +414,8 @@ void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *
 				 struct rdtgroup *rdtgrp, struct mon_evt *mevt);
 int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
 		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
+void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *d);
+void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d);
 
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
fs/resctrl/monitor.c +12 -0
index 618c94cd1ad8..504b869570e6 100644
@@ -1045,6 +1045,33 @@ static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id)
 	memset(&d->cntr_cfg[cntr_id], 0, sizeof(struct mbm_cntr_cfg));
 }
 
+/**
+ * mbm_cntr_free_all() - Clear all the counter ID configuration details in the
+ *			 domain @d. Called when mbm_assign_mode is changed.
+ */
+void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d)
+{
+	memset(d->cntr_cfg, 0, sizeof(*d->cntr_cfg) * r->mon.num_mbm_cntrs);
+}
+
+/**
+ * resctrl_reset_rmid_all() - Reset all non-architecture states for all the
+ *			      supported RMIDs.
Quoted 8 lines

fs/resctrl/monitor.c static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id) · line 1061

Quoted 2 lines
fs/resctrl/monitor.c +2 -0
+ */
+void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *d)

struct rdt_resource *r is unused? At this time it seems unnecessary to check if an MBM event belongs to particular resource since at this point I expect only L3 is possible. Even so, to be consistent and robust I think it would make flows easier to understand by always ensureing that mon_evt::rid matches expected resource.

Agree. But in this we dont access mon_evt structure here.

Quoted 14 lines

fs/resctrl/monitor.c static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id) · line 1071

Quoted 11 lines
fs/resctrl/monitor.c +10 -0
+{
+	u32 idx_limit = resctrl_arch_system_num_rmid_idx();
+	enum resctrl_event_id evt;
+	int idx;
+
+	for_each_mbm_event_id(evt) {
+		if (!resctrl_is_mon_event_enabled(evt))
+			continue;
+		idx = MBM_STATE_IDX(evt);
+		memset(d->mbm_states[idx], 0, sizeof(struct mbm_state) * idx_limit);

sizeof(*d->mbm_states[0])?

Sure.

Quoted 36 lines
Quoted 36 lines
fs/resctrl/monitor.c +3 -0
+	}
+}
+
 /**
  * resctrl_alloc_config_cntr() - Allocate a counter ID and configure it for the
  * event pointed to by @mevt and the resctrl group @rdtgrp within the domain @d.
fs/resctrl/rdtgroup.c +22 -0
index 8c67e0897f25..6bb61fcf8673 100644
@@ -1876,6 +1876,77 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of,
+					     char *buf, size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *d;
+	int ret = 0;
+	bool enable;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+
+	buf[nbytes - 1] = '\0';
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "default")) {
+		enable = 0;
+	} else if (!strcmp(buf, "mbm_event")) {
Quoted 9 lines

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1906

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+		if (r->mon.mbm_cntr_assignable) {
+			enable = 1;
+		} else {
+			ret = -EINVAL;
+			rdt_last_cmd_puts("mbm_event mode is not supported\n");
+			goto write_exit;

write_exit -> out_unlock

Sure.

Quoted 61 lines
Quoted 17 lines
fs/resctrl/rdtgroup.c +17 -0
+		}
+	} else {
+		ret = -EINVAL;
+		rdt_last_cmd_puts("Unsupported assign mode\n");
+		goto write_exit;
+	}
+
+	if (enable != resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		ret = resctrl_arch_mbm_cntr_assign_set(r, enable);
+		if (ret)
+			goto write_exit;
+
+		/* Update the visibility of BMEC related files */
+		resctrl_bmec_files_show(r, !enable);
+
+		/*
+		 * Initialize the default memory transaction values for

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1933

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+		 * total and local events.
+		 */
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+			resctrl_set_mon_evt_cfg(QOS_L3_MBM_TOTAL_EVENT_ID,
+						MAX_EVT_CONFIG_BITS);
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+			resctrl_set_mon_evt_cfg(QOS_L3_MBM_LOCAL_EVENT_ID,
+						READS_TO_LOCAL_MEM |
+						READS_TO_LOCAL_S_MEM |
+						NON_TEMP_WRITE_TO_LOCAL_MEM);

Nice, yes, this belongs in resctrl fs.

Quoted 31 lines
fs/resctrl/rdtgroup.c +17 -1
+		/*
+		 * Reset all the non-achitectural RMID state and assignable counters.
+		 */
+		list_for_each_entry(d, &r->mon_domains, hdr.list) {
+			mbm_cntr_free_all(r, d);
+			resctrl_reset_rmid_all(r, d);
+		}
+	}
+
+write_exit:
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret ?: nbytes;
+}
+
 static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
 				      struct seq_file *s, void *v)
 {
@@ -2203,8 +2274,8 @@ static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup *rdtgr
 	struct mon_evt *mevt;
 	int assign_state;
 	char domain[10];
+	int ret = 0;
 	bool found;
-	int ret;
 
 	mevt = mbm_get_mon_event_by_name(r, event);
 	if (!mevt) {
@@ -2249,7 +2320,7 @@ static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup *rdtgr
 
Quoted 10 lines

fs/resctrl/rdtgroup.c static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup *rdtgr · line 2326

Quoted 7 lines
fs/resctrl/rdtgroup.c +1 -1
 	switch (assign_state) {
 	case ASSIGN_NONE:
-		ret = resctrl_unassign_cntr_event(r, d, rdtgrp, mevt);
+		resctrl_unassign_cntr_event(r, d, rdtgrp, mevt);
 		break;
 	case ASSIGN_EXCLUSIVE:
 		ret = resctrl_assign_cntr_event(r, d, rdtgrp, mevt);

Two stray hunks?

Yes. Fixed it.

Quoted 15 lines

fs/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2543

Quoted 12 lines
fs/resctrl/rdtgroup.c +2 -1
@@ -2463,9 +2534,10 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "mbm_assign_mode",
-		.mode		= 0444,
+		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
 		.seq_show	= resctrl_mbm_assign_mode_show,
+		.write		= resctrl_mbm_assign_mode_write,
 		.fflags		= RFTYPE_MON_INFO | RFTYPE_RES_CACHE,
 	},
 	{

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#112 lore raw

PATCH v14 32/32 x86/resctrl: Configure mbm_event mode if supported

In reply to Babu Moger

Configure mbm_event mode on AMD platforms. On AMD platforms, it is recommended to use the mbm_event mode, if supported, to prevent the hardware from resetting counters between reads. This can result in misleading values or display "Unavailable" if no counter is assigned to the event.

The mbm_event mode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system.

Update ABMC across all logical processors within the resctrl domain to ensure proper functionality.

---
v14: Updated the changelog to reflect the change in name of the monitor mode
to mbm_event.

v13 : Added the call resctrl_init_evt_configuration() to setup the event
configuration during init.
Resolved conflicts caused by the recent FS/ARCH code restructure.

v12: Moved the resctrl_arch_mbm_cntr_assign_set_one to domain_add_cpu_mon().
Updated the commit log.

v11: Commit text in imperative tone. Added few more details.
Moved resctrl_arch_mbm_cntr_assign_set_one() to monitor.c.

v10: Commit text in imperative tone.

v9: Minor code change due to merge. Actual code did not change.

v8: Renamed resctrl_arch_mbm_cntr_assign_configure to
resctrl_arch_mbm_cntr_assign_set_one.
Adde r->mon_capable check.
Commit message update.

v7: Introduced resctrl_arch_mbm_cntr_assign_configure() to configure.
Moved the default settings to rdt_get_mon_l3_config(). It should be done before the hotplug handler is called. It cannot be done at rdtgroup_init().

v6: Keeping the default enablement in arch init code for now.
This may need some discussion.
Renamed resctrl_arch_configure_abmc to resctrl_arch_mbm_cntr_assign_configure.

v5: New patch to enable ABMC by default.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 7 +++++++
 arch/x86/kernel/cpu/resctrl/internal.h | 1 +
 arch/x86/kernel/cpu/resctrl/monitor.c  | 8 ++++++++
 3 files changed, 16 insertions(+)
arch/x86/kernel/cpu/resctrl/core.c +7 -0
index 1df171d04bea..a8fda1b408c7 100644
@@ -518,6 +518,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 		d = container_of(hdr, struct rdt_mon_domain, hdr);
 
 		cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
+		/* Update the mbm_assign_mode state for the CPU if supported */
+		if (r->mon.mbm_cntr_assignable)
+			resctrl_arch_mbm_cntr_assign_set_one(r);
 		return;
 	}
 
@@ -537,6 +540,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 	d->ci_id = ci->id;
 	cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
 
+	/* Update the mbm_mbm_assign state for the CPU if supported */
+	if (r->mon.mbm_cntr_assignable)
+		resctrl_arch_mbm_cntr_assign_set_one(r);
+
 	arch_mon_domain_online(r, d);
 
 	if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) {
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index 77a9ce4a8403..f03abae3a2c4 100644
@@ -216,5 +216,6 @@ bool rdt_cpu_has(int flag);
 void __init intel_rdt_mbm_apply_quirk(void);
 
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);
 
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +8 -0
index 053f516a8e67..74282dab7c2b 100644
@@ -430,6 +430,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
 		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
 		r->mon.mbm_assign_on_mkdir = true;
+		hw_res->mbm_cntr_assign_enabled = true;
 	}
 
 	r->mon_capable = true;
@@ -533,3 +534,10 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
 			memset(am, 0, sizeof(*am));
 	}
 }
+
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r)
+{
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+
+	resctrl_abmc_set_one_amd(&hw_res->mbm_cntr_assign_enabled);
+}
Signature · 1 line
2.34.1
maintainer
#113 lore raw

Re: [PATCH v14 32/32] x86/resctrl: Configure mbm_event mode if supported

Hi Babu,

arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 543

Quoted 5 lines · Babu Moger
arch/x86/kernel/cpu/resctrl/core.c +1 -0
@@ -537,6 +540,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 	d->ci_id = ci->id;
 	cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
 
+	/* Update the mbm_mbm_assign state for the CPU if supported */

"mbm_mbm_assign" -> "mbm_assign_mode"?

arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 549

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +3 -0
+	if (r->mon.mbm_cntr_assignable)
+		resctrl_arch_mbm_cntr_assign_set_one(r);
+
 	arch_mon_domain_online(r, d);
 
 	if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) {

Reinette

author reviewer
#114 lore raw

Re: [PATCH v14 32/32] x86/resctrl: Configure mbm_event mode if supported

Hi Reinette,

Quoted 4 lines · Reinette Chatre

Hi Babu,

On 6/13/25 2:05 PM, Babu Moger wrote:

Quoted 8 lines

arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 543

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +1 -0
@@ -537,6 +540,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 	d->ci_id = ci->id;
 	cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
 
+	/* Update the mbm_mbm_assign state for the CPU if supported */

"mbm_mbm_assign" -> "mbm_assign_mode"?

Sure.

Signature · 2 lines
Thanks
Babu Moger
maintainer
#115 lore raw
In reply to Babu Moger

Babu,

Compiling with "make W=1" you have several kerneldoc comments on new functions that do not describe their parameters.

E.g.

/**
* resctrl_config_cntr() - Configure the counter ID for the event, RMID pair in
* the domain.
*
* Assign the counter if @assign is true else unassign the counter. Reset the
* associated non-architectural state.
*/
static void resctrl_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
enum resctrl_event_id evtid, u32 rmid, u32 closid, u32 cntr_id, bool assign)

Warning: fs/resctrl/monitor.c:984 function parameter 'r' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'd' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'evtid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'rmid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'closid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'cntr_id' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'assign' not described in 'resctrl_config_cntr'

-Tony

author reviewer
#116 lore raw

Hi Tony,

Quoted 19 lines · Tony

Babu,

Compiling with "make W=1" you have several kerneldoc comments on new functions that do not describe their parameters.

E.g.

/**
* resctrl_config_cntr() - Configure the counter ID for the event, RMID pair in
* the domain.
*
* Assign the counter if @assign is true else unassign the counter. Reset the
* associated non-architectural state.
*/
static void resctrl_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
enum resctrl_event_id evtid, u32 rmid, u32 closid, u32 cntr_id, bool assign)

Quoted 8 lines

Warning: fs/resctrl/monitor.c:984 function parameter 'r' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'd' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'evtid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'rmid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'closid' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'cntr_id' not described in 'resctrl_config_cntr'
Warning: fs/resctrl/monitor.c:984 function parameter 'assign' not described in 'resctrl_config_cntr'

Yes. I noticed several of them.
Warning goes away after replacing "/**" with "/*".

Now I am not sure if we fix it with replacing with "/*" or adding definitions for each of these parameters. There will be too many repetitions. All these functions take r, d, eventid, and rmid as parameters. Also these are static functions.

Signature · 2 lines
Thanks
Babu Moger
maintainer
#117 lore raw
In reply to Babu Moger

Hi Babu,

Quoted 18 lines · Babu Moger

This series adds the support for Assignable Bandwidth Monitoring Counters (ABMC). It is also called QoS RMID Pinning feature

Series is written such that it is easier to support other assignable features supported from different vendors.

The feature details are documented in the APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). The documentation is available at

The patches are based on top of commit
b75dc5e1399df (tip/master) Merge branch into tip/master: 'sched/core'

# Introduction

Quoted 11 lines

Users can create as many monitor groups as RMIDs supported by the hardware. However, the bandwidth monitoring feature on AMD systems only guarantees that RMIDs currently assigned to a processor will be tracked by hardware. The counters of any other RMIDs which are no longer being tracked will be reset to zero. The MBM event counters return "Unavailable" for the RMIDs that are not tracked by hardware. So, there can be only limited number of groups that can give guaranteed monitoring numbers. With ever changing configurations there is no way to definitely know which of these groups are being tracked during a particular time. Users do not have the option to monitor a group or set of groups for a certain period of time without worrying about counter being reset in between.

"about counter" -> "about counters" ?

Quoted 51 lines

The ABMC feature allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Additionally, the user can specify the type of memory transactions (e.g., reads, writes) to be tracked by the counter for the assigned RMID.

Without ABMC enabled, monitoring will work in current 'default' mode without assignment option.

# History

Earlier implementation of ABMC had dependancy on BMEC (Bandwidth Monitoring Event Configuration). Peter had concerns with that implementation because it may be not be compatible with ARM's MPAM.

Here are the threads discussing the concerns and new interface to address the concerns.
https://lore.kernel.org/lkml/CALPaoCg97cLVVAcacnarp+880xjsedEWGJPXhYpy4P7=ky4MZw@mail.gmail.com/
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/

Here are the finalized requirements based on the discussion:

* BMEC and ABMC are incompatible with each other. They need to be mutually exclusive.

* Eliminate global assignment listing. The interface
/sys/fs/resctrl/info/L3_MON/mbm_assign_control is no longer required.

* Create the configuration directories at /sys/fs/resctrl/info/L3_MON/counter_configs/.
The configuration file names should be free-form, allowing users to create them as needed.

* Perform assignment listing at the group level by introducing mbm_L3_assignments
in each monitoring group level. The listing should provide the following details:

Event Configuration: Specifies the event configuration applied. This will be crucial when "mkdir" on event configuration is added in the future, leading to the creation of mon_data/mon_l3_*/<event configuration>.

Domains: Identifies the domains where the configuration is applied, supporting multi-domain setups.

Assignment Type: Indicates whether the assignment is Exclusive (e or d), Shared (s), or Unassigned (_).

Exclusive assignment: Assign the counter ID the RMID, event pair exclusively.

Shared assignment: A shared assignment applies to both soft-ABMC and ABMC. A user can designate a
"counter" (could be hardware counter or "active" RMID) as shared and that means the counter within that domain is shared between different monitor groups and actual assignment is scheduled by resctrl.

Unassigned: No longer assigned.

Quoted 7 lines

* Provide option to enable or disable auto assignment when new group is created.

* Keep the flexibilty to support future assign options like Soft-ABMC etc.

    https://lore.kernel.org/lkml/[email protected]/

This series tries to address all the requirements listed above.

Please drop the "tries to". Also please do not say "address all requirements" when this is not the case. This series does not address all the requirements listed (no dynamic event configurations via mkdir and no shared assignment). Please be specific about what this series addresses and what it leaves for "future", but highlight that while this series does not implement all requirements it does create framework to support their future implementation.

Quoted 4 lines

# Implementation details

Create a generic interface aimed to support user space assignment of scarce

drop "aimed"

Quoted 9 lines

counters used for monitoring. First usage of interface is by ABMC with option to expand usage to "soft-ABMC" and MPAM counters in future.

Feature adds following interface files:

/sys/fs/resctrl/info/L3_MON/mbm_assign_mode: Reports the list of assignable monitoring features supported. The enclosed brackets indicate which feature is enabled.

Quoted 6 lines

/sys/fs/resctrl/info/L3_MON/num_mbm_cntrs: The maximum number of monitoring counters (total of available and assigned counters) in each domain when the system supports mbm_assign_mode.

/sys/fs/resctrl/info/L3_MON/available_mbm_cntrs: The number of monitoring counters available for assignment in each domain when mbm_event mode is enabled on the system.

Why is "num_mbm_cntrs" connected to mbm_assign_mode while "available_mbm_cntrs" is connected to mbm_event mode? Perhaps both can be "mbm_event" mode to reduce confusion?

Quoted 43 lines

/sys/fs/resctrl/info/L3_MON/event_configs: Contains sub-directory for each MBM event
that can be assigned to a counter.

/sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter: The type of
memory transactions tracked by the event mbm_total_bytes.

/sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter: The type of
memory transactions tracked by the event mbm_local_bytes.

/sys/fs/resctrl/mbm_L3_assignments: Per monitor group interface to list or modify
counters assigned to the group.

# Examples

a. Check if MBM assign support is available
#mount -t resctrl resctrl /sys/fs/resctrl/

# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event]
default

mbm_event feature is detected and it is enabled.

b. Check how many assignable counters are supported.

	# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 
	0=32;1=32

c. Check how many assignable counters are available for assignment in each domain.

	# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 
	0=30;1=30

d. Check default event configuration.

	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter 
	local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
        local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter 
	local_reads,local_non_temporal_writes,local_reads_slow_memory
Quoted 6 lines

e. Series adds a new interface file "mbm_L3_assignments" in each monitoring group
to list and modify that group's monitoring states.

The list is displayed in the following format:

<Event>:<Domain ID>=<Assignment type>

Suggest adding multiple domains to example. Above creates impression that each domain is listed on its own line (until example below clears that up).

Quoted 53 lines

Event: A valid MBM event listed in the /sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID.

Assignment types:

_ : No counter assigned.

e : Counter assigned exclusively.

To list the default group states:
# cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on domain 0:
# echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=_;1=e
mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on all domains:
# echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
# cat /sys/fs/resctrl/mbm_L3_assignment
mbm_total_bytes:0=_;1=_
mbm_local_bytes:0=e;1=e

To assign a counter associated with the mbm_total_bytes event on all domains in exclusive mode:
# echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
# cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

g. Read the events mbm_total_bytes and mbm_local_bytes of the default group.
There is no change in reading the events with the assignment. If the event is unassigned when reading, then the read will come back as "Unassigned".

	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes
	779247936
	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes 
	765207488

h. Check the default event configurations.

	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
	local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
	local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
	local_reads,local_non_temporal_writes,local_reads_slow_memory
Quoted 7 lines

i. Change the event configuration for mbm_local_bytes.

	# echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
	/sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	# cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads

Note that examples are inconsistent wrt spacing in output of this file. This is expected to match how the implementation in series does the spacing.

Quoted 6 lines

This will update all (across all domains of all monitor groups) counter assignments associated with the mbm_local_bytes event.

j. Now read the local event again. The first read may come back with "Unavailable"
status. The subsequent read of mbm_local_bytes will display only the read events.

Above specifies "will display only the read events" while previous step added "local_non_temporal_writes" to the memory transactions. What is meant with "only the read events"?

Quoted 16 lines
	
	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
	Unavailable
	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
	314101

k. Users have the option to go back to 'default' mbm_assign_mode if required.
This can be done using the following command. Note that switching the mbm_assign_mode will reset all the MBM counters (and thus all MBM events) of all the resctrl groups.

	# echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
	# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
	mbm_event
	[default]
Quoted 4 lines

l. Unmount the resctrl

#umount /sys/fs/resctrl/
---

Reinette