aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq_ondemand.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cpufreq/cpufreq_ondemand.c')
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 7731f7c7e79a..f3eb26cd848f 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -26,7 +26,7 @@
26 26
27#include "cpufreq_governor.h" 27#include "cpufreq_governor.h"
28 28
29/* On-demand governor macors */ 29/* On-demand governor macros */
30#define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10) 30#define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
31#define DEF_FREQUENCY_UP_THRESHOLD (80) 31#define DEF_FREQUENCY_UP_THRESHOLD (80)
32#define DEF_SAMPLING_DOWN_FACTOR (1) 32#define DEF_SAMPLING_DOWN_FACTOR (1)
@@ -47,7 +47,8 @@ static struct cpufreq_governor cpufreq_gov_ondemand;
47static struct od_dbs_tuners od_tuners = { 47static struct od_dbs_tuners od_tuners = {
48 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 48 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
49 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, 49 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
50 .down_differential = DEF_FREQUENCY_DOWN_DIFFERENTIAL, 50 .adj_up_threshold = DEF_FREQUENCY_UP_THRESHOLD -
51 DEF_FREQUENCY_DOWN_DIFFERENTIAL,
51 .ignore_nice = 0, 52 .ignore_nice = 0,
52 .powersave_bias = 0, 53 .powersave_bias = 0,
53}; 54};
@@ -65,7 +66,7 @@ static void ondemand_powersave_bias_init_cpu(int cpu)
65 * efficient idling at a higher frequency/voltage is. 66 * efficient idling at a higher frequency/voltage is.
66 * Pavel Machek says this is not so for various generations of AMD and old 67 * Pavel Machek says this is not so for various generations of AMD and old
67 * Intel systems. 68 * Intel systems.
68 * Mike Chan (androidlcom) calis this is also not true for ARM. 69 * Mike Chan (android.com) claims this is also not true for ARM.
69 * Because of this, whitelist specific known (series) of CPUs by default, and 70 * Because of this, whitelist specific known (series) of CPUs by default, and
70 * leave all others up to the user. 71 * leave all others up to the user.
71 */ 72 */
@@ -73,7 +74,7 @@ static int should_io_be_busy(void)
73{ 74{
74#if defined(CONFIG_X86) 75#if defined(CONFIG_X86)
75 /* 76 /*
76 * For Intel, Core 2 (model 15) andl later have an efficient idle. 77 * For Intel, Core 2 (model 15) and later have an efficient idle.
77 */ 78 */
78 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && 79 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
79 boot_cpu_data.x86 == 6 && 80 boot_cpu_data.x86 == 6 &&
@@ -158,8 +159,8 @@ static void dbs_freq_increase(struct cpufreq_policy *p, unsigned int freq)
158 159
159/* 160/*
160 * Every sampling_rate, we check, if current idle time is less than 20% 161 * Every sampling_rate, we check, if current idle time is less than 20%
161 * (default), then we try to increase frequency Every sampling_rate, we look for 162 * (default), then we try to increase frequency. Every sampling_rate, we look
162 * a the lowest frequency which can sustain the load while keeping idle time 163 * for the lowest frequency which can sustain the load while keeping idle time
163 * over 30%. If such a frequency exist, we try to decrease to this frequency. 164 * over 30%. If such a frequency exist, we try to decrease to this frequency.
164 * 165 *
165 * Any frequency increase takes it to the maximum frequency. Frequency reduction 166 * Any frequency increase takes it to the maximum frequency. Frequency reduction
@@ -192,11 +193,9 @@ static void od_check_cpu(int cpu, unsigned int load_freq)
192 * support the current CPU usage without triggering the up policy. To be 193 * support the current CPU usage without triggering the up policy. To be
193 * safe, we focus 10 points under the threshold. 194 * safe, we focus 10 points under the threshold.
194 */ 195 */
195 if (load_freq < (od_tuners.up_threshold - od_tuners.down_differential) * 196 if (load_freq < od_tuners.adj_up_threshold * policy->cur) {
196 policy->cur) {
197 unsigned int freq_next; 197 unsigned int freq_next;
198 freq_next = load_freq / (od_tuners.up_threshold - 198 freq_next = load_freq / od_tuners.adj_up_threshold;
199 od_tuners.down_differential);
200 199
201 /* No longer fully busy, reset rate_mult */ 200 /* No longer fully busy, reset rate_mult */
202 dbs_info->rate_mult = 1; 201 dbs_info->rate_mult = 1;
@@ -218,33 +217,42 @@ static void od_check_cpu(int cpu, unsigned int load_freq)
218 217
219static void od_dbs_timer(struct work_struct *work) 218static void od_dbs_timer(struct work_struct *work)
220{ 219{
220 struct delayed_work *dw = to_delayed_work(work);
221 struct od_cpu_dbs_info_s *dbs_info = 221 struct od_cpu_dbs_info_s *dbs_info =
222 container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work); 222 container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work);
223 unsigned int cpu = dbs_info->cdbs.cpu; 223 unsigned int cpu = dbs_info->cdbs.cur_policy->cpu;
224 int delay, sample_type = dbs_info->sample_type; 224 struct od_cpu_dbs_info_s *core_dbs_info = &per_cpu(od_cpu_dbs_info,
225 cpu);
226 int delay, sample_type = core_dbs_info->sample_type;
227 bool eval_load;
225 228
226 mutex_lock(&dbs_info->cdbs.timer_mutex); 229 mutex_lock(&core_dbs_info->cdbs.timer_mutex);
230 eval_load = need_load_eval(&core_dbs_info->cdbs,
231 od_tuners.sampling_rate);
227 232
228 /* Common NORMAL_SAMPLE setup */ 233 /* Common NORMAL_SAMPLE setup */
229 dbs_info->sample_type = OD_NORMAL_SAMPLE; 234 core_dbs_info->sample_type = OD_NORMAL_SAMPLE;
230 if (sample_type == OD_SUB_SAMPLE) { 235 if (sample_type == OD_SUB_SAMPLE) {
231 delay = dbs_info->freq_lo_jiffies; 236 delay = core_dbs_info->freq_lo_jiffies;
232 __cpufreq_driver_target(dbs_info->cdbs.cur_policy, 237 if (eval_load)
233 dbs_info->freq_lo, CPUFREQ_RELATION_H); 238 __cpufreq_driver_target(core_dbs_info->cdbs.cur_policy,
239 core_dbs_info->freq_lo,
240 CPUFREQ_RELATION_H);
234 } else { 241 } else {
235 dbs_check_cpu(&od_dbs_data, cpu); 242 if (eval_load)
236 if (dbs_info->freq_lo) { 243 dbs_check_cpu(&od_dbs_data, cpu);
244 if (core_dbs_info->freq_lo) {
237 /* Setup timer for SUB_SAMPLE */ 245 /* Setup timer for SUB_SAMPLE */
238 dbs_info->sample_type = OD_SUB_SAMPLE; 246 core_dbs_info->sample_type = OD_SUB_SAMPLE;
239 delay = dbs_info->freq_hi_jiffies; 247 delay = core_dbs_info->freq_hi_jiffies;
240 } else { 248 } else {
241 delay = delay_for_sampling_rate(od_tuners.sampling_rate 249 delay = delay_for_sampling_rate(od_tuners.sampling_rate
242 * dbs_info->rate_mult); 250 * core_dbs_info->rate_mult);
243 } 251 }
244 } 252 }
245 253
246 schedule_delayed_work_on(cpu, &dbs_info->cdbs.work, delay); 254 schedule_delayed_work_on(smp_processor_id(), dw, delay);
247 mutex_unlock(&dbs_info->cdbs.timer_mutex); 255 mutex_unlock(&core_dbs_info->cdbs.timer_mutex);
248} 256}
249 257
250/************************** sysfs interface ************************/ 258/************************** sysfs interface ************************/
@@ -259,7 +267,7 @@ static ssize_t show_sampling_rate_min(struct kobject *kobj,
259 * update_sampling_rate - update sampling rate effective immediately if needed. 267 * update_sampling_rate - update sampling rate effective immediately if needed.
260 * @new_rate: new sampling rate 268 * @new_rate: new sampling rate
261 * 269 *
262 * If new rate is smaller than the old, simply updaing 270 * If new rate is smaller than the old, simply updating
263 * dbs_tuners_int.sampling_rate might not be appropriate. For example, if the 271 * dbs_tuners_int.sampling_rate might not be appropriate. For example, if the
264 * original sampling_rate was 1 second and the requested new sampling rate is 10 272 * original sampling_rate was 1 second and the requested new sampling rate is 10
265 * ms because the user needs immediate reaction from ondemand governor, but not 273 * ms because the user needs immediate reaction from ondemand governor, but not
@@ -287,7 +295,7 @@ static void update_sampling_rate(unsigned int new_rate)
287 cpufreq_cpu_put(policy); 295 cpufreq_cpu_put(policy);
288 continue; 296 continue;
289 } 297 }
290 dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu); 298 dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
291 cpufreq_cpu_put(policy); 299 cpufreq_cpu_put(policy);
292 300
293 mutex_lock(&dbs_info->cdbs.timer_mutex); 301 mutex_lock(&dbs_info->cdbs.timer_mutex);
@@ -306,8 +314,7 @@ static void update_sampling_rate(unsigned int new_rate)
306 cancel_delayed_work_sync(&dbs_info->cdbs.work); 314 cancel_delayed_work_sync(&dbs_info->cdbs.work);
307 mutex_lock(&dbs_info->cdbs.timer_mutex); 315 mutex_lock(&dbs_info->cdbs.timer_mutex);
308 316
309 schedule_delayed_work_on(dbs_info->cdbs.cpu, 317 schedule_delayed_work_on(cpu, &dbs_info->cdbs.work,
310 &dbs_info->cdbs.work,
311 usecs_to_jiffies(new_rate)); 318 usecs_to_jiffies(new_rate));
312 319
313 } 320 }
@@ -351,6 +358,10 @@ static ssize_t store_up_threshold(struct kobject *a, struct attribute *b,
351 input < MIN_FREQUENCY_UP_THRESHOLD) { 358 input < MIN_FREQUENCY_UP_THRESHOLD) {
352 return -EINVAL; 359 return -EINVAL;
353 } 360 }
361 /* Calculate the new adj_up_threshold */
362 od_tuners.adj_up_threshold += input;
363 od_tuners.adj_up_threshold -= od_tuners.up_threshold;
364
354 od_tuners.up_threshold = input; 365 od_tuners.up_threshold = input;
355 return count; 366 return count;
356} 367}
@@ -507,7 +518,8 @@ static int __init cpufreq_gov_dbs_init(void)
507 if (idle_time != -1ULL) { 518 if (idle_time != -1ULL) {
508 /* Idle micro accounting is supported. Use finer thresholds */ 519 /* Idle micro accounting is supported. Use finer thresholds */
509 od_tuners.up_threshold = MICRO_FREQUENCY_UP_THRESHOLD; 520 od_tuners.up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
510 od_tuners.down_differential = MICRO_FREQUENCY_DOWN_DIFFERENTIAL; 521 od_tuners.adj_up_threshold = MICRO_FREQUENCY_UP_THRESHOLD -
522 MICRO_FREQUENCY_DOWN_DIFFERENTIAL;
511 /* 523 /*
512 * In nohz/micro accounting case we set the minimum frequency 524 * In nohz/micro accounting case we set the minimum frequency
513 * not depending on HZ, but fixed (very low). The deferred 525 * not depending on HZ, but fixed (very low). The deferred