|
@@ -28,7 +28,7 @@
|
|
#include <linux/jiffies.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/percpu.h>
|
|
-
|
|
|
|
|
|
+#include <linux/mutex.h>
|
|
/*
|
|
/*
|
|
* dbs is used in this file as a shortform for demandbased switching
|
|
* dbs is used in this file as a shortform for demandbased switching
|
|
* It helps to keep variable names smaller, simpler
|
|
* It helps to keep variable names smaller, simpler
|
|
@@ -71,7 +71,7 @@ static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
|
|
|
|
|
|
static unsigned int dbs_enable; /* number of CPUs using this policy */
|
|
static unsigned int dbs_enable; /* number of CPUs using this policy */
|
|
|
|
|
|
-static DECLARE_MUTEX (dbs_sem);
|
|
|
|
|
|
+static DEFINE_MUTEX (dbs_mutex);
|
|
static DECLARE_WORK (dbs_work, do_dbs_timer, NULL);
|
|
static DECLARE_WORK (dbs_work, do_dbs_timer, NULL);
|
|
|
|
|
|
struct dbs_tuners {
|
|
struct dbs_tuners {
|
|
@@ -139,9 +139,9 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
|
|
if (ret != 1 )
|
|
if (ret != 1 )
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
dbs_tuners_ins.sampling_down_factor = input;
|
|
dbs_tuners_ins.sampling_down_factor = input;
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -153,14 +153,14 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
|
|
int ret;
|
|
int ret;
|
|
ret = sscanf (buf, "%u", &input);
|
|
ret = sscanf (buf, "%u", &input);
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) {
|
|
if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) {
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
dbs_tuners_ins.sampling_rate = input;
|
|
dbs_tuners_ins.sampling_rate = input;
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -172,16 +172,16 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
|
|
int ret;
|
|
int ret;
|
|
ret = sscanf (buf, "%u", &input);
|
|
ret = sscanf (buf, "%u", &input);
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
|
|
if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
|
|
input < MIN_FREQUENCY_UP_THRESHOLD ||
|
|
input < MIN_FREQUENCY_UP_THRESHOLD ||
|
|
input <= dbs_tuners_ins.down_threshold) {
|
|
input <= dbs_tuners_ins.down_threshold) {
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
dbs_tuners_ins.up_threshold = input;
|
|
dbs_tuners_ins.up_threshold = input;
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -193,16 +193,16 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused,
|
|
int ret;
|
|
int ret;
|
|
ret = sscanf (buf, "%u", &input);
|
|
ret = sscanf (buf, "%u", &input);
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD ||
|
|
if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD ||
|
|
input < MIN_FREQUENCY_DOWN_THRESHOLD ||
|
|
input < MIN_FREQUENCY_DOWN_THRESHOLD ||
|
|
input >= dbs_tuners_ins.up_threshold) {
|
|
input >= dbs_tuners_ins.up_threshold) {
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
dbs_tuners_ins.down_threshold = input;
|
|
dbs_tuners_ins.down_threshold = input;
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -222,9 +222,9 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
|
|
if ( input > 1 )
|
|
if ( input > 1 )
|
|
input = 1;
|
|
input = 1;
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */
|
|
if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
dbs_tuners_ins.ignore_nice = input;
|
|
dbs_tuners_ins.ignore_nice = input;
|
|
@@ -236,7 +236,7 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
|
|
j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j);
|
|
j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j);
|
|
j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up;
|
|
j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up;
|
|
}
|
|
}
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -257,9 +257,9 @@ static ssize_t store_freq_step(struct cpufreq_policy *policy,
|
|
|
|
|
|
/* no need to test here if freq_step is zero as the user might actually
|
|
/* no need to test here if freq_step is zero as the user might actually
|
|
* want this, they would be crazy though :) */
|
|
* want this, they would be crazy though :) */
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
dbs_tuners_ins.freq_step = input;
|
|
dbs_tuners_ins.freq_step = input;
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
@@ -444,12 +444,12 @@ static void dbs_check_cpu(int cpu)
|
|
static void do_dbs_timer(void *data)
|
|
static void do_dbs_timer(void *data)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
for_each_online_cpu(i)
|
|
for_each_online_cpu(i)
|
|
dbs_check_cpu(i);
|
|
dbs_check_cpu(i);
|
|
schedule_delayed_work(&dbs_work,
|
|
schedule_delayed_work(&dbs_work,
|
|
usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
|
|
usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
}
|
|
}
|
|
|
|
|
|
static inline void dbs_timer_init(void)
|
|
static inline void dbs_timer_init(void)
|
|
@@ -487,7 +487,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
|
|
if (this_dbs_info->enable) /* Already enabled */
|
|
if (this_dbs_info->enable) /* Already enabled */
|
|
break;
|
|
break;
|
|
|
|
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
for_each_cpu_mask(j, policy->cpus) {
|
|
for_each_cpu_mask(j, policy->cpus) {
|
|
struct cpu_dbs_info_s *j_dbs_info;
|
|
struct cpu_dbs_info_s *j_dbs_info;
|
|
j_dbs_info = &per_cpu(cpu_dbs_info, j);
|
|
j_dbs_info = &per_cpu(cpu_dbs_info, j);
|
|
@@ -521,11 +521,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
|
|
dbs_timer_init();
|
|
dbs_timer_init();
|
|
}
|
|
}
|
|
|
|
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
break;
|
|
break;
|
|
|
|
|
|
case CPUFREQ_GOV_STOP:
|
|
case CPUFREQ_GOV_STOP:
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
this_dbs_info->enable = 0;
|
|
this_dbs_info->enable = 0;
|
|
sysfs_remove_group(&policy->kobj, &dbs_attr_group);
|
|
sysfs_remove_group(&policy->kobj, &dbs_attr_group);
|
|
dbs_enable--;
|
|
dbs_enable--;
|
|
@@ -536,12 +536,12 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
|
|
if (dbs_enable == 0)
|
|
if (dbs_enable == 0)
|
|
dbs_timer_exit();
|
|
dbs_timer_exit();
|
|
|
|
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case CPUFREQ_GOV_LIMITS:
|
|
case CPUFREQ_GOV_LIMITS:
|
|
- down(&dbs_sem);
|
|
|
|
|
|
+ mutex_lock(&dbs_mutex);
|
|
if (policy->max < this_dbs_info->cur_policy->cur)
|
|
if (policy->max < this_dbs_info->cur_policy->cur)
|
|
__cpufreq_driver_target(
|
|
__cpufreq_driver_target(
|
|
this_dbs_info->cur_policy,
|
|
this_dbs_info->cur_policy,
|
|
@@ -550,7 +550,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
|
|
__cpufreq_driver_target(
|
|
__cpufreq_driver_target(
|
|
this_dbs_info->cur_policy,
|
|
this_dbs_info->cur_policy,
|
|
policy->min, CPUFREQ_RELATION_L);
|
|
policy->min, CPUFREQ_RELATION_L);
|
|
- up(&dbs_sem);
|
|
|
|
|
|
+ mutex_unlock(&dbs_mutex);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|