From: "zhenglifeng (A)" <zhenglifeng1@huawei.com>
To: Zihuan Zhang <zhangzihuan@kylinos.cn>,
"rafael J . wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] cpufreq: Avoid get_governor() for first policy
Date: Thu, 24 Jul 2025 19:28:21 +0800 [thread overview]
Message-ID: <456c9900-1ce3-4a87-8c29-46e65e1240cb@huawei.com> (raw)
In-Reply-To: <20250724093621.61871-1-zhangzihuan@kylinos.cn>
On 2025/7/24 17:36, Zihuan Zhang wrote:
> When a cpufreq driver registers the first policy, it may attempt to
> initialize the policy governor from `last_governor`. However, this is
> meaningless for the first policy instance, because `last_governor` is
> only updated when policies are removed (e.g. during CPU offline).
>
> The `last_governor` mechanism is intended to restore the previously
> used governor across CPU hotplug events. For the very first policy,
> there is no "previous governor" to restore, so calling
> get_governor(last_governor) is unnecessary and potentially confusing.
>
> This patch skips looking up `last_governor` when registering the first
> policy. Instead, it directly uses the default governor after all
> governors have been registered and are available.
>
> This avoids meaningless lookups, reduces unnecessary module reference
> handling, and simplifies the initial policy path.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index d7426e1d8bdd..b5ebd4519eab 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1121,9 +1121,9 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
> int ret;
>
> if (has_target()) {
> - /* Update policy governor to the one used before hotplug. */
> - gov = get_governor(policy->last_governor);
> - if (gov) {
> + if (policy->last_governor[0] != '\0') {
> + /* Update policy governor to the one used before hotplug. */
> + gov = get_governor(policy->last_governor);
What if gov is null here? For example, the last governor has been removed.
The default governor should be used in this situation I think.
> pr_debug("Restoring governor %s for cpu %d\n",
> gov->name, policy->cpu);
> } else {
next prev parent reply other threads:[~2025-07-24 11:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 9:36 Zihuan Zhang
2025-07-24 11:28 ` zhenglifeng (A) [this message]
2025-07-25 0:32 ` Zihuan Zhang
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=456c9900-1ce3-4a87-8c29-46e65e1240cb@huawei.com \
--to=zhenglifeng1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhangzihuan@kylinos.cn \
/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®