From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Lifeng Zheng <zhenglifeng1@huawei.com>,
Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 1/2] cpufreq: Avoid redundant target() calls for unchanged limits
Date: Wed, 25 Nov 2026 11:27:11 -0500 [thread overview]
Message-ID: <20261125162652.774210-1-sashal@kernel.org> (raw)
In-Reply-To: <2026112508-whenever-distress-43ae@gregkh>
From: Viresh Kumar <viresh.kumar@linaro.org>
[ Upstream commit 9801be8bef65dbcbc40c1a9c2f03d70ed67a5d30 ]
Drivers setting CPUFREQ_NEED_UPDATE_LIMITS expect target() to be
invoked even if the target frequency remains unchanged, so they can
update their internal policy limits state.
Currently the core invokes target() unconditionally whenever the
requested frequency matches policy->cur for such drivers, even if
policy->min and policy->max haven't changed since the previous update.
Track pending policy limit updates explicitly and skip redundant
target() invocations when neither the target frequency nor the
effective limits changed.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Lifeng Zheng <zhenglifeng1@huawei.com>
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Link: https://patch.msgid.link/d0107c364b709abca21acf88072220bc05478594.1779423281.git.viresh.kumar@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Stable-dep-of: 342d3a73c5db ("cpufreq: Force passing target frequency to driver during resume")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/cpufreq/cpufreq.c | 31 ++++++++++++++++++++++---------
include/linux/cpufreq.h | 3 +++
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 962faa2463db6..94f611512cfc8 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2407,9 +2407,13 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
* exactly same freq is called again and so we can save on few function
* calls.
*/
- if (target_freq == policy->cur &&
- !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS))
- return 0;
+ if (target_freq == policy->cur) {
+ if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
+ !policy->update_limits)
+ return 0;
+
+ policy->update_limits = false;
+ }
if (cpufreq_driver->target) {
/*
@@ -2669,6 +2673,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
{
struct cpufreq_policy_data new_data;
struct cpufreq_governor *old_gov;
+ unsigned int freq;
int ret;
memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
@@ -2701,12 +2706,20 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
* compiler optimizations around them because they may be accessed
* concurrently by cpufreq_driver_resolve_freq() during the update.
*/
- WRITE_ONCE(policy->max, __resolve_freq(policy, new_data.max,
- new_data.min, new_data.max,
- CPUFREQ_RELATION_H));
- new_data.min = __resolve_freq(policy, new_data.min, new_data.min,
- new_data.max, CPUFREQ_RELATION_L);
- WRITE_ONCE(policy->min, new_data.min > policy->max ? policy->max : new_data.min);
+ freq = __resolve_freq(policy, new_data.max, new_data.min, new_data.max,
+ CPUFREQ_RELATION_H);
+ if (freq != policy->max) {
+ WRITE_ONCE(policy->max, freq);
+ policy->update_limits = true;
+ }
+
+ freq = __resolve_freq(policy, new_data.min, new_data.min, new_data.max,
+ CPUFREQ_RELATION_L);
+ freq = min(freq, policy->max);
+ if (freq != policy->min) {
+ WRITE_ONCE(policy->min, freq);
+ policy->update_limits = true;
+ }
trace_cpu_frequency_limits(policy);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 69034172a7558..fa5d92d408a8c 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -145,6 +145,9 @@ struct cpufreq_policy {
/* Per policy boost supported flag. */
bool boost_supported;
+ /* Pending policy->min/max update for the driver */
+ bool update_limits;
+
/* The policy has been suspended. */
bool suspended;
--
2.53.0
next prev parent reply other threads:[~2026-11-25 16:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 10:10 FAILED: patch "[PATCH] cpufreq: Force passing target frequency to driver during" failed to apply to 6.18-stable tree gregkh
2026-11-25 16:27 ` Sasha Levin [this message]
2026-11-25 16:27 ` [PATCH 6.18.y 2/2] cpufreq: Force passing target frequency to driver during resume Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2026-11-25 10:10 FAILED: patch "[PATCH] cpufreq: Fix updates of cached resolved frequency and index" failed to apply to 6.18-stable tree gregkh
2026-11-25 17:02 ` [PATCH 6.18.y 1/2] cpufreq: Avoid redundant target() calls for unchanged limits Sasha Levin
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=20261125162652.774210-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=stable@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhenglifeng1@huawei.com \
--cc=zhongqiu.han@oss.qualcomm.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