1 From: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
2 Subject: cpufreq,ondemand: Use get_cpu_idle_time_us() to get micro-accounted idle information
4 Use get_cpu_idle_time_us() to get micro-accounted idle information.
5 This enables ondemand to get more accurate idle and busy timings
6 than the jiffy based calculation. As a result, we can decrease
7 the ondemand safety gaurd band from 80-10 to 95-3.
9 Results in more aggressive power savings.
11 Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
12 Signed-off-by: Thomas Renninger <trenn@suse.de>
15 drivers/cpufreq/cpufreq_ondemand.c | 46 ++++++++++++++++++++++++++++++++++++-
16 1 file changed, 45 insertions(+), 1 deletion(-)
18 Index: cpufreq.git/drivers/cpufreq/cpufreq_ondemand.c
19 ===================================================================
20 --- cpufreq.git.orig/drivers/cpufreq/cpufreq_ondemand.c 2008-07-31 14:52:15.000000000 -0700
21 +++ cpufreq.git/drivers/cpufreq/cpufreq_ondemand.c 2008-07-31 14:52:22.000000000 -0700
23 #include <linux/jiffies.h>
24 #include <linux/kernel_stat.h>
25 #include <linux/mutex.h>
26 +#include <linux/hrtimer.h>
27 +#include <linux/tick.h>
28 +#include <linux/ktime.h>
31 * dbs is used in this file as a shortform for demandbased switching
34 #define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
35 #define DEF_FREQUENCY_UP_THRESHOLD (80)
36 +#define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3)
37 +#define MICRO_FREQUENCY_UP_THRESHOLD (95)
38 #define MIN_FREQUENCY_UP_THRESHOLD (11)
39 #define MAX_FREQUENCY_UP_THRESHOLD (100)
41 @@ -58,6 +63,7 @@ enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE}
42 struct cpu_dbs_info_s {
43 cputime64_t prev_cpu_idle;
44 cputime64_t prev_cpu_wall;
45 + cputime64_t prev_cpu_nice;
46 struct cpufreq_policy *cur_policy;
47 struct delayed_work work;
48 struct cpufreq_frequency_table *freq_table;
49 @@ -97,7 +103,8 @@ static struct dbs_tuners {
53 -static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
54 +static inline cputime64_t get_cpu_idle_time_jiffy(unsigned int cpu,
57 cputime64_t idle_time;
58 cputime64_t cur_wall_time;
59 @@ -123,6 +130,33 @@ static inline cputime64_t get_cpu_idle_t
63 +static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
65 + u64 idle_time = get_cpu_idle_time_us(cpu, wall);
67 + if (idle_time == -1ULL)
68 + return get_cpu_idle_time_jiffy(cpu, wall);
70 + if (dbs_tuners_ins.ignore_nice) {
71 + cputime64_t cur_nice;
72 + unsigned long cur_nice_jiffies;
73 + struct cpu_dbs_info_s *dbs_info;
75 + dbs_info = &per_cpu(cpu_dbs_info, cpu);
76 + cur_nice = cputime64_sub(kstat_cpu(cpu).cpustat.nice,
77 + dbs_info->prev_cpu_nice);
79 + * Assumption: nice time between sampling periods will be
80 + * less than 2^32 jiffies for 32 bit sys
82 + cur_nice_jiffies = (unsigned long)
83 + cputime64_to_jiffies64(cur_nice);
84 + dbs_info->prev_cpu_nice = kstat_cpu(cpu).cpustat.nice;
85 + return idle_time + jiffies_to_usecs(cur_nice_jiffies);
91 * Find right freq to be set now with powersave_bias on.
92 * Returns the freq_hi to be used right now and will set freq_hi_jiffies,
93 @@ -602,6 +636,16 @@ EXPORT_SYMBOL(cpufreq_gov_ondemand);
95 static int __init cpufreq_gov_dbs_init(void)
98 + u64 idle_time = get_cpu_idle_time_us(smp_processor_id(), &wall);
100 + if (idle_time != -1ULL) {
101 + /* Idle micro accounting is supported. Use finer thresholds */
102 + dbs_tuners_ins.up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
103 + dbs_tuners_ins.down_differential =
104 + MICRO_FREQUENCY_DOWN_DIFFERENTIAL;
107 kondemand_wq = create_workqueue("kondemand");
109 printk(KERN_ERR "Creation of kondemand failed\n");