Skip to content

Commit db9ea3b

Browse files
Xuewen Yanrafaeljw
authored andcommitted
cpufreq: Use a smaller freq for the policy->max when verify
When driver use the cpufreq_frequency_table_verify() as the cpufreq_driver->verify's callback. It may cause the policy->max bigger than the freq_qos's max freq. Just as follow: unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_available_frequencies 614400 768000 988000 1228800 1469000 1586000 1690000 1833000 2002000 2093000 unisoc:/sys/devices/system/cpu/cpufreq/policy0 # echo 1900000 > scaling_max_freq unisoc:/sys/devices/system/cpu/cpufreq/policy0 # echo 1900000 > scaling_min_freq unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_max_freq 2002000 unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_min_freq 2002000 When user set the qos_min and qos_max as the same value, and the value is not in the freq-table, the above scenario will occur. This is because in cpufreq_frequency_table_verify() func, when it can not find the freq in table, it will change the policy->max to be a bigger freq, as above, because there is no 1.9G in the freq-table, the policy->max would be set to 2.002G. As a result, the cpufreq_policy->max is bigger than the user's qos_max. This is unreasonable. So use a smaller freq when can not find the freq in fre-table, to prevent the policy->max exceed the qos's max freq. Signed-off-by: Xuewen Yan <[email protected]> Acked-by: Viresh Kumar <[email protected]> Reviewed-by: Dhruva Gole <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4cece76 commit db9ea3b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/cpufreq/freq_table.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
7070
struct cpufreq_frequency_table *table)
7171
{
7272
struct cpufreq_frequency_table *pos;
73-
unsigned int freq, next_larger = ~0;
73+
unsigned int freq, prev_smaller = 0;
7474
bool found = false;
7575

7676
pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
@@ -86,12 +86,12 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
8686
break;
8787
}
8888

89-
if ((next_larger > freq) && (freq > policy->max))
90-
next_larger = freq;
89+
if ((prev_smaller < freq) && (freq <= policy->max))
90+
prev_smaller = freq;
9191
}
9292

9393
if (!found) {
94-
policy->max = next_larger;
94+
policy->max = prev_smaller;
9595
cpufreq_verify_within_cpu_limits(policy);
9696
}
9797

0 commit comments

Comments
 (0)