Commit 99522fe6 authored by Viresh Kumar's avatar Viresh Kumar Committed by Rafael J. Wysocki

cpufreq: Remove cpufreq_governor_lock

We used to drop policy->rwsem just before calling __cpufreq_governor()
in some cases earlier and so it was possible that __cpufreq_governor()
ran concurrently via separate threads for the same policy.

In order to guarantee valid state transitions for governors,
'governor_enabled' was required to be protected using some locking
and cpufreq_governor_lock was added for that.

But now __cpufreq_governor() is always called under policy->rwsem,
and 'governor_enabled' is protected against races even without
cpufreq_governor_lock.

Get rid of the extra lock now.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Tested-by: default avatarJuri Lelli <juri.lelli@arm.com>
Tested-by: default avatarShilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
[ rjw : Changelog ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 49f18560
...@@ -147,8 +147,6 @@ void cpufreq_update_util(u64 time, unsigned long util, unsigned long max) ...@@ -147,8 +147,6 @@ void cpufreq_update_util(u64 time, unsigned long util, unsigned long max)
rcu_read_unlock(); rcu_read_unlock();
} }
DEFINE_MUTEX(cpufreq_governor_lock);
/* Flag to suspend/resume CPUFreq governors */ /* Flag to suspend/resume CPUFreq governors */
static bool cpufreq_suspended; static bool cpufreq_suspended;
...@@ -2015,11 +2013,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, ...@@ -2015,11 +2013,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event); pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event);
mutex_lock(&cpufreq_governor_lock);
if ((policy->governor_enabled && event == CPUFREQ_GOV_START) if ((policy->governor_enabled && event == CPUFREQ_GOV_START)
|| (!policy->governor_enabled || (!policy->governor_enabled
&& (event == CPUFREQ_GOV_LIMITS || event == CPUFREQ_GOV_STOP))) { && (event == CPUFREQ_GOV_LIMITS || event == CPUFREQ_GOV_STOP))) {
mutex_unlock(&cpufreq_governor_lock);
return -EBUSY; return -EBUSY;
} }
...@@ -2028,8 +2024,6 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, ...@@ -2028,8 +2024,6 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
else if (event == CPUFREQ_GOV_START) else if (event == CPUFREQ_GOV_START)
policy->governor_enabled = true; policy->governor_enabled = true;
mutex_unlock(&cpufreq_governor_lock);
ret = policy->governor->governor(policy, event); ret = policy->governor->governor(policy, event);
if (!ret) { if (!ret) {
...@@ -2039,12 +2033,10 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, ...@@ -2039,12 +2033,10 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
policy->governor->initialized--; policy->governor->initialized--;
} else { } else {
/* Restore original values */ /* Restore original values */
mutex_lock(&cpufreq_governor_lock);
if (event == CPUFREQ_GOV_STOP) if (event == CPUFREQ_GOV_STOP)
policy->governor_enabled = true; policy->governor_enabled = true;
else if (event == CPUFREQ_GOV_START) else if (event == CPUFREQ_GOV_START)
policy->governor_enabled = false; policy->governor_enabled = false;
mutex_unlock(&cpufreq_governor_lock);
} }
if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) || if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
......
...@@ -232,7 +232,6 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate) ...@@ -232,7 +232,6 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate)
} }
extern struct mutex dbs_data_mutex; extern struct mutex dbs_data_mutex;
extern struct mutex cpufreq_governor_lock;
void dbs_check_cpu(struct cpufreq_policy *policy); void dbs_check_cpu(struct cpufreq_policy *policy);
int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event); int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
void od_register_powersave_bias_handler(unsigned int (*f) void od_register_powersave_bias_handler(unsigned int (*f)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment