[PATCH v2 12/16] fs/resctrl: Add info/kernel_mode_assignment to show kernel-mode rdtgroup

Babu Moger
2026-03-12T20:39:03Z

Add the interface info/kernel_mode_assignment file to show the rdtgroup
enabled for kernel mode (e.g. PLZA).

The assigned rdtgroup list is printed in following format:

"<CTRL_MON group>/<MON group>/"

Format for specific type of groups:

* Default CTRL_MON group:
"//"

* Non-default CTRL_MON group:
"<CTRL_MON group>//"

* Child MON group of default CTRL_MON group:
"/<MON group>/"

* Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/"

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v2: New patch to handle PLZA interfaces with /sys/fs/resctrl/info/ directory.
https://lore.kernel.org/lkml/2ab556af-095b-422b-9396-f845c6fd0342@intel.com/
---
fs/resctrl/rdtgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 6cd928fabaa2..c2d6d1995dff 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1117,6 +1117,45 @@ static ssize_t resctrl_kernel_mode_write(struct kernfs_open_file *of,
return ret ?: nbytes;
}

+/**
+ * resctrl_kernel_mode_assignment_show() - Show rdtgroup assigned to kernel mode
+ * @of: kernfs file handle.
+ * @s: seq_file to write to.
+ * @v: unused.
+ *
+ * Prints the rdtgroup (resctrl_kcfg.k_rdtgrp) used for kernel work when a
+ * kernel mode is active (e.g. PLZA).
+ * Format: "CTRL_MON/MON/\n"
+ * "//" for default CTRL_MON,
+ * "ctrl_name//" for a CTRL_MON group,
+ * "/mon_name/" for a MON group under default,
+ * "ctrl_name/mon_name/" otherwise.
+ *
+ * Prints "Kmode is not configured" if no rdtgroup is assigned.
+ */
+static int resctrl_kernel_mode_assignment_show(struct kernfs_open_file *of,
+ struct seq_file *s, void *v)
+{
+ mutex_lock(&rdtgroup_mutex);
+ if (!resctrl_kcfg.k_rdtgrp) {
+ seq_puts(s, "Kmode is not configured");
+ } else if (resctrl_kcfg.k_rdtgrp == &rdtgroup_default) {
+ seq_puts(s, "//");
+ } else if (resctrl_kcfg.k_rdtgrp->type == RDTCTRL_GROUP) {
+ seq_printf(s, "%s//", rdt_kn_name(resctrl_kcfg.k_rdtgrp->kn));
+ } else if (resctrl_kcfg.k_rdtgrp->type == RDTMON_GROUP) {
+ if (resctrl_kcfg.k_rdtgrp->mon.parent == &rdtgroup_default)
+ seq_printf(s, "/%s/", rdt_kn_name(resctrl_kcfg.k_rdtgrp->kn));
+ else
+ seq_printf(s, "%s/%s/",
+ rdt_kn_name(resctrl_kcfg.k_rdtgrp->mon.parent->kn),
+ rdt_kn_name(resctrl_kcfg.k_rdtgrp->kn));
+ }
+ seq_puts(s, "\n");
+ mutex_unlock(&rdtgroup_mutex);
+ return 0;
+}
+
void *rdt_kn_parent_priv(struct kernfs_node *kn)
{
/*
@@ -2026,6 +2065,13 @@ static struct rftype res_common_files[] = {
.write = resctrl_kernel_mode_write,
.fflags = RFTYPE_TOP_INFO,
},
+ {
+ .name = "kernel_mode_assignment",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = resctrl_kernel_mode_assignment_show,
+ .fflags = RFTYPE_TOP_INFO,
+ },
{
.name = "mbm_assign_on_mkdir",
.mode = 0644,
--
2.43.0