From 57a354d20a01287bd173b13231eb5afcda337eee Mon Sep 17 00:00:00 2001 From: Dave Martin Date: Fri, 11 Sep 2026 17:36:11 +0100 Subject: [PATCH 1/8] x86,fs/resctrl: Add resctrl_arch_preconvert_bw() On MPAM systems the rounding behaviour of the MBA control would be improved if the rounding in the fs/resctrl code is removed but this is not the case for x86. To allow any rounding or conversion of the bandwidth value provided by the user to be specified by the arch code a new arch hook is required. Introduce resctrl_arch_preconvert_bw(), and add its x86 implementation. This is currently unused in resctrl but when plumbed in it will replace the call to roundup() in bw_validate(). Signed-off-by: Dave Martin Signed-off-by: Ben Horgan Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Reviewed-by: Gavin Shan Link: https://patch.msgid.link/20260911163613.1131447-2-ben.horgan@arm.com --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 6 ++++++ include/linux/resctrl.h | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index e74f1ed54b86..62044489b052 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -16,9 +16,15 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include "internal.h" +u32 resctrl_arch_preconvert_bw(const struct rdt_resource *r, u32 val) +{ + return roundup(val, (unsigned long)r->membw.bw_gran); +} + int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, u32 closid, enum resctrl_conf_type t, u32 cfg_val) { diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index dd09c2ce9a0f..10dfdca7f4bf 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -505,6 +505,25 @@ bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r); */ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable); +/** + * resctrl_arch_preconvert_bw() - Prepare bandwidth control value for arch use. + * @r: Resource whose schema was written. + * @val: Bandwidth control value written to the schemata file by userspace. + * + * Convert the user provided bandwidth control value to an appropriate form for + * consumption by the hardware driver for resource @r. Converted value is stored + * in rdt_ctrl_domain::staged_config[] for later consumption by + * resctrl_arch_update_domains(). Is not called when MBA software controller is + * enabled. + * + * Architectures for which this pre-conversion hook is not useful should supply + * an implementation of this function that just returns @val unmodified. + * + * Return: + * The converted value. + */ +u32 resctrl_arch_preconvert_bw(const struct rdt_resource *r, u32 val); + /* * Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. From 255f92316ac1017478e9ace42cafdeb6c98c1f25 Mon Sep 17 00:00:00 2001 From: Ben Horgan Date: Fri, 11 Sep 2026 17:36:12 +0100 Subject: [PATCH 2/8] arm_mpam: resctrl: Add pass-through resctrl_arch_preconvert_bw() resctrl rounds up the percentage value of the MBA based on the bw_gran. As MPAM uses a binary fixed point fraction format for MBA rather than a decimal percentage, this introduces rounding errors. Without this additional rounding, if the user reads the value in an MB schema and then writes it back to the schema, the value in hardware won't change. However, with this additional rounding, this guarantee is broken for systems with mbw_wd < 7. resctrl is introducing resctrl_arch_preconvert_bw() to allow the arch code to specify the conversion resctrl does to the user-provided bandwidth value. Add the MPAM version of resctrl_arch_preconvert_bw(). This does no conversion. Signed-off-by: Ben Horgan Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Reviewed-by: Gavin Shan Link: https://patch.msgid.link/20260911163613.1131447-3-ben.horgan@arm.com --- drivers/resctrl/mpam_resctrl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 9d223057953a..f2c651e9f6ea 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -148,6 +148,11 @@ bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level rid) return mpam_resctrl_controls[rid].cdp_enabled; } +u32 resctrl_arch_preconvert_bw(const struct rdt_resource *r, u32 val) +{ + return val; +} + /** * resctrl_reset_task_closids() - Reset the PARTID/PMG values for all tasks. * From 942135446059a63778f1121a75c5b3c959341b47 Mon Sep 17 00:00:00 2001 From: Dave Martin Date: Fri, 11 Sep 2026 17:36:13 +0100 Subject: [PATCH 3/8] fs/resctrl: Factor MBA parse-time conversion to be per-arch The control value parser for the MB resource currently coerces the memory bandwidth percentage value from userspace to be an exact multiple of the rdt_resource::resctrl_membw::bw_gran parameter. On MPAM systems, this results in somewhat worse-than-worst-case rounding, since the bandwidth granularity advertised to resctrl by the MPAM driver is in general only an approximation to the actual hardware granularity on these systems, and the hardware bandwidth allocation control value is not natively a percentage -- necessitating a further conversion in the resctrl_arch_update_domains() path, regardless of the conversion done at parse time. For MPAM and x86 use their custom pre-prepared parse-time conversion, resctrl_arch_preconvert_bw(). This will avoid accumulated error from rounding the value twice on MPAM systems. For x86 systems there is no functional change. Clarify the documentation, but avoid overly exact promises. Clamping to bw_min and bw_max still feels generic: leave it in the core code, for now. Signed-off-by: Dave Martin Signed-off-by: Ben Horgan Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Ben Horgan Reviewed-by: Reinette Chatre Reviewed-by: Gavin Shan Link: https://patch.msgid.link/20260911163613.1131447-4-ben.horgan@arm.com --- Documentation/filesystems/resctrl.rst | 17 +++++++++-------- fs/resctrl/ctrlmondata.c | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst index e4b66af55ffb..dd4f80da419c 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -236,12 +236,11 @@ with respect to allocation: user can request. "bandwidth_gran": - The granularity in which the memory bandwidth - percentage is allocated. The allocated - b/w percentage is rounded off to the next - control step available on the hardware. The - available bandwidth control steps are: - min_bandwidth + N * bandwidth_gran. + The approximate granularity in which the memory bandwidth + percentage is allocated. The allocated bandwidth percentage is + rounded up or down to the closest control step available on the + hardware. The available hardware steps are no larger than this + value. "delay_linear": Indicates if the delay scale is linear or @@ -881,8 +880,10 @@ The minimum bandwidth percentage value for each cpu model is predefined and can be looked up through "info/MB/min_bandwidth". The bandwidth granularity that is allocated is also dependent on the cpu model and can be looked up at "info/MB/bandwidth_gran". The available bandwidth -control steps are: min_bw + N * bw_gran. Intermediate values are rounded -to the next control step available on the hardware. +control steps are, approximately, min_bw + N * bw_gran. The steps may +appear irregular due to rounding to an exact percentage: bw_gran is the +maximum interval between the percentage values corresponding to any two +adjacent steps in the hardware. The bandwidth throttling is a core specific mechanism on some of Intel SKUs. Using a high bandwidth and a low bandwidth setting on two threads diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 18ec9f564b5a..cafebdff70dc 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -37,8 +37,8 @@ typedef int (ctrlval_parser_t)(struct rdt_parse_data *data, /* * Check whether MBA bandwidth percentage value is correct. The value is * checked against the minimum and max bandwidth values specified by the - * hardware. The allocated bandwidth percentage is rounded to the next - * control step available on the hardware. + * hardware. The allocated bandwidth percentage is converted as appropriate + * for consumption by the specific hardware driver. */ static bool bw_validate(char *buf, u32 *data, struct rdt_resource *r) { @@ -71,7 +71,7 @@ static bool bw_validate(char *buf, u32 *data, struct rdt_resource *r) return false; } - *data = roundup(bw, (unsigned long)r->membw.bw_gran); + *data = resctrl_arch_preconvert_bw(r, bw); return true; } From 4b31656d917c46c6d9f874162ede4f54b2a5959f Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 21 Aug 2026 11:11:27 +0300 Subject: [PATCH 4/8] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() After passing an overflow check, it's safe to assume that snprintf() returns the number of characters emitted. So drop the unnecessary call to strlen(). Signed-off-by: Dmitry Antipov Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://patch.msgid.link/20260821081128.19242-1-dmantipov@yandex.ru --- fs/resctrl/rdtgroup.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5dcbb0a964e8..68be9b903ac6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2858,7 +2858,7 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type { struct resctrl_schema *s; const char *suffix = ""; - int ret, cl; + int cl; s = kzalloc_obj(*s); if (!s) @@ -2882,14 +2882,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type break; } - ret = snprintf(s->name, sizeof(s->name), "%s%s", r->name, suffix); - if (ret >= sizeof(s->name)) { + cl = snprintf(s->name, sizeof(s->name), "%s%s", r->name, suffix); + if (cl >= sizeof(s->name)) { kfree(s); return -EINVAL; } - cl = strlen(s->name); - /* * If CDP is supported by this resource, but not enabled, * include the suffix. This ensures the tabular format of the From a3f5e6eba41885dcffb635b54d6c4a18aa579cd5 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 21 Aug 2026 11:11:28 +0300 Subject: [PATCH 5/8] fs/resctrl: Simplify pseudo_lock_measure_trigger() Use convenient kstrtoint_from_user() to simplify pseudo_lock_measure_trigger(). No functional changes. Signed-off-by: Dmitry Antipov Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://patch.msgid.link/20260821081128.19242-2-dmantipov@yandex.ru --- fs/resctrl/pseudo_lock.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c index dea2b4bf966f..56ab63f19bad 100644 --- a/fs/resctrl/pseudo_lock.c +++ b/fs/resctrl/pseudo_lock.c @@ -750,17 +750,10 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file, size_t count, loff_t *ppos) { struct rdtgroup *rdtgrp = file->private_data; - size_t buf_size; - char buf[32]; int ret; int sel; - buf_size = min(count, (sizeof(buf) - 1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; - - buf[buf_size] = '\0'; - ret = kstrtoint(buf, 10, &sel); + ret = kstrtoint_from_user(user_buf, count, 10, &sel); if (ret == 0) { if (sel != 1 && sel != 2 && sel != 3) return -EINVAL; From a17d099481bd11f0911993a8e69992269f92ad12 Mon Sep 17 00:00:00 2001 From: Tony Luck Date: Tue, 15 Sep 2026 12:04:31 -0700 Subject: [PATCH 6/8] x86/resctrl: Update documented unit for the "activity" event The unit for the AET (Application Energy Telemetry) activity event[1] is nF, not F, see https://github.com/intel/Intel-PMT/blob/main/xml/CWF/OOBMSM/RMID-ENERGY/cwf_common.xml#L9 Fixes: a8848c4b43ad ("x86,fs/resctrl: Update documentation for telemetry events") Signed-off-by: Tony Luck Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://patch.msgid.link/20260915190431.18189-1-tony.luck@intel.com --- Documentation/filesystems/resctrl.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst index dd4f80da419c..b52795e03303 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -642,7 +642,7 @@ When monitoring is enabled all MON groups will also contain: during execution of instructions summed across all logical CPUs on a package for the current monitoring group. - "activity" also reports a floating point value (in Farads). This provides + "activity" also reports a floating point value (in nanofarads). This provides an estimate of work done independent of the frequency that the CPUs used for execution. From 50e5282df427830fcd810e553f0e355d9cccb3e2 Mon Sep 17 00:00:00 2001 From: Tony Luck Date: Wed, 30 Sep 2026 10:15:54 -0700 Subject: [PATCH 7/8] x86,fs/resctrl: Add event group descriptions for Intel Diamond Rapids Intel Diamond Rapids exposes Application Energy Telemetry through two new PMT aggregator GUIDs: one covering the "energy" feature, and one covering the "perf" feature, both documented in the Intel-PMT XML repository at https://github.com/intel/Intel-PMT The "perf" aggregator references two events not previously enumerated by resctrl: retired instructions (INST_RETIRED), and a count of unhalted core clock cycles perceived by hardware as contributing to instruction execution (PCNT). Add definitions for both aggregators, and add the two new events to the resctrl filesystem so they can be exposed to user space. Signed-off-by: Tony Luck Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://patch.msgid.link/20260930171554.12794-1-tony.luck@intel.com --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 34 +++++++++++++++++++++++++ fs/resctrl/monitor.c | 2 ++ include/linux/resctrl_types.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c index c22c3cf5167d..66cd8c2c7a51 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -125,9 +125,43 @@ static struct event_group perf_0x26557651 = { } }; +/* + * Link: https://github.com/intel/Intel-PMT/blob/main/xml/DMR/OOBMSM/RMID-ENERGY/dmr_aggregator.xml + */ +static struct event_group energy_0x47903099 = { + .pfname = "energy", + .guid = 0x47903099, + .num_rmid = 256, + .mmio_size = XML_MMIO_SIZE(256, 2, 3), + .num_events = 2, + .evts = { + EVT(PMT_EVENT_ENERGY, 0, 18), + EVT(PMT_EVENT_ACTIVITY, 1, 18), + } +}; + +/* + * Link: https://github.com/intel/Intel-PMT/blob/main/xml/DMR/OOBMSM/RMID-PERF/dmr_aggregator.xml + */ +static struct event_group perf_0x1415910a = { + .pfname = "perf", + .guid = 0x1415910a, + .num_rmid = 256, + .mmio_size = XML_MMIO_SIZE(256, 4, 3), + .num_events = 4, + .evts = { + EVT(PMT_EVENT_UNHALTED_REF_CYCLES, 0, 0), + EVT(PMT_EVENT_UNHALTED_CORE_CYCLES, 1, 0), + EVT(PMT_EVENT_INST_RETIRED, 2, 0), + EVT(PMT_EVENT_PCNT, 3, 0), + } +}; + static struct event_group *known_event_groups[] = { &energy_0x26696143, + &energy_0x47903099, &perf_0x26557651, + &perf_0x1415910a, }; #define for_each_event_group(_peg) \ diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 73413cb128ea..04e4ea612b7c 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1041,6 +1041,8 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] = { 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), }; bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a5f56faa18d2..e2e2cf3d9ff6 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -60,6 +60,8 @@ enum resctrl_event_id { PMT_EVENT_AUTO_C6_RES, PMT_EVENT_UNHALTED_REF_CYCLES, PMT_EVENT_UOPS_RETIRED, + PMT_EVENT_INST_RETIRED, + PMT_EVENT_PCNT, /* Must be the last */ QOS_NUM_EVENTS, From 2c10b3fa5bdf61e344bc522e6c2e00d870ce7ab8 Mon Sep 17 00:00:00 2001 From: Tony Luck Date: Fri, 9 Oct 2026 12:39:23 -0700 Subject: [PATCH 8/8] fs/resctrl: Ensure default group reports tasks on monitor-only systems resctrl can be mounted on a system that supports monitoring but not allocation. On such a system reading the "tasks" file in the default group reports no tasks, even when there are tasks assigned to the default group. This problem occurs because the check for whether a task belongs to a CTRL_MON group is gated by a check for whether the system supports allocation. The resctrl_arch_alloc_capable() check in is_closid_match() breaks task reporting for the default group on monitor-only systems so remove this check. On systems that support allocation the check is redundant. Fixes: e6b2fac36fcc ("x86/resctrl: Use is_closid_match() in more places") Closes: https://sashiko.dev/#/patchset/20260831174421.13921-1-tony.luck%40intel.com?part=9 Reported-by: Sashiko Signed-off-by: Tony Luck Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://patch.msgid.link/20261009193923.15498-1-tony.luck@intel.com --- fs/resctrl/rdtgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 68be9b903ac6..57ab090072c2 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -685,7 +685,7 @@ static int __rdtgroup_move_task(struct task_struct *tsk, static bool is_closid_match(struct task_struct *t, struct rdtgroup *r) { - return (resctrl_arch_alloc_capable() && (r->type == RDTCTRL_GROUP) && + return (r->type == RDTCTRL_GROUP && resctrl_arch_match_closid(t, r->closid)); }