Re: [PATCH v5 12/16] fs/resctrl: Program kernel mode assignments on CPU hotplug

From: Reinette Chatre

Date: Wed Sep 16 2026 - 01:44:57 EST


Hi Babu,

On 8/26/26 12:32 PM, Babu Moger wrote:


> ---
> fs/resctrl/rdtgroup.c | 59 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 06e74b027044..97e4176669e5 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -4951,11 +4951,67 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
> return err;
> }
>
> +/*
> + * resctrl_kmode_online_cpu() - Program kernel mode association for @cpu
> + * @cpu: CPU that has just been brought online
> + *
> + * If assign_global_enable_per_cpu is active and the rdtgroup has an active
> + * kernel-mode association, add @cpu to kmode_cpu_mask and program the
> + * corresponding kernel mode association.
> + */
> +static void resctrl_kmode_online_cpu(unsigned int cpu)
> +{
> + struct rdtgroup *rdtgrp = resctrl_kcfg.active.k_rdtgrp;
> + bool assign_ctrl, assign_mon;
> +
> + if (resctrl_kcfg.active.kmode_cur != RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU ||
> + !rdtgrp || !rdtgrp->kmode)
> + return;
> +
> + assign_ctrl = (resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN);
> + assign_mon = (resctrl_kcfg.active.mon_mode == KMODE_ASSIGN);
> +
> + cpumask_set_cpu(cpu, &rdtgrp->kmode_cpu_mask);
> +
> + resctrl_arch_configure_kmode(cpumask_of(cpu), rdtgrp->closid, assign_ctrl,
> + rdtgrp->mon.rmid, assign_mon, true);

If I counted right, at end of this series, resctrl_arch_configure_kmode() is called
six times and _every_ call is preceded with the same two line pattern above:

assign_ctrl = (resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN);
assign_mon = (resctrl_kcfg.active.mon_mode == KMODE_ASSIGN);

Could this be simplified with a single helper that does something like:

static void resctrl_configure_global_kmode(const struct cpumask *mask,
struct rdtgroup *rdtgrp, bool enable)
{
resctrl_arch_configure_global_kmode(mask, rdtgrp->closid,
resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN,
rdtgrp->mon.rmid,
resctrl_kcfg.active.mon_mode == KMODE_ASSIGN,
enable);
}


> +}
> +
> +/*
> + * resctrl_kmode_offline_cpu() - Clear kernel mode association for @cpu
> + * @cpu: CPU being taken offline.
> + *
> + * If assign_global_enable_per_cpu is active, disable the kernel mode
> + * association for @cpu and remove it from kmode_cpu_mask.
> + */
> +static void resctrl_kmode_offline_cpu(unsigned int cpu)
> +{
> + struct rdtgroup *rdtgrp = resctrl_kcfg.active.k_rdtgrp;
> + bool assign_ctrl, assign_mon;
> +
> + if (resctrl_kcfg.active.kmode_cur != RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU ||
> + !rdtgrp || !rdtgrp->kmode)
> + return;
> +
> + if (!cpumask_test_cpu(cpu, &rdtgrp->kmode_cpu_mask))
> + return;
> +
> + assign_ctrl = (resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN);
> + assign_mon = (resctrl_kcfg.active.mon_mode == KMODE_ASSIGN);
> +
> + cpumask_clear_cpu(cpu, &rdtgrp->kmode_cpu_mask);
> +
> + resctrl_arch_configure_kmode(cpumask_of(cpu), rdtgrp->closid, assign_ctrl,
> + rdtgrp->mon.rmid, assign_mon, false);
> +}
> +
> void resctrl_online_cpu(unsigned int cpu)
> {
> mutex_lock(&rdtgroup_mutex);
> /* The CPU is set in default rdtgroup after online. */
> cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask);
> + /* Program any active kernel mode association on this CPU. */

This comment is not helpful.

> + resctrl_kmode_online_cpu(cpu);
> mutex_unlock(&rdtgroup_mutex);
> }
>
> @@ -4999,6 +5055,9 @@ void resctrl_offline_cpu(unsigned int cpu)
> }
> }
>
> + /* Clear any active kernel mode association on this CPU. */
> + resctrl_kmode_offline_cpu(cpu);
> +
> if (!l3->mon_capable)
> goto out_unlock;
>

Reinette