Skip to content

Commit 1517176

Browse files
Vincent Donnefortrafaeljw
authored andcommitted
cpufreq: Make policy min/max hard requirements
When applying the policy min/max limits, the requested frequency is simply clamped to not be out of range. It means, however, if one of the boundaries isn't an available frequency, the frequency resolution can return a value out of those limits, depending on the relation used. e.g. freq{0,1,2} being available frequencies. freq0 policy->min freq1 policy->max freq2 | | | | | 17kHz 18kHz 19kHz 20kHz 21kHz __resolve_freq(21kHz, CPUFREQ_RELATION_L) -> 21kHz (out of bounds) __resolve_freq(17kHz, CPUFREQ_RELATION_H) -> 17kHz (out of bounds) If, during the policy init, we resolve the requested min/max to existing frequencies, we ensure that any CPUFREQ_RELATION_* would resolve to a frequency which is inside the policy min/max range. Making the policy limits rigid helps to introduce the inefficient frequencies support. Resolving an inefficient frequency to an efficient one should not transgress policy->max (which can be set for thermal reason) and having a value we can trust simplify this comparison. Signed-off-by: Vincent Donnefort <[email protected]> Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8354eb9 commit 1517176

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,8 +2523,15 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
25232523
if (ret)
25242524
return ret;
25252525

2526+
/*
2527+
* Resolve policy min/max to available frequencies. It ensures
2528+
* no frequency resolution will neither overshoot the requested maximum
2529+
* nor undershoot the requested minimum.
2530+
*/
25262531
policy->min = new_data.min;
25272532
policy->max = new_data.max;
2533+
policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L);
2534+
policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H);
25282535
trace_cpu_frequency_limits(policy);
25292536

25302537
policy->cached_target_freq = UINT_MAX;

0 commit comments

Comments
 (0)