From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Viresh Kumar <viresh.kumar@linaro.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
Sumit Semwal <sumit.semwal@linaro.org>,
Lifeng Zheng <zhenglifeng1@huawei.com>,
linux-kernel@vger.kernel.org, zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH V2] cpufreq: conservative: Reset requested_freq on limits change
Date: Fri, 20 Mar 2026 18:02:00 +0800 [thread overview]
Message-ID: <4c75f644-2c06-48b1-a72b-1b84be7ba4ab@oss.qualcomm.com> (raw)
In-Reply-To: <d846a141a98ac0482f20560fcd7525c0f0ec2f30.1773999467.git.viresh.kumar@linaro.org>
On 3/20/2026 5:38 PM, Viresh Kumar wrote:
> A recently reported issue highlighted that the cached requested_freq
> is not guaranteed to stay in sync with policy->cur. If the platform
> changes the actual CPU frequency after the governor sets one (e.g.
> due to platform-specific frequency scaling) and a re-sync occurs
> later, policy->cur may diverge from requested_freq.
>
> This can lead to incorrect behavior in the conservative governor.
> For example, the governor may assume the CPU is already running at
> the maximum frequency and skip further increases even though there
> is still headroom.
>
> Avoid this by resetting the cached requested_freq to policy->cur on
> detecting a change in policy limits.
>
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
> Reported-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> Tested-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> Link: https://lore.kernel.org/all/20260210115458.3493646-1-zhenglifeng1@huawei.com/
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> [v2]
> - Completely different design to solve the problem.
>
> drivers/cpufreq/cpufreq_conservative.c | 12 ++++++++++++
> drivers/cpufreq/cpufreq_governor.c | 3 +++
> drivers/cpufreq/cpufreq_governor.h | 1 +
> 3 files changed, 16 insertions(+)
>
> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index e0e847764511..df01d33993d8 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -313,6 +313,17 @@ static void cs_start(struct cpufreq_policy *policy)
> dbs_info->requested_freq = policy->cur;
> }
>
> +static void cs_limits(struct cpufreq_policy *policy)
> +{
> + struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
> +
> + /*
> + * The limits have changed, so may have the current frequency. Reset
> + * requested_freq to avoid any unintended outcomes due to the mismatch.
> + */
> + dbs_info->requested_freq = policy->cur;
> +}
> +
> static struct dbs_governor cs_governor = {
> .gov = CPUFREQ_DBS_GOVERNOR_INITIALIZER("conservative"),
> .kobj_type = { .default_groups = cs_groups },
> @@ -322,6 +333,7 @@ static struct dbs_governor cs_governor = {
> .init = cs_init,
> .exit = cs_exit,
> .start = cs_start,
> + .limits = cs_limits,
> };
>
> #define CPU_FREQ_GOV_CONSERVATIVE (cs_governor.gov)
> diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
> index 36eb7aee4bcd..acf101878733 100644
> --- a/drivers/cpufreq/cpufreq_governor.c
> +++ b/drivers/cpufreq/cpufreq_governor.c
> @@ -563,6 +563,7 @@ EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_stop);
>
> void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy)
> {
> + struct dbs_governor *gov = dbs_governor_of(policy);
> struct policy_dbs_info *policy_dbs;
>
> /* Protect gov->gdbs_data against cpufreq_dbs_governor_exit() */
> @@ -574,6 +575,8 @@ void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy)
> mutex_lock(&policy_dbs->update_mutex);
> cpufreq_policy_apply_limits(policy);
> gov_update_sample_delay(policy_dbs, 0);
> + if (gov->limits)
> + gov->limits(policy);
> mutex_unlock(&policy_dbs->update_mutex);
>
> out:
> diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
> index 168c23fd7fca..1462d59277bd 100644
> --- a/drivers/cpufreq/cpufreq_governor.h
> +++ b/drivers/cpufreq/cpufreq_governor.h
> @@ -138,6 +138,7 @@ struct dbs_governor {
> int (*init)(struct dbs_data *dbs_data);
> void (*exit)(struct dbs_data *dbs_data);
> void (*start)(struct cpufreq_policy *policy);
> + void (*limits)(struct cpufreq_policy *policy);
> };
>
> static inline struct dbs_governor *dbs_governor_of(struct cpufreq_policy *policy)
--
Thx and BRs,
Zhongqiu Han
next prev parent reply other threads:[~2026-03-20 10:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 9:38 [PATCH V2] cpufreq: conservative: Reset requested_freq on limits change Viresh Kumar
2026-03-20 10:02 ` Zhongqiu Han [this message]
2026-03-20 11:51 ` Rafael J. Wysocki
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=4c75f644-2c06-48b1-a72b-1b84be7ba4ab@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=sumit.semwal@linaro.org \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=zhenglifeng1@huawei.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