[PATCH v12 23/26] x86/resctrl: Introduce mbm_L3_assignments to list assignments in a group

Babu Moger
2025-04-04T00:22:23Z

The interface displays the assignment states for each group when
mbm_cntr_assign mode is enabled.

The list is displayed in the following format:
<Event configuration>:<Domain id>=<Assignment type>

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

Domain ID: A valid domain ID number.

The assignment type can be one of the following:

_ : No event configuration assigned

e : Event configuration assigned in exclusive mode

Example:
$cd /sys/fs/resctrl
$cat mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v12: New patch:
Assignment interface moved inside the group based the discussion
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/#t
---
Documentation/arch/x86/resctrl.rst | 27 +++++++++++++++
arch/x86/kernel/cpu/resctrl/monitor.c | 1 +
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 48 ++++++++++++++++++++++++++
3 files changed, 76 insertions(+)

diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index a67f09323da0..31085b4e15f6 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -503,6 +503,33 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
/sys/fs/resctrl/info/L3_MON/mon_features changes the input
event.

+"mbm_L3_assignments":
+ The interface displays the assignment states for each group when
+ mbm_cntr_assign mode is enabled.
+
+ The list is displayed in the following format:
+
+ <Event configuration>:<Domain id>=<Assignment type>
+
+ Event configuration: A valid event configuration listed in the
+ /sys/fs/resctrl/info/L3_MON/counter_configs directory.
+
+ Domain ID: A valid domain ID number.
+
+ Assignment types:
+
+ _ : No event configuration assigned
+
+ e : Event configuration assigned in exclusive mode
+
+ Example:
+ ::
+
+ # cd /sys/fs/resctrl
+ # cat mbm_L3_assignments
+ mbm_total_bytes:0=e;1=e
+ mbm_local_bytes:0=e;1=e
+
Resource allocation rules
-------------------------

diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 4e22563dda60..0c6fd5f6ec19 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -1266,6 +1266,7 @@ int __init resctrl_mon_resource_init(void)
resctrl_file_fflags_init("available_mbm_cntrs", RFTYPE_MON_INFO);
resctrl_file_fflags_init("event_filter", RFTYPE_MON_CONFIG);
resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO);
+ resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
}

return 0;
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 3e440ace60e0..ee1c949c2436 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2083,6 +2083,48 @@ static ssize_t event_filter_write(struct kernfs_open_file *of, char *buf,
return ret ?: nbytes;
}

+static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file *s, void *v)
+{
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_mon_domain *d;
+ struct rdtgroup *rdtgrp;
+ int i, ret = 0;
+ bool sep;
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+ if (!rdtgrp)
+ return -ENOENT;
+
+ rdt_last_cmd_clear();
+ if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+ rdt_last_cmd_puts("mbm_cntr_assign mode not enabled\n");
+ ret = -ENOENT;
+ goto assign_out;
+ }
+
+ for (i = 0; i < NUM_MBM_ASSIGN_CONFIGS; i++) {
+ sep = false;
+ seq_printf(s, "%s:", mbm_assign_configs[i].name);
+ list_for_each_entry(d, &r->mon_domains, hdr.list) {
+ if (sep)
+ seq_puts(s, ";");
+
+ if (mbm_cntr_get(r, d, rdtgrp, mbm_assign_configs[i].evtid) >= 0)
+ seq_printf(s, "%d=e", d->hdr.id);
+ else
+ seq_printf(s, "%d=_", d->hdr.id);
+
+ sep = true;
+ }
+ seq_puts(s, "\n");
+ }
+
+assign_out:
+ rdtgroup_kn_unlock(of->kn);
+
+ return ret;
+}
+
/* rdtgroup information files for one cache resource. */
static struct rftype res_common_files[] = {
{
@@ -2202,6 +2244,12 @@ static struct rftype res_common_files[] = {
.seq_show = event_filter_show,
.write = event_filter_write,
},
+ {
+ .name = "mbm_L3_assignments",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = mbm_L3_assignments_show,
+ },
{
.name = "mbm_assign_mode",
.mode = 0444,
--
2.34.1