[PATCH v3 03/26] fs/resctrl: Change how events are initialized

Tony Luck
2025-04-07T23:40:47Z

New monitor events break some assumptions:

1) New events can be in resources other than L3.
2) Enumeration of events may not be complete during early
boot.

Prepare for events in other resources.

Delay building the event lists until first mount of the resctrl
file system.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
fs/resctrl/internal.h | 3 +++
fs/resctrl/monitor.c | 30 +++++++++++++++++++-----------
fs/resctrl/rdtgroup.c | 2 ++
3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 7a65ea02d442..08dbf89939ac 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -76,6 +76,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
*/
struct mon_evt {
enum resctrl_event_id evtid;
+ enum resctrl_res_level rid;
char *name;
bool configurable;
struct list_head list;
@@ -390,6 +391,8 @@ int rdt_lookup_evtid_by_name(char *name);

char *rdt_event_name(enum resctrl_event_id evt);

+void resctrl_init_mon_events(void);
+
#ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);

diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 66e613906f3e..472754d082cb 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -846,14 +846,17 @@ static struct mon_evt all_events[QOS_NUM_EVENTS] = {
[QOS_L3_OCCUP_EVENT_ID] = {
.name = "llc_occupancy",
.evtid = QOS_L3_OCCUP_EVENT_ID,
+ .rid = RDT_RESOURCE_L3,
},
[QOS_L3_MBM_TOTAL_EVENT_ID] = {
.name = "mbm_total_bytes",
.evtid = QOS_L3_MBM_TOTAL_EVENT_ID,
+ .rid = RDT_RESOURCE_L3,
},
[QOS_L3_MBM_LOCAL_EVENT_ID] = {
.name = "mbm_local_bytes",
.evtid = QOS_L3_MBM_LOCAL_EVENT_ID,
+ .rid = RDT_RESOURCE_L3,
},
};

@@ -878,22 +881,29 @@ char *rdt_event_name(enum resctrl_event_id evt)
}

/*
- * Initialize the event list for the resource.
+ * Initialize the event list for all mon_capable resources.
*
- * Note that MBM events are also part of RDT_RESOURCE_L3 resource
- * because as per the SDM the total and local memory bandwidth
- * are enumerated as part of L3 monitoring.
- *
- * mon_put_default_kn_priv_all() also assumes monitor events are only supported
- * on the L3 resource.
+ * Called on each mount of the resctrl file system when all
+ * events have been enumerated. Only needs to build the per-resource
+ * event lists once.
*/
-static void l3_mon_evt_init(struct rdt_resource *r)
+void resctrl_init_mon_events(void)
{
+ struct rdt_resource *r;
+ static bool only_once;
int evt;

- INIT_LIST_HEAD(&r->evt_list);
+ if (only_once)
+ return;
+ only_once = true;
+
+ for_each_mon_capable_rdt_resource(r)
+ INIT_LIST_HEAD(&r->evt_list);

for_each_set_bit(evt, rdt_mon_features, QOS_NUM_EVENTS) {
+ r = resctrl_arch_get_resource(all_events[evt].rid);
+ if (!r->mon_capable)
+ continue;
list_add_tail(&all_events[evt].list, &r->evt_list);
}
}
@@ -922,8 +932,6 @@ int resctrl_mon_resource_init(void)
if (ret)
return ret;

- l3_mon_evt_init(r);
-
if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) {
all_events[QOS_L3_MBM_TOTAL_EVENT_ID].configurable = true;
resctrl_file_fflags_init("mbm_total_bytes_config",
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 8d15d53fae76..1433fc098a90 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2574,6 +2574,8 @@ static int rdt_get_tree(struct fs_context *fc)
goto out;
}

+ resctrl_init_mon_events();
+
ret = rdtgroup_setup_root(ctx);
if (ret)
goto out;
--
2.48.1