[RFC PATCH v3 15/17] x86/resctrl: Introduce the interface switch between ABMC and legacy_mbm
From: Babu Moger
Date: Thu Mar 28 2024 - 21:11:07 EST
Introduce rdtgroup_mbm_assign_write to switch between ABMC and legacy_mbm.
By default ABMC is enabled on resctrl mount if the feature is available.
However, user will have the option to go back to legacy_mbm if required.
Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v3: New patch to address the review comments from upstream.
---
Documentation/arch/x86/resctrl.rst | 14 ++++++++-
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 39 +++++++++++++++++++++++++-
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index e06ffddb64f6..3e441b828765 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -260,7 +260,19 @@ with the following files:
"mbm_assign":
Available when assignable monitoring features are supported.
Reports the list of assignable features supported and the enclosed brackets
- indicate the feature is enabled.
+ indicate the feature is enabled. Users will have the option to switch
+ between the monitoring features.
+ Examples:
+
+ * To enable ABMC feature:
+ ::
+
+ # echo "abmc" > /sys/fs/resctrl/info/L3_MON/mbm_assign
+
+ * To enable the legacy monitoring feature:
+ ::
+
+ # echo "legacy_mbm" > /sys/fs/resctrl/info/L3_MON/mbm_assign
"mbm_assign_cntrs":
The number of assignable counters available when the assignable monitoring
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 2e58024e95e2..a6e0ef2631ae 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -896,6 +896,42 @@ static int rdtgroup_mbm_assign_show(struct kernfs_open_file *of,
return 0;
}
+/*
+ * rdtgroup_mode_write - Modify the resource group's mode
+ */
+static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct rdt_resource *r = of->kn->parent->priv;
+ int ret;
+
+ if (!r->mbm_assign_capable)
+ return -EINVAL;
+
+ /* 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, "legacy_mbm"))
+ ret = resctrl_arch_set_abmc_enabled(RDT_RESOURCE_L3, false);
+ else if (!strcmp(buf, "abmc"))
+ ret = resctrl_arch_set_abmc_enabled(RDT_RESOURCE_L3, true);
+ else
+ ret = -EINVAL;
+
+ mutex_unlock(&rdtgroup_mutex);
+ cpus_read_unlock();
+
+ return ret ?: nbytes;
+}
+
static int rdtgroup_mbm_assign_cntrs_show(struct kernfs_open_file *of,
struct seq_file *s, void *v)
{
@@ -2078,9 +2114,10 @@ static struct rftype res_common_files[] = {
},
{
.name = "mbm_assign",
- .mode = 0444,
+ .mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdtgroup_mbm_assign_show,
+ .write = rdtgroup_mbm_assign_write,
},
{
.name = "mbm_assign_cntrs",
--
2.34.1