diff options
Diffstat (limited to 'drivers/cpufreq/cpufreq_ondemand.c')
| -rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index e69fd8dd1f1c..9ee9411f186f 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
| 28 | #include <linux/kernel_stat.h> | 28 | #include <linux/kernel_stat.h> |
| 29 | #include <linux/percpu.h> | 29 | #include <linux/percpu.h> |
| 30 | #include <linux/mutex.h> | ||
| 30 | 31 | ||
| 31 | /* | 32 | /* |
| 32 | * dbs is used in this file as a shortform for demandbased switching | 33 | * dbs is used in this file as a shortform for demandbased switching |
| @@ -70,7 +71,7 @@ static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); | |||
| 70 | 71 | ||
| 71 | static unsigned int dbs_enable; /* number of CPUs using this policy */ | 72 | static unsigned int dbs_enable; /* number of CPUs using this policy */ |
| 72 | 73 | ||
| 73 | static DECLARE_MUTEX (dbs_sem); | 74 | static DEFINE_MUTEX (dbs_mutex); |
| 74 | static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); | 75 | static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); |
| 75 | 76 | ||
| 76 | struct dbs_tuners { | 77 | struct dbs_tuners { |
| @@ -136,9 +137,9 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | |||
| 136 | if (input > MAX_SAMPLING_DOWN_FACTOR || input < 1) | 137 | if (input > MAX_SAMPLING_DOWN_FACTOR || input < 1) |
| 137 | return -EINVAL; | 138 | return -EINVAL; |
| 138 | 139 | ||
| 139 | down(&dbs_sem); | 140 | mutex_lock(&dbs_mutex); |
| 140 | dbs_tuners_ins.sampling_down_factor = input; | 141 | dbs_tuners_ins.sampling_down_factor = input; |
| 141 | up(&dbs_sem); | 142 | mutex_unlock(&dbs_mutex); |
| 142 | 143 | ||
| 143 | return count; | 144 | return count; |
| 144 | } | 145 | } |
| @@ -150,14 +151,14 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused, | |||
| 150 | int ret; | 151 | int ret; |
| 151 | ret = sscanf (buf, "%u", &input); | 152 | ret = sscanf (buf, "%u", &input); |
| 152 | 153 | ||
| 153 | down(&dbs_sem); | 154 | mutex_lock(&dbs_mutex); |
| 154 | if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) { | 155 | if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) { |
| 155 | up(&dbs_sem); | 156 | mutex_unlock(&dbs_mutex); |
| 156 | return -EINVAL; | 157 | return -EINVAL; |
| 157 | } | 158 | } |
| 158 | 159 | ||
| 159 | dbs_tuners_ins.sampling_rate = input; | 160 | dbs_tuners_ins.sampling_rate = input; |
| 160 | up(&dbs_sem); | 161 | mutex_unlock(&dbs_mutex); |
| 161 | 162 | ||
| 162 | return count; | 163 | return count; |
| 163 | } | 164 | } |
| @@ -169,15 +170,15 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused, | |||
| 169 | int ret; | 170 | int ret; |
| 170 | ret = sscanf (buf, "%u", &input); | 171 | ret = sscanf (buf, "%u", &input); |
| 171 | 172 | ||
| 172 | down(&dbs_sem); | 173 | mutex_lock(&dbs_mutex); |
| 173 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || | 174 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
| 174 | input < MIN_FREQUENCY_UP_THRESHOLD) { | 175 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
| 175 | up(&dbs_sem); | 176 | mutex_unlock(&dbs_mutex); |
| 176 | return -EINVAL; | 177 | return -EINVAL; |
| 177 | } | 178 | } |
| 178 | 179 | ||
| 179 | dbs_tuners_ins.up_threshold = input; | 180 | dbs_tuners_ins.up_threshold = input; |
| 180 | up(&dbs_sem); | 181 | mutex_unlock(&dbs_mutex); |
| 181 | 182 | ||
| 182 | return count; | 183 | return count; |
| 183 | } | 184 | } |
| @@ -197,9 +198,9 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy, | |||
| 197 | if ( input > 1 ) | 198 | if ( input > 1 ) |
| 198 | input = 1; | 199 | input = 1; |
| 199 | 200 | ||
| 200 | down(&dbs_sem); | 201 | mutex_lock(&dbs_mutex); |
| 201 | if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ | 202 | if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ |
| 202 | up(&dbs_sem); | 203 | mutex_unlock(&dbs_mutex); |
| 203 | return count; | 204 | return count; |
| 204 | } | 205 | } |
| 205 | dbs_tuners_ins.ignore_nice = input; | 206 | dbs_tuners_ins.ignore_nice = input; |
| @@ -211,7 +212,7 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy, | |||
| 211 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | 212 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); |
| 212 | j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; | 213 | j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; |
| 213 | } | 214 | } |
| 214 | up(&dbs_sem); | 215 | mutex_unlock(&dbs_mutex); |
| 215 | 216 | ||
| 216 | return count; | 217 | return count; |
| 217 | } | 218 | } |
| @@ -356,12 +357,12 @@ static void dbs_check_cpu(int cpu) | |||
| 356 | static void do_dbs_timer(void *data) | 357 | static void do_dbs_timer(void *data) |
| 357 | { | 358 | { |
| 358 | int i; | 359 | int i; |
| 359 | down(&dbs_sem); | 360 | mutex_lock(&dbs_mutex); |
| 360 | for_each_online_cpu(i) | 361 | for_each_online_cpu(i) |
| 361 | dbs_check_cpu(i); | 362 | dbs_check_cpu(i); |
| 362 | schedule_delayed_work(&dbs_work, | 363 | schedule_delayed_work(&dbs_work, |
| 363 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); | 364 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); |
| 364 | up(&dbs_sem); | 365 | mutex_unlock(&dbs_mutex); |
| 365 | } | 366 | } |
| 366 | 367 | ||
| 367 | static inline void dbs_timer_init(void) | 368 | static inline void dbs_timer_init(void) |
| @@ -399,7 +400,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 399 | if (this_dbs_info->enable) /* Already enabled */ | 400 | if (this_dbs_info->enable) /* Already enabled */ |
| 400 | break; | 401 | break; |
| 401 | 402 | ||
| 402 | down(&dbs_sem); | 403 | mutex_lock(&dbs_mutex); |
| 403 | for_each_cpu_mask(j, policy->cpus) { | 404 | for_each_cpu_mask(j, policy->cpus) { |
| 404 | struct cpu_dbs_info_s *j_dbs_info; | 405 | struct cpu_dbs_info_s *j_dbs_info; |
| 405 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 406 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
| @@ -435,11 +436,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 435 | dbs_timer_init(); | 436 | dbs_timer_init(); |
| 436 | } | 437 | } |
| 437 | 438 | ||
| 438 | up(&dbs_sem); | 439 | mutex_unlock(&dbs_mutex); |
| 439 | break; | 440 | break; |
| 440 | 441 | ||
| 441 | case CPUFREQ_GOV_STOP: | 442 | case CPUFREQ_GOV_STOP: |
| 442 | down(&dbs_sem); | 443 | mutex_lock(&dbs_mutex); |
| 443 | this_dbs_info->enable = 0; | 444 | this_dbs_info->enable = 0; |
| 444 | sysfs_remove_group(&policy->kobj, &dbs_attr_group); | 445 | sysfs_remove_group(&policy->kobj, &dbs_attr_group); |
| 445 | dbs_enable--; | 446 | dbs_enable--; |
| @@ -450,12 +451,12 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 450 | if (dbs_enable == 0) | 451 | if (dbs_enable == 0) |
| 451 | dbs_timer_exit(); | 452 | dbs_timer_exit(); |
| 452 | 453 | ||
| 453 | up(&dbs_sem); | 454 | mutex_unlock(&dbs_mutex); |
| 454 | 455 | ||
| 455 | break; | 456 | break; |
| 456 | 457 | ||
| 457 | case CPUFREQ_GOV_LIMITS: | 458 | case CPUFREQ_GOV_LIMITS: |
| 458 | down(&dbs_sem); | 459 | mutex_lock(&dbs_mutex); |
| 459 | if (policy->max < this_dbs_info->cur_policy->cur) | 460 | if (policy->max < this_dbs_info->cur_policy->cur) |
| 460 | __cpufreq_driver_target( | 461 | __cpufreq_driver_target( |
| 461 | this_dbs_info->cur_policy, | 462 | this_dbs_info->cur_policy, |
| @@ -464,7 +465,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 464 | __cpufreq_driver_target( | 465 | __cpufreq_driver_target( |
| 465 | this_dbs_info->cur_policy, | 466 | this_dbs_info->cur_policy, |
| 466 | policy->min, CPUFREQ_RELATION_L); | 467 | policy->min, CPUFREQ_RELATION_L); |
| 467 | up(&dbs_sem); | 468 | mutex_unlock(&dbs_mutex); |
| 468 | break; | 469 | break; |
| 469 | } | 470 | } |
| 470 | return 0; | 471 | return 0; |
