From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Yury Norov <ynorov@nvidia.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>, zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH] cpufreq: optimize policy_is_shared()
Date: Mon, 16 Mar 2026 16:38:07 +0800 [thread overview]
Message-ID: <20c1e58c-bbd8-49b0-bda0-91e3459134dd@oss.qualcomm.com> (raw)
In-Reply-To: <20260314192544.605914-1-ynorov@nvidia.com>
On 3/15/2026 3:25 AM, 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@nvidia.com>
> ---
> 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
Hi Yury,
Thanks for the patch.
I see the intent of switching from cpumask_weight() to cpumask_nth() to
allow an early exit once we know there are at least two CPUs in the
mask. Functionally this looks equivalent.
That said, policy_is_shared() appears to be used mostly during governor
/driver bring-up paths (e.g. sugov_start(),cpufreq_dbs_governor_start(),
acpi_cpufreq_cpu_init(), etc.), rather than a hot runtime path. Given
that, I'm not sure the micro-optimization is worth the readability cost.
Also, cpumask_nth()'s documented return value is ">= nr_cpu_ids if such
cpu doesn't exist", so comparing against nr_cpu_ids would match the API
contract more directly than nr_cpumask_bits (even if they are currently
equivalent). [1][2]
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/cpumask.h#n540
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/cpumask.h#n78
--
Thx and BRs,
Zhongqiu Han
next prev parent reply other threads:[~2026-03-16 8:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 19:25 Yury Norov
2026-03-16 8:38 ` Zhongqiu Han [this message]
2026-03-17 6:47 ` Viresh Kumar
2026-03-18 20:29 ` Rafael J. Wysocki
2026-03-17 9:20 ` Zhongqiu Han
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20c1e58c-bbd8-49b0-bda0-91e3459134dd@oss.qualcomm.com \
--to=zhongqiu.han@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=ynorov@nvidia.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®