[RFC PATCH 21/38] arm_mpam: resctrl: Pre-allocate assignable monitors
Jonathan Cameron
jonathan.cameron at huawei.com
Thu Dec 18 05:42:40 PST 2025
On Fri, 5 Dec 2025 21:58:44 +0000
James Morse <james.morse at arm.com> wrote:
> 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 at arm.com>
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index de5220fed97d..f607feaf0126 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -806,6 +863,41 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
> return comp->comp_id;
> }
>
> +/*
> + * 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];
> + size_t array_size = resctrl_arch_system_num_rmid_idx() * sizeof(int);
> + int *rmid_array __free(kfree) = kmalloc(array_size, GFP_KERNEL);
kcalloc? Given you call it an array I assume it is one. Will zero though
and if you really care about optimizing that out add a comment.
Move this...
> + 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;
> + }
Down to here. See cleanup.h notes that summarize how much Linus doesn't want
people not declaring these inline because of how much it hurts readability.
> +
> + if (!rmid_array) {
> + pr_debug("Failed to allocate RMID array\n");
> + return -ENOMEM;
> + }
> + memset(rmid_array, -1, array_size);
> +
> + 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;
> +}
> +
> static void mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
> enum resctrl_event_id type)
> {
> @@ -847,6 +939,16 @@ static void mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
> * space.
> */
> l3->mon.num_rmid = 1;
> +
> + switch (type) {
> + case QOS_L3_MBM_LOCAL_EVENT_ID:
> + case QOS_L3_MBM_TOTAL_EVENT_ID:
> + mpam_resctrl_monitor_init_abmc(mon);
> +
> + return;
> + default:
> + return;
> + }
> }
> }
>
More information about the linux-arm-kernel
mailing list