Skip to content

Commit 3f49582

Browse files
rafaeljwSasha Levin
authored and
Sasha Levin
committed
cpufreq/sched: Fix the usage of CPUFREQ_NEED_UPDATE_LIMITS
[ Upstream commit cfde542 ] Commit 8e461a1 ("cpufreq: schedutil: Fix superfluous updates caused by need_freq_update") modified sugov_should_update_freq() to set the need_freq_update flag only for drivers with CPUFREQ_NEED_UPDATE_LIMITS set, but that flag generally needs to be set when the policy limits change because the driver callback may need to be invoked for the new limits to take effect. However, if the return value of cpufreq_driver_resolve_freq() after applying the new limits is still equal to the previously selected frequency, the driver callback needs to be invoked only in the case when CPUFREQ_NEED_UPDATE_LIMITS is set (which means that the driver specifically wants its callback to be invoked every time the policy limits change). Update the code accordingly to avoid missing policy limits changes for drivers without CPUFREQ_NEED_UPDATE_LIMITS. Fixes: 8e461a1 ("cpufreq: schedutil: Fix superfluous updates caused by need_freq_update") Closes: https://lore.kernel.org/lkml/[email protected]/ Reported-by: Stephan Gerhold <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Christian Loehle <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 2d4fbad commit 3f49582

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

kernel/sched/cpufreq_schedutil.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
8383

8484
if (unlikely(sg_policy->limits_changed)) {
8585
sg_policy->limits_changed = false;
86-
sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
86+
sg_policy->need_freq_update = true;
8787
return true;
8888
}
8989

@@ -95,10 +95,22 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
9595
static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
9696
unsigned int next_freq)
9797
{
98-
if (sg_policy->need_freq_update)
98+
if (sg_policy->need_freq_update) {
9999
sg_policy->need_freq_update = false;
100-
else if (sg_policy->next_freq == next_freq)
100+
/*
101+
* The policy limits have changed, but if the return value of
102+
* cpufreq_driver_resolve_freq() after applying the new limits
103+
* is still equal to the previously selected frequency, the
104+
* driver callback need not be invoked unless the driver
105+
* specifically wants that to happen on every update of the
106+
* policy limits.
107+
*/
108+
if (sg_policy->next_freq == next_freq &&
109+
!cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS))
110+
return false;
111+
} else if (sg_policy->next_freq == next_freq) {
101112
return false;
113+
}
102114

103115
sg_policy->next_freq = next_freq;
104116
sg_policy->last_freq_update_time = time;

0 commit comments

Comments
 (0)