Re: [PATCH v2 30/45] arm_mpam: resctrl: Pre-allocate assignable monitors
From: Jonathan Cameron <jonathan.cameron@huawei.com>
Date: 2026-01-06 14:29:42
Also in:
kvmarm, lkml
On Fri, 19 Dec 2025 18:11:32 +0000 Ben Horgan [off-list ref] wrote:
From: James Morse <james.morse@arm.com> When there are not enough monitors, MPAM is able to emulate ABMC by making a smaller number of monitors assignable. These monitors still need to be allocated from the driver, and mapped to whichever control/monitor group resctrl wants to use them with. Add a second array to hold the monitor values indexed by resctrl's cntr_id. When CDP is in use, two monitors are needed so the available number of counters halves. Platforms with one monitor will have zero monitors when CDP is in use. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> --- Changes since rfc: Move __free kmalloc -> kcalloc
Trivial comments only, Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
quoted hunk ↗ jump to hunk
static inline int mpam_alloc_csu_mon(struct mpam_class *class)diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index bea16bc096f7..e96d320c219c 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c
+/*
+ * 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)
+{
+ struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
+ struct rdt_resource *l3 = &res->resctrl_res;
+ struct mpam_class *class = mon->class;
+ u16 num_mbwu_mon;
+
+ if (mon->mbwu_idx_to_mon) {
+ pr_debug("monitors free running\n");
+ return 0;
+ }
+
+ int *rmid_array __free(kfree) =
+ kcalloc(resctrl_arch_system_num_rmid_idx(), sizeof(int), GFP_KERNEL);It's a long line, but I'd prefer sizeof(*rmid_array). could use kmalloc_array to avoid zeroing just before you fill it with -1.
+
+ if (!rmid_array) {
+ pr_debug("Failed to allocate RMID array\n");
+ return -ENOMEM;
+ }
+ memset(rmid_array, -1, resctrl_arch_system_num_rmid_idx() * sizeof(int));
+
+ num_mbwu_mon = class->props.num_mbwu_mon;
+ mon->assigned_counters = __alloc_mbwu_array(mon->class, num_mbwu_mon);
+ if (IS_ERR(mon->assigned_counters))
+ return PTR_ERR(mon->assigned_counters);
+ mon->mbwu_idx_to_mon = no_free_ptr(rmid_array);
+
+ mpam_resctrl_monitor_sync_abmc_vals(l3);
+
+ return 0;
+}