[PATCH 13/23] resctrl: Make MBM paths resource-aware

From: Fenghua Yu

Date: Thu Jul 16 2026 - 17:07:58 EST


The MBM overflow, counter-assignment and event-configuration paths
hard-coded RDT_RESOURCE_L3 and the individual L3 MBM event ids. That
cannot express the node-scoped MBM total event, which is backed by the
MBA resource.

Iterate mon_event_all[] and act on every enabled MBM event whose owning
resource matches, instead of naming the L3 events explicitly. Derive the
resource of an overflow work item from the domain's rid, only run mba_sc
bandwidth feedback for the L3 resource, and initialise event
configuration for whichever MBM events a resource actually exposes. No
functional change on L3-only systems.

Signed-off-by: Fenghua Yu <fenghuay@xxxxxxxxxx>
---
fs/resctrl/ctrlmondata.c | 5 +-
fs/resctrl/monitor.c | 105 ++++++++++++++++++++++++---------------
fs/resctrl/rdtgroup.c | 53 ++++++++++++--------
3 files changed, 102 insertions(+), 61 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index ee7823cf9493..77221c6f1e9a 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -693,7 +693,9 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
else
ret = -EINVAL;
} else if (!strcmp(buf, "mbm_total_bytes")) {
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_NODE_MBM_TOTAL_EVENT_ID))
+ rdtgrp->mba_mbps_event = QOS_NODE_MBM_TOTAL_EVENT_ID;
+ else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
else
ret = -EINVAL;
@@ -724,6 +726,7 @@ int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
seq_puts(s, "mbm_local_bytes\n");
break;
case QOS_L3_MBM_TOTAL_EVENT_ID:
+ case QOS_NODE_MBM_TOTAL_EVENT_ID:
seq_puts(s, "mbm_total_bytes\n");
break;
default:
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 25b5038b3e16..665a28bdca7d 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -790,11 +790,15 @@ static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
* This is protected from concurrent reads from user as both
* the user and overflow handler hold the global mutex.
*/
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_TOTAL_EVENT_ID);
+ struct mon_evt *mevt;

- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_LOCAL_EVENT_ID);
+ for_each_mon_event(mevt) {
+ if (mevt->rid != r->rid || !mevt->enabled ||
+ !resctrl_is_mbm_event(mevt->evtid))
+ continue;
+
+ mbm_update_one_event(r, d, rdtgrp, mevt->evtid);
+ }
}

/*
@@ -863,8 +867,8 @@ void mbm_handle_overflow(struct work_struct *work)
if (!resctrl_mounted || !resctrl_arch_mon_capable())
goto out_unlock;

- r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
d = container_of(work, struct rdt_l3_mon_domain, mbm_over.work);
+ r = resctrl_arch_get_resource(d->hdr.rid);

list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
mbm_update(r, d, prgrp);
@@ -873,7 +877,7 @@ void mbm_handle_overflow(struct work_struct *work)
list_for_each_entry(crgrp, head, mon.crdtgrp_list)
mbm_update(r, d, crgrp);

- if (is_mba_sc(NULL, NULL))
+ if (is_mba_sc(NULL, NULL) && r->rid == RDT_RESOURCE_L3)
update_mba_bw(prgrp, d);
}

@@ -1267,19 +1271,20 @@ static int rdtgroup_assign_cntr_event(struct rdt_l3_mon_domain *d, struct rdtgro
*/
void rdtgroup_assign_cntrs(struct rdtgroup *rdtgrp)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_resource *r;
+ struct mon_evt *mevt;

- if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r) ||
- !r->mon.mbm_assign_on_mkdir)
- return;
+ for_each_mon_event(mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ continue;

- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]);
+ r = resctrl_arch_get_resource(mevt->rid);
+ if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r) ||
+ !r->mon.mbm_assign_on_mkdir)
+ continue;

- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]);
+ rdtgroup_assign_cntr_event(NULL, rdtgrp, mevt);
+ }
}

/*
@@ -1326,18 +1331,19 @@ static void rdtgroup_unassign_cntr_event(struct rdt_l3_mon_domain *d, struct rdt
*/
void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_resource *r;
+ struct mon_evt *mevt;

- if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
- return;
+ for_each_mon_event(mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ continue;

- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]);
+ r = resctrl_arch_get_resource(mevt->rid);
+ if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
+ continue;

- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]);
+ rdtgroup_unassign_cntr_event(NULL, rdtgrp, mevt);
+ }
}

static int resctrl_parse_mem_transactions(char *tok, u32 *val)
@@ -1497,6 +1503,7 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,
{
struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
struct rdt_l3_mon_domain *d;
+ struct mon_evt *mevt;
int ret = 0;
bool enable;

@@ -1548,13 +1555,19 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,
* Initialize the default memory transaction values for
* total and local events.
*/
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
- (READS_TO_LOCAL_MEM |
- READS_TO_LOCAL_S_MEM |
- NON_TEMP_WRITE_TO_LOCAL_MEM);
+ for_each_mon_event(mevt) {
+ if (mevt->rid != r->rid || !mevt->enabled ||
+ !resctrl_is_mbm_event(mevt->evtid))
+ continue;
+
+ if (mevt->evtid == QOS_L3_MBM_LOCAL_EVENT_ID)
+ mevt->evt_cfg = r->mon.mbm_cfg_mask &
+ (READS_TO_LOCAL_MEM |
+ READS_TO_LOCAL_S_MEM |
+ NON_TEMP_WRITE_TO_LOCAL_MEM);
+ else
+ mevt->evt_cfg = r->mon.mbm_cfg_mask;
+ }
/* Enable auto assignment when switching to "mbm_event" mode */
if (enable)
r->mon.mbm_assign_on_mkdir = true;
@@ -1896,6 +1909,7 @@ static void closid_num_dirty_rmid_free(void)

static void resctrl_mon_resource_init(struct rdt_resource *r)
{
+ struct mon_evt *mevt;
unsigned long fflags;

fflags = (r->rid == RDT_RESOURCE_MBA) ? RFTYPE_RES_MB : RFTYPE_RES_CACHE;
@@ -1905,6 +1919,11 @@ static void resctrl_mon_resource_init(struct rdt_resource *r)
resctrl_file_fflags_init("mbm_total_bytes_config",
RFTYPE_MON_INFO | fflags);
}
+ if (resctrl_arch_is_evt_configurable(QOS_NODE_MBM_TOTAL_EVENT_ID)) {
+ mon_event_all[QOS_NODE_MBM_TOTAL_EVENT_ID].configurable = true;
+ resctrl_file_fflags_init("mbm_total_bytes_config",
+ RFTYPE_MON_INFO | fflags);
+ }
if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_LOCAL_EVENT_ID)) {
mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].configurable = true;
resctrl_file_fflags_init("mbm_local_bytes_config",
@@ -1913,17 +1932,25 @@ static void resctrl_mon_resource_init(struct rdt_resource *r)

if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+ else if (resctrl_is_mon_event_enabled(QOS_NODE_MBM_TOTAL_EVENT_ID))
+ mba_mbps_default_event = QOS_NODE_MBM_TOTAL_EVENT_ID;
else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;

if (r->mon.mbm_cntr_assignable) {
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
- (READS_TO_LOCAL_MEM |
- READS_TO_LOCAL_S_MEM |
- NON_TEMP_WRITE_TO_LOCAL_MEM);
+ for_each_mon_event(mevt) {
+ if (mevt->rid != r->rid || !mevt->enabled ||
+ !resctrl_is_mbm_event(mevt->evtid))
+ continue;
+
+ if (mevt->evtid == QOS_L3_MBM_LOCAL_EVENT_ID)
+ mevt->evt_cfg = r->mon.mbm_cfg_mask &
+ (READS_TO_LOCAL_MEM |
+ READS_TO_LOCAL_S_MEM |
+ NON_TEMP_WRITE_TO_LOCAL_MEM);
+ else
+ mevt->evt_cfg = r->mon.mbm_cfg_mask;
+ }
r->mon.mbm_assign_on_mkdir = true;
resctrl_file_fflags_init("num_mbm_cntrs",
RFTYPE_MON_INFO | fflags);
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index db0255951f0e..5be285487df7 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -129,7 +129,8 @@ void rdt_staged_configs_clear(void)
static bool resctrl_is_mbm_enabled(void)
{
return (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID) ||
- resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID));
+ resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID) ||
+ resctrl_is_mon_event_enabled(QOS_NODE_MBM_TOTAL_EVENT_ID));
}

/*
@@ -1766,7 +1767,7 @@ static int mbm_total_bytes_config_show(struct kernfs_open_file *of,
{
struct rdt_resource *r = rdt_kn_parent_priv(of->kn);

- mbm_config_show(seq, r, QOS_L3_MBM_TOTAL_EVENT_ID);
+ mbm_config_show(seq, r, resctrl_mbm_total_event_id());

return 0;
}
@@ -1885,7 +1886,7 @@ static ssize_t mbm_total_bytes_config_write(struct kernfs_open_file *of,

buf[nbytes - 1] = '\0';

- ret = mon_config_write(r, buf, QOS_L3_MBM_TOTAL_EVENT_ID);
+ ret = mon_config_write(r, buf, resctrl_mbm_total_event_id());

out_unlock:
mutex_unlock(&rdtgroup_mutex);
@@ -5250,10 +5251,32 @@ static struct rdt_l3_mon_domain *get_mon_domain_from_cpu(int cpu,
return NULL;
}

-void resctrl_offline_cpu(unsigned int cpu)
+static void resctrl_migrate_mon_domain_workers(unsigned int cpu,
+ struct rdt_resource *r)
{
- struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdt_l3_mon_domain *d;
+
+ if (!r->mon_capable)
+ return;
+
+ d = get_mon_domain_from_cpu(cpu, r);
+ if (!d)
+ return;
+
+ if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
+ cancel_delayed_work(&d->mbm_over);
+ mbm_setup_overflow_handler(d, 0, cpu);
+ }
+ if (r->rid == RDT_RESOURCE_L3 &&
+ resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) &&
+ cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
+ cancel_delayed_work(&d->cqm_limbo);
+ cqm_setup_limbo_handler(d, 0, cpu);
+ }
+}
+
+void resctrl_offline_cpu(unsigned int cpu)
+{
struct rdtgroup *rdtgrp;

mutex_lock(&rdtgroup_mutex);
@@ -5264,23 +5287,11 @@ void resctrl_offline_cpu(unsigned int cpu)
}
}

- if (!l3->mon_capable)
- goto out_unlock;
-
- d = get_mon_domain_from_cpu(cpu, l3);
- if (d) {
- if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
- cancel_delayed_work(&d->mbm_over);
- mbm_setup_overflow_handler(d, 0, cpu);
- }
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) &&
- cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
- cancel_delayed_work(&d->cqm_limbo);
- cqm_setup_limbo_handler(d, 0, cpu);
- }
- }
+ resctrl_migrate_mon_domain_workers(cpu,
+ resctrl_arch_get_resource(RDT_RESOURCE_L3));
+ resctrl_migrate_mon_domain_workers(cpu,
+ resctrl_arch_get_resource(RDT_RESOURCE_MBA));

-out_unlock:
mutex_unlock(&rdtgroup_mutex);
}

--
2.43.0