summaryrefslogtreecommitdiff
path: root/drivers/cpufreq/qcom-cpufreq.c
diff options
context:
space:
mode:
authorJunjie Wu <junjiew@codeaurora.org>2015-06-10 17:57:07 -0700
committerDavid Keitel <dkeitel@codeaurora.org>2016-03-23 20:03:00 -0700
commit1a7d6caef616f6ad46ecf3b9548464e6972a3bea (patch)
tree84a0a3164a0d3a7c3c1db0d6233da8e02832f93e /drivers/cpufreq/qcom-cpufreq.c
parentdb44d1e057ce4c3396668fd0e55cba71729ce71e (diff)
cpufreq: Check current frequency in device driver
__cpufreq_driver_target() checks if policy->cur is same as target_freq without holding any lock. This function is used by governor to directly set CPU frequency. Governor calling this function can't hold any CPUfreq framework locks due to deadlock possibility. However, this results in a race condition where one thread could see a stale policy->cur while another thread is changing CPU frequency. Thread A: Governor calls __cpufreq_driver_target(), starts increasing frequency but hasn't sent out CPUFREQ_POSTCHANGE notification yet. Thread B: Some other driver (could be thermal mitigation) starts limiting frequency using cpufreq_update_policy(). Every limits are applied to policy->min/max and final policy->max happens to be same as policy->cur. __cpufreq_driver_target() simply returns 0. Thread A: Governor finish scaling and now policy->cur violates policy->max and could last forever until next CPU frequency scaling happens. Shifting the responsibility of checking policy->cur and target_freq to CPUfreq device driver would resolve the race as long as the device driver holds a common mutex. Change-Id: I6f943228e793a4a4300c58b3ae0143e09ed01d7d Signed-off-by: Junjie Wu <junjiew@codeaurora.org>
Diffstat (limited to 'drivers/cpufreq/qcom-cpufreq.c')
-rw-r--r--drivers/cpufreq/qcom-cpufreq.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/cpufreq/qcom-cpufreq.c b/drivers/cpufreq/qcom-cpufreq.c
index 009f8d9911be..09f10647982b 100644
--- a/drivers/cpufreq/qcom-cpufreq.c
+++ b/drivers/cpufreq/qcom-cpufreq.c
@@ -71,12 +71,15 @@ static int msm_cpufreq_target(struct cpufreq_policy *policy,
unsigned int target_freq,
unsigned int relation)
{
- int ret = -EFAULT;
+ int ret = 0;
int index;
struct cpufreq_frequency_table *table;
mutex_lock(&per_cpu(suspend_data, policy->cpu).suspend_mutex);
+ if (target_freq == policy->cur)
+ goto done;
+
if (per_cpu(suspend_data, policy->cpu).device_suspended) {
pr_debug("cpufreq: cpu%d scheduling frequency change "
"in suspend.\n", policy->cpu);