aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDave Jones <davej@redhat.com>2006-03-27 14:56:39 -0500
committerDave Jones <davej@redhat.com>2006-03-27 14:56:39 -0500
commit0bb065f29bffc7895f0dbac1fc7d74b3a8d357a9 (patch)
tree44c80e038d4500d2878634fcc692d69062fcb60f /drivers
parent329b10bb0feacb7fb9a41389313ff0a51ae56f2a (diff)
parent7c9d8c0e84d395a01289ebd1597758939a875a86 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/brodo/cpufreq-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c151
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c11
2 files changed, 71 insertions, 91 deletions
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index ac38766b2583..a152d2c46be7 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 */
55static unsigned int def_sampling_rate; 50static 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
62static void do_dbs_timer(void *data); 61static void do_dbs_timer(void *data);
@@ -66,6 +65,8 @@ struct cpu_dbs_info_s {
66 unsigned int prev_cpu_idle_up; 65 unsigned int prev_cpu_idle_up;
67 unsigned int prev_cpu_idle_down; 66 unsigned int prev_cpu_idle_down;
68 unsigned int enable; 67 unsigned int enable;
68 unsigned int down_skip;
69 unsigned int requested_freq;
69}; 70};
70static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 71static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
71 72
@@ -136,7 +137,7 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
136 unsigned int input; 137 unsigned int input;
137 int ret; 138 int ret;
138 ret = sscanf (buf, "%u", &input); 139 ret = sscanf (buf, "%u", &input);
139 if (ret != 1 ) 140 if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
140 return -EINVAL; 141 return -EINVAL;
141 142
142 mutex_lock(&dbs_mutex); 143 mutex_lock(&dbs_mutex);
@@ -173,8 +174,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
173 ret = sscanf (buf, "%u", &input); 174 ret = sscanf (buf, "%u", &input);
174 175
175 mutex_lock(&dbs_mutex); 176 mutex_lock(&dbs_mutex);
176 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 177 if (ret != 1 || input > 100 || input < 0 ||
177 input < MIN_FREQUENCY_UP_THRESHOLD ||
178 input <= dbs_tuners_ins.down_threshold) { 178 input <= dbs_tuners_ins.down_threshold) {
179 mutex_unlock(&dbs_mutex); 179 mutex_unlock(&dbs_mutex);
180 return -EINVAL; 180 return -EINVAL;
@@ -194,8 +194,7 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused,
194 ret = sscanf (buf, "%u", &input); 194 ret = sscanf (buf, "%u", &input);
195 195
196 mutex_lock(&dbs_mutex); 196 mutex_lock(&dbs_mutex);
197 if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || 197 if (ret != 1 || input > 100 || input < 0 ||
198 input < MIN_FREQUENCY_DOWN_THRESHOLD ||
199 input >= dbs_tuners_ins.up_threshold) { 198 input >= dbs_tuners_ins.up_threshold) {
200 mutex_unlock(&dbs_mutex); 199 mutex_unlock(&dbs_mutex);
201 return -EINVAL; 200 return -EINVAL;
@@ -297,31 +296,17 @@ static struct attribute_group dbs_attr_group = {
297static void dbs_check_cpu(int cpu) 296static void dbs_check_cpu(int cpu)
298{ 297{
299 unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; 298 unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
299 unsigned int tmp_idle_ticks, total_idle_ticks;
300 unsigned int freq_step; 300 unsigned int freq_step;
301 unsigned int freq_down_sampling_rate; 301 unsigned int freq_down_sampling_rate;
302 static int down_skip[NR_CPUS]; 302 struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
303 static int requested_freq[NR_CPUS];
304 static unsigned short init_flag = 0;
305 struct cpu_dbs_info_s *this_dbs_info;
306 struct cpu_dbs_info_s *dbs_info;
307
308 struct cpufreq_policy *policy; 303 struct cpufreq_policy *policy;
309 unsigned int j;
310 304
311 this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
312 if (!this_dbs_info->enable) 305 if (!this_dbs_info->enable)
313 return; 306 return;
314 307
315 policy = this_dbs_info->cur_policy; 308 policy = this_dbs_info->cur_policy;
316 309
317 if ( init_flag == 0 ) {
318 for_each_online_cpu(j) {
319 dbs_info = &per_cpu(cpu_dbs_info, j);
320 requested_freq[j] = dbs_info->cur_policy->cur;
321 }
322 init_flag = 1;
323 }
324
325 /* 310 /*
326 * The default safe range is 20% to 80% 311 * The default safe range is 20% to 80%
327 * Every sampling_rate, we check 312 * Every sampling_rate, we check
@@ -337,39 +322,29 @@ static void dbs_check_cpu(int cpu)
337 */ 322 */
338 323
339 /* Check for frequency increase */ 324 /* Check for frequency increase */
340
341 idle_ticks = UINT_MAX; 325 idle_ticks = UINT_MAX;
342 for_each_cpu_mask(j, policy->cpus) {
343 unsigned int tmp_idle_ticks, total_idle_ticks;
344 struct cpu_dbs_info_s *j_dbs_info;
345 326
346 j_dbs_info = &per_cpu(cpu_dbs_info, j); 327 /* Check for frequency increase */
347 /* Check for frequency increase */ 328 total_idle_ticks = get_cpu_idle_time(cpu);
348 total_idle_ticks = get_cpu_idle_time(j); 329 tmp_idle_ticks = total_idle_ticks -
349 tmp_idle_ticks = total_idle_ticks - 330 this_dbs_info->prev_cpu_idle_up;
350 j_dbs_info->prev_cpu_idle_up; 331 this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
351 j_dbs_info->prev_cpu_idle_up = total_idle_ticks; 332
352 333 if (tmp_idle_ticks < idle_ticks)
353 if (tmp_idle_ticks < idle_ticks) 334 idle_ticks = tmp_idle_ticks;
354 idle_ticks = tmp_idle_ticks;
355 }
356 335
357 /* Scale idle ticks by 100 and compare with up and down ticks */ 336 /* Scale idle ticks by 100 and compare with up and down ticks */
358 idle_ticks *= 100; 337 idle_ticks *= 100;
359 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * 338 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) *
360 usecs_to_jiffies(dbs_tuners_ins.sampling_rate); 339 usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
361 340
362 if (idle_ticks < up_idle_ticks) { 341 if (idle_ticks < up_idle_ticks) {
363 down_skip[cpu] = 0; 342 this_dbs_info->down_skip = 0;
364 for_each_cpu_mask(j, policy->cpus) { 343 this_dbs_info->prev_cpu_idle_down =
365 struct cpu_dbs_info_s *j_dbs_info; 344 this_dbs_info->prev_cpu_idle_up;
366 345
367 j_dbs_info = &per_cpu(cpu_dbs_info, j);
368 j_dbs_info->prev_cpu_idle_down =
369 j_dbs_info->prev_cpu_idle_up;
370 }
371 /* if we are already at full speed then break out early */ 346 /* if we are already at full speed then break out early */
372 if (requested_freq[cpu] == policy->max) 347 if (this_dbs_info->requested_freq == policy->max)
373 return; 348 return;
374 349
375 freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; 350 freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100;
@@ -378,49 +353,45 @@ static void dbs_check_cpu(int cpu)
378 if (unlikely(freq_step == 0)) 353 if (unlikely(freq_step == 0))
379 freq_step = 5; 354 freq_step = 5;
380 355
381 requested_freq[cpu] += freq_step; 356 this_dbs_info->requested_freq += freq_step;
382 if (requested_freq[cpu] > policy->max) 357 if (this_dbs_info->requested_freq > policy->max)
383 requested_freq[cpu] = policy->max; 358 this_dbs_info->requested_freq = policy->max;
384 359
385 __cpufreq_driver_target(policy, requested_freq[cpu], 360 __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
386 CPUFREQ_RELATION_H); 361 CPUFREQ_RELATION_H);
387 return; 362 return;
388 } 363 }
389 364
390 /* Check for frequency decrease */ 365 /* Check for frequency decrease */
391 down_skip[cpu]++; 366 this_dbs_info->down_skip++;
392 if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) 367 if (this_dbs_info->down_skip < dbs_tuners_ins.sampling_down_factor)
393 return; 368 return;
394 369
395 idle_ticks = UINT_MAX; 370 /* Check for frequency decrease */
396 for_each_cpu_mask(j, policy->cpus) { 371 total_idle_ticks = this_dbs_info->prev_cpu_idle_up;
397 unsigned int tmp_idle_ticks, total_idle_ticks; 372 tmp_idle_ticks = total_idle_ticks -
398 struct cpu_dbs_info_s *j_dbs_info; 373 this_dbs_info->prev_cpu_idle_down;
374 this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
399 375
400 j_dbs_info = &per_cpu(cpu_dbs_info, j); 376 if (tmp_idle_ticks < idle_ticks)
401 total_idle_ticks = j_dbs_info->prev_cpu_idle_up; 377 idle_ticks = tmp_idle_ticks;
402 tmp_idle_ticks = total_idle_ticks -
403 j_dbs_info->prev_cpu_idle_down;
404 j_dbs_info->prev_cpu_idle_down = total_idle_ticks;
405
406 if (tmp_idle_ticks < idle_ticks)
407 idle_ticks = tmp_idle_ticks;
408 }
409 378
410 /* Scale idle ticks by 100 and compare with up and down ticks */ 379 /* Scale idle ticks by 100 and compare with up and down ticks */
411 idle_ticks *= 100; 380 idle_ticks *= 100;
412 down_skip[cpu] = 0; 381 this_dbs_info->down_skip = 0;
413 382
414 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * 383 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
415 dbs_tuners_ins.sampling_down_factor; 384 dbs_tuners_ins.sampling_down_factor;
416 down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * 385 down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
417 usecs_to_jiffies(freq_down_sampling_rate); 386 usecs_to_jiffies(freq_down_sampling_rate);
418 387
419 if (idle_ticks > down_idle_ticks) { 388 if (idle_ticks > down_idle_ticks) {
420 /* if we are already at the lowest speed then break out early 389 /*
390 * 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 391 * or if we 'cannot' reduce the speed as the user might want
422 * freq_step to be zero */ 392 * freq_step to be zero
423 if (requested_freq[cpu] == policy->min 393 */
394 if (this_dbs_info->requested_freq == policy->min
424 || dbs_tuners_ins.freq_step == 0) 395 || dbs_tuners_ins.freq_step == 0)
425 return; 396 return;
426 397
@@ -430,13 +401,12 @@ static void dbs_check_cpu(int cpu)
430 if (unlikely(freq_step == 0)) 401 if (unlikely(freq_step == 0))
431 freq_step = 5; 402 freq_step = 5;
432 403
433 requested_freq[cpu] -= freq_step; 404 this_dbs_info->requested_freq -= freq_step;
434 if (requested_freq[cpu] < policy->min) 405 if (this_dbs_info->requested_freq < policy->min)
435 requested_freq[cpu] = policy->min; 406 this_dbs_info->requested_freq = policy->min;
436 407
437 __cpufreq_driver_target(policy, 408 __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
438 requested_freq[cpu], 409 CPUFREQ_RELATION_H);
439 CPUFREQ_RELATION_H);
440 return; 410 return;
441 } 411 }
442} 412}
@@ -493,11 +463,13 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
493 j_dbs_info = &per_cpu(cpu_dbs_info, j); 463 j_dbs_info = &per_cpu(cpu_dbs_info, j);
494 j_dbs_info->cur_policy = policy; 464 j_dbs_info->cur_policy = policy;
495 465
496 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 466 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(cpu);
497 j_dbs_info->prev_cpu_idle_down 467 j_dbs_info->prev_cpu_idle_down
498 = j_dbs_info->prev_cpu_idle_up; 468 = j_dbs_info->prev_cpu_idle_up;
499 } 469 }
500 this_dbs_info->enable = 1; 470 this_dbs_info->enable = 1;
471 this_dbs_info->down_skip = 0;
472 this_dbs_info->requested_freq = policy->cur;
501 sysfs_create_group(&policy->kobj, &dbs_attr_group); 473 sysfs_create_group(&policy->kobj, &dbs_attr_group);
502 dbs_enable++; 474 dbs_enable++;
503 /* 475 /*
@@ -507,13 +479,16 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
507 if (dbs_enable == 1) { 479 if (dbs_enable == 1) {
508 unsigned int latency; 480 unsigned int latency;
509 /* policy latency is in nS. Convert it to uS first */ 481 /* policy latency is in nS. Convert it to uS first */
482 latency = policy->cpuinfo.transition_latency / 1000;
483 if (latency == 0)
484 latency = 1;
510 485
511 latency = policy->cpuinfo.transition_latency; 486 def_sampling_rate = 10 * latency *
512 if (latency < 1000)
513 latency = 1000;
514
515 def_sampling_rate = (latency / 1000) *
516 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 487 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER;
488
489 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
490 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
491
517 dbs_tuners_ins.sampling_rate = def_sampling_rate; 492 dbs_tuners_ins.sampling_rate = def_sampling_rate;
518 dbs_tuners_ins.ignore_nice = 0; 493 dbs_tuners_ins.ignore_nice = 0;
519 dbs_tuners_ins.freq_step = 5; 494 dbs_tuners_ins.freq_step = 5;
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 69aa1db8336c..956d121cb161 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -84,6 +84,7 @@ struct dbs_tuners {
84static struct dbs_tuners dbs_tuners_ins = { 84static struct dbs_tuners dbs_tuners_ins = {
85 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 85 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
86 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, 86 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
87 .ignore_nice = 0,
87}; 88};
88 89
89static inline unsigned int get_cpu_idle_time(unsigned int cpu) 90static inline unsigned int get_cpu_idle_time(unsigned int cpu)
@@ -350,6 +351,9 @@ static void dbs_check_cpu(int cpu)
350 freq_next = (freq_next * policy->cur) / 351 freq_next = (freq_next * policy->cur) /
351 (dbs_tuners_ins.up_threshold - 10); 352 (dbs_tuners_ins.up_threshold - 10);
352 353
354 if (freq_next < policy->min)
355 freq_next = policy->min;
356
353 if (freq_next <= ((policy->cur * 95) / 100)) 357 if (freq_next <= ((policy->cur * 95) / 100))
354 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); 358 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L);
355} 359}
@@ -395,8 +399,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
395 return -EINVAL; 399 return -EINVAL;
396 400
397 if (policy->cpuinfo.transition_latency > 401 if (policy->cpuinfo.transition_latency >
398 (TRANSITION_LATENCY_LIMIT * 1000)) 402 (TRANSITION_LATENCY_LIMIT * 1000)) {
403 printk(KERN_WARNING "ondemand governor failed to load "
404 "due to too long transition latency\n");
399 return -EINVAL; 405 return -EINVAL;
406 }
400 if (this_dbs_info->enable) /* Already enabled */ 407 if (this_dbs_info->enable) /* Already enabled */
401 break; 408 break;
402 409
@@ -431,8 +438,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
431 def_sampling_rate = MIN_STAT_SAMPLING_RATE; 438 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
432 439
433 dbs_tuners_ins.sampling_rate = def_sampling_rate; 440 dbs_tuners_ins.sampling_rate = def_sampling_rate;
434 dbs_tuners_ins.ignore_nice = 0;
435
436 dbs_timer_init(); 441 dbs_timer_init();
437 } 442 }
438 443