[RESEND PATCH v4 08/15] fs/resctrl: Add interface to display supported and active kernel-mode policy

From: Babu Moger

Date: Tue Jul 07 2026 - 17:54:43 EST


Kernel-mode resctrl policies define how kernel work is associated with
resource allocation and monitoring relative to the user task. Generic
resctrl tracks the supported policies, the active policy, and the resctrl
group backing any global assignment policy. However, this information is
not exposed to user space.

Introduce a new resctrl file, info/kernel_mode, to expose the global
kernel-mode policy and its associated resource group (when applicable).
This read-only sysfs file lists all supported policies, one per line, and
highlights the active policy using square brackets.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v4: Fixed the display of inherit_ctrl_and_mon policy. It is not
associated with any group.
Added "uninitialized" for the non-active group.
Rewrote the changelog.

v3: New patch to handle the changed interface file info/kernel_mode.
Changed the group name to "none" if kmode binding is not done.
Reinette suggested "uninitialized". "none" seemed more relevent.
---
fs/resctrl/rdtgroup.c | 91 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 0ee0dfaf9065..346aa4df62a4 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1012,6 +1012,90 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
return 0;
}

+/* Sysfs lines for info/kernel_mode; indexed by enum resctrl_kernel_mode */
+static const char * const resctrl_mode_str[] = {
+ [INHERIT_CTRL_AND_MON] = "inherit_ctrl_and_mon",
+ [GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU] = "global_assign_ctrl_inherit_mon_per_cpu",
+ [GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU] = "global_assign_ctrl_assign_mon_per_cpu",
+};
+
+static_assert(ARRAY_SIZE(resctrl_mode_str) == RESCTRL_NUM_KERNEL_MODES);
+
+/**
+ * resctrl_kernel_mode_show() - Display supported and active kernel-mode policies
+ * @of: kernfs open file
+ * @seq: output seq_file
+ * @v: unused
+ *
+ * Displays one line per mode set in resctrl_kcfg.kmode. Bracket the active
+ * policy (resctrl_kcfg.kmode_cur).
+ *
+ * INHERIT_CTRL_AND_MON is displayed as "[inherit_ctrl_and_mon]" when active
+ * or "inherit_ctrl_and_mon" when supported but inactive, with no :group=
+ * suffix in either case.
+ *
+ * Global-assign modes append :group=. An inactive mode is emitted as
+ * "<mode>:group=uninitialized". An active mode with a bound group is emitted
+ * as "[<mode>:group=<ctrl>/<mon>/]", where <ctrl>/<mon>/ is derived from
+ * resctrl_kcfg.k_rdtgrp.
+ *
+ * Return: 0 on success, or -ENOENT on error.
+ */
+static int resctrl_kernel_mode_show(struct kernfs_open_file *of,
+ struct seq_file *seq, void *v)
+{
+ enum resctrl_kernel_mode mode;
+ struct rdtgroup *rdtgrp;
+ const char *ctrl, *mon;
+ bool active;
+ int ret = 0;
+
+ mutex_lock(&rdtgroup_mutex);
+ for (mode = 0; mode < RESCTRL_NUM_KERNEL_MODES; mode++) {
+ if (!test_bit(mode, &resctrl_kcfg.kmode))
+ continue;
+
+ active = (resctrl_kcfg.kmode_cur == mode);
+
+ if (mode == INHERIT_CTRL_AND_MON) {
+ seq_printf(seq, active ? "[%s]\n" : "%s\n",
+ resctrl_mode_str[mode]);
+ continue;
+ }
+
+ if (!active) {
+ seq_printf(seq, "%s:group=uninitialized\n",
+ resctrl_mode_str[mode]);
+ continue;
+ }
+
+ /*
+ * There should be a valid group when any of the global
+ * assign mode is active; otherwise, report an error.
+ */
+ rdtgrp = resctrl_kcfg.k_rdtgrp;
+ if (!rdtgrp) {
+ ret = -ENOENT;
+ goto out_unlock;
+ }
+
+ ctrl = "";
+ mon = "";
+ if (rdtgrp->type == RDTMON_GROUP) {
+ ctrl = rdt_kn_name(rdtgrp->mon.parent->kn);
+ mon = rdt_kn_name(rdtgrp->kn);
+ } else {
+ ctrl = rdt_kn_name(rdtgrp->kn);
+ }
+ seq_printf(seq, "[%s:group=%s/%s/]\n",
+ resctrl_mode_str[mode], ctrl, mon);
+ }
+
+out_unlock:
+ mutex_unlock(&rdtgroup_mutex);
+ return ret;
+}
+
void *rdt_kn_parent_priv(struct kernfs_node *kn)
{
/*
@@ -1915,6 +1999,13 @@ static struct rftype res_common_files[] = {
.seq_show = rdt_last_cmd_status_show,
.fflags = RFTYPE_TOP_INFO,
},
+ {
+ .name = "kernel_mode",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = resctrl_kernel_mode_show,
+ .fflags = RFTYPE_TOP_INFO,
+ },
{
.name = "mbm_assign_on_mkdir",
.mode = 0644,
--
2.43.0