[PATCH 09/15] x86/resctrl: Add interface to display monitor state of the group

From: Babu Moger
Date: Thu Nov 30 2023 - 19:58:18 EST


The ABMC feature provides an option to the user to pin (or assign) the
RMID to the hardware counter and monitor the bandwidth for the longer
duration. The RMID will be active until user unpins (unassigns) the
RMID.

Add a new field monitor_state in resctrl group interface to display the
assignment state of the group. This field is available when resctrl
interface is mounted with "-o abmc".

By default the monitor_state is initialized to unassigned state.
$cat /sys/fs/resctrl/monitor_state
total=unassign;local=unassign

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
Documentation/arch/x86/resctrl.rst | 20 ++++++++++++++
arch/x86/kernel/cpu/resctrl/internal.h | 8 ++++++
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 36 ++++++++++++++++++++++++++
3 files changed, 64 insertions(+)

diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index 87aa8eec71b7..d3df7d467eec 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -390,6 +390,26 @@ When monitoring is enabled all MON groups will also contain:
the sum for all tasks in the CTRL_MON group and all tasks in
MON groups. Please see example section for more details on usage.

+"monitor_state":
+ Available when ABMC feature is enabled. ABMC feature provides an
+ option to the user to pin (or assign) the RMID to hardware counter
+ and monitor the bandwidth for the longer duration. The RMID will
+ be active until user unpins (unassigns) it manually. Each group
+ will have two events that are assignable. By default, the events
+ are unassigned. Index 0 holds the monitor_state for MBM total bytes.
+ Index 1 holds the monitor_state for MBM local bytes.
+
+ Example::
+
+ # cat /sys/fs/resctrl/monitor_state
+ total=unassign;local=unassign
+
+ When the events are assigned, the output will look like below.
+ Example::
+
+ # cat /sys/fs/resctrl/monitor_state
+ total=assign;local=assign
+
"mon_hw_id":
Available only with debug option. The identifier used by hardware
for the monitor group. On x86 this is the RMID.
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index 2801bc0dc132..bc36acd152be 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -53,6 +53,12 @@
/* ABMC ENABLE */
#define ABMC_ENABLE BIT(0)

+/*
+ * monitor group's state when ABMC is enabled
+ */
+#define TOTAL_ASSIGN BIT(0)
+#define LOCAL_ASSIGN BIT(1)
+
struct rdt_fs_context {
struct kernfs_fs_context kfc;
bool enable_cdpl2;
@@ -161,12 +167,14 @@ enum rdtgrp_mode {
* @parent: parent rdtgrp
* @crdtgrp_list: child rdtgroup node list
* @rmid: rmid for this rdtgroup
+ * @monitor_state: ABMC state of the group
*/
struct mongroup {
struct kernfs_node *mon_data_kn;
struct rdtgroup *parent;
struct list_head crdtgrp_list;
u32 rmid;
+ u32 monitor_state;
};

/**
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 897707694cc8..edb679b22b7b 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -779,6 +779,26 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of,
return ret;
}

+static int rdtgroup_monitor_state_show(struct kernfs_open_file *of,
+ struct seq_file *s, void *v)
+{
+ struct rdtgroup *rdtgrp;
+ int ret = 0;
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+ if (rdtgrp)
+ seq_printf(s, "total=%s;local=%s\n",
+ rdtgrp->mon.monitor_state & TOTAL_ASSIGN ?
+ "assign" : "unassign",
+ rdtgrp->mon.monitor_state & LOCAL_ASSIGN ?
+ "assign" : "unassign");
+ else
+ ret = -ENOENT;
+ rdtgroup_kn_unlock(of->kn);
+
+ return ret;
+}
+
static int rdtgroup_closid_show(struct kernfs_open_file *of,
struct seq_file *s, void *v)
{
@@ -1895,6 +1915,12 @@ static struct rftype res_common_files[] = {
.flags = RFTYPE_FLAGS_CPUS_LIST,
.fflags = RFTYPE_BASE,
},
+ {
+ .name = "monitor_state",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = rdtgroup_monitor_state_show,
+ },
{
.name = "tasks",
.mode = 0644,
@@ -2446,6 +2472,12 @@ int resctrl_arch_set_abmc_enabled(enum resctrl_res_level l, bool enable)
if (rft)
rft->fflags = RFTYPE_MON_INFO;

+ rft = rdtgroup_get_rftype_by_name("monitor_state");
+ if (rft)
+ rft->fflags = RFTYPE_MON_BASE;
+
+ rdtgroup_default.mon.monitor_state = 0;
+
return resctrl_abmc_enable(l);
}

@@ -2453,6 +2485,10 @@ int resctrl_arch_set_abmc_enabled(enum resctrl_res_level l, bool enable)
if (rft)
rft->fflags &= ~RFTYPE_MON_INFO;

+ rft = rdtgroup_get_rftype_by_name("monitor_state");
+ if (rft)
+ rft->fflags &= ~RFTYPE_MON_BASE;
+
resctrl_abmc_disable(l);

return 0;
--
2.34.1