The call on_each_cpu_mask() runs the function on each CPU specified
by cpumask, which may include the local processor. So, replace the call
smp_call_function_many() with on_each_cpu_mask() to simplify the code.
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 6897c480ae55..68e14831a638 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -325,12 +325,7 @@ static void update_cpu_closid_rmid(void *info)
static void
update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
{
- int cpu = get_cpu();
-
- if (cpumask_test_cpu(cpu, cpu_mask))
- update_cpu_closid_rmid(r);
- smp_call_function_many(cpu_mask, update_cpu_closid_rmid, r, 1);
- put_cpu();
+ on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
}
static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
@@ -2135,13 +2130,9 @@ static int set_cache_qos_cfg(int level, bool enable)
/* Pick one CPU from each domain instance to update MSR */
cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
}
- cpu = get_cpu();
- /* Update QOS_CFG MSR on this cpu if it's in cpu_mask. */
- if (cpumask_test_cpu(cpu, cpu_mask))
- update(&enable);
- /* Update QOS_CFG MSR on all other cpus in cpu_mask. */
- smp_call_function_many(cpu_mask, update, &enable, 1);
- put_cpu();
+
+ /* Update QOS_CFG MSR on all the CPUs in cpu_mask */
+ on_each_cpu_mask(cpu_mask, update, &enable, 1);
free_cpumask_var(cpu_mask);
@@ -2618,7 +2609,7 @@ static int reset_all_ctrls(struct rdt_resource *r)
struct msr_param msr_param;
cpumask_var_t cpu_mask;
struct rdt_domain *d;
- int i, cpu;
+ int i;
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
return -ENOMEM;
@@ -2639,13 +2630,9 @@ static int reset_all_ctrls(struct rdt_resource *r)
for (i = 0; i < hw_res->num_closid; i++)
hw_dom->ctrl_val[i] = r->default_ctrl;
}
- cpu = get_cpu();
- /* Update CBM on this cpu if it's in cpu_mask. */
- if (cpumask_test_cpu(cpu, cpu_mask))
- rdt_ctrl_update(&msr_param);
- /* Update CBM on all other cpus in cpu_mask. */
- smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
- put_cpu();
+
+ /* Update CBM on all the CPUs in cpu_mask */
+ on_each_cpu_mask(cpu_mask, rdt_ctrl_update, &msr_param, 1);
free_cpumask_var(cpu_mask);
Hi Babu,
On 12/1/2022 7:37 AM, Babu Moger wrote:
> The call on_each_cpu_mask() runs the function on each CPU specified
> by cpumask, which may include the local processor. So, replace the call
> smp_call_function_many() with on_each_cpu_mask() to simplify the code.
Please move the solution to a new paragraph and drop the "So,". The two
instances of "the call" can be dropped also.
>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
Could you please move this patch to the beginning of this series?
Fixes and cleanups should go before new features.
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 29 ++++++++---------------------
> 1 file changed, 8 insertions(+), 21 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index 6897c480ae55..68e14831a638 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -325,12 +325,7 @@ static void update_cpu_closid_rmid(void *info)
> static void
> update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
> {
> - int cpu = get_cpu();
> -
> - if (cpumask_test_cpu(cpu, cpu_mask))
> - update_cpu_closid_rmid(r);
> - smp_call_function_many(cpu_mask, update_cpu_closid_rmid, r, 1);
> - put_cpu();
> + on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
> }
>
> static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
> @@ -2135,13 +2130,9 @@ static int set_cache_qos_cfg(int level, bool enable)
> /* Pick one CPU from each domain instance to update MSR */
> cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
> }
> - cpu = get_cpu();
> - /* Update QOS_CFG MSR on this cpu if it's in cpu_mask. */
> - if (cpumask_test_cpu(cpu, cpu_mask))
> - update(&enable);
> - /* Update QOS_CFG MSR on all other cpus in cpu_mask. */
> - smp_call_function_many(cpu_mask, update, &enable, 1);
> - put_cpu();
> +
> + /* Update QOS_CFG MSR on all the CPUs in cpu_mask */
> + on_each_cpu_mask(cpu_mask, update, &enable, 1);
>
> free_cpumask_var(cpu_mask);
>
> @@ -2618,7 +2609,7 @@ static int reset_all_ctrls(struct rdt_resource *r)
> struct msr_param msr_param;
> cpumask_var_t cpu_mask;
> struct rdt_domain *d;
> - int i, cpu;
> + int i;
>
> if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
> return -ENOMEM;
> @@ -2639,13 +2630,9 @@ static int reset_all_ctrls(struct rdt_resource *r)
> for (i = 0; i < hw_res->num_closid; i++)
> hw_dom->ctrl_val[i] = r->default_ctrl;
> }
> - cpu = get_cpu();
> - /* Update CBM on this cpu if it's in cpu_mask. */
> - if (cpumask_test_cpu(cpu, cpu_mask))
> - rdt_ctrl_update(&msr_param);
> - /* Update CBM on all other cpus in cpu_mask. */
> - smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
> - put_cpu();
> +
> + /* Update CBM on all the CPUs in cpu_mask */
> + on_each_cpu_mask(cpu_mask, rdt_ctrl_update, &msr_param, 1);
>
> free_cpumask_var(cpu_mask);
>
>
>
Should the snippet in resctrl_arch_update_domains() also be updated?
Reinette
[AMD Official Use Only - General]
Hi Reinette,
> -----Original Message-----
> From: Reinette Chatre <reinette.chatre@intel.com>
> Sent: Thursday, December 15, 2022 12:27 PM
> To: Moger, Babu <Babu.Moger@amd.com>; corbet@lwn.net;
> tglx@linutronix.de; mingo@redhat.com; bp@alien8.de
> Cc: fenghua.yu@intel.com; dave.hansen@linux.intel.com; x86@kernel.org;
> hpa@zytor.com; paulmck@kernel.org; akpm@linux-foundation.org;
> quic_neeraju@quicinc.com; rdunlap@infradead.org;
> damien.lemoal@opensource.wdc.com; songmuchun@bytedance.com;
> peterz@infradead.org; jpoimboe@kernel.org; pbonzini@redhat.com;
> chang.seok.bae@intel.com; pawan.kumar.gupta@linux.intel.com;
> jmattson@google.com; daniel.sneddon@linux.intel.com; Das1, Sandipan
> <Sandipan.Das@amd.com>; tony.luck@intel.com; james.morse@arm.com;
> linux-doc@vger.kernel.org; linux-kernel@vger.kernel.org;
> bagasdotme@gmail.com; eranian@google.com; christophe.leroy@csgroup.eu;
> jarkko@kernel.org; adrian.hunter@intel.com; quic_jiles@quicinc.com;
> peternewman@google.com
> Subject: Re: [PATCH v9 12/13] x86/resctrl: Replace smp_call_function_many()
> with on_each_cpu_mask()
>
> Hi Babu,
>
> On 12/1/2022 7:37 AM, Babu Moger wrote:
> > The call on_each_cpu_mask() runs the function on each CPU specified by
> > cpumask, which may include the local processor. So, replace the call
> > smp_call_function_many() with on_each_cpu_mask() to simplify the code.
>
> Please move the solution to a new paragraph and drop the "So,". The two
> instances of "the call" can be dropped also.
Sure.
>
> >
> > Signed-off-by: Babu Moger <babu.moger@amd.com>
> > ---
>
> Could you please move this patch to the beginning of this series?
> Fixes and cleanups should go before new features.
Sure.
>
> > arch/x86/kernel/cpu/resctrl/rdtgroup.c | 29 ++++++++---------------------
> > 1 file changed, 8 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > index 6897c480ae55..68e14831a638 100644
> > --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > @@ -325,12 +325,7 @@ static void update_cpu_closid_rmid(void *info)
> > static void update_closid_rmid(const struct cpumask *cpu_mask, struct
> > rdtgroup *r) {
> > - int cpu = get_cpu();
> > -
> > - if (cpumask_test_cpu(cpu, cpu_mask))
> > - update_cpu_closid_rmid(r);
> > - smp_call_function_many(cpu_mask, update_cpu_closid_rmid, r, 1);
> > - put_cpu();
> > + on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
> > }
> >
> > static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t
> > newmask, @@ -2135,13 +2130,9 @@ static int set_cache_qos_cfg(int level,
> bool enable)
> > /* Pick one CPU from each domain instance to update
> MSR */
> > cpumask_set_cpu(cpumask_any(&d->cpu_mask),
> cpu_mask);
> > }
> > - cpu = get_cpu();
> > - /* Update QOS_CFG MSR on this cpu if it's in cpu_mask. */
> > - if (cpumask_test_cpu(cpu, cpu_mask))
> > - update(&enable);
> > - /* Update QOS_CFG MSR on all other cpus in cpu_mask. */
> > - smp_call_function_many(cpu_mask, update, &enable, 1);
> > - put_cpu();
> > +
> > + /* Update QOS_CFG MSR on all the CPUs in cpu_mask */
> > + on_each_cpu_mask(cpu_mask, update, &enable, 1);
> >
> > free_cpumask_var(cpu_mask);
> >
> > @@ -2618,7 +2609,7 @@ static int reset_all_ctrls(struct rdt_resource *r)
> > struct msr_param msr_param;
> > cpumask_var_t cpu_mask;
> > struct rdt_domain *d;
> > - int i, cpu;
> > + int i;
> >
> > if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
> > return -ENOMEM;
> > @@ -2639,13 +2630,9 @@ static int reset_all_ctrls(struct rdt_resource *r)
> > for (i = 0; i < hw_res->num_closid; i++)
> > hw_dom->ctrl_val[i] = r->default_ctrl;
> > }
> > - cpu = get_cpu();
> > - /* Update CBM on this cpu if it's in cpu_mask. */
> > - if (cpumask_test_cpu(cpu, cpu_mask))
> > - rdt_ctrl_update(&msr_param);
> > - /* Update CBM on all other cpus in cpu_mask. */
> > - smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
> > - put_cpu();
> > +
> > + /* Update CBM on all the CPUs in cpu_mask */
> > + on_each_cpu_mask(cpu_mask, rdt_ctrl_update, &msr_param, 1);
> >
> > free_cpumask_var(cpu_mask);
> >
> >
> >
>
> Should the snippet in resctrl_arch_update_domains() also be updated?
Yes. It should be changed also. Will fix it.
Thanks
Babu
>
> Reinette
© 2016 - 2026 Red Hat, Inc.