Skip to content

Commit

Permalink
cpufreq: Limit resolving a frequency to policy min/max
Browse files Browse the repository at this point in the history
[ Upstream commit d394abc ]

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: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Shivnandan Kumar authored and gregkh committed Apr 3, 2024
1 parent c6e60e7 commit 39a8e54
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion include/linux/cpufreq.h
Expand Up @@ -1021,6 +1021,18 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
efficiencies);
}

static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy, int idx)
{
unsigned int freq;

if (idx < 0)
return false;

freq = policy->freq_table[idx].frequency;

return freq == clamp_val(freq, policy->min, policy->max);
}

static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
unsigned int target_freq,
unsigned int relation)
Expand Down Expand Up @@ -1054,7 +1066,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
return 0;
}

if (idx < 0 && efficiencies) {
/* Limit frequency index to honor policy->min/max */
if (!cpufreq_is_in_limits(policy, idx) && efficiencies) {
efficiencies = false;
goto retry;
}
Expand Down

0 comments on commit 39a8e54

Please sign in to comment.