Skip to content

Commit 10e1498

Browse files
committed
cpufreq: Limit resolving a frequency to policy min/max
JIRA: https://issues.redhat.com/browse/RHEL-83803 commit d394abc Author: Shivnandan Kumar <quic_kshivnan@quicinc.com> Date: Tue Feb 27 14:43:51 2024 +0530 Resolving a frequency to an efficient one should not transgress policy->max (which can be set for thermal reason) and policy->min. Currently, there is possibility where scaling_cur_freq can exceed scaling_max_freq when scaling_max_freq is an inefficient frequency. Add a check to ensure that resolving a frequency will respect policy->min/max. Cc: All applicable <stable@vger.kernel.org> Fixes: 1f39fa0 ("cpufreq: Introducing CPUFREQ_RELATION_E") Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com> [ rjw: Whitespace adjustment, changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent e53ec8a commit 10e1498

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

include/linux/cpufreq.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,18 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
10451045
efficiencies);
10461046
}
10471047

1048+
static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy, int idx)
1049+
{
1050+
unsigned int freq;
1051+
1052+
if (idx < 0)
1053+
return false;
1054+
1055+
freq = policy->freq_table[idx].frequency;
1056+
1057+
return freq == clamp_val(freq, policy->min, policy->max);
1058+
}
1059+
10481060
static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
10491061
unsigned int target_freq,
10501062
unsigned int relation)
@@ -1078,7 +1090,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
10781090
return 0;
10791091
}
10801092

1081-
if (idx < 0 && efficiencies) {
1093+
/* Limit frequency index to honor policy->min/max */
1094+
if (!cpufreq_is_in_limits(policy, idx) && efficiencies) {
10821095
efficiencies = false;
10831096
goto retry;
10841097
}

0 commit comments

Comments
 (0)