[RFC PATCH v3 16/17] x86/resctrl: Introduce interface to list assignment states of all the groups

From: Babu Moger
Date: Thu Mar 28 2024 - 21:11:41 EST


Introduce rdtgroup_mbm_assign_control_show list assignment states of all the
resctrl groups.

List follows the following format:

- Default CTRL_MON group:
"//<domain_id>=<assignment_flags>"

- Non-default CTRL_MON group:
"<CTRL_MON group>//<domain_id>=<assignment_flags>"

- Child MON group of default CTRL_MON group:
"/<MON group>/<domain_id>=<assignment_flags>"

- Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/<domain_id>=<assignment_flags>"

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v3: New patch.
Addresses the feedback to provide the global assignment interface.
https://lore.kernel.org/lkml/c73f444b-83a1-4e9a-95d3-54c5165ee782@xxxxxxxxx/
---
Documentation/arch/x86/resctrl.rst | 51 ++++++++++++++++
arch/x86/kernel/cpu/resctrl/monitor.c | 1 +
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 85 ++++++++++++++++++++++++++
3 files changed, 137 insertions(+)

diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index 3e441b828765..2d96565501ab 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -278,6 +278,57 @@ with the following files:
The number of assignable counters available when the assignable monitoring
feature is supported.

+"mbm_assign_control":
+ Available when assignable monitoring features are supported.
+ Reports the resctrl group and assignment status of each group.
+
+ List follows the following format:
+
+ * Default CTRL_MON group:
+ "//<domain_id>=<assignment_flags>"
+
+ * Non-default CTRL_MON group:
+ "<CTRL_MON group>//<domain_id>=<assignment_flags>"
+
+ * Child MON group of default CTRL_MON group:
+ "/<MON group>/<domain_id>=<assignment_flags>"
+
+ * Child MON group of non-default CTRL_MON group:
+ "<CTRL_MON group>/<MON group>/<domain_id>=<assignment_flags>"
+
+ Assignment flags can be one of the following:
+ ::
+
+ t MBM total event is assigned
+ l MBM local event is assigned
+ tl Both total and local MBM events are assigned
+ _ None of the MBM events are assigned
+
+ Examples:
+ ::
+
+ # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control
+ //0=tl;1=tl;
+ /child_default_mon_grp/0=t;1=t;
+ non_default_ctrl_mon_grp//0=l;1=l;
+ non_default_ctrl_mon_grp/child_non_default_mon_grp/0=_;1=_;
+
+ //0=tl;1=tl;
+ Both the events on the default group are assigned.
+
+ /child_default_mon_grp/0=t;1=t;
+ Only total event on this mon group is assigned. This is a child
+ monitor group of the default control mon group.
+
+ non_default_ctrl_mon_grp//0=l;1=l;
+ Only local event on this control mon group is assigned. This is a
+ non default control mon group.
+
+ non_default_ctrl_mon_grp/child_non_default_mon_grp/0=_;1=_;
+ None of events are assigned on this mon group. This is a child
+ monitor group of the non default control mon group.
+
+
"max_threshold_occupancy":
Read/write file provides the largest value (in
bytes) at which a previously used LLC_occupancy
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 8677dbf6de43..8a2e2afc85e8 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -1062,6 +1062,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
r->mbm_assign_capable = ABMC_ASSIGN;
resctrl_file_fflags_init("mbm_assign", RFTYPE_MON_INFO);
resctrl_file_fflags_init("mbm_assign_cntrs", RFTYPE_MON_INFO);
+ resctrl_file_fflags_init("mbm_assign_control", RFTYPE_MON_INFO);
}
}

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index a6e0ef2631ae..9fd37b6c3b24 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -932,6 +932,85 @@ static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
return ret ?: nbytes;
}

+static char *mon_state_to_str(int mon_state, char *str)
+{
+ char *tmp = str;
+
+ switch (mon_state) {
+ case ASSIGN_NONE:
+ *tmp++ = '_';
+ break;
+ case (ASSIGN_TOTAL | ASSIGN_LOCAL):
+ *tmp++ = 't';
+ *tmp++ = 'l';
+ break;
+ case ASSIGN_TOTAL:
+ *tmp++ = 't';
+ break;
+ case ASSIGN_LOCAL:
+ *tmp++ = 'l';
+ break;
+ default:
+ break;
+ }
+
+ *tmp = '\0';
+ return str;
+}
+
+static int rdtgroup_mbm_assign_control_show(struct kernfs_open_file *of,
+ struct seq_file *s, void *v)
+{
+ struct rdt_resource *r = of->kn->parent->priv;
+ struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+ struct rdt_domain *dom;
+ struct rdtgroup *rdtg;
+ int grp_default = 0;
+ char str[10];
+
+ if (!hw_res->abmc_enabled) {
+ rdt_last_cmd_puts("ABMC feature is not enabled\n");
+ return -EINVAL;
+ }
+
+ mutex_lock(&rdtgroup_mutex);
+
+ list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) {
+ struct rdtgroup *crg;
+
+ if (rdtg == &rdtgroup_default) {
+ grp_default = 1;
+ seq_puts(s, "//");
+ } else {
+ grp_default = 0;
+ seq_printf(s, "%s//", rdtg->kn->name);
+ }
+
+ list_for_each_entry(dom, &r->domains, list)
+ seq_printf(s, "%d=%s;", dom->id,
+ mon_state_to_str(rdtg->mon.mon_state, str));
+ seq_putc(s, '\n');
+
+ list_for_each_entry(crg, &rdtg->mon.crdtgrp_list,
+ mon.crdtgrp_list) {
+ if (grp_default)
+ seq_printf(s, "/%s/", crg->kn->name);
+ else
+ seq_printf(s, "%s/%s/", rdtg->kn->name,
+ crg->kn->name);
+
+ list_for_each_entry(dom, &r->domains, list)
+ seq_printf(s, "%d=%s;", dom->id,
+ mon_state_to_str(crg->mon.mon_state, str));
+ seq_putc(s, '\n');
+ }
+ }
+
+ mutex_unlock(&rdtgroup_mutex);
+
+ return 0;
+}
+
static int rdtgroup_mbm_assign_cntrs_show(struct kernfs_open_file *of,
struct seq_file *s, void *v)
{
@@ -2119,6 +2198,12 @@ static struct rftype res_common_files[] = {
.seq_show = rdtgroup_mbm_assign_show,
.write = rdtgroup_mbm_assign_write,
},
+ {
+ .name = "mbm_assign_control",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = rdtgroup_mbm_assign_control_show,
+ },
{
.name = "mbm_assign_cntrs",
.mode = 0444,
--
2.34.1