Re: [PATCH] cpufreq: optimize policy_is_shared()

From: Rafael J. Wysocki

Date: Wed Mar 18 2026 - 16:29:50 EST


On Tue, Mar 17, 2026 at 7:47 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
>
> On 14-03-26, 15:25, Yury Norov wrote:
> > The switch to cpumask_nth() over cpumask_weight(), as it may return
> > earlier - as soon as the function counts the required number of CPUs.
> >
> > Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
> > ---
> > include/linux/cpufreq.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> > index cc894fc38971..8ca2bcb3d7ae 100644
> > --- a/include/linux/cpufreq.h
> > +++ b/include/linux/cpufreq.h
> > @@ -232,7 +232,7 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy)
> >
> > static inline bool policy_is_shared(struct cpufreq_policy *policy)
> > {
> > - return cpumask_weight(policy->cpus) > 1;
> > + return cpumask_nth(1, policy->cpus) < nr_cpumask_bits;
> > }
> >
> > #ifdef CONFIG_CPU_FREQ
>
> Acked-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>

Applied as 7.1 material, thanks!