* [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors
@ 2026-11-16 12:58 Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 01/19] fs/resctrl: Rename monitor events to drop the L3 prefix Jinjie Ruan
` (19 more replies)
0 siblings, 20 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:58 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Resctrl exposes cache occupancy and bandwidth monitoring only at the L3
scope. MPAM can count the same things on an L2 cache: firmware points
an MSC at the cache it belongs to, and its CSU and MBWU counters can
report the occupancy of that L2 slice and the traffic the cache sees.
This series first reworks resctrl's monitor bookkeeping to track events
by scope instead of by resource, and then exposes those counters as
"l2c_occupancy" and "mbm_core_bytes"
The patch set is organized as follows:
- Patches 1-4: Rename to drop the L3 prefix
- Patches 5-7: Rework the bookkeeping, index monitor state by resource
and event, index the event table by scope and eventid
- Patches 8-13: Make the core per-resource and add the L2 events
- Patches 14-18: Let the driver pick L2 classes for the L2 resource,
and expose the L2 events
- Patch 19: Update the documentation
Notes on the user interface
===========================
The L3 event names and semantics, the L3_MON and mon_L3_xx names and
the x86 PERF_PKG files are unchanged.
The L2 bandwidth event is called mbm_core_bytes because it counts the
bytes the L2 cache sees, which is not memory bandwidth.
And mbm_L3_assignments remains L3-only.
Testing
=======
QEMU, topology with L2, L3 and memory-controller MSCs:
- info/L2_MON lists l2c_occupancy and mbm_core_bytes, and per-core
mon_L2_xx directories are created.
- Reads: l2c_occupancy 262144 bytes (50% of a 512KiB L2),
llc_occupancy unchanged, mbm_core_bytes advances about 20GB per 2s
sample.
- CDP halves num_closids and the monitor counts of every monitor
resource.
- RMID limbo: a freed RMID is marked busy in every L2 and L3 monitor
domain, and becomes allocatable again once those domains are
offlined and the busy count reaches zero.
QEMU branch: https://github.com/ruanjinjie-eng/qemu/tree/mpam
Test cases: https://github.com/ruanjinjie-eng/mpam_testcase
This series is rebased on v7.4 rc3 and also available at:
https://github.com/ruanjinjie-eng/linux/commits/mpam-l2mon-scope
Changes in RFC v3
- The event table is indexed by scope instead of by resource (Reinette)
- Patch 6 is split out so no helper takes an unused argument.
- The RMID limbo threshold is kept per resource, so an L3 domain no
longer compares its occupancy with an L2-sized value
- Bugfixes are split out as their own series.
- RFC v2: https://lore.kernel.org/all/20261029123611.1108424-1-ruanjinjie@huawei.com/
Changes in RFC v2:
- As Ben suggested, the existing event types now apply to any resource,
instead of adding L2-only event IDs.
- As Ben suggested, L2 bandwidth uses an assignable counter that stays
with the monitoring group, not a monitor borrowed for each read.
- The CDP change also halves the assignable counter count, for every
monitor resource.
- Split by subsystem so resctrl, x86 and MPAM can be reviewed separately.
- Fix a CDP bug: a failed enable left the driver believing CDP was on.
- RFC v1: https://lore.kernel.org/all/20261022084821.4014873-1-ruanjinjie@huawei.com/
Jinjie Ruan (19):
fs/resctrl: Rename monitor events to drop the L3 prefix
x86/resctrl: Use the resource-agnostic monitor event names
arm_mpam: resctrl: Use the resource-agnostic monitor event names
resctrl: Remove the L3 monitor event names
arm_mpam: resctrl: Index monitor state by resource and event
x86,fs/resctrl: Record the resource that enables a monitor event
x86,fs/resctrl: Track monitor events by scope
fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources
fs/resctrl: Add the L2 monitor events
fs/resctrl: Set up MBM state and workers for every monitor resource
resctrl: Keep the RMID limbo threshold per resource
fs/resctrl: Check RMID limbo on every resource with occupancy
fs/resctrl: Manage assignable counters for every monitor resource
arm_mpam: resctrl: Halve the monitor counts of every resource on CDP
arm_mpam: resctrl: Look up the monitor domain id from the components
arm_mpam: resctrl: Report counter assignment per resource
arm_mpam: resctrl: Allow monitoring on resources other than the L3
arm_mpam: resctrl: Expose the L2 monitor events
Documentation: arm64: mpam: Describe the L2 monitor events
Documentation/arch/arm64/mpam.rst | 25 +-
Documentation/filesystems/resctrl.rst | 11 +
arch/x86/kernel/cpu/resctrl/core.c | 13 +-
arch/x86/kernel/cpu/resctrl/intel_aet.c | 2 +-
arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
arch/x86/kernel/cpu/resctrl/monitor.c | 10 +-
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 +-
drivers/resctrl/mpam_resctrl.c | 357 ++++++++++++++----------
fs/resctrl/ctrlmondata.c | 13 +-
fs/resctrl/internal.h | 55 +++-
fs/resctrl/monitor.c | 328 +++++++++++++---------
fs/resctrl/rdtgroup.c | 158 ++++++-----
include/linux/resctrl.h | 36 ++-
include/linux/resctrl_types.h | 16 +-
14 files changed, 619 insertions(+), 415 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 01/19] fs/resctrl: Rename monitor events to drop the L3 prefix
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
@ 2026-11-16 12:58 ` Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 02/19] x86/resctrl: Use the resource-agnostic monitor event names Jinjie Ruan
` (18 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:58 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
The monitor event IDs have L3 in their names because L3 was the only
scope resctrl supported. MPAM can count the same things on an L2 cache,
so the scope belongs to the resource, not to the event.
Drop the L3 prefix from the event names and use the new names in
resctrl. The values stay the same for x86.
And keep the old names as aliases until the architectures have
been converted.
No functional change.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/ctrlmondata.c | 12 +++---
fs/resctrl/monitor.c | 72 +++++++++++++++++------------------
fs/resctrl/rdtgroup.c | 24 ++++++------
include/linux/resctrl.h | 16 ++++----
include/linux/resctrl_types.h | 21 ++++++----
5 files changed, 76 insertions(+), 69 deletions(-)
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index cafebdff70dc..c70a9939d126 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -484,13 +484,13 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
buf[nbytes - 1] = '\0';
if (!strcmp(buf, "mbm_local_bytes")) {
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ rdtgrp->mba_mbps_event = QOS_MBM_LOCAL_EVENT_ID;
else
ret = -EINVAL;
} else if (!strcmp(buf, "mbm_total_bytes")) {
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ rdtgrp->mba_mbps_event = QOS_MBM_TOTAL_EVENT_ID;
else
ret = -EINVAL;
} else {
@@ -516,10 +516,10 @@ int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
if (rdtgrp) {
switch (rdtgrp->mba_mbps_event) {
- case QOS_L3_MBM_LOCAL_EVENT_ID:
+ case QOS_MBM_LOCAL_EVENT_ID:
seq_puts(s, "mbm_local_bytes\n");
break;
- case QOS_L3_MBM_TOTAL_EVENT_ID:
+ case QOS_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 b9336464cc53..1b0fb3c2aaee 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -141,8 +141,8 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
void *arch_priv;
u64 val = 0;
- arch_priv = mon_event_all[QOS_L3_OCCUP_EVENT_ID].arch_priv;
- arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_L3_OCCUP_EVENT_ID);
+ arch_priv = mon_event_all[QOS_OCCUP_EVENT_ID].arch_priv;
+ arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_OCCUP_EVENT_ID);
if (IS_ERR(arch_mon_ctx)) {
pr_warn_ratelimited("Failed to allocate monitor context: %pe",
arch_mon_ctx);
@@ -163,7 +163,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
entry = __rmid_entry(idx);
if (!force_free) {
if (resctrl_arch_rmid_read(r, &d->hdr, entry->closid,
- entry->rmid, QOS_L3_OCCUP_EVENT_ID,
+ entry->rmid, QOS_OCCUP_EVENT_ID,
arch_priv, &val, arch_mon_ctx)) {
rmid_dirty = true;
} else {
@@ -192,7 +192,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
cur_idx = idx + 1;
}
- resctrl_arch_mon_ctx_free(r, QOS_L3_OCCUP_EVENT_ID, arch_mon_ctx);
+ resctrl_arch_mon_ctx_free(r, QOS_OCCUP_EVENT_ID, arch_mon_ctx);
}
bool has_busy_rmid(struct rdt_l3_mon_domain *d)
@@ -345,7 +345,7 @@ void free_rmid(u32 closid, u32 rmid)
entry = __rmid_entry(idx);
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
add_rmid_to_limbo(entry);
else
list_add_tail(&entry->list, &rmid_free_lru);
@@ -801,11 +801,11 @@ 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);
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ mbm_update_one_event(r, d, rdtgrp, QOS_MBM_TOTAL_EVENT_ID);
- 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);
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ mbm_update_one_event(r, d, rdtgrp, QOS_MBM_LOCAL_EVENT_ID);
}
/*
@@ -1029,9 +1029,9 @@ void free_rmid_lru_list(void)
* to set .enabled.
*/
struct mon_evt mon_event_all[QOS_NUM_EVENTS] = {
- MON_EVENT(QOS_L3_OCCUP_EVENT_ID, "llc_occupancy", RDT_RESOURCE_L3, false),
- MON_EVENT(QOS_L3_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", RDT_RESOURCE_L3, false),
- MON_EVENT(QOS_L3_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", RDT_RESOURCE_L3, false),
+ MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", RDT_RESOURCE_L3, false),
+ MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", RDT_RESOURCE_L3, false),
+ MON_EVENT(QOS_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", RDT_RESOURCE_L3, false),
MON_EVENT(PMT_EVENT_ENERGY, "core_energy", RDT_RESOURCE_PERF_PKG, true),
MON_EVENT(PMT_EVENT_ACTIVITY, "activity", RDT_RESOURCE_PERF_PKG, true),
MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", RDT_RESOURCE_PERF_PKG, false),
@@ -1319,13 +1319,13 @@ void rdtgroup_assign_cntrs(struct rdtgroup *rdtgrp)
!r->mon.mbm_assign_on_mkdir)
return;
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]);
+ &mon_event_all[QOS_MBM_TOTAL_EVENT_ID]);
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]);
+ &mon_event_all[QOS_MBM_LOCAL_EVENT_ID]);
}
/*
@@ -1377,13 +1377,13 @@ void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp)
if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
return;
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]);
+ &mon_event_all[QOS_MBM_TOTAL_EVENT_ID]);
- if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]);
+ &mon_event_all[QOS_MBM_LOCAL_EVENT_ID]);
}
static int resctrl_parse_mem_transactions(char *tok, u32 *val)
@@ -1594,10 +1594,10 @@ 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 &
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ mon_event_all[QOS_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ mon_event_all[QOS_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);
@@ -1936,27 +1936,27 @@ int resctrl_l3_mon_resource_init(void)
if (ret)
return ret;
- if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) {
- mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable = true;
+ if (resctrl_arch_is_evt_configurable(QOS_MBM_TOTAL_EVENT_ID)) {
+ mon_event_all[QOS_MBM_TOTAL_EVENT_ID].configurable = true;
resctrl_file_fflags_init("mbm_total_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
- if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_LOCAL_EVENT_ID)) {
- mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].configurable = true;
+ if (resctrl_arch_is_evt_configurable(QOS_MBM_LOCAL_EVENT_ID)) {
+ mon_event_all[QOS_MBM_LOCAL_EVENT_ID].configurable = true;
resctrl_file_fflags_init("mbm_local_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
- 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_L3_MBM_TOTAL_EVENT_ID))
- mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ mba_mbps_default_event = QOS_MBM_LOCAL_EVENT_ID;
+ else if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ mba_mbps_default_event = QOS_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 &
+ if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ mon_event_all[QOS_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ mon_event_all[QOS_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);
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 57ab090072c2..92f0e3b68784 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -124,8 +124,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));
+ return (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID) ||
+ resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID));
}
/*
@@ -191,7 +191,7 @@ static int closid_alloc(void)
lockdep_assert_held(&rdtgroup_mutex);
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
- resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) {
+ resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID)) {
cleanest_closid = resctrl_find_cleanest_closid();
if (cleanest_closid < 0)
return cleanest_closid;
@@ -1755,7 +1755,7 @@ static int mbm_total_bytes_config_show(struct kernfs_open_file *of,
if (!info_kn_lock(of->kn))
return -ENOENT;
- mbm_config_show(seq, r, QOS_L3_MBM_TOTAL_EVENT_ID);
+ mbm_config_show(seq, r, QOS_MBM_TOTAL_EVENT_ID);
info_kn_unlock(of->kn);
return 0;
@@ -1769,7 +1769,7 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,
if (!info_kn_lock(of->kn))
return -ENOENT;
- mbm_config_show(seq, r, QOS_L3_MBM_LOCAL_EVENT_ID);
+ mbm_config_show(seq, r, QOS_MBM_LOCAL_EVENT_ID);
info_kn_unlock(of->kn);
return 0;
@@ -1879,7 +1879,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, QOS_MBM_TOTAL_EVENT_ID);
out_unlock:
info_kn_unlock(of->kn);
@@ -1908,7 +1908,7 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
buf[nbytes - 1] = '\0';
- ret = mon_config_write(r, buf, QOS_L3_MBM_LOCAL_EVENT_ID);
+ ret = mon_config_write(r, buf, QOS_MBM_LOCAL_EVENT_ID);
out_unlock:
info_kn_unlock(of->kn);
@@ -4561,7 +4561,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
if (resctrl_is_mbm_enabled())
cancel_delayed_work_sync(&d->mbm_over);
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
cancel_delayed_work_sync(&d->cqm_limbo);
}
@@ -4581,7 +4581,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
goto out_unlock;
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
/*
* When a package is going down, forcefully
* decrement rmid->ebusy. There is no way to know
@@ -4624,7 +4624,7 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
enum resctrl_event_id eventid;
int idx;
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) {
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID)) {
d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
if (!d->rmid_busy_llc)
return -ENOMEM;
@@ -4697,7 +4697,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
RESCTRL_PICK_ANY_CPU);
}
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
mkdir:
@@ -4776,7 +4776,7 @@ void resctrl_offline_cpu(unsigned int cpu)
mutex_lock(&rdtgroup_mutex);
mbm_setup_overflow_handler(d, 0, cpu);
}
- if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) &&
+ if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID) &&
cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
mutex_unlock(&rdtgroup_mutex);
cancel_delayed_work_sync(&d->cqm_limbo);
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 10dfdca7f4bf..c844f99fb824 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -198,7 +198,7 @@ struct rdt_l3_mon_domain {
struct rdt_domain_hdr hdr;
unsigned int ci_id;
unsigned long *rmid_busy_llc;
- struct mbm_state *mbm_states[QOS_NUM_L3_MBM_EVENTS];
+ struct mbm_state *mbm_states[QOS_NUM_MBM_EVENTS];
struct delayed_work mbm_over;
struct delayed_work cqm_limbo;
int mbm_work_cpu;
@@ -428,20 +428,20 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid)
{
- return (eventid >= QOS_L3_MBM_TOTAL_EVENT_ID &&
- eventid <= QOS_L3_MBM_LOCAL_EVENT_ID);
+ return (eventid >= QOS_MBM_TOTAL_EVENT_ID &&
+ eventid <= QOS_MBM_LOCAL_EVENT_ID);
}
u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid);
/* Iterate over all memory bandwidth events */
#define for_each_mbm_event_id(eventid) \
- for (eventid = QOS_L3_MBM_TOTAL_EVENT_ID; \
- eventid <= QOS_L3_MBM_LOCAL_EVENT_ID; eventid++)
+ for (eventid = QOS_MBM_TOTAL_EVENT_ID; \
+ eventid <= QOS_MBM_LOCAL_EVENT_ID; eventid++)
/* Iterate over memory bandwidth arrays in domain structures */
#define for_each_mbm_idx(idx) \
- for (idx = 0; idx < QOS_NUM_L3_MBM_EVENTS; idx++)
+ for (idx = 0; idx < QOS_NUM_MBM_EVENTS; idx++)
/**
* resctrl_arch_mon_event_config_write() - Write the config for an event.
@@ -650,8 +650,8 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);
* and event details.
* @r: Resource structure.
* @d: The domain in which counter with ID @cntr_id should be configured.
- * @evtid: Monitoring event type (e.g., QOS_L3_MBM_TOTAL_EVENT_ID
- * or QOS_L3_MBM_LOCAL_EVENT_ID).
+ * @evtid: Monitoring event type (e.g., QOS_MBM_TOTAL_EVENT_ID
+ * or QOS_MBM_LOCAL_EVENT_ID).
* @rmid: RMID.
* @closid: CLOSID.
* @cntr_id: Counter ID to configure.
diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h
index e2e2cf3d9ff6..8679cbe589ec 100644
--- a/include/linux/resctrl_types.h
+++ b/include/linux/resctrl_types.h
@@ -43,12 +43,13 @@ enum resctrl_event_id {
QOS_FIRST_EVENT = 0x01,
/*
- * These values match those used to program IA32_QM_EVTSEL before
- * reading IA32_QM_CTR on RDT systems.
+ * Monitor event types. The resource an event belongs to is tracked
+ * separately. These values match those used to program IA32_QM_EVTSEL
+ * before reading IA32_QM_CTR on RDT systems.
*/
- QOS_L3_OCCUP_EVENT_ID = 0x01,
- QOS_L3_MBM_TOTAL_EVENT_ID = 0x02,
- QOS_L3_MBM_LOCAL_EVENT_ID = 0x03,
+ QOS_OCCUP_EVENT_ID = 0x01,
+ QOS_MBM_TOTAL_EVENT_ID = 0x02,
+ QOS_MBM_LOCAL_EVENT_ID = 0x03,
/* Intel Telemetry Events */
PMT_EVENT_ENERGY,
@@ -67,7 +68,13 @@ enum resctrl_event_id {
QOS_NUM_EVENTS,
};
-#define QOS_NUM_L3_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTAL_EVENT_ID + 1)
-#define MBM_STATE_IDX(evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID)
+#define QOS_NUM_MBM_EVENTS (QOS_MBM_LOCAL_EVENT_ID - QOS_MBM_TOTAL_EVENT_ID + 1)
+#define MBM_STATE_IDX(evt) ((evt) - QOS_MBM_TOTAL_EVENT_ID)
+
+/* Old names, kept until every architecture has been converted. */
+#define QOS_L3_OCCUP_EVENT_ID QOS_OCCUP_EVENT_ID
+#define QOS_L3_MBM_TOTAL_EVENT_ID QOS_MBM_TOTAL_EVENT_ID
+#define QOS_L3_MBM_LOCAL_EVENT_ID QOS_MBM_LOCAL_EVENT_ID
+#define QOS_NUM_L3_MBM_EVENTS QOS_NUM_MBM_EVENTS
#endif /* __LINUX_RESCTRL_TYPES_H */
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 02/19] x86/resctrl: Use the resource-agnostic monitor event names
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 01/19] fs/resctrl: Rename monitor events to drop the L3 prefix Jinjie Ruan
@ 2026-11-16 12:58 ` Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 03/19] arm_mpam: resctrl: " Jinjie Ruan
` (17 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:58 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
The monitor event IDs no longer carry L3 in their names. Switch x86 over
to the new names. The values are unchanged, so this does not change what
is written to IA32_QM_EVTSEL.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/cpu/resctrl/core.c | 10 +++++-----
arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++----
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index bd9e4cf9f7cb..fab126ae2eba 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -886,9 +886,9 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt)
return false;
switch (evt) {
- case QOS_L3_MBM_TOTAL_EVENT_ID:
+ case QOS_MBM_TOTAL_EVENT_ID:
return rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL);
- case QOS_L3_MBM_LOCAL_EVENT_ID:
+ case QOS_MBM_LOCAL_EVENT_ID:
return rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL);
default:
return false;
@@ -968,15 +968,15 @@ static __init bool get_rdt_mon_resources(void)
bool ret = false;
if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) {
- resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(QOS_OCCUP_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
- resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(QOS_MBM_TOTAL_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
- resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(QOS_MBM_LOCAL_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_ABMC))
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index ffd74a68671b..57563c35d158 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -77,7 +77,7 @@ struct rdt_hw_ctrl_domain {
*/
struct rdt_hw_l3_mon_domain {
struct rdt_l3_mon_domain d_resctrl;
- struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS];
+ struct arch_mbm_state *arch_mbm_states[QOS_NUM_MBM_EVENTS];
};
static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct rdt_ctrl_domain *r)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 5ffa39fa86fa..825d71b14b4f 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -68,16 +68,16 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info)
* configurable event
* @evtid: event id.
*
- * Return: 0 for evtid == QOS_L3_MBM_TOTAL_EVENT_ID
- * 1 for evtid == QOS_L3_MBM_LOCAL_EVENT_ID
+ * Return: 0 for evtid == QOS_MBM_TOTAL_EVENT_ID
+ * 1 for evtid == QOS_MBM_LOCAL_EVENT_ID
* INVALID_CONFIG_INDEX for invalid evtid
*/
static inline unsigned int mon_event_config_index_get(u32 evtid)
{
switch (evtid) {
- case QOS_L3_MBM_TOTAL_EVENT_ID:
+ case QOS_MBM_TOTAL_EVENT_ID:
return 0;
- case QOS_L3_MBM_LOCAL_EVENT_ID:
+ case QOS_MBM_LOCAL_EVENT_ID:
return 1;
default:
/* Should never reach here */
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 03/19] arm_mpam: resctrl: Use the resource-agnostic monitor event names
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 01/19] fs/resctrl: Rename monitor events to drop the L3 prefix Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 02/19] x86/resctrl: Use the resource-agnostic monitor event names Jinjie Ruan
@ 2026-11-16 12:58 ` Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 04/19] resctrl: Remove the L3 " Jinjie Ruan
` (16 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:58 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
The monitor event IDs no longer carry L3 in their names. Switch
the MPAM driver over to the new names.
No functional change intended.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 5468367776e2..a31c36c302d8 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -45,7 +45,7 @@ static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
* to those supported by MPAM.
* Class pointer may be NULL.
*/
-#define MPAM_MAX_EVENT QOS_L3_MBM_TOTAL_EVENT_ID
+#define MPAM_MAX_EVENT QOS_MBM_TOTAL_EVENT_ID
static struct mpam_resctrl_mon mpam_resctrl_counters[MPAM_MAX_EVENT + 1];
#define for_each_mpam_resctrl_mon(mon, eventid) \
@@ -173,7 +173,7 @@ static void resctrl_reset_task_closids(void)
static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[QOS_L3_MBM_TOTAL_EVENT_ID];
+ struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[QOS_MBM_TOTAL_EVENT_ID];
if (!mon->class)
return;
@@ -388,11 +388,11 @@ static int resctrl_arch_mon_ctx_alloc_no_wait(enum resctrl_event_id evtid)
return -EINVAL;
switch (evtid) {
- case QOS_L3_OCCUP_EVENT_ID:
+ case QOS_OCCUP_EVENT_ID:
/* With CDP, one monitor gets used for both code/data reads */
return mpam_alloc_csu_mon(mon->class);
- case QOS_L3_MBM_LOCAL_EVENT_ID:
- case QOS_L3_MBM_TOTAL_EVENT_ID:
+ case QOS_MBM_LOCAL_EVENT_ID:
+ case QOS_MBM_TOTAL_EVENT_ID:
return USE_PRE_ALLOCATED;
default:
return -EOPNOTSUPP;
@@ -432,7 +432,7 @@ static void resctrl_arch_mon_ctx_free_no_wait(enum resctrl_event_id evtid,
if (!mon->class)
return;
- if (evtid == QOS_L3_OCCUP_EVENT_ID)
+ if (evtid == QOS_OCCUP_EVENT_ID)
mpam_free_csu_mon(mon->class, mon_idx);
wake_up(&resctrl_mon_ctx_waiters);
@@ -532,7 +532,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
l3_dom = container_of(hdr, struct mpam_resctrl_dom, resctrl_mon_dom.hdr);
mon_comp = l3_dom->mon_comp[eventid];
- if (eventid != QOS_L3_OCCUP_EVENT_ID)
+ if (eventid != QOS_OCCUP_EVENT_ID)
return -EINVAL;
mon_type = mpam_feat_msmon_csu;
@@ -553,7 +553,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
if (!mpam_is_enabled())
return -EINVAL;
- if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+ if (eventid == QOS_OCCUP_EVENT_ID || !mon->class)
return -EINVAL;
l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
@@ -610,7 +610,7 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
if (!mpam_is_enabled())
return;
- if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+ if (eventid == QOS_OCCUP_EVENT_ID || !mon->class)
return;
l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
@@ -1127,7 +1127,7 @@ static void mpam_resctrl_pick_counters(void)
if (update_rmid_limits(class))
break;
- counter_update_class(QOS_L3_OCCUP_EVENT_ID, class);
+ counter_update_class(QOS_OCCUP_EVENT_ID, class);
break;
default:
break;
@@ -1149,7 +1149,7 @@ static void mpam_resctrl_pick_counters(void)
* and it's equivalent to mbm_total and so always use
* mbm_total.
*/
- counter_update_class(QOS_L3_MBM_TOTAL_EVENT_ID, class);
+ counter_update_class(QOS_MBM_TOTAL_EVENT_ID, class);
}
}
}
@@ -1176,7 +1176,7 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *
{
struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
- if (evtid != QOS_L3_MBM_TOTAL_EVENT_ID) {
+ if (evtid != QOS_MBM_TOTAL_EVENT_ID) {
pr_debug("unexpected event id\n");
return;
}
@@ -1193,7 +1193,7 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *
__config_cntr(mon, cntr_id, CDP_NONE, closid, rmid, assign);
}
- resctrl_arch_reset_cntr(r, d, closid, rmid, cntr_id, QOS_L3_MBM_TOTAL_EVENT_ID);
+ resctrl_arch_reset_cntr(r, d, closid, rmid, cntr_id, QOS_MBM_TOTAL_EVENT_ID);
}
static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
@@ -1354,7 +1354,7 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
*/
l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
- if (type == QOS_L3_MBM_TOTAL_EVENT_ID) {
+ if (type == QOS_MBM_TOTAL_EVENT_ID) {
int err;
err = mpam_resctrl_monitor_init_abmc(mon);
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 04/19] resctrl: Remove the L3 monitor event names
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (2 preceding siblings ...)
2026-11-16 12:58 ` [RFC PATCH v3 03/19] arm_mpam: resctrl: " Jinjie Ruan
@ 2026-11-16 12:58 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 05/19] arm_mpam: resctrl: Index monitor state by resource and event Jinjie Ruan
` (15 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:58 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Every user has moved to the resource-agnostic monitor
event names. So remove the old ones.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
include/linux/resctrl_types.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h
index 8679cbe589ec..d0e56de038f0 100644
--- a/include/linux/resctrl_types.h
+++ b/include/linux/resctrl_types.h
@@ -71,10 +71,4 @@ enum resctrl_event_id {
#define QOS_NUM_MBM_EVENTS (QOS_MBM_LOCAL_EVENT_ID - QOS_MBM_TOTAL_EVENT_ID + 1)
#define MBM_STATE_IDX(evt) ((evt) - QOS_MBM_TOTAL_EVENT_ID)
-/* Old names, kept until every architecture has been converted. */
-#define QOS_L3_OCCUP_EVENT_ID QOS_OCCUP_EVENT_ID
-#define QOS_L3_MBM_TOTAL_EVENT_ID QOS_MBM_TOTAL_EVENT_ID
-#define QOS_L3_MBM_LOCAL_EVENT_ID QOS_MBM_LOCAL_EVENT_ID
-#define QOS_NUM_L3_MBM_EVENTS QOS_NUM_MBM_EVENTS
-
#endif /* __LINUX_RESCTRL_TYPES_H */
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 05/19] arm_mpam: resctrl: Index monitor state by resource and event
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (3 preceding siblings ...)
2026-11-16 12:58 ` [RFC PATCH v3 04/19] resctrl: Remove the L3 " Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 06/19] x86,fs/resctrl: Record the resource that enables a monitor event Jinjie Ruan
` (14 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Currently, the picked monitor class and assignable counter state are
stored in an array indexed solely by event ID, and every monitor
domain's component array is populated with all events.
Since the monitor class implementing an event is a property of the
resource rather than the display scope, index the array by both
resource and event, and populate each domain using only the events
belonging to its resource.
Also replace the MPAM_MAX_EVENT bound with QOS_NUM_EVENTS to prevent
out-of-bounds array indexing by event ID.
This is done in preparation for L2 support.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 146 ++++++++++++++++++---------------
1 file changed, 82 insertions(+), 64 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index a31c36c302d8..385c54604872 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -37,21 +37,30 @@ static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
rid++, res = &mpam_resctrl_controls[rid])
/*
- * The classes we've picked to map to resctrl events.
- * Resctrl believes all the worlds a Xeon, and these are all on the L3. This
- * array lets us find the actual class backing the event counters. e.g.
+ * The classes we've picked to map to resctrl events, for each resource.
+ * This array lets us find the actual class backing the event counters. e.g.
* the only memory bandwidth counters may be on the memory controller, but to
- * make use of them, we pretend they are on L3. Restrict the events considered
- * to those supported by MPAM.
+ * make use of them, we pretend they are on L3.
* Class pointer may be NULL.
*/
-#define MPAM_MAX_EVENT QOS_MBM_TOTAL_EVENT_ID
-static struct mpam_resctrl_mon mpam_resctrl_counters[MPAM_MAX_EVENT + 1];
+static struct mpam_resctrl_mon mpam_resctrl_counters[RDT_NUM_RESOURCES][QOS_NUM_EVENTS];
-#define for_each_mpam_resctrl_mon(mon, eventid) \
- for (eventid = QOS_FIRST_EVENT, mon = &mpam_resctrl_counters[eventid]; \
- eventid <= MPAM_MAX_EVENT; \
- eventid++, mon = &mpam_resctrl_counters[eventid])
+static struct mpam_resctrl_mon *
+mpam_resctrl_mon_by_rid(enum resctrl_res_level rid, enum resctrl_event_id evtid)
+{
+ return &mpam_resctrl_counters[rid][evtid];
+}
+
+static struct mpam_resctrl_mon *
+mpam_resctrl_mon(struct rdt_resource *r, enum resctrl_event_id evtid)
+{
+ return mpam_resctrl_mon_by_rid(r->rid, evtid);
+}
+
+#define for_each_mpam_resctrl_mon(mon, r, eventid) \
+ for (eventid = QOS_FIRST_EVENT, mon = mpam_resctrl_mon(r, eventid); \
+ eventid < QOS_NUM_EVENTS; \
+ eventid++, mon = mpam_resctrl_mon(r, eventid))
/* The lock for modifying resctrl's domain lists from cpuhp callbacks. */
static DEFINE_MUTEX(domain_list_lock);
@@ -171,9 +180,9 @@ static void resctrl_reset_task_closids(void)
read_unlock(&tasklist_lock);
}
-static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3)
+static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *r)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[QOS_MBM_TOTAL_EVENT_ID];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, QOS_MBM_TOTAL_EVENT_ID);
if (!mon->class)
return;
@@ -181,9 +190,9 @@ static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3)
if (!mon->assigned_counters)
return;
- l3->mon.num_mbm_cntrs = mon->class->props.num_mbwu_mon;
+ r->mon.num_mbm_cntrs = mon->class->props.num_mbwu_mon;
if (cdp_enabled)
- l3->mon.num_mbm_cntrs /= 2;
+ r->mon.num_mbm_cntrs /= 2;
/*
* Continue as normal even if enabling cdp causes there to be
@@ -377,9 +386,10 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
return &mpam_resctrl_controls[l].resctrl_res;
}
-static int resctrl_arch_mon_ctx_alloc_no_wait(enum resctrl_event_id evtid)
+static int resctrl_arch_mon_ctx_alloc_no_wait(struct rdt_resource *r,
+ enum resctrl_event_id evtid)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, evtid);
if (!mpam_is_enabled())
return -EINVAL;
@@ -412,7 +422,7 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
do {
prepare_to_wait(&resctrl_mon_ctx_waiters, &wait,
TASK_INTERRUPTIBLE);
- *ret = resctrl_arch_mon_ctx_alloc_no_wait(evtid);
+ *ret = resctrl_arch_mon_ctx_alloc_no_wait(r, evtid);
if (*ret == -ENOSPC)
schedule();
} while (*ret == -ENOSPC && !signal_pending(current));
@@ -421,10 +431,11 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
return ret;
}
-static void resctrl_arch_mon_ctx_free_no_wait(enum resctrl_event_id evtid,
+static void resctrl_arch_mon_ctx_free_no_wait(struct rdt_resource *r,
+ enum resctrl_event_id evtid,
u32 mon_idx)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, evtid);
if (!mpam_is_enabled())
return;
@@ -445,7 +456,7 @@ void resctrl_arch_mon_ctx_free(struct rdt_resource *r,
kfree(arch_mon_ctx);
- resctrl_arch_mon_ctx_free_no_wait(evtid, mon_idx);
+ resctrl_arch_mon_ctx_free_no_wait(r, evtid, mon_idx);
}
static int __read_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
@@ -519,7 +530,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
struct mpam_component *mon_comp;
u32 mon_idx = *(u32 *)arch_mon_ctx;
enum mpam_device_features mon_type;
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, eventid);
resctrl_arch_rmid_read_context_check();
@@ -546,7 +557,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
u32 closid, u32 rmid, int mon_idx,
enum resctrl_event_id eventid, u64 *val)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, eventid);
struct mpam_resctrl_dom *l3_dom;
struct mpam_component *mon_comp;
@@ -603,7 +614,7 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
u32 closid, u32 rmid, int cntr_id,
enum resctrl_event_id eventid)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, eventid);
struct mpam_resctrl_dom *l3_dom;
struct mpam_component *mon_comp;
@@ -1075,10 +1086,11 @@ static int *__alloc_mbwu_array(struct mpam_class *class, u16 num_mbwu_mon)
return_ptr(array);
}
-static void counter_update_class(enum resctrl_event_id evt_id,
+static void counter_update_class(enum resctrl_res_level rid,
+ enum resctrl_event_id evt_id,
struct mpam_class *class)
{
- struct mpam_class *existing_class = mpam_resctrl_counters[evt_id].class;
+ struct mpam_class *existing_class = mpam_resctrl_mon_by_rid(rid, evt_id)->class;
if (existing_class) {
if (existing_class->level == 3) {
@@ -1093,7 +1105,7 @@ static void counter_update_class(enum resctrl_event_id evt_id,
}
}
- mpam_resctrl_counters[evt_id].class = class;
+ mpam_resctrl_mon_by_rid(rid, evt_id)->class = class;
}
static void mpam_resctrl_pick_counters(void)
@@ -1127,7 +1139,7 @@ static void mpam_resctrl_pick_counters(void)
if (update_rmid_limits(class))
break;
- counter_update_class(QOS_OCCUP_EVENT_ID, class);
+ counter_update_class(RDT_RESOURCE_L3, QOS_OCCUP_EVENT_ID, class);
break;
default:
break;
@@ -1149,7 +1161,7 @@ static void mpam_resctrl_pick_counters(void)
* and it's equivalent to mbm_total and so always use
* mbm_total.
*/
- counter_update_class(QOS_MBM_TOTAL_EVENT_ID, class);
+ counter_update_class(RDT_RESOURCE_L3, QOS_MBM_TOTAL_EVENT_ID, class);
}
}
}
@@ -1174,7 +1186,7 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *
enum resctrl_event_id evtid, u32 rmid, u32 closid,
u32 cntr_id, bool assign)
{
- struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, evtid);
if (evtid != QOS_MBM_TOTAL_EVENT_ID) {
pr_debug("unexpected event id\n");
@@ -1277,11 +1289,10 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
* This must run after all event counters have been picked so that any free
* running counters have already been allocated.
*/
-static int mpam_resctrl_monitor_init_abmc(struct mpam_resctrl_mon *mon)
+static int mpam_resctrl_monitor_init_abmc(struct rdt_resource *r,
+ struct mpam_resctrl_mon *mon)
{
- struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
size_t num_rmid = resctrl_arch_system_num_rmid_idx();
- struct rdt_resource *l3 = &res->resctrl_res;
struct mpam_class *class = mon->class;
u16 num_mbwu_mon;
int *cntrs;
@@ -1300,21 +1311,22 @@ static int mpam_resctrl_monitor_init_abmc(struct mpam_resctrl_mon *mon)
mon->assigned_counters = cntrs;
mon->mbwu_idx_to_mon = no_free_ptr(rmid_array);
- l3->mon.mbm_cntr_assignable = true;
- l3->mon.mbm_assign_on_mkdir = true;
- l3->mon.mbm_cntr_configurable = false;
- l3->mon.mbm_cntr_assign_fixed = true;
+ r->mon.mbm_cntr_assignable = true;
+ r->mon.mbm_assign_on_mkdir = true;
+ r->mon.mbm_cntr_configurable = false;
+ r->mon.mbm_cntr_assign_fixed = true;
- mpam_resctrl_monitor_sync_abmc_vals(l3);
+ mpam_resctrl_monitor_sync_abmc_vals(r);
return 0;
}
-static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
+static int mpam_resctrl_monitor_init(struct rdt_resource *r,
enum resctrl_event_id type)
{
- struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
- struct rdt_resource *l3 = &res->resctrl_res;
+ struct mpam_resctrl_res *res = container_of(r, struct mpam_resctrl_res,
+ resctrl_res);
+ struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, type);
lockdep_assert_cpus_held();
@@ -1333,7 +1345,7 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
*/
if (!res->class) {
pr_warn_once("Faking L3 MSC to enable counters.\n");
- res->class = mpam_resctrl_counters[type].class;
+ res->class = mon->class;
}
/*
@@ -1341,8 +1353,8 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
* monitoring class.
* Setting name is necessary on monitor only platforms.
*/
- l3->name = "L3";
- l3->mon_scope = RESCTRL_L3_CACHE;
+ r->name = "L3";
+ r->mon_scope = RESCTRL_L3_CACHE;
/*
* num-rmid is the upper bound for the number of monitoring groups that
@@ -1352,23 +1364,23 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
* this does mean userspace needs to know the architecture to correctly
* interpret this value.
*/
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
+ r->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
if (type == QOS_MBM_TOTAL_EVENT_ID) {
int err;
- err = mpam_resctrl_monitor_init_abmc(mon);
+ err = mpam_resctrl_monitor_init_abmc(r, mon);
if (err)
return err;
static_assert(MAX_EVT_CONFIG_BITS == 0x7f);
- l3->mon.mbm_cfg_mask = MAX_EVT_CONFIG_BITS;
+ r->mon.mbm_cfg_mask = MAX_EVT_CONFIG_BITS;
}
if (!resctrl_enable_mon_event(type, false, 0, NULL))
return -EINVAL;
- l3->mon_capable = true;
+ r->mon_capable = true;
return 0;
}
@@ -1679,7 +1691,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
* overlapping CPUs and set up the dom->mon_comp array.
*/
- for_each_mpam_resctrl_mon(mon, eventid) {
+ for_each_mpam_resctrl_mon(mon, r, eventid) {
struct mpam_component *mon_comp;
if (!mon->class)
@@ -1855,11 +1867,12 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
int mpam_resctrl_setup(void)
{
- int err = 0;
+ enum resctrl_event_id eventid;
struct mpam_resctrl_res *res;
- enum resctrl_res_level rid;
struct mpam_resctrl_mon *mon;
- enum resctrl_event_id eventid;
+ enum resctrl_res_level rid;
+ struct rdt_resource *r;
+ int err = 0;
wait_event(wait_cacheinfo_ready, cacheinfo_ready);
@@ -1889,14 +1902,16 @@ int mpam_resctrl_setup(void)
/* Find some classes to use for monitors */
mpam_resctrl_pick_counters();
- for_each_mpam_resctrl_mon(mon, eventid) {
- if (!mon->class)
- continue; // dummy resource
+ for_each_rdt_resource(r) {
+ for_each_mpam_resctrl_mon(mon, r, eventid) {
+ if (!mon->class)
+ continue; // dummy resource
- err = mpam_resctrl_monitor_init(mon, eventid);
- if (err) {
- pr_debug("Failed to initialise event %u\n", eventid);
- goto internal_error;
+ err = mpam_resctrl_monitor_init(r, eventid);
+ if (err) {
+ pr_debug("Failed to initialise event %u\n", eventid);
+ goto internal_error;
+ }
}
}
@@ -1950,10 +1965,11 @@ static void mpam_resctrl_teardown_mon(struct mpam_resctrl_mon *mon, struct mpam_
void mpam_resctrl_teardown_class(struct mpam_class *class)
{
+ enum resctrl_event_id eventid;
+ struct mpam_resctrl_mon *mon;
struct mpam_resctrl_res *res;
enum resctrl_res_level rid;
- struct mpam_resctrl_mon *mon;
- enum resctrl_event_id eventid;
+ struct rdt_resource *r;
might_sleep();
@@ -1961,10 +1977,12 @@ void mpam_resctrl_teardown_class(struct mpam_class *class)
if (res->class == class)
res->class = NULL;
}
- for_each_mpam_resctrl_mon(mon, eventid) {
- if (mon->class == class) {
- mon->class = NULL;
+ for_each_rdt_resource(r) {
+ for_each_mpam_resctrl_mon(mon, r, eventid) {
+ if (mon->class != class)
+ continue;
+ mon->class = NULL;
mpam_resctrl_teardown_mon(mon, class);
}
}
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 06/19] x86,fs/resctrl: Record the resource that enables a monitor event
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (4 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 05/19] arm_mpam: resctrl: Index monitor state by resource and event Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 07/19] x86,fs/resctrl: Track monitor events by scope Jinjie Ruan
` (13 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
mon_evt::rid is initialised from a static table that guesses which
resource each event belongs to. The architecture enabling the event
knows the answer, so pass the resource to resctrl_enable_mon_event()
and record it in mon_evt::rid.
Every architecture records the value the table guessed, so this does
not change which events are shown where.
No functional change intended.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/cpu/resctrl/core.c | 6 +--
arch/x86/kernel/cpu/resctrl/intel_aet.c | 2 +-
drivers/resctrl/mpam_resctrl.c | 2 +-
fs/resctrl/internal.h | 3 +-
fs/resctrl/monitor.c | 54 ++++++++++++++-----------
include/linux/resctrl.h | 3 +-
6 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index fab126ae2eba..707fa4e7ed24 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -968,15 +968,15 @@ static __init bool get_rdt_mon_resources(void)
bool ret = false;
if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) {
- resctrl_enable_mon_event(QOS_OCCUP_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(r, QOS_OCCUP_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
- resctrl_enable_mon_event(QOS_MBM_TOTAL_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(r, QOS_MBM_TOTAL_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
- resctrl_enable_mon_event(QOS_MBM_LOCAL_EVENT_ID, false, 0, NULL);
+ resctrl_enable_mon_event(r, QOS_MBM_LOCAL_EVENT_ID, false, 0, NULL);
ret = true;
}
if (rdt_cpu_has(X86_FEATURE_ABMC))
diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
index 66cd8c2c7a51..a5978019a48c 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
@@ -290,7 +290,7 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)
}
for (int j = 0; j < e->num_events; j++) {
- if (!resctrl_enable_mon_event(e->evts[j].id, true,
+ if (!resctrl_enable_mon_event(r, e->evts[j].id, true,
e->evts[j].bin_bits, &e->evts[j]))
skipped_events++;
}
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 385c54604872..961210af3159 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1377,7 +1377,7 @@ static int mpam_resctrl_monitor_init(struct rdt_resource *r,
r->mon.mbm_cfg_mask = MAX_EVT_CONFIG_BITS;
}
- if (!resctrl_enable_mon_event(type, false, 0, NULL))
+ if (!resctrl_enable_mon_event(r, type, false, 0, NULL))
return -EINVAL;
r->mon_capable = true;
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index e62a277dee85..f7815e4fb53e 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -54,7 +54,8 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
/**
* struct mon_evt - Properties of a monitor event
* @evtid: event id
- * @rid: resource id for this event
+ * @rid: resource that implements this event, recorded by the
+ * architecture when it enables the event
* @name: name of the event
* @evt_cfg: Event configuration value that represents the
* memory transactions (e.g., READS_TO_LOCAL_MEM,
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 1b0fb3c2aaee..23c1838a7661 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1015,11 +1015,10 @@ void free_rmid_lru_list(void)
mutex_unlock(&rdtgroup_mutex);
}
-#define MON_EVENT(_eventid, _name, _res, _fp) \
+#define MON_EVENT(_eventid, _name, _fp) \
[_eventid] = { \
.name = _name, \
.evtid = _eventid, \
- .rid = _res, \
.is_floating_point = _fp, \
}
@@ -1029,41 +1028,48 @@ void free_rmid_lru_list(void)
* to set .enabled.
*/
struct mon_evt mon_event_all[QOS_NUM_EVENTS] = {
- MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", RDT_RESOURCE_L3, false),
- MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", RDT_RESOURCE_L3, false),
- MON_EVENT(QOS_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", RDT_RESOURCE_L3, false),
- MON_EVENT(PMT_EVENT_ENERGY, "core_energy", RDT_RESOURCE_PERF_PKG, true),
- MON_EVENT(PMT_EVENT_ACTIVITY, "activity", RDT_RESOURCE_PERF_PKG, true),
- MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_C1_RES, "c1_res", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_UNHALTED_CORE_CYCLES, "unhalted_core_cycles", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_STALLS_LLC_MISS, "stalls_llc_miss", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_AUTO_C6_RES, "c6_res", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_UNHALTED_REF_CYCLES, "unhalted_ref_cycles", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_INST_RETIRED, "inst_retired", RDT_RESOURCE_PERF_PKG, false),
- MON_EVENT(PMT_EVENT_PCNT, "pcnt", RDT_RESOURCE_PERF_PKG, false),
+ MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", false),
+ MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", false),
+ MON_EVENT(QOS_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", false),
+ MON_EVENT(PMT_EVENT_ENERGY, "core_energy", true),
+ MON_EVENT(PMT_EVENT_ACTIVITY, "activity", true),
+ MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", false),
+ MON_EVENT(PMT_EVENT_C1_RES, "c1_res", false),
+ MON_EVENT(PMT_EVENT_UNHALTED_CORE_CYCLES, "unhalted_core_cycles", false),
+ MON_EVENT(PMT_EVENT_STALLS_LLC_MISS, "stalls_llc_miss", false),
+ MON_EVENT(PMT_EVENT_AUTO_C6_RES, "c6_res", false),
+ MON_EVENT(PMT_EVENT_UNHALTED_REF_CYCLES, "unhalted_ref_cycles", false),
+ MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", false),
+ MON_EVENT(PMT_EVENT_INST_RETIRED, "inst_retired", false),
+ MON_EVENT(PMT_EVENT_PCNT, "pcnt", false),
};
-bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
+bool resctrl_enable_mon_event(struct rdt_resource *r,
+ enum resctrl_event_id eventid, bool any_cpu,
unsigned int binary_bits, void *arch_priv)
{
+ struct mon_evt *mevt;
+
if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >= QOS_NUM_EVENTS ||
binary_bits > MAX_BINARY_BITS))
return false;
- if (mon_event_all[eventid].enabled) {
- pr_warn("Duplicate enable for event %d\n", eventid);
+
+ mevt = &mon_event_all[eventid];
+ if (mevt->enabled) {
+ pr_warn("Duplicate enable for event %d on resource %d\n",
+ eventid, r->rid);
return false;
}
- if (binary_bits && !mon_event_all[eventid].is_floating_point) {
+ if (binary_bits && !mevt->is_floating_point) {
pr_warn("Event %d may not be floating point\n", eventid);
return false;
}
- mon_event_all[eventid].any_cpu = any_cpu;
- mon_event_all[eventid].binary_bits = binary_bits;
- mon_event_all[eventid].arch_priv = arch_priv;
- mon_event_all[eventid].enabled = true;
+ mevt->rid = r->rid;
+ mevt->any_cpu = any_cpu;
+ mevt->binary_bits = binary_bits;
+ mevt->arch_priv = arch_priv;
+ mevt->enabled = true;
return true;
}
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index c844f99fb824..f09169c964e6 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -419,7 +419,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
u32 resctrl_arch_system_num_rmid_idx(void);
int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
-bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
+bool resctrl_enable_mon_event(struct rdt_resource *r,
+ enum resctrl_event_id eventid, bool any_cpu,
unsigned int binary_bits, void *arch_priv);
bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 07/19] x86,fs/resctrl: Track monitor events by scope
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (5 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 06/19] x86,fs/resctrl: Record the resource that enables a monitor event Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 08/19] fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources Jinjie Ruan
` (12 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Monitor data is shown in directories named after the scope where the
counters live: "mon_L3_xx" holds "llc_occupancy" from the L3 resource
and "mbm_total_bytes" from the memory bandwidth resource. resctrl has
been using L3 as both the resource name and the scope name, but they
are not the same thing. A monitor can be shown at a scope that is not
the scope of the resource that implements it, for example memory
bandwidth on a CPU-less node.
L2 and L3 caches support the same monitor event types, so the event ID
alone no longer says which scope an event belongs to.
Index the event table by scope and event ID, and pass the resource to
the helpers that need to find an event: resctrl_is_mon_event_enabled()
and resctrl_get_mon_evt_cfg(). Code that only needs to know whether any
resource has an event uses the new resctrl_is_mon_event_enabled_any().
SNC slices remain part of the L3 scope.
No functional change.
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/cpu/resctrl/core.c | 3 +-
arch/x86/kernel/cpu/resctrl/monitor.c | 4 +-
fs/resctrl/ctrlmondata.c | 5 +-
fs/resctrl/internal.h | 52 +++++++++-
fs/resctrl/monitor.c | 143 +++++++++++++++-----------
fs/resctrl/rdtgroup.c | 46 ++++-----
include/linux/resctrl.h | 6 +-
include/linux/resctrl_types.h | 7 +-
8 files changed, 169 insertions(+), 97 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 707fa4e7ed24..e6c1ac5daeda 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -432,12 +432,13 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_domain *
*/
static int l3_mon_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_l3_mon_domain *hw_dom)
{
+ struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
size_t tsize = sizeof(*hw_dom->arch_mbm_states[0]);
enum resctrl_event_id eventid;
int idx;
for_each_mbm_event_id(eventid) {
- if (!resctrl_is_mon_event_enabled(eventid))
+ if (!resctrl_is_mon_event_enabled(r, eventid))
continue;
idx = MBM_STATE_IDX(eventid);
hw_dom->arch_mbm_states[idx] = kcalloc(num_rmid, tsize, GFP_KERNEL);
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index a6a9090c4808..e9c2b4ae9ed4 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -202,7 +202,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon_domai
int idx;
for_each_mbm_event_id(eventid) {
- if (!resctrl_is_mon_event_enabled(eventid))
+ if (!resctrl_is_mon_event_enabled(r, eventid))
continue;
idx = MBM_STATE_IDX(eventid);
memset(hw_dom->arch_mbm_states[idx], 0,
@@ -561,7 +561,7 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *
abmc_cfg.split.cntr_id = cntr_id;
abmc_cfg.split.bw_src = rmid;
if (assign)
- abmc_cfg.split.bw_type = resctrl_get_mon_evt_cfg(evtid);
+ abmc_cfg.split.bw_type = resctrl_get_mon_evt_cfg(r, evtid);
smp_call_function_any(&d->hdr.cpu_mask, resctrl_abmc_config_one_amd, &abmc_cfg, 1);
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index c70a9939d126..2503970a1479 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -465,6 +465,7 @@ static int smp_mon_event_count(void *arg)
ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdtgroup *rdtgrp;
int ret = 0;
@@ -484,12 +485,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
buf[nbytes - 1] = '\0';
if (!strcmp(buf, "mbm_local_bytes")) {
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
rdtgrp->mba_mbps_event = QOS_MBM_LOCAL_EVENT_ID;
else
ret = -EINVAL;
} else if (!strcmp(buf, "mbm_total_bytes")) {
- if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
rdtgrp->mba_mbps_event = QOS_MBM_TOTAL_EVENT_ID;
else
ret = -EINVAL;
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index f7815e4fb53e..fc98c8e7a2d8 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -54,8 +54,8 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
/**
* struct mon_evt - Properties of a monitor event
* @evtid: event id
- * @rid: resource that implements this event, recorded by the
- * architecture when it enables the event
+ * @rid: resource that implements this event. This is not
+ * necessarily the scope the event is shown in.
* @name: name of the event
* @evt_cfg: Event configuration value that represents the
* memory transactions (e.g., READS_TO_LOCAL_MEM,
@@ -84,10 +84,52 @@ struct mon_evt {
void *arch_priv;
};
-extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];
+/*
+ * Monitor scopes. A scope is where the counters live, and is what the
+ * "mon_<name>_<id>" directories and the "<NAME>_MON" directories are named
+ * after. The resource that implements an event is recorded in mon_evt::rid
+ * and may be different from the scope, for example "mbm_total_bytes" is
+ * implemented by the memory bandwidth resource but shown at L3 scope.
+ *
+ * SNC slices are domains of the L3 scope, so RESCTRL_L3_NODE maps to the
+ * L3 row.
+ */
+enum resctrl_mon_scope {
+ RESCTRL_MON_SCOPE_NONE,
+ RESCTRL_MON_SCOPE_L2,
+ RESCTRL_MON_SCOPE_L3,
+ RESCTRL_MON_SCOPE_PACKAGE,
+ RESCTRL_MON_SCOPE_NUM,
+};
+
+static inline int resctrl_mon_scope_idx(enum resctrl_scope scope)
+{
+ switch (scope) {
+ case RESCTRL_L2_CACHE:
+ return RESCTRL_MON_SCOPE_L2;
+ case RESCTRL_L3_CACHE:
+ case RESCTRL_L3_NODE:
+ return RESCTRL_MON_SCOPE_L3;
+ case RESCTRL_PACKAGE:
+ return RESCTRL_MON_SCOPE_PACKAGE;
+ default:
+ return RESCTRL_MON_SCOPE_NONE;
+ }
+}
+
+extern struct mon_evt mon_event_all[RESCTRL_MON_SCOPE_NUM][QOS_NUM_EVENTS];
+
+bool resctrl_is_mon_event_enabled_any(enum resctrl_event_id eventid);
+
+static inline struct mon_evt *resctrl_mon_evt(struct rdt_resource *r,
+ enum resctrl_event_id evtid)
+{
+ return &mon_event_all[resctrl_mon_scope_idx(r->mon_scope)][evtid];
+}
-#define for_each_mon_event(mevt) for (mevt = &mon_event_all[QOS_FIRST_EVENT]; \
- mevt < &mon_event_all[QOS_NUM_EVENTS]; mevt++)
+#define for_each_mon_event(r, mevt) \
+ for (mevt = resctrl_mon_evt(r, QOS_FIRST_EVENT); \
+ mevt < resctrl_mon_evt(r, QOS_NUM_EVENTS); mevt++)
/* Limit for mon_evt::binary_bits */
#define MAX_BINARY_BITS 27
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 23c1838a7661..ae6c5ecc1019 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -141,7 +141,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
void *arch_priv;
u64 val = 0;
- arch_priv = mon_event_all[QOS_OCCUP_EVENT_ID].arch_priv;
+ arch_priv = resctrl_mon_evt(r, QOS_OCCUP_EVENT_ID)->arch_priv;
arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_OCCUP_EVENT_ID);
if (IS_ERR(arch_mon_ctx)) {
pr_warn_ratelimited("Failed to allocate monitor context: %pe",
@@ -345,7 +345,7 @@ void free_rmid(u32 closid, u32 rmid)
entry = __rmid_entry(idx);
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled_any(QOS_OCCUP_EVENT_ID))
add_rmid_to_limbo(entry);
else
list_add_tail(&entry->list, &rmid_free_lru);
@@ -769,7 +769,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon_domai
rr.r = r;
rr.hdr = &d->hdr;
- rr.evt = &mon_event_all[evtid];
+ rr.evt = resctrl_mon_evt(r, evtid);
if (resctrl_arch_mbm_cntr_assign_enabled(r)) {
rr.is_mbm_cntr = true;
} else {
@@ -797,15 +797,16 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon_domai
static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
struct rdtgroup *rdtgrp)
{
+ enum resctrl_event_id evtid;
+
/*
* 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_MBM_TOTAL_EVENT_ID))
- mbm_update_one_event(r, d, rdtgrp, QOS_MBM_TOTAL_EVENT_ID);
-
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
- mbm_update_one_event(r, d, rdtgrp, QOS_MBM_LOCAL_EVENT_ID);
+ for_each_mbm_event_id(evtid) {
+ if (resctrl_is_mon_event_enabled(r, evtid))
+ mbm_update_one_event(r, d, rdtgrp, evtid);
+ }
}
/*
@@ -1023,25 +1024,30 @@ void free_rmid_lru_list(void)
}
/*
- * All available events. Architecture code marks the ones that
- * are supported by a system using resctrl_enable_mon_event()
- * to set .enabled.
+ * All available events, indexed by monitor scope and event type. Architecture
+ * code marks the ones that are supported by a system using
+ * resctrl_enable_mon_event() to set .enabled. An entity supports an event
+ * when the entry has a name.
*/
-struct mon_evt mon_event_all[QOS_NUM_EVENTS] = {
- MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", false),
- MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", false),
- MON_EVENT(QOS_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", false),
- MON_EVENT(PMT_EVENT_ENERGY, "core_energy", true),
- MON_EVENT(PMT_EVENT_ACTIVITY, "activity", true),
- MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", false),
- MON_EVENT(PMT_EVENT_C1_RES, "c1_res", false),
- MON_EVENT(PMT_EVENT_UNHALTED_CORE_CYCLES, "unhalted_core_cycles", false),
- MON_EVENT(PMT_EVENT_STALLS_LLC_MISS, "stalls_llc_miss", false),
- MON_EVENT(PMT_EVENT_AUTO_C6_RES, "c6_res", false),
- MON_EVENT(PMT_EVENT_UNHALTED_REF_CYCLES, "unhalted_ref_cycles", false),
- MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", false),
- MON_EVENT(PMT_EVENT_INST_RETIRED, "inst_retired", false),
- MON_EVENT(PMT_EVENT_PCNT, "pcnt", false),
+struct mon_evt mon_event_all[RESCTRL_MON_SCOPE_NUM][QOS_NUM_EVENTS] = {
+ [RESCTRL_MON_SCOPE_L3] = {
+ MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", false),
+ MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", false),
+ MON_EVENT(QOS_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", false),
+ },
+ [RESCTRL_MON_SCOPE_PACKAGE] = {
+ MON_EVENT(PMT_EVENT_ENERGY, "core_energy", true),
+ MON_EVENT(PMT_EVENT_ACTIVITY, "activity", true),
+ MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", false),
+ MON_EVENT(PMT_EVENT_C1_RES, "c1_res", false),
+ MON_EVENT(PMT_EVENT_UNHALTED_CORE_CYCLES, "unhalted_core_cycles", false),
+ MON_EVENT(PMT_EVENT_STALLS_LLC_MISS, "stalls_llc_miss", false),
+ MON_EVENT(PMT_EVENT_AUTO_C6_RES, "c6_res", false),
+ MON_EVENT(PMT_EVENT_UNHALTED_REF_CYCLES, "unhalted_ref_cycles", false),
+ MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", false),
+ MON_EVENT(PMT_EVENT_INST_RETIRED, "inst_retired", false),
+ MON_EVENT(PMT_EVENT_PCNT, "pcnt", false),
+ },
};
bool resctrl_enable_mon_event(struct rdt_resource *r,
@@ -1054,10 +1060,14 @@ bool resctrl_enable_mon_event(struct rdt_resource *r,
binary_bits > MAX_BINARY_BITS))
return false;
- mevt = &mon_event_all[eventid];
+ mevt = resctrl_mon_evt(r, eventid);
+ if (!mevt->name) {
+ pr_warn("Resource %d does not support event %d\n", r->rid, eventid);
+ return false;
+ }
if (mevt->enabled) {
- pr_warn("Duplicate enable for event %d on resource %d\n",
- eventid, r->rid);
+ pr_warn("Duplicate enable for event %d at scope %d\n",
+ eventid, resctrl_mon_scope_idx(r->mon_scope));
return false;
}
if (binary_bits && !mevt->is_floating_point) {
@@ -1074,15 +1084,31 @@ bool resctrl_enable_mon_event(struct rdt_resource *r,
return true;
}
-bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)
+bool resctrl_is_mon_event_enabled(struct rdt_resource *r,
+ enum resctrl_event_id eventid)
{
return eventid >= QOS_FIRST_EVENT && eventid < QOS_NUM_EVENTS &&
- mon_event_all[eventid].enabled;
+ resctrl_mon_evt(r, eventid)->enabled;
+}
+
+bool resctrl_is_mon_event_enabled_any(enum resctrl_event_id eventid)
+{
+ int scope;
+
+ if (eventid < QOS_FIRST_EVENT || eventid >= QOS_NUM_EVENTS)
+ return false;
+
+ for (scope = 0; scope < RESCTRL_MON_SCOPE_NUM; scope++) {
+ if (mon_event_all[scope][eventid].enabled)
+ return true;
+ }
+
+ return false;
}
-u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id evtid)
+u32 resctrl_get_mon_evt_cfg(struct rdt_resource *r, enum resctrl_event_id evtid)
{
- return mon_event_all[evtid].evt_cfg;
+ return resctrl_mon_evt(r, evtid)->evt_cfg;
}
/**
@@ -1216,7 +1242,7 @@ static void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon_dom
int idx;
for_each_mbm_event_id(evt) {
- if (!resctrl_is_mon_event_enabled(evt))
+ if (!resctrl_is_mon_event_enabled(r, evt))
continue;
idx = MBM_STATE_IDX(evt);
memset(d->mbm_states[idx], 0, sizeof(*d->mbm_states[0]) * idx_limit);
@@ -1325,13 +1351,13 @@ void rdtgroup_assign_cntrs(struct rdtgroup *rdtgrp)
!r->mon.mbm_assign_on_mkdir)
return;
- if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_MBM_TOTAL_EVENT_ID]);
+ resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID));
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
rdtgroup_assign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_MBM_LOCAL_EVENT_ID]);
+ resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID));
}
/*
@@ -1383,13 +1409,13 @@ void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp)
if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
return;
- if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_MBM_TOTAL_EVENT_ID]);
+ resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID));
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- &mon_event_all[QOS_MBM_LOCAL_EVENT_ID]);
+ resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID));
}
static int resctrl_parse_mem_transactions(char *tok, u32 *val)
@@ -1600,10 +1626,10 @@ 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_MBM_TOTAL_EVENT_ID))
- mon_event_all[QOS_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
- mon_event_all[QOS_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
+ resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID)->evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
+ resctrl_mon_evt(r, QOS_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);
@@ -1710,8 +1736,8 @@ int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file *s, voi
goto out_unlock;
}
- for_each_mon_event(mevt) {
- if (mevt->rid != r->rid || !mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
continue;
sep = false;
@@ -1744,9 +1770,8 @@ static struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, char *n
{
struct mon_evt *mevt;
- for_each_mon_event(mevt) {
- if (mevt->rid == r->rid && mevt->enabled &&
- resctrl_is_mbm_event(mevt->evtid) &&
+ for_each_mon_event(r, mevt) {
+ if (mevt->enabled && resctrl_is_mbm_event(mevt->evtid) &&
!strcmp(mevt->name, name))
return mevt;
}
@@ -1943,26 +1968,26 @@ int resctrl_l3_mon_resource_init(void)
return ret;
if (resctrl_arch_is_evt_configurable(QOS_MBM_TOTAL_EVENT_ID)) {
- mon_event_all[QOS_MBM_TOTAL_EVENT_ID].configurable = true;
+ resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID)->configurable = true;
resctrl_file_fflags_init("mbm_total_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
if (resctrl_arch_is_evt_configurable(QOS_MBM_LOCAL_EVENT_ID)) {
- mon_event_all[QOS_MBM_LOCAL_EVENT_ID].configurable = true;
+ resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID)->configurable = true;
resctrl_file_fflags_init("mbm_local_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
mba_mbps_default_event = QOS_MBM_LOCAL_EVENT_ID;
- else if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
+ else if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
mba_mbps_default_event = QOS_MBM_TOTAL_EVENT_ID;
if (r->mon.mbm_cntr_assignable) {
- if (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID))
- mon_event_all[QOS_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- if (resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID))
- mon_event_all[QOS_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
+ resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID)->evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
+ resctrl_mon_evt(r, QOS_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);
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 92f0e3b68784..8154e02b3d1c 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -122,10 +122,10 @@ void rdt_staged_configs_clear(void)
}
}
-static bool resctrl_is_mbm_enabled(void)
+static bool resctrl_is_mbm_enabled(struct rdt_resource *r)
{
- return (resctrl_is_mon_event_enabled(QOS_MBM_TOTAL_EVENT_ID) ||
- resctrl_is_mon_event_enabled(QOS_MBM_LOCAL_EVENT_ID));
+ return (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID) ||
+ resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID));
}
/*
@@ -191,7 +191,7 @@ static int closid_alloc(void)
lockdep_assert_held(&rdtgroup_mutex);
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
- resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID)) {
+ resctrl_is_mon_event_enabled_any(QOS_OCCUP_EVENT_ID)) {
cleanest_closid = resctrl_find_cleanest_closid();
if (cleanest_closid < 0)
return cleanest_closid;
@@ -1208,8 +1208,8 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,
if (!info_kn_lock(of->kn))
return -ENOENT;
- for_each_mon_event(mevt) {
- if (mevt->rid != r->rid || !mevt->enabled)
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled)
continue;
seq_printf(seq, "%s\n", mevt->name);
if (mevt->configurable &&
@@ -2426,8 +2426,8 @@ static int resctrl_mkdir_event_configs(struct rdt_resource *r, struct kernfs_nod
if (ret)
return ret;
- for_each_mon_event(mevt) {
- if (mevt->rid != r->rid || !mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
continue;
kn_subdir2 = kernfs_create_dir(kn_subdir, mevt->name, kn_subdir->mode, mevt);
@@ -2620,7 +2620,7 @@ static bool supports_mba_mbps(void)
struct rdt_resource *rmbm = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
- return (resctrl_is_mbm_enabled() &&
+ return (resctrl_is_mbm_enabled(rmbm) &&
r->alloc_capable && is_mba_linear() &&
r->ctrl_scope == rmbm->mon_scope &&
!rmbm->mon.mbm_cntr_assignable);
@@ -3254,8 +3254,8 @@ static int rdt_get_tree(struct fs_context *fc)
if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
resctrl_mounted = true;
- if (resctrl_is_mbm_enabled()) {
- r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ if (resctrl_is_mbm_enabled(r)) {
list_for_each_entry_rcu(dom, &r->mon_domains, hdr.list, lockdep_is_cpus_held())
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
RESCTRL_PICK_ANY_CPU);
@@ -3520,8 +3520,8 @@ static struct kernfs_node *_mkdir_mondata_subdir(struct kernfs_node *parent_kn,
if (ret)
goto out_destroy;
- for_each_mon_event(mevt) {
- if (mevt->rid != r->rid || !mevt->enabled)
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled)
continue;
priv = mon_get_kn_priv(r->rid, domid, mevt, !hdr);
if (WARN_ON_ONCE(!priv)) {
@@ -4559,9 +4559,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
if (r->rid == RDT_RESOURCE_L3 &&
domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) {
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
- if (resctrl_is_mbm_enabled())
+ if (resctrl_is_mbm_enabled(r))
cancel_delayed_work_sync(&d->mbm_over);
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID))
cancel_delayed_work_sync(&d->cqm_limbo);
}
@@ -4581,7 +4581,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
goto out_unlock;
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
+ if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
/*
* When a package is going down, forcefully
* decrement rmid->ebusy. There is no way to know
@@ -4624,14 +4624,14 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
enum resctrl_event_id eventid;
int idx;
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID)) {
+ if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID)) {
d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
if (!d->rmid_busy_llc)
return -ENOMEM;
}
for_each_mbm_event_id(eventid) {
- if (!resctrl_is_mon_event_enabled(eventid))
+ if (!resctrl_is_mon_event_enabled(r, eventid))
continue;
idx = MBM_STATE_IDX(eventid);
d->mbm_states[idx] = kcalloc(idx_limit, tsize, GFP_KERNEL);
@@ -4639,7 +4639,7 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
goto cleanup;
}
- if (resctrl_is_mbm_enabled() && r->mon.mbm_cntr_assignable) {
+ if (resctrl_is_mbm_enabled(r) && r->mon.mbm_cntr_assignable) {
tsize = sizeof(*d->cntr_cfg);
d->cntr_cfg = kcalloc(r->mon.num_mbm_cntrs, tsize, GFP_KERNEL);
if (!d->cntr_cfg)
@@ -4691,13 +4691,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
if (err)
goto out_unlock;
- if (resctrl_is_mbm_enabled()) {
+ if (resctrl_is_mbm_enabled(r)) {
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
RESCTRL_PICK_ANY_CPU);
}
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID))
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
mkdir:
@@ -4770,13 +4770,13 @@ void resctrl_offline_cpu(unsigned int cpu)
d = get_mon_domain_from_cpu(cpu, l3);
if (d) {
- if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
+ if (resctrl_is_mbm_enabled(l3) && cpu == d->mbm_work_cpu) {
mutex_unlock(&rdtgroup_mutex);
cancel_delayed_work_sync(&d->mbm_over);
mutex_lock(&rdtgroup_mutex);
mbm_setup_overflow_handler(d, 0, cpu);
}
- if (resctrl_is_mon_event_enabled(QOS_OCCUP_EVENT_ID) &&
+ if (resctrl_is_mon_event_enabled(l3, QOS_OCCUP_EVENT_ID) &&
cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
mutex_unlock(&rdtgroup_mutex);
cancel_delayed_work_sync(&d->cqm_limbo);
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index f09169c964e6..0a60372299c5 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -423,7 +423,8 @@ bool resctrl_enable_mon_event(struct rdt_resource *r,
enum resctrl_event_id eventid, bool any_cpu,
unsigned int binary_bits, void *arch_priv);
-bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);
+bool resctrl_is_mon_event_enabled(struct rdt_resource *r,
+ enum resctrl_event_id eventid);
bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
@@ -433,7 +434,8 @@ static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid)
eventid <= QOS_MBM_LOCAL_EVENT_ID);
}
-u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid);
+u32 resctrl_get_mon_evt_cfg(struct rdt_resource *r,
+ enum resctrl_event_id eventid);
/* Iterate over all memory bandwidth events */
#define for_each_mbm_event_id(eventid) \
diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h
index d0e56de038f0..307a74d3c928 100644
--- a/include/linux/resctrl_types.h
+++ b/include/linux/resctrl_types.h
@@ -43,9 +43,10 @@ enum resctrl_event_id {
QOS_FIRST_EVENT = 0x01,
/*
- * Monitor event types. The resource an event belongs to is tracked
- * separately. These values match those used to program IA32_QM_EVTSEL
- * before reading IA32_QM_CTR on RDT systems.
+ * Monitor event types. More than one resource may support the same
+ * event type; the resource supplies the scope. These values match
+ * those used to program IA32_QM_EVTSEL before reading IA32_QM_CTR on
+ * RDT systems.
*/
QOS_OCCUP_EVENT_ID = 0x01,
QOS_MBM_TOTAL_EVENT_ID = 0x02,
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 08/19] fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (6 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 07/19] x86,fs/resctrl: Track monitor events by scope Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 09/19] fs/resctrl: Add the L2 monitor events Jinjie Ruan
` (11 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
__l3_mon_event_count() reads a single monitor domain. Its only L3-specific
part is the resource id in the domain_header_is_valid() check; the rest
goes through rr->r and the monitor domain, which every monitor resource
uses. Check rr->r->rid instead and rename the helper to
__mon_event_count_one_domain().
No functional change.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/monitor.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index ae6c5ecc1019..7c392bd57eff 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -422,7 +422,7 @@ static void mbm_cntr_free(struct rdt_l3_mon_domain *d, int cntr_id)
memset(&d->cntr_cfg[cntr_id], 0, sizeof(*d->cntr_cfg));
}
-static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
+static int __mon_event_count_one_domain(struct rdtgroup *rdtgrp, struct rmid_read *rr)
{
int cpu = smp_processor_id();
u32 closid = rdtgrp->closid;
@@ -432,7 +432,7 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
struct mbm_state *m;
u64 tval = 0;
- if (!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) {
+ if (!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, rr->r->rid)) {
rr->err = -EIO;
return -EINVAL;
}
@@ -540,7 +540,7 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
case RDT_RESOURCE_L3:
WARN_ON_ONCE(rr->evt->any_cpu);
if (rr->hdr)
- return __l3_mon_event_count(rdtgrp, rr);
+ return __mon_event_count_one_domain(rdtgrp, rr);
else
return __l3_mon_event_count_sum(rdtgrp, rr);
case RDT_RESOURCE_PERF_PKG: {
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 09/19] fs/resctrl: Add the L2 monitor events
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (7 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 08/19] fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 10/19] fs/resctrl: Set up MBM state and workers for every monitor resource Jinjie Ruan
` (10 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
MPAM monitors belong to a cache, and firmware says which level that
cache is. Add the L2 entries to the event table: l2c_occupancy for
occupancy and mbm_core_bytes for bandwidth. They have their own names
because an L2 counts the traffic the cache sees, not memory bandwidth.
Read the L2 events through the same per-domain path as the L3. The L2
has no domains to sum, so a read without a domain fails. The events only
show up once an architecture enables them; x86 never does.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/monitor.c | 12 +++++++++++-
include/linux/resctrl.h | 2 +-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 7c392bd57eff..d72d53ba25c7 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -537,12 +537,18 @@ static int __l3_mon_event_count_sum(struct rdtgroup *rdtgrp, struct rmid_read *r
static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
{
switch (rr->r->rid) {
+ case RDT_RESOURCE_L2:
case RDT_RESOURCE_L3:
WARN_ON_ONCE(rr->evt->any_cpu);
if (rr->hdr)
return __mon_event_count_one_domain(rdtgrp, rr);
- else
+
+ /* Only the L3 has SNC domains to sum. */
+ if (rr->r->rid == RDT_RESOURCE_L3)
return __l3_mon_event_count_sum(rdtgrp, rr);
+
+ rr->err = -EINVAL;
+ return -EINVAL;
case RDT_RESOURCE_PERF_PKG: {
u64 tval = 0;
@@ -1030,6 +1036,10 @@ void free_rmid_lru_list(void)
* when the entry has a name.
*/
struct mon_evt mon_event_all[RESCTRL_MON_SCOPE_NUM][QOS_NUM_EVENTS] = {
+ [RESCTRL_MON_SCOPE_L2] = {
+ MON_EVENT(QOS_OCCUP_EVENT_ID, "l2c_occupancy", false),
+ MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_core_bytes", false),
+ },
[RESCTRL_MON_SCOPE_L3] = {
MON_EVENT(QOS_OCCUP_EVENT_ID, "llc_occupancy", false),
MON_EVENT(QOS_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", false),
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 0a60372299c5..95ffff4c7925 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -180,7 +180,7 @@ struct mbm_cntr_cfg {
};
/**
- * struct rdt_l3_mon_domain - group of CPUs sharing RDT_RESOURCE_L3 monitoring
+ * struct rdt_l3_mon_domain - group of CPUs sharing L2 or L3 cache monitoring
* @hdr: common header for different domain types
* @ci_id: cache info id for this domain
* @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 10/19] fs/resctrl: Set up MBM state and workers for every monitor resource
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (8 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 09/19] fs/resctrl: Add the L2 monitor events Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 11/19] resctrl: Keep the RMID limbo threshold per resource Jinjie Ruan
` (9 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Monitor domain state and the MBM overflow worker are only set up for L3
domains. Set them up for any resource that has the matching events
enabled, and let the overflow worker find the resource from its domain.
The MBA software controller still uses the L3, so only the L3 worker
updates its bandwidth numbers.
No functional change as only the L3 has monitoring enabled.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/monitor.c | 8 +++---
fs/resctrl/rdtgroup.c | 57 +++++++++++++++++++++++--------------------
2 files changed, 35 insertions(+), 30 deletions(-)
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index d72d53ba25c7..5924cc7d64f8 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -589,7 +589,7 @@ static void mbm_bw_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
struct rdt_l3_mon_domain *d;
struct mbm_state *m;
- if (!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
+ if (!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, rr->r->rid))
return;
d = container_of(rr->hdr, struct rdt_l3_mon_domain, hdr);
m = get_mbm_state(d, closid, rmid, rr->evt->evtid);
@@ -793,7 +793,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon_domai
* If the software controller is enabled, compute the
* bandwidth for this event id.
*/
- if (is_mba_sc(NULL))
+ if (is_mba_sc(NULL) && r->rid == RDT_RESOURCE_L3)
mbm_bw_count(rdtgrp, &rr);
if (rr.arch_mon_ctx)
@@ -909,8 +909,8 @@ void mbm_handle_overflow(struct work_struct *work)
if (!is_percpu_thread())
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);
/* Domain is going offline */
if (cpumask_empty(&d->hdr.cpu_mask))
@@ -923,7 +923,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))
+ if (is_mba_sc(NULL) && r->rid == RDT_RESOURCE_L3)
update_mba_bw(prgrp, d);
}
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 8154e02b3d1c..afd6ffa9e324 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -3254,9 +3254,11 @@ static int rdt_get_tree(struct fs_context *fc)
if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
resctrl_mounted = true;
- r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
- if (resctrl_is_mbm_enabled(r)) {
- list_for_each_entry_rcu(dom, &r->mon_domains, hdr.list, lockdep_is_cpus_held())
+ for_each_mon_capable_rdt_resource(r) {
+ if (!resctrl_is_mbm_enabled(r))
+ continue;
+ list_for_each_entry_rcu(dom, &r->mon_domains, hdr.list,
+ lockdep_is_cpus_held())
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
RESCTRL_PICK_ANY_CPU);
}
@@ -4498,7 +4500,13 @@ static void rdtgroup_setup_default(void)
mutex_unlock(&rdtgroup_mutex);
}
-static void domain_destroy_l3_mon_state(struct rdt_l3_mon_domain *d)
+/* Only cache resources use the struct rdt_l3_mon_domain layout. */
+static bool rdt_mon_domain_is_cache(const struct rdt_domain_hdr *hdr)
+{
+ return hdr->rid == RDT_RESOURCE_L2 || hdr->rid == RDT_RESOURCE_L3;
+}
+
+static void domain_destroy_mon_state(struct rdt_l3_mon_domain *d)
{
int idx;
@@ -4556,8 +4564,8 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
* the domain that has the workers' struct delayed_work embedded.
* Do so before taking rdtgroup_mutex since the workers also acquire it.
*/
- if (r->rid == RDT_RESOURCE_L3 &&
- domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) {
+ if (rdt_mon_domain_is_cache(hdr) &&
+ domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) {
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
if (resctrl_is_mbm_enabled(r))
cancel_delayed_work_sync(&d->mbm_over);
@@ -4574,10 +4582,8 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
if (resctrl_mounted && resctrl_arch_mon_capable())
rmdir_mondata_subdir_allrdtgrp(r, hdr);
- if (r->rid != RDT_RESOURCE_L3)
- goto out_unlock;
-
- if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
+ if (!rdt_mon_domain_is_cache(hdr) ||
+ !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid))
goto out_unlock;
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
@@ -4593,13 +4599,13 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
__check_limbo(d, true);
}
- domain_destroy_l3_mon_state(d);
+ domain_destroy_mon_state(d);
out_unlock:
mutex_unlock(&rdtgroup_mutex);
}
/**
- * domain_setup_l3_mon_state() - Initialise domain monitoring structures.
+ * domain_setup_mon_state() - Initialise domain monitoring structures.
* @r: The resource for the newly online domain.
* @d: The newly online domain.
*
@@ -4617,7 +4623,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
*
* Return: 0 for success, or -ENOMEM.
*/
-static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_domain *d)
+static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_l3_mon_domain *d)
{
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
size_t tsize = sizeof(*d->mbm_states[0]);
@@ -4680,21 +4686,21 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
mutex_lock(&rdtgroup_mutex);
- if (r->rid != RDT_RESOURCE_L3)
+ if (!rdt_mon_domain_is_cache(hdr))
goto mkdir;
- if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
+ if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid))
goto out_unlock;
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
- err = domain_setup_l3_mon_state(r, d);
+ err = domain_setup_mon_state(r, d);
if (err)
goto out_unlock;
if (resctrl_is_mbm_enabled(r)) {
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
- RESCTRL_PICK_ANY_CPU);
+ RESCTRL_PICK_ANY_CPU);
}
if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID))
@@ -4753,7 +4759,7 @@ static struct rdt_l3_mon_domain *get_mon_domain_from_cpu(int cpu,
void resctrl_offline_cpu(unsigned int cpu)
{
- struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_resource *r;
struct rdt_l3_mon_domain *d;
struct rdtgroup *rdtgrp;
@@ -4765,18 +4771,18 @@ 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(l3) && cpu == d->mbm_work_cpu) {
+ for_each_mon_capable_rdt_resource(r) {
+ d = get_mon_domain_from_cpu(cpu, r);
+ /* Only cache domains carry the MBM and limbo work fields. */
+ if (!d || !rdt_mon_domain_is_cache(&d->hdr))
+ continue;
+ if (resctrl_is_mbm_enabled(r) && cpu == d->mbm_work_cpu) {
mutex_unlock(&rdtgroup_mutex);
cancel_delayed_work_sync(&d->mbm_over);
mutex_lock(&rdtgroup_mutex);
mbm_setup_overflow_handler(d, 0, cpu);
}
- if (resctrl_is_mon_event_enabled(l3, QOS_OCCUP_EVENT_ID) &&
+ if (resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID) &&
cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
mutex_unlock(&rdtgroup_mutex);
cancel_delayed_work_sync(&d->cqm_limbo);
@@ -4785,7 +4791,6 @@ void resctrl_offline_cpu(unsigned int cpu)
}
}
-out_unlock:
mutex_unlock(&rdtgroup_mutex);
}
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 11/19] resctrl: Keep the RMID limbo threshold per resource
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (9 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 10/19] fs/resctrl: Set up MBM state and workers for every monitor resource Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 12/19] fs/resctrl: Check RMID limbo on every resource with occupancy Jinjie Ruan
` (8 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Currently, the RMID reallocation threshold and its upper limit are
stored as system-wide globals. To support L2 cache occupancy monitoring
alongside L3, each cache resource needs its own threshold and limit
matching its capacity, and writing max_threshold_occupancy in one
resource's info directory must not affect the other.
Move both values into struct resctrl_mon in preparation for L2 support.
Update __check_limbo() and max_threshold_occupancy to use the values
from the owning resource, keeping existing L3 behavior on x86 and
setting them from the smallest cache of each resource in MPAM.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/cpu/resctrl/monitor.c | 6 +++---
drivers/resctrl/mpam_resctrl.c | 17 +++++++++++++----
fs/resctrl/monitor.c | 17 +++--------------
fs/resctrl/rdtgroup.c | 11 +++++++----
include/linux/resctrl.h | 9 ++++++---
5 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index e9c2b4ae9ed4..e69e2bbb8804 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -425,7 +425,7 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r)
snc_nodes_per_l3_cache = snc_get_config();
- resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
+ r->mon.rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache;
r->mon.num_rmid = (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3_cache;
hw_res->mbm_width = MBM_CNTR_WIDTH_BASE;
@@ -442,14 +442,14 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r)
*
* For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
*/
- threshold = resctrl_rmid_realloc_limit / r->mon.num_rmid;
+ threshold = r->mon.rmid_realloc_limit / r->mon.num_rmid;
/*
* Because num_rmid may not be a power of two, round the value
* to the nearest multiple of hw_res->mon_scale so it matches a
* value the hardware will measure. mon_scale may not be a power of 2.
*/
- resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
+ r->mon.rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) {
/* Detect list of bandwidth sources that can be tracked */
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 961210af3159..d40c8eb7b300 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -634,8 +634,17 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
* The rmid realloc threshold should be for the smallest cache exposed to
* resctrl.
*/
+
+/* A cache class backs the resctrl resource of its level, L2 or L3. */
+static enum resctrl_res_level mpam_class_rid(struct mpam_class *class)
+{
+ return class->level == 2 ? RDT_RESOURCE_L2 : RDT_RESOURCE_L3;
+}
+
static int update_rmid_limits(struct mpam_class *class)
{
+ enum resctrl_res_level rid = mpam_class_rid(class);
+ struct rdt_resource *r = resctrl_arch_get_resource(rid);
u32 num_unique_pmg = resctrl_arch_system_num_rmid_idx();
struct mpam_props *cprops = &class->props;
struct cacheinfo *ci;
@@ -657,10 +666,10 @@ static int update_rmid_limits(struct mpam_class *class)
return -EINVAL;
}
- if (!resctrl_rmid_realloc_limit ||
- ci->size < resctrl_rmid_realloc_limit) {
- resctrl_rmid_realloc_limit = ci->size;
- resctrl_rmid_realloc_threshold = ci->size / num_unique_pmg;
+ if (!r->mon.rmid_realloc_limit ||
+ ci->size < r->mon.rmid_realloc_limit) {
+ r->mon.rmid_realloc_limit = ci->size;
+ r->mon.rmid_realloc_threshold = ci->size / num_unique_pmg;
}
return 0;
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 5924cc7d64f8..4132258760fa 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -65,8 +65,8 @@ static u32 *closid_num_dirty_rmid;
* @rmid_limbo_count - count of currently unused but (potentially)
* dirty RMIDs.
* This counts RMIDs that no one is currently using but that
- * may have a occupancy value > resctrl_rmid_realloc_threshold. User can
- * change the threshold occupancy value.
+ * may have a occupancy value above the resource's reallocation
+ * threshold. User can change the threshold occupancy value.
*/
static unsigned int rmid_limbo_count;
@@ -75,17 +75,6 @@ static unsigned int rmid_limbo_count;
*/
static struct rmid_entry *rmid_ptrs;
-/*
- * This is the threshold cache occupancy in bytes at which we will consider an
- * RMID available for re-allocation.
- */
-unsigned int resctrl_rmid_realloc_threshold;
-
-/*
- * This is the maximum value for the reallocation threshold, in bytes.
- */
-unsigned int resctrl_rmid_realloc_limit;
-
/*
* x86 and arm64 differ in their handling of monitoring.
* x86's RMID are independent numbers, there is only one source of traffic
@@ -167,7 +156,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
arch_priv, &val, arch_mon_ctx)) {
rmid_dirty = true;
} else {
- rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
+ rmid_dirty = (val >= r->mon.rmid_realloc_threshold);
/*
* x86's CLOSID and RMID are independent numbers,
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index afd6ffa9e324..328e78324f54 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1255,9 +1255,11 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
static int max_threshold_occ_show(struct kernfs_open_file *of,
struct seq_file *seq, void *v)
{
+ struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+
if (!info_kn_lock(of->kn))
return -ENOENT;
- seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
+ seq_printf(seq, "%u\n", r->mon.rmid_realloc_threshold);
info_kn_unlock(of->kn);
return 0;
@@ -1295,6 +1297,7 @@ static int rdt_thread_throttle_mode_show(struct kernfs_open_file *of,
static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
+ struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
unsigned int bytes;
int ret;
@@ -1309,14 +1312,14 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
goto out_unlock;
}
- if (bytes > resctrl_rmid_realloc_limit) {
+ if (bytes > r->mon.rmid_realloc_limit) {
rdt_last_cmd_printf("max_threshold_occupancy: Exceeds limit (before adjustment) of %u bytes\n",
- resctrl_rmid_realloc_limit);
+ r->mon.rmid_realloc_limit);
ret = -EINVAL;
goto out_unlock;
}
- resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
+ r->mon.rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
out_unlock:
info_kn_unlock(of->kn);
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 95ffff4c7925..6562c1698474 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -288,6 +288,10 @@ enum resctrl_schema_fmt {
/**
* struct resctrl_mon - Monitoring related data of a resctrl resource.
* @num_rmid: Number of RMIDs available.
+ * @rmid_realloc_limit: Largest value for the reallocation threshold,
+ * in bytes.
+ * @rmid_realloc_threshold: Cache occupancy in bytes at which an RMID is
+ * considered available for re-allocation.
* @mbm_cfg_mask: Memory transactions that can be tracked when
* bandwidth monitoring events can be configured.
* @num_mbm_cntrs: Number of assignable counters.
@@ -299,6 +303,8 @@ enum resctrl_schema_fmt {
*/
struct resctrl_mon {
u32 num_rmid;
+ unsigned int rmid_realloc_limit;
+ unsigned int rmid_realloc_threshold;
unsigned int mbm_cfg_mask;
int num_mbm_cntrs;
bool mbm_cntr_assignable;
@@ -726,9 +732,6 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);
*/
bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r);
-extern unsigned int resctrl_rmid_realloc_threshold;
-extern unsigned int resctrl_rmid_realloc_limit;
-
int resctrl_init(void);
void resctrl_exit(void);
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 12/19] fs/resctrl: Check RMID limbo on every resource with occupancy
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (10 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 11/19] resctrl: Keep the RMID limbo threshold per resource Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 13/19] fs/resctrl: Manage assignable counters for every monitor resource Jinjie Ruan
` (7 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
An RMID is only reused once the L3 occupancy counter shows the cache has
gone cold. When occupancy is monitored on more than one resource, the
RMID has to wait for all of them.
Mark the RMID busy in the domains of every resource that has the
occupancy event, and have the limbo worker read the occupancy of the
resource its domain belongs to, against that resource's reallocation
threshold.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/monitor.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 4132258760fa..b7a21cbafa42 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -115,13 +115,13 @@ static void limbo_release_entry(struct rmid_entry *entry)
/*
* Check the RMIDs that are marked as busy for this domain. If the
- * reported LLC occupancy is below the threshold clear the busy bit and
+ * reported occupancy is below the threshold clear the busy bit and
* decrement the count. If the busy count gets to zero on an RMID, we
* free the RMID
*/
void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_resource *r = resctrl_arch_get_resource(d->hdr.rid);
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
struct rmid_entry *entry;
bool rmid_dirty = true;
@@ -286,8 +286,8 @@ int alloc_rmid(u32 closid)
static void add_rmid_to_limbo(struct rmid_entry *entry)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdt_l3_mon_domain *d;
+ struct rdt_resource *r;
u32 idx;
lockdep_assert_held(&rdtgroup_mutex);
@@ -298,16 +298,23 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
idx = resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid);
entry->busy = 0;
- list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, lockdep_is_cpus_held()) {
- /*
- * For the first limbo RMID in the domain,
- * setup up the limbo worker.
- */
- if (!has_busy_rmid(d))
- cqm_setup_limbo_handler(d, CQM_LIMBOCHECK_INTERVAL,
- RESCTRL_PICK_ANY_CPU);
- set_bit(idx, d->rmid_busy_llc);
- entry->busy++;
+ for_each_mon_capable_rdt_resource(r) {
+ /* Only resources with the occupancy event have a busy bitmap */
+ if (!resctrl_is_mon_event_enabled(r, QOS_OCCUP_EVENT_ID))
+ continue;
+
+ list_for_each_entry_rcu(d, &r->mon_domains, hdr.list,
+ lockdep_is_cpus_held()) {
+ /*
+ * For the first limbo RMID in the domain,
+ * setup up the limbo worker.
+ */
+ if (!has_busy_rmid(d))
+ cqm_setup_limbo_handler(d, CQM_LIMBOCHECK_INTERVAL,
+ RESCTRL_PICK_ANY_CPU);
+ set_bit(idx, d->rmid_busy_llc);
+ entry->busy++;
+ }
}
rmid_limbo_count++;
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 13/19] fs/resctrl: Manage assignable counters for every monitor resource
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (11 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 12/19] fs/resctrl: Check RMID limbo on every resource with occupancy Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 14/19] arm_mpam: resctrl: Halve the monitor counts of every resource on CDP Jinjie Ruan
` (6 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Creating or removing a monitor group only assigns or frees counters for
the L3 MBM events. Walk every resource that has assignable counters and
handle each of its MBM events.
Set the default event filter for each such resource, build the BMEC file
names from the event names, and register the shared info files once.
resctrl_l3_mon_resource_init() now covers more than the L3, so drop L3
from its name. mbm_L3_assignments keeps its name and stays L3 only.
No functional change as only the L3 can have assignable counters.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
fs/resctrl/internal.h | 4 +-
fs/resctrl/monitor.c | 99 +++++++++++++++++++++++++++----------------
fs/resctrl/rdtgroup.c | 44 ++++++++++---------
3 files changed, 87 insertions(+), 60 deletions(-)
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index fc98c8e7a2d8..79e458efe727 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -421,9 +421,9 @@ int alloc_rmid(u32 closid);
void free_rmid(u32 closid, u32 rmid);
-int resctrl_l3_mon_resource_init(void);
+int resctrl_mon_resource_init(void);
-void resctrl_l3_mon_resource_exit(void);
+void resctrl_mon_resource_exit(void);
void mon_event_count(void *info);
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index b7a21cbafa42..3e6acdf34121 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1351,19 +1351,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);
-
- if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r) ||
- !r->mon.mbm_assign_on_mkdir)
- return;
+ struct rdt_resource *r;
+ struct mon_evt *mevt;
- if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
- rdtgroup_assign_cntr_event(NULL, rdtgrp,
- resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID));
+ for_each_mon_capable_rdt_resource(r) {
+ if (!resctrl_arch_mbm_cntr_assign_enabled(r) ||
+ !r->mon.mbm_assign_on_mkdir)
+ continue;
- if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
- rdtgroup_assign_cntr_event(NULL, rdtgrp,
- resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID));
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ continue;
+ rdtgroup_assign_cntr_event(NULL, rdtgrp, mevt);
+ }
+ }
}
/*
@@ -1410,18 +1411,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);
-
- if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
- return;
+ struct rdt_resource *r;
+ struct mon_evt *mevt;
- if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
- rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID));
+ for_each_mon_capable_rdt_resource(r) {
+ if (!resctrl_arch_mbm_cntr_assign_enabled(r))
+ continue;
- if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
- rdtgroup_unassign_cntr_event(NULL, rdtgrp,
- resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID));
+ for_each_mon_event(r, mevt) {
+ if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+ continue;
+ rdtgroup_unassign_cntr_event(NULL, rdtgrp, mevt);
+ }
+ }
}
static int resctrl_parse_mem_transactions(char *tok, u32 *val)
@@ -1949,7 +1951,7 @@ static void closid_num_dirty_rmid_free(void)
}
/**
- * resctrl_l3_mon_resource_init() - Initialise global monitoring structures.
+ * resctrl_mon_resource_init() - Initialise global monitoring structures.
*
* Allocate and initialise global monitor resources that do not belong to a
* specific domain. i.e. the closid_num_dirty_rmid[] used to find the CLOSID
@@ -1959,37 +1961,49 @@ static void closid_num_dirty_rmid_free(void)
* Resctrl's cpuhp callbacks may be called before this point to bring a domain
* online.
*
+ * The L3 events remain the backing for the MBA software controller and for the
+ * event configuration files, which are named after the L3 events.
+ *
* Return: 0 for success, or -ENOMEM.
*/
-int resctrl_l3_mon_resource_init(void)
+int resctrl_mon_resource_init(void)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ bool assignable = false, configurable = true;
+ struct rdt_resource *r;
int ret;
- if (!r->mon_capable)
+ if (!resctrl_arch_mon_capable())
return 0;
- ret = closid_num_dirty_rmid_alloc(r);
+ ret = closid_num_dirty_rmid_alloc(l3);
if (ret)
return ret;
+ /*
+ * BMEC is L3 only: resctrl_arch_is_evt_configurable() has no resource
+ * argument. The L2 events are not configurable.
+ */
if (resctrl_arch_is_evt_configurable(QOS_MBM_TOTAL_EVENT_ID)) {
- resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID)->configurable = true;
+ resctrl_mon_evt(l3, QOS_MBM_TOTAL_EVENT_ID)->configurable = true;
resctrl_file_fflags_init("mbm_total_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
if (resctrl_arch_is_evt_configurable(QOS_MBM_LOCAL_EVENT_ID)) {
- resctrl_mon_evt(r, QOS_MBM_LOCAL_EVENT_ID)->configurable = true;
+ resctrl_mon_evt(l3, QOS_MBM_LOCAL_EVENT_ID)->configurable = true;
resctrl_file_fflags_init("mbm_local_bytes_config",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
}
- if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
+ if (resctrl_is_mon_event_enabled(l3, QOS_MBM_LOCAL_EVENT_ID))
mba_mbps_default_event = QOS_MBM_LOCAL_EVENT_ID;
- else if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
+ else if (resctrl_is_mon_event_enabled(l3, QOS_MBM_TOTAL_EVENT_ID))
mba_mbps_default_event = QOS_MBM_TOTAL_EVENT_ID;
- if (r->mon.mbm_cntr_assignable) {
+ for_each_mon_capable_rdt_resource(r) {
+ if (!r->mon.mbm_cntr_assignable)
+ continue;
+
if (resctrl_is_mon_event_enabled(r, QOS_MBM_TOTAL_EVENT_ID))
resctrl_mon_evt(r, QOS_MBM_TOTAL_EVENT_ID)->evt_cfg = r->mon.mbm_cfg_mask;
if (resctrl_is_mon_event_enabled(r, QOS_MBM_LOCAL_EVENT_ID))
@@ -1998,26 +2012,37 @@ int resctrl_l3_mon_resource_init(void)
READS_TO_LOCAL_S_MEM |
NON_TEMP_WRITE_TO_LOCAL_MEM);
r->mon.mbm_assign_on_mkdir = true;
+ assignable = true;
+ configurable &= r->mon.mbm_cntr_configurable;
+ }
+
+ if (assignable) {
resctrl_file_fflags_init("num_mbm_cntrs",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
resctrl_file_fflags_init("available_mbm_cntrs",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
- if (r->mon.mbm_cntr_configurable)
+ /*
+ * One file mode is shared by every resource's event_filter,
+ * so only make it writable when all assignable resources can
+ * configure their filter.
+ */
+ if (configurable)
resctrl_file_mode_init("event_filter", 0644);
resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
RFTYPE_RES_CACHE);
- resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
}
+ /* The counter assignment interface is named after the L3 events. */
+ if (l3->mon.mbm_cntr_assignable)
+ resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
+
return 0;
}
-void resctrl_l3_mon_resource_exit(void)
+void resctrl_mon_resource_exit(void)
{
- struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
-
- if (!r->mon_capable)
+ if (!resctrl_arch_mon_capable())
return;
closid_num_dirty_rmid_free();
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 328e78324f54..da84829f3d20 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1926,35 +1926,37 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
* Don't treat kernfs_find_and_get failure as an error, since this function may
* be called regardless of whether BMEC is supported or the event is enabled.
*/
-void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn,
+void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *mon_kn,
bool show)
{
- struct kernfs_node *kn_config, *mon_kn = NULL;
+ struct kernfs_node *kn_config, *lookup_kn = NULL;
+ struct mon_evt *mevt;
char name[32];
- if (!l3_mon_kn) {
+ if (!mon_kn) {
sprintf(name, "%s_MON", r->name);
- mon_kn = kernfs_find_and_get(kn_info, name);
- if (!mon_kn)
+ lookup_kn = kernfs_find_and_get(kn_info, name);
+ if (!lookup_kn)
return;
- l3_mon_kn = mon_kn;
+ mon_kn = lookup_kn;
}
- kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_total_bytes_config");
- if (kn_config) {
- kernfs_show(kn_config, show);
- kernfs_put(kn_config);
- }
+ for_each_mon_event(r, mevt) {
+ if (!mevt->configurable)
+ continue;
+
+ sprintf(name, "%s_config", mevt->name);
+ kn_config = kernfs_find_and_get(mon_kn, name);
+ if (!kn_config)
+ continue;
- kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_local_bytes_config");
- if (kn_config) {
kernfs_show(kn_config, show);
kernfs_put(kn_config);
}
/* Release the reference only if it was acquired */
- if (mon_kn)
- kernfs_put(mon_kn);
+ if (lookup_kn)
+ kernfs_put(lookup_kn);
}
const char *rdtgroup_name_by_closid(u32 closid)
@@ -4616,7 +4618,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
* Called when the first CPU of a domain comes online, regardless of whether
* the filesystem is mounted.
* During boot this may be called before global allocations have been made by
- * resctrl_l3_mon_resource_init().
+ * resctrl_mon_resource_init().
*
* Called during CPU online that may run as soon as CPU online callbacks
* are set up during resctrl initialization. The number of supported RMIDs
@@ -4818,13 +4820,13 @@ int resctrl_init(void)
io_alloc_init();
- ret = resctrl_l3_mon_resource_init();
+ ret = resctrl_mon_resource_init();
if (ret)
return ret;
ret = sysfs_create_mount_point(fs_kobj, "resctrl");
if (ret) {
- resctrl_l3_mon_resource_exit();
+ resctrl_mon_resource_exit();
return ret;
}
@@ -4859,7 +4861,7 @@ int resctrl_init(void)
cleanup_mountpoint:
sysfs_remove_mount_point(fs_kobj, "resctrl");
- resctrl_l3_mon_resource_exit();
+ resctrl_mon_resource_exit();
return ret;
}
@@ -4895,7 +4897,7 @@ static bool resctrl_online_domains_exist(void)
* When called by the architecture code, all CPUs and resctrl domains must be
* offline. This ensures the limbo and overflow handlers are not scheduled to
* run, meaning the data structures they access can be freed by
- * resctrl_l3_mon_resource_exit().
+ * resctrl_mon_resource_exit().
*
* After resctrl_exit() returns, the architecture code should return an
* error from all resctrl_arch_ functions that can do this.
@@ -4922,6 +4924,6 @@ void resctrl_exit(void)
* it can be used to umount resctrl.
*/
- resctrl_l3_mon_resource_exit();
+ resctrl_mon_resource_exit();
free_rmid_lru_list();
}
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 14/19] arm_mpam: resctrl: Halve the monitor counts of every resource on CDP
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (12 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 13/19] fs/resctrl: Manage assignable counters for every monitor resource Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 15/19] arm_mpam: resctrl: Look up the monitor domain id from the components Jinjie Ruan
` (5 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
CDP uses two PARTIDs per closid, which halves the number of monitoring
groups. resctrl_arch_set_cdp_enabled() only updates num_rmid and the
assignable counter count of the L3.
Update both counts for every resource that can monitor. Only the L3 has
monitors so far, so the counts do not change yet.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index d40c8eb7b300..df2f0674535e 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -203,8 +203,7 @@ static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *r)
int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable)
{
u32 partid_i = RESCTRL_RESERVED_CLOSID, partid_d = RESCTRL_RESERVED_CLOSID;
- struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
- struct rdt_resource *l3 = &res->resctrl_res;
+ struct rdt_resource *r;
int cpu;
if (!IS_ENABLED(CONFIG_EXPERT) && enable) {
@@ -226,11 +225,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable)
cdp_enabled = enable;
mpam_resctrl_controls[rid].cdp_enabled = enable;
- if (enable)
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx() / 2;
- else
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
-
/* The mbw_max feature can't hide cdp as it's a per-partid maximum. */
if (cdp_enabled && !mpam_resctrl_controls[RDT_RESOURCE_MBA].cdp_enabled)
mpam_resctrl_controls[RDT_RESOURCE_MBA].resctrl_res.alloc_capable = false;
@@ -259,7 +253,14 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable)
WRITE_ONCE(arm64_mpam_global_default, mpam_get_regval(current));
resctrl_reset_task_closids();
- mpam_resctrl_monitor_sync_abmc_vals(l3);
+
+ /* Each PARTID is split in two, which halves every monitor resource */
+ for_each_mon_capable_rdt_resource(r) {
+ r->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
+ if (cdp_enabled)
+ r->mon.num_rmid /= 2;
+ mpam_resctrl_monitor_sync_abmc_vals(r);
+ }
for_each_possible_cpu(cpu)
mpam_set_cpu_defaults(cpu, partid_d, partid_i, 0, 0);
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 15/19] arm_mpam: resctrl: Look up the monitor domain id from the components
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (13 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 14/19] arm_mpam: resctrl: Halve the monitor counts of every resource on CDP Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 16/19] arm_mpam: resctrl: Report counter assignment per resource Jinjie Ruan
` (4 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
The monitor domain id comes from whichever monitoring component the loop
happened to find last, and the monitor domain lookup uses the L3
cache-id. Neither works if the monitors of a resource are in a different
component from its controls, or if there are no controls at all, which
is the case on monitor only platforms.
Add mpam_resctrl_domain_id() to find the component that covers a CPU for
each of the resource's events. It returns the id of the first component
found and warns if another component reports a different id. Also pass
the id, not the component, to mpam_resctrl_domain_hdr_init().
No functional change: every resource has a single component covering a
CPU today, so the same id is returned.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 66 +++++++++++++++++++++++-----------
1 file changed, 45 insertions(+), 21 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index df2f0674535e..8a68b51d5811 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1568,14 +1568,14 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r)
mpam_reset_class_locked(res->class);
}
-static void mpam_resctrl_domain_hdr_init(int cpu, struct mpam_component *comp,
+static void mpam_resctrl_domain_hdr_init(int cpu, int id,
enum resctrl_res_level rid,
struct rdt_domain_hdr *hdr)
{
lockdep_assert_cpus_held();
INIT_LIST_HEAD(&hdr->list);
- hdr->id = mpam_resctrl_pick_domain_id(cpu, comp);
+ hdr->id = id;
hdr->rid = rid;
cpumask_set_cpu(cpu, &hdr->cpu_mask);
}
@@ -1642,6 +1642,43 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
return NULL;
}
+/*
+ * Find the domain ID for @cpu from the monitoring components of @r. Also
+ * fill @mon_comp, if not NULL, with the component that covers @cpu for each
+ * event. A negative ID means no component covers this CPU.
+ */
+static int mpam_resctrl_domain_id(int cpu, struct rdt_resource *r,
+ struct mpam_component **mon_comp)
+{
+ struct mpam_resctrl_mon *mon;
+ enum resctrl_event_id eventid;
+ int id = -1;
+
+ lockdep_assert_cpus_held();
+
+ for_each_mpam_resctrl_mon(mon, r, eventid) {
+ struct mpam_component *comp;
+ int comp_id;
+
+ if (!mon->class)
+ continue; // dummy resource
+
+ comp = find_component(mon->class, cpu);
+ if (mon_comp)
+ mon_comp[eventid] = comp;
+ if (!comp)
+ continue;
+
+ comp_id = mpam_resctrl_pick_domain_id(cpu, comp);
+ if (id < 0)
+ id = comp_id;
+ else
+ WARN_ON_ONCE(id != comp_id);
+ }
+
+ return id;
+}
+
static struct mpam_resctrl_dom *
mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
{
@@ -1677,7 +1714,8 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
dom->ctrl_comp = ctrl_comp;
ctrl_d = &dom->resctrl_ctrl_dom;
- mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
+ mpam_resctrl_domain_hdr_init(cpu, mpam_resctrl_pick_domain_id(cpu, ctrl_comp),
+ r->rid, &ctrl_d->hdr);
ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
err = resctrl_online_ctrl_domain(r, ctrl_d);
if (err)
@@ -1689,9 +1727,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
}
if (r->mon_capable) {
- struct mpam_component *any_mon_comp = NULL;
- struct mpam_resctrl_mon *mon;
- enum resctrl_event_id eventid;
+ int id;
/*
* Even if the monitor domain is backed by a different
@@ -1700,26 +1736,14 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
* Search each event's class list for a component with
* overlapping CPUs and set up the dom->mon_comp array.
*/
-
- for_each_mpam_resctrl_mon(mon, r, eventid) {
- struct mpam_component *mon_comp;
-
- if (!mon->class)
- continue; // dummy resource
-
- mon_comp = find_component(mon->class, cpu);
- dom->mon_comp[eventid] = mon_comp;
- if (mon_comp)
- any_mon_comp = mon_comp;
- }
- if (!any_mon_comp) {
- WARN_ON_ONCE(0);
+ id = mpam_resctrl_domain_id(cpu, r, dom->mon_comp);
+ if (WARN_ON_ONCE(id < 0)) {
err = -EFAULT;
goto offline_ctrl_domain;
}
mon_d = &dom->resctrl_mon_dom;
- mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
+ mpam_resctrl_domain_hdr_init(cpu, id, r->rid, &mon_d->hdr);
mon_d->hdr.type = RESCTRL_MON_DOMAIN;
err = resctrl_online_mon_domain(r, &mon_d->hdr);
if (err)
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 16/19] arm_mpam: resctrl: Report counter assignment per resource
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (14 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 15/19] arm_mpam: resctrl: Look up the monitor domain id from the components Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 17/19] arm_mpam: resctrl: Allow monitoring on resources other than the L3 Jinjie Ruan
` (3 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
resctrl_arch_mbm_cntr_assign_enabled() says assignment is on by checking
whether the resource is the L3. A platform whose L3 has no bandwidth
counters is then told assignment is on, although no counters were set
up.
Report the per-resource flag MPAM sets when it sets up the assignable
counters. Other resources can then report their own state.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 8a68b51d5811..470b37587890 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -130,7 +130,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_domain *d
bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r)
{
- return (r == &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res);
+ return r->mon.mbm_cntr_assignable;
}
int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 17/19] arm_mpam: resctrl: Allow monitoring on resources other than the L3
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (15 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 16/19] arm_mpam: resctrl: Report counter assignment per resource Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 18/19] arm_mpam: resctrl: Expose the L2 monitor events Jinjie Ruan
` (2 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
The MPAM driver assumes only the L3 monitors. resctrl_arch_mon_capable()
looks at the L3 only, a CPU's monitor-only domain is found with the L3
cache-id, and mpam_resctrl_monitor_init() always names the resource L3.
Check every resource for monitoring, find a monitor domain by the id its
component reports, and set the name and scope from the resource.
No functional change as only the L3 has monitors so far.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 77 +++++++++++++++++-----------------
1 file changed, 38 insertions(+), 39 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 470b37587890..704383304f6b 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -99,11 +99,12 @@ bool resctrl_arch_alloc_capable(void)
bool resctrl_arch_mon_capable(void)
{
- struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
- struct rdt_resource *l3 = &res->resctrl_res;
+ struct rdt_resource *r;
+
+ for_each_mon_capable_rdt_resource(r)
+ return true;
- /* All monitors are presented as being on the L3 cache */
- return l3->mon_capable;
+ return false;
}
bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt)
@@ -1337,35 +1338,39 @@ static int mpam_resctrl_monitor_init(struct rdt_resource *r,
struct mpam_resctrl_res *res = container_of(r, struct mpam_resctrl_res,
resctrl_res);
struct mpam_resctrl_mon *mon = mpam_resctrl_mon(r, type);
+ unsigned int level;
lockdep_assert_cpus_held();
+ /* Called once per event. The name is needed on monitor only platforms. */
+ if (r->rid == RDT_RESOURCE_L2) {
+ level = 2;
+ r->name = "L2";
+ r->mon_scope = RESCTRL_L2_CACHE;
+ } else {
+ level = 3;
+ r->name = "L3";
+ r->mon_scope = RESCTRL_L3_CACHE;
+ }
+
/*
- * There also needs to be an L3 cache present.
+ * There also needs to be a cache at this level present.
* The check just requires any online CPU and it can't go offline as we
* hold the cpu lock.
*/
- if (get_cpu_cacheinfo_id(raw_smp_processor_id(), 3) == -1)
+ if (get_cpu_cacheinfo_id(raw_smp_processor_id(), level) == -1)
return 0;
/*
- * If there are no MPAM resources on L3, force it into existence.
- * topology_matches_l3() already ensures this looks like the L3.
- * The domain-ids will be fixed up by mpam_resctrl_domain_hdr_init().
+ * If there are no MPAM resources on this cache level, force it into
+ * existence. The domain-ids will be fixed up by
+ * mpam_resctrl_domain_hdr_init().
*/
if (!res->class) {
- pr_warn_once("Faking L3 MSC to enable counters.\n");
+ pr_warn_once("Faking L%u MSC to enable counters.\n", level);
res->class = mon->class;
}
- /*
- * Called multiple times!, once per event type that has a
- * monitoring class.
- * Setting name is necessary on monitor only platforms.
- */
- r->name = "L3";
- r->mon_scope = RESCTRL_L3_CACHE;
-
/*
* num-rmid is the upper bound for the number of monitoring groups that
* can exist simultaneously, including the default monitoring group for
@@ -1730,9 +1735,8 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
int id;
/*
- * Even if the monitor domain is backed by a different
- * component, the L3 component IDs need to be used... only
- * there may be no ctrl_comp for the L3.
+ * The monitor domain ID comes from the monitor components, as
+ * there may be no ctrl_comp for this resource.
* Search each event's class list for a component with
* overlapping CPUs and set up the dom->mon_comp array.
*/
@@ -1769,28 +1773,26 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
}
/*
- * We know all the monitors are associated with the L3, even if there are no
- * controls and therefore no control component. Find the cache-id for the CPU
- * and use that to search for existing resctrl domains.
- * This relies on mpam_resctrl_pick_domain_id() using the L3 cache-id
- * for anything that is not a cache.
+ * There may be no control component to search, for example on monitor only
+ * platforms. Find the domain-id the monitors' component would report for
+ * this CPU and use that to search the resource's monitor domains.
+ * This relies on mpam_resctrl_pick_domain_id() giving the same id for every
+ * CPU that shares the component.
*/
-static struct mpam_resctrl_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu)
+static struct mpam_resctrl_dom *
+mpam_resctrl_get_mon_domain_from_cpu(int cpu, struct rdt_resource *r)
{
- int cache_id;
struct mpam_resctrl_dom *dom;
- struct mpam_resctrl_res *l3 = &mpam_resctrl_controls[RDT_RESOURCE_L3];
+ int id;
lockdep_assert_cpus_held();
- if (!l3->class)
- return NULL;
- cache_id = get_cpu_cacheinfo_id(cpu, 3);
- if (cache_id < 0)
+ id = mpam_resctrl_domain_id(cpu, r, NULL);
+ if (id < 0)
return NULL;
- list_for_each_entry_rcu(dom, &l3->resctrl_res.mon_domains, resctrl_mon_dom.hdr.list) {
- if (dom->resctrl_mon_dom.hdr.id == cache_id)
+ list_for_each_entry_rcu(dom, &r->mon_domains, resctrl_mon_dom.hdr.list) {
+ if (dom->resctrl_mon_dom.hdr.id == id)
return dom;
}
@@ -1810,11 +1812,8 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
return dom;
}
- if (r->rid != RDT_RESOURCE_L3)
- return NULL;
-
/* Search the mon domain list too - needed on monitor only platforms. */
- return mpam_resctrl_get_mon_domain_from_cpu(cpu);
+ return mpam_resctrl_get_mon_domain_from_cpu(cpu, r);
}
int mpam_resctrl_online_cpu(unsigned int cpu)
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 18/19] arm_mpam: resctrl: Expose the L2 monitor events
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (16 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 17/19] arm_mpam: resctrl: Allow monitoring on resources other than the L3 Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 19/19] Documentation: arm64: mpam: Describe " Jinjie Ruan
2026-11-27 2:42 ` [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
mpam_resctrl_pick_counters() skips cache classes that are not the L3, so
the CSU and MBWU monitors of an L2 MSC are never used. Allow L2 cache
classes to supply the L2 resource, and let an L2 class with usable MBWU
counters become the L2 bandwidth event.
Check the traffic match before the topology match. An L2 class can never
match the L3 traffic, and topology_matches_l3() warns when a cache has no
online CPU, which is reachable for an L2 cache during boot.
The L3 checks describe where memory bandwidth is measured.
'mbm_core_bytes' is the number of bytes the L2 cache sees rather than the
memory bandwidth, and an L2 class has its own scope and domain ids, so
neither check is needed for it.
No function change for the L3.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/resctrl/mpam_resctrl.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 704383304f6b..ce16afcdc1b0 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1128,9 +1128,10 @@ static void mpam_resctrl_pick_counters(void)
guard(srcu)(&mpam_srcu);
list_for_each_entry_srcu(class, &mpam_classes, classes_list,
srcu_read_lock_held(&mpam_srcu)) {
- /* The name of the resource is L3... */
- if (class->type == MPAM_CLASS_CACHE && class->level != 3) {
- pr_debug("class %u is a cache but not the L3", class->level);
+ if (class->type == MPAM_CLASS_CACHE && class->level != 2 &&
+ class->level != 3) {
+ pr_debug("class %u is a cache but not L2 or L3",
+ class->level);
continue;
}
@@ -1150,13 +1151,22 @@ static void mpam_resctrl_pick_counters(void)
if (update_rmid_limits(class))
break;
- counter_update_class(RDT_RESOURCE_L3, QOS_OCCUP_EVENT_ID, class);
+ counter_update_class(mpam_class_rid(class),
+ QOS_OCCUP_EVENT_ID, class);
break;
default:
break;
}
}
+ if (class->type == MPAM_CLASS_CACHE && class->level == 2 &&
+ class_has_usable_mbwu(class)) {
+ pr_debug("class %u has usable MBWU for the L2 resource\n",
+ class->level);
+ counter_update_class(RDT_RESOURCE_L2, QOS_MBM_TOTAL_EVENT_ID, class);
+ continue;
+ }
+
if (class_has_usable_mbwu(class) &&
topology_matches_l3(class) &&
traffic_matches_l3(class)) {
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [RFC PATCH v3 19/19] Documentation: arm64: mpam: Describe the L2 monitor events
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (17 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 18/19] arm_mpam: resctrl: Expose the L2 monitor events Jinjie Ruan
@ 2026-11-16 12:59 ` Jinjie Ruan
2026-11-27 2:42 ` [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-16 12:59 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
Cc: ruanjinjie
Resctrl can now monitor at the L2 scope, so MPAM exposes the CSU and
MBWU counters of an L2 group as l2c_occupancy and mbm_core_bytes.
Also update the resctrl documentation.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
Documentation/arch/arm64/mpam.rst | 25 ++++++++++++++++---------
Documentation/filesystems/resctrl.rst | 11 +++++++++++
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/Documentation/arch/arm64/mpam.rst b/Documentation/arch/arm64/mpam.rst
index e445f4078ee1..f0d24fdc7677 100644
--- a/Documentation/arch/arm64/mpam.rst
+++ b/Documentation/arch/arm64/mpam.rst
@@ -32,8 +32,9 @@ Because the user interface to MPAM is via resctrl, only MPAM features that are
compatible with resctrl can be exposed to user-space.
MSC are considered as a group based on the topology. MSC that correspond with
-the L3 cache are considered together, it is not possible to mix MSC between L2
-and L3 to 'cover' a resctrl schema.
+the L3 cache are considered together, as are MSC that correspond with the L2
+cache; it is not possible to mix MSC between L2 and L3 to 'cover' a resctrl
+schema.
The supported features are:
@@ -61,9 +62,11 @@ The supported features are:
When the MPAM driver finds multiple groups of MSC it can use for the 'MB'
schema, it prefers the group closest to the L3 cache.
-* Cache Storage Usage (CSU) counters can expose the 'llc_occupancy' provided
- there is at least one CSU monitor on each MSC that makes up the L3 group.
- Exposing CSU counters from other caches or devices is not supported.
+* Cache Storage Usage (CSU) counters expose the occupancy of the cache they
+ monitor: 'llc_occupancy' for the L3 group and 'l2c_occupancy' for the L2
+ group, provided there is at least one CSU monitor on each MSC that makes up
+ the group. Exposing CSU counters from other caches or devices is not
+ supported.
* Memory Bandwidth Usage (MBWU) on or after the L3 cache. resctrl uses the
L3 cache-id to identify where the memory bandwidth is measured. For this
@@ -82,10 +85,14 @@ The supported features are:
have a corresponding L3 cache. 'mbm_local_bytes' is not exposed as MPAM
cannot distinguish local traffic from global traffic.
- All these restrictions based on L3 cache are due to resctrl, currently, only
- supporting monitoring at the L3 scope. It is expected that going forward more
- MBWU monitors can be exposed to the user after support for more monitoring
- scopes is added to resctrl.
+* Memory Bandwidth Usage (MBWU) on the L2 cache. An MBWU monitor in an L2 MSC
+ counts the bytes the cache sees, which resctrl exposes as the
+ 'mbm_core_bytes' event on the L2 resource. The MSC is used for the L2 group
+ in the same way as for the L3 group above.
+
+These restrictions are due to resctrl only supporting monitoring at the L2
+and L3 cache scopes. MBWU monitors on caches at other levels, or on devices,
+are not exposed.
Command line parameters
=======================
diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index 2750f2eabf70..506ba55793b4 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -510,6 +510,17 @@ with the following files:
bytes) at which a previously used LLC_occupancy
counter can be considered for reuse.
+If monitoring is available at other cache levels there will be a
+"<LEVEL>_MON" directory for each of them. For example an L2 cache exposes
+"l2c_occupancy" and "mbm_core_bytes" in "L2_MON". These directories have the
+same "num_rmids", "mon_features", "mbm_assign_mode" and
+"max_threshold_occupancy" files as "L3_MON", and when the resource supports
+assignable counters, also "num_mbm_cntrs", "available_mbm_cntrs",
+"mbm_assign_on_mkdir" and "event_configs".
+
+The "mbm_L3_assignments" file in the resource group directories is specific
+to the L3 scope.
+
If telemetry monitoring is available there will be a "PERF_PKG_MON" directory
with the following files:
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
` (18 preceding siblings ...)
2026-11-16 12:59 ` [RFC PATCH v3 19/19] Documentation: arm64: mpam: Describe " Jinjie Ruan
@ 2026-11-27 2:42 ` Jinjie Ruan
19 siblings, 0 replies; 21+ messages in thread
From: Jinjie Ruan @ 2026-11-27 2:42 UTC (permalink / raw)
To: james.morse, ben.horgan, reinette.chatre, fenghuay,
catalin.marinas, will, mark.rutland, corbet, skhan, rdunlap,
tony.luck, Dave.Martin, babu.moger, fustini, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-arm-kernel, linux-doc, linux-kernel
在 2026/11/16 20:58, Jinjie Ruan 写道:
> Resctrl exposes cache occupancy and bandwidth monitoring only at the L3
> scope. MPAM can count the same things on an L2 cache: firmware points
> an MSC at the cache it belongs to, and its CSU and MBWU counters can
> report the occupancy of that L2 slice and the traffic the cache sees.
>
> This series first reworks resctrl's monitor bookkeeping to track events
> by scope instead of by resource, and then exposes those counters as
> "l2c_occupancy" and "mbm_core_bytes"
>
> The patch set is organized as follows:
>
> - Patches 1-4: Rename to drop the L3 prefix
> - Patches 5-7: Rework the bookkeeping, index monitor state by resource
> and event, index the event table by scope and eventid
> - Patches 8-13: Make the core per-resource and add the L2 events
> - Patches 14-18: Let the driver pick L2 classes for the L2 resource,
> and expose the L2 events
> - Patch 19: Update the documentation
Hi Reinette and Ben,
Does this refactoring now meet your expectations? or any new suggestions
for improvement?
In my opinion, the compatibility issue of the CPU-less node seems to
have been resolved, and L2 also reuses the monitoring path related to L3.
Best regards,
Jinjie
>
> Notes on the user interface
> ===========================
>
> The L3 event names and semantics, the L3_MON and mon_L3_xx names and
> the x86 PERF_PKG files are unchanged.
>
> The L2 bandwidth event is called mbm_core_bytes because it counts the
> bytes the L2 cache sees, which is not memory bandwidth.
>
> And mbm_L3_assignments remains L3-only.
>
> Testing
> =======
>
> QEMU, topology with L2, L3 and memory-controller MSCs:
>
> - info/L2_MON lists l2c_occupancy and mbm_core_bytes, and per-core
> mon_L2_xx directories are created.
>
> - Reads: l2c_occupancy 262144 bytes (50% of a 512KiB L2),
> llc_occupancy unchanged, mbm_core_bytes advances about 20GB per 2s
> sample.
>
> - CDP halves num_closids and the monitor counts of every monitor
> resource.
>
> - RMID limbo: a freed RMID is marked busy in every L2 and L3 monitor
> domain, and becomes allocatable again once those domains are
> offlined and the busy count reaches zero.
>
> QEMU branch: https://github.com/ruanjinjie-eng/qemu/tree/mpam
> Test cases: https://github.com/ruanjinjie-eng/mpam_testcase
>
> This series is rebased on v7.4 rc3 and also available at:
> https://github.com/ruanjinjie-eng/linux/commits/mpam-l2mon-scope
>
> Changes in RFC v3
> - The event table is indexed by scope instead of by resource (Reinette)
> - Patch 6 is split out so no helper takes an unused argument.
> - The RMID limbo threshold is kept per resource, so an L3 domain no
> longer compares its occupancy with an L2-sized value
> - Bugfixes are split out as their own series.
> - RFC v2: https://lore.kernel.org/all/20261029123611.1108424-1-ruanjinjie@huawei.com/
>
> Changes in RFC v2:
> - As Ben suggested, the existing event types now apply to any resource,
> instead of adding L2-only event IDs.
> - As Ben suggested, L2 bandwidth uses an assignable counter that stays
> with the monitoring group, not a monitor borrowed for each read.
> - The CDP change also halves the assignable counter count, for every
> monitor resource.
> - Split by subsystem so resctrl, x86 and MPAM can be reviewed separately.
> - Fix a CDP bug: a failed enable left the driver believing CDP was on.
> - RFC v1: https://lore.kernel.org/all/20261022084821.4014873-1-ruanjinjie@huawei.com/
>
> Jinjie Ruan (19):
> fs/resctrl: Rename monitor events to drop the L3 prefix
> x86/resctrl: Use the resource-agnostic monitor event names
> arm_mpam: resctrl: Use the resource-agnostic monitor event names
> resctrl: Remove the L3 monitor event names
> arm_mpam: resctrl: Index monitor state by resource and event
> x86,fs/resctrl: Record the resource that enables a monitor event
> x86,fs/resctrl: Track monitor events by scope
> fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources
> fs/resctrl: Add the L2 monitor events
> fs/resctrl: Set up MBM state and workers for every monitor resource
> resctrl: Keep the RMID limbo threshold per resource
> fs/resctrl: Check RMID limbo on every resource with occupancy
> fs/resctrl: Manage assignable counters for every monitor resource
> arm_mpam: resctrl: Halve the monitor counts of every resource on CDP
> arm_mpam: resctrl: Look up the monitor domain id from the components
> arm_mpam: resctrl: Report counter assignment per resource
> arm_mpam: resctrl: Allow monitoring on resources other than the L3
> arm_mpam: resctrl: Expose the L2 monitor events
> Documentation: arm64: mpam: Describe the L2 monitor events
>
> Documentation/arch/arm64/mpam.rst | 25 +-
> Documentation/filesystems/resctrl.rst | 11 +
> arch/x86/kernel/cpu/resctrl/core.c | 13 +-
> arch/x86/kernel/cpu/resctrl/intel_aet.c | 2 +-
> arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
> arch/x86/kernel/cpu/resctrl/monitor.c | 10 +-
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 +-
> drivers/resctrl/mpam_resctrl.c | 357 ++++++++++++++----------
> fs/resctrl/ctrlmondata.c | 13 +-
> fs/resctrl/internal.h | 55 +++-
> fs/resctrl/monitor.c | 328 +++++++++++++---------
> fs/resctrl/rdtgroup.c | 158 ++++++-----
> include/linux/resctrl.h | 36 ++-
> include/linux/resctrl_types.h | 16 +-
> 14 files changed, 619 insertions(+), 415 deletions(-)
>
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-11-27 2:42 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 12:58 [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 01/19] fs/resctrl: Rename monitor events to drop the L3 prefix Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 02/19] x86/resctrl: Use the resource-agnostic monitor event names Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 03/19] arm_mpam: resctrl: " Jinjie Ruan
2026-11-16 12:58 ` [RFC PATCH v3 04/19] resctrl: Remove the L3 " Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 05/19] arm_mpam: resctrl: Index monitor state by resource and event Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 06/19] x86,fs/resctrl: Record the resource that enables a monitor event Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 07/19] x86,fs/resctrl: Track monitor events by scope Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 08/19] fs/resctrl: Generalize __l3_mon_event_count for non-L3 resources Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 09/19] fs/resctrl: Add the L2 monitor events Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 10/19] fs/resctrl: Set up MBM state and workers for every monitor resource Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 11/19] resctrl: Keep the RMID limbo threshold per resource Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 12/19] fs/resctrl: Check RMID limbo on every resource with occupancy Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 13/19] fs/resctrl: Manage assignable counters for every monitor resource Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 14/19] arm_mpam: resctrl: Halve the monitor counts of every resource on CDP Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 15/19] arm_mpam: resctrl: Look up the monitor domain id from the components Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 16/19] arm_mpam: resctrl: Report counter assignment per resource Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 17/19] arm_mpam: resctrl: Allow monitoring on resources other than the L3 Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 18/19] arm_mpam: resctrl: Expose the L2 monitor events Jinjie Ruan
2026-11-16 12:59 ` [RFC PATCH v3 19/19] Documentation: arm64: mpam: Describe " Jinjie Ruan
2026-11-27 2:42 ` [RFC PATCH v3 00/19] arm_mpam: Add L2 cache monitors Jinjie Ruan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®