diff options
Diffstat (limited to 'drivers/cpufreq/cpufreq_conservative.c')
-rw-r--r-- | drivers/cpufreq/cpufreq_conservative.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index ac38766b2583..adecd31f6156 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -35,12 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #define DEF_FREQUENCY_UP_THRESHOLD (80) | 37 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
38 | #define MIN_FREQUENCY_UP_THRESHOLD (0) | ||
39 | #define MAX_FREQUENCY_UP_THRESHOLD (100) | ||
40 | |||
41 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) | 38 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) |
42 | #define MIN_FREQUENCY_DOWN_THRESHOLD (0) | ||
43 | #define MAX_FREQUENCY_DOWN_THRESHOLD (100) | ||
44 | 39 | ||
45 | /* | 40 | /* |
46 | * The polling frequency of this governor depends on the capability of | 41 | * The polling frequency of this governor depends on the capability of |
@@ -53,10 +48,14 @@ | |||
53 | * All times here are in uS. | 48 | * All times here are in uS. |
54 | */ | 49 | */ |
55 | static unsigned int def_sampling_rate; | 50 | static unsigned int def_sampling_rate; |
56 | #define MIN_SAMPLING_RATE (def_sampling_rate / 2) | 51 | #define MIN_SAMPLING_RATE_RATIO (2) |
52 | /* for correct statistics, we need at least 10 ticks between each measure */ | ||
53 | #define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) | ||
54 | #define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) | ||
57 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | 55 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) |
58 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (100000) | 56 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) |
59 | #define DEF_SAMPLING_DOWN_FACTOR (5) | 57 | #define DEF_SAMPLING_DOWN_FACTOR (1) |
58 | #define MAX_SAMPLING_DOWN_FACTOR (10) | ||
60 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) | 59 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) |
61 | 60 | ||
62 | static void do_dbs_timer(void *data); | 61 | static void do_dbs_timer(void *data); |
@@ -136,7 +135,7 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | |||
136 | unsigned int input; | 135 | unsigned int input; |
137 | int ret; | 136 | int ret; |
138 | ret = sscanf (buf, "%u", &input); | 137 | ret = sscanf (buf, "%u", &input); |
139 | if (ret != 1 ) | 138 | if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1) |
140 | return -EINVAL; | 139 | return -EINVAL; |
141 | 140 | ||
142 | mutex_lock(&dbs_mutex); | 141 | mutex_lock(&dbs_mutex); |
@@ -173,8 +172,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused, | |||
173 | ret = sscanf (buf, "%u", &input); | 172 | ret = sscanf (buf, "%u", &input); |
174 | 173 | ||
175 | mutex_lock(&dbs_mutex); | 174 | mutex_lock(&dbs_mutex); |
176 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || | 175 | if (ret != 1 || input > 100 || input < 0 || |
177 | input < MIN_FREQUENCY_UP_THRESHOLD || | ||
178 | input <= dbs_tuners_ins.down_threshold) { | 176 | input <= dbs_tuners_ins.down_threshold) { |
179 | mutex_unlock(&dbs_mutex); | 177 | mutex_unlock(&dbs_mutex); |
180 | return -EINVAL; | 178 | return -EINVAL; |
@@ -194,8 +192,7 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused, | |||
194 | ret = sscanf (buf, "%u", &input); | 192 | ret = sscanf (buf, "%u", &input); |
195 | 193 | ||
196 | mutex_lock(&dbs_mutex); | 194 | mutex_lock(&dbs_mutex); |
197 | if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || | 195 | if (ret != 1 || input > 100 || input < 0 || |
198 | input < MIN_FREQUENCY_DOWN_THRESHOLD || | ||
199 | input >= dbs_tuners_ins.up_threshold) { | 196 | input >= dbs_tuners_ins.up_threshold) { |
200 | mutex_unlock(&dbs_mutex); | 197 | mutex_unlock(&dbs_mutex); |
201 | return -EINVAL; | 198 | return -EINVAL; |
@@ -337,7 +334,6 @@ static void dbs_check_cpu(int cpu) | |||
337 | */ | 334 | */ |
338 | 335 | ||
339 | /* Check for frequency increase */ | 336 | /* Check for frequency increase */ |
340 | |||
341 | idle_ticks = UINT_MAX; | 337 | idle_ticks = UINT_MAX; |
342 | for_each_cpu_mask(j, policy->cpus) { | 338 | for_each_cpu_mask(j, policy->cpus) { |
343 | unsigned int tmp_idle_ticks, total_idle_ticks; | 339 | unsigned int tmp_idle_ticks, total_idle_ticks; |
@@ -357,7 +353,7 @@ static void dbs_check_cpu(int cpu) | |||
357 | /* Scale idle ticks by 100 and compare with up and down ticks */ | 353 | /* Scale idle ticks by 100 and compare with up and down ticks */ |
358 | idle_ticks *= 100; | 354 | idle_ticks *= 100; |
359 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * | 355 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * |
360 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); | 356 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
361 | 357 | ||
362 | if (idle_ticks < up_idle_ticks) { | 358 | if (idle_ticks < up_idle_ticks) { |
363 | down_skip[cpu] = 0; | 359 | down_skip[cpu] = 0; |
@@ -398,6 +394,7 @@ static void dbs_check_cpu(int cpu) | |||
398 | struct cpu_dbs_info_s *j_dbs_info; | 394 | struct cpu_dbs_info_s *j_dbs_info; |
399 | 395 | ||
400 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 396 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
397 | /* Check for frequency decrease */ | ||
401 | total_idle_ticks = j_dbs_info->prev_cpu_idle_up; | 398 | total_idle_ticks = j_dbs_info->prev_cpu_idle_up; |
402 | tmp_idle_ticks = total_idle_ticks - | 399 | tmp_idle_ticks = total_idle_ticks - |
403 | j_dbs_info->prev_cpu_idle_down; | 400 | j_dbs_info->prev_cpu_idle_down; |
@@ -414,12 +411,14 @@ static void dbs_check_cpu(int cpu) | |||
414 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * | 411 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * |
415 | dbs_tuners_ins.sampling_down_factor; | 412 | dbs_tuners_ins.sampling_down_factor; |
416 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * | 413 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * |
417 | usecs_to_jiffies(freq_down_sampling_rate); | 414 | usecs_to_jiffies(freq_down_sampling_rate); |
418 | 415 | ||
419 | if (idle_ticks > down_idle_ticks) { | 416 | if (idle_ticks > down_idle_ticks) { |
420 | /* if we are already at the lowest speed then break out early | 417 | /* |
418 | * if we are already at the lowest speed then break out early | ||
421 | * or if we 'cannot' reduce the speed as the user might want | 419 | * or if we 'cannot' reduce the speed as the user might want |
422 | * freq_step to be zero */ | 420 | * freq_step to be zero |
421 | */ | ||
423 | if (requested_freq[cpu] == policy->min | 422 | if (requested_freq[cpu] == policy->min |
424 | || dbs_tuners_ins.freq_step == 0) | 423 | || dbs_tuners_ins.freq_step == 0) |
425 | return; | 424 | return; |
@@ -434,9 +433,8 @@ static void dbs_check_cpu(int cpu) | |||
434 | if (requested_freq[cpu] < policy->min) | 433 | if (requested_freq[cpu] < policy->min) |
435 | requested_freq[cpu] = policy->min; | 434 | requested_freq[cpu] = policy->min; |
436 | 435 | ||
437 | __cpufreq_driver_target(policy, | 436 | __cpufreq_driver_target(policy, requested_freq[cpu], |
438 | requested_freq[cpu], | 437 | CPUFREQ_RELATION_H); |
439 | CPUFREQ_RELATION_H); | ||
440 | return; | 438 | return; |
441 | } | 439 | } |
442 | } | 440 | } |
@@ -507,13 +505,16 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
507 | if (dbs_enable == 1) { | 505 | if (dbs_enable == 1) { |
508 | unsigned int latency; | 506 | unsigned int latency; |
509 | /* policy latency is in nS. Convert it to uS first */ | 507 | /* policy latency is in nS. Convert it to uS first */ |
508 | latency = policy->cpuinfo.transition_latency / 1000; | ||
509 | if (latency == 0) | ||
510 | latency = 1; | ||
510 | 511 | ||
511 | latency = policy->cpuinfo.transition_latency; | 512 | def_sampling_rate = latency * |
512 | if (latency < 1000) | ||
513 | latency = 1000; | ||
514 | |||
515 | def_sampling_rate = (latency / 1000) * | ||
516 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; | 513 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; |
514 | |||
515 | if (def_sampling_rate < MIN_STAT_SAMPLING_RATE) | ||
516 | def_sampling_rate = MIN_STAT_SAMPLING_RATE; | ||
517 | |||
517 | dbs_tuners_ins.sampling_rate = def_sampling_rate; | 518 | dbs_tuners_ins.sampling_rate = def_sampling_rate; |
518 | dbs_tuners_ins.ignore_nice = 0; | 519 | dbs_tuners_ins.ignore_nice = 0; |
519 | dbs_tuners_ins.freq_step = 5; | 520 | dbs_tuners_ins.freq_step = 5; |