diff options
Diffstat (limited to 'drivers/cpufreq')
| -rw-r--r-- | drivers/cpufreq/Kconfig | 24 | ||||
| -rw-r--r-- | drivers/cpufreq/Makefile | 1 | ||||
| -rw-r--r-- | drivers/cpufreq/cpufreq.c | 8 | ||||
| -rw-r--r-- | drivers/cpufreq/cpufreq_conservative.c | 586 | ||||
| -rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 180 | ||||
| -rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 47 |
6 files changed, 736 insertions, 110 deletions
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index 95882bb1950e..60c9be99c6d9 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig | |||
| @@ -46,6 +46,10 @@ config CPU_FREQ_STAT_DETAILS | |||
| 46 | This will show detail CPU frequency translation table in sysfs file | 46 | This will show detail CPU frequency translation table in sysfs file |
| 47 | system | 47 | system |
| 48 | 48 | ||
| 49 | # Note that it is not currently possible to set the other governors (such as ondemand) | ||
| 50 | # as the default, since if they fail to initialise, cpufreq will be | ||
| 51 | # left in an undefined state. | ||
| 52 | |||
| 49 | choice | 53 | choice |
| 50 | prompt "Default CPUFreq governor" | 54 | prompt "Default CPUFreq governor" |
| 51 | default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110 | 55 | default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110 |
| @@ -115,4 +119,24 @@ config CPU_FREQ_GOV_ONDEMAND | |||
| 115 | 119 | ||
| 116 | If in doubt, say N. | 120 | If in doubt, say N. |
| 117 | 121 | ||
| 122 | config CPU_FREQ_GOV_CONSERVATIVE | ||
| 123 | tristate "'conservative' cpufreq governor" | ||
| 124 | depends on CPU_FREQ | ||
| 125 | help | ||
| 126 | 'conservative' - this driver is rather similar to the 'ondemand' | ||
| 127 | governor both in its source code and its purpose, the difference is | ||
| 128 | its optimisation for better suitability in a battery powered | ||
| 129 | environment. The frequency is gracefully increased and decreased | ||
| 130 | rather than jumping to 100% when speed is required. | ||
| 131 | |||
| 132 | If you have a desktop machine then you should really be considering | ||
| 133 | the 'ondemand' governor instead, however if you are using a laptop, | ||
| 134 | PDA or even an AMD64 based computer (due to the unacceptable | ||
| 135 | step-by-step latency issues between the minimum and maximum frequency | ||
| 136 | transitions in the CPU) you will probably want to use this governor. | ||
| 137 | |||
| 138 | For details, take a look at linux/Documentation/cpu-freq. | ||
| 139 | |||
| 140 | If in doubt, say N. | ||
| 141 | |||
| 118 | endif # CPU_FREQ | 142 | endif # CPU_FREQ |
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 67b16e5a41a7..71fc3b4173f1 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
| @@ -8,6 +8,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_PERFORMANCE) += cpufreq_performance.o | |||
| 8 | obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o | 8 | obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o |
| 9 | obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o | 9 | obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o |
| 10 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o | 10 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o |
| 11 | obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o | ||
| 11 | 12 | ||
| 12 | # CPUfreq cross-arch helpers | 13 | # CPUfreq cross-arch helpers |
| 13 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o | 14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o |
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8e561313d094..03b5fb2ddcf4 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
| @@ -258,7 +258,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
| 258 | (likely(cpufreq_cpu_data[freqs->cpu]->cur)) && | 258 | (likely(cpufreq_cpu_data[freqs->cpu]->cur)) && |
| 259 | (unlikely(freqs->old != cpufreq_cpu_data[freqs->cpu]->cur))) | 259 | (unlikely(freqs->old != cpufreq_cpu_data[freqs->cpu]->cur))) |
| 260 | { | 260 | { |
| 261 | printk(KERN_WARNING "Warning: CPU frequency is %u, " | 261 | dprintk(KERN_WARNING "Warning: CPU frequency is %u, " |
| 262 | "cpufreq assumed %u kHz.\n", freqs->old, cpufreq_cpu_data[freqs->cpu]->cur); | 262 | "cpufreq assumed %u kHz.\n", freqs->old, cpufreq_cpu_data[freqs->cpu]->cur); |
| 263 | freqs->old = cpufreq_cpu_data[freqs->cpu]->cur; | 263 | freqs->old = cpufreq_cpu_data[freqs->cpu]->cur; |
| 264 | } | 264 | } |
| @@ -814,7 +814,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigne | |||
| 814 | { | 814 | { |
| 815 | struct cpufreq_freqs freqs; | 815 | struct cpufreq_freqs freqs; |
| 816 | 816 | ||
| 817 | printk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing " | 817 | dprintk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing " |
| 818 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); | 818 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); |
| 819 | 819 | ||
| 820 | freqs.cpu = cpu; | 820 | freqs.cpu = cpu; |
| @@ -923,7 +923,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, u32 state) | |||
| 923 | struct cpufreq_freqs freqs; | 923 | struct cpufreq_freqs freqs; |
| 924 | 924 | ||
| 925 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) | 925 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) |
| 926 | printk(KERN_DEBUG "Warning: CPU frequency is %u, " | 926 | dprintk(KERN_DEBUG "Warning: CPU frequency is %u, " |
| 927 | "cpufreq assumed %u kHz.\n", | 927 | "cpufreq assumed %u kHz.\n", |
| 928 | cur_freq, cpu_policy->cur); | 928 | cur_freq, cpu_policy->cur); |
| 929 | 929 | ||
| @@ -1004,7 +1004,7 @@ static int cpufreq_resume(struct sys_device * sysdev) | |||
| 1004 | struct cpufreq_freqs freqs; | 1004 | struct cpufreq_freqs freqs; |
| 1005 | 1005 | ||
| 1006 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) | 1006 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) |
| 1007 | printk(KERN_WARNING "Warning: CPU frequency" | 1007 | dprintk(KERN_WARNING "Warning: CPU frequency" |
| 1008 | "is %u, cpufreq assumed %u kHz.\n", | 1008 | "is %u, cpufreq assumed %u kHz.\n", |
| 1009 | cur_freq, cpu_policy->cur); | 1009 | cur_freq, cpu_policy->cur); |
| 1010 | 1010 | ||
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c new file mode 100644 index 000000000000..e1df376e709e --- /dev/null +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
| @@ -0,0 +1,586 @@ | |||
| 1 | /* | ||
| 2 | * drivers/cpufreq/cpufreq_conservative.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2001 Russell King | ||
| 5 | * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. | ||
| 6 | * Jun Nakajima <jun.nakajima@intel.com> | ||
| 7 | * (C) 2004 Alexander Clouter <alex-kernel@digriz.org.uk> | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2 as | ||
| 11 | * published by the Free Software Foundation. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/smp.h> | ||
| 17 | #include <linux/init.h> | ||
| 18 | #include <linux/interrupt.h> | ||
| 19 | #include <linux/ctype.h> | ||
| 20 | #include <linux/cpufreq.h> | ||
| 21 | #include <linux/sysctl.h> | ||
| 22 | #include <linux/types.h> | ||
| 23 | #include <linux/fs.h> | ||
| 24 | #include <linux/sysfs.h> | ||
| 25 | #include <linux/sched.h> | ||
| 26 | #include <linux/kmod.h> | ||
| 27 | #include <linux/workqueue.h> | ||
| 28 | #include <linux/jiffies.h> | ||
| 29 | #include <linux/kernel_stat.h> | ||
| 30 | #include <linux/percpu.h> | ||
| 31 | |||
| 32 | /* | ||
| 33 | * dbs is used in this file as a shortform for demandbased switching | ||
| 34 | * It helps to keep variable names smaller, simpler | ||
| 35 | */ | ||
| 36 | |||
| 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) | ||
| 42 | #define MIN_FREQUENCY_DOWN_THRESHOLD (0) | ||
| 43 | #define MAX_FREQUENCY_DOWN_THRESHOLD (100) | ||
| 44 | |||
| 45 | /* | ||
| 46 | * The polling frequency of this governor depends on the capability of | ||
| 47 | * the processor. Default polling frequency is 1000 times the transition | ||
| 48 | * latency of the processor. The governor will work on any processor with | ||
| 49 | * transition latency <= 10mS, using appropriate sampling | ||
| 50 | * rate. | ||
| 51 | * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL) | ||
| 52 | * this governor will not work. | ||
| 53 | * All times here are in uS. | ||
| 54 | */ | ||
| 55 | static unsigned int def_sampling_rate; | ||
| 56 | #define MIN_SAMPLING_RATE (def_sampling_rate / 2) | ||
| 57 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | ||
| 58 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (100000) | ||
| 59 | #define DEF_SAMPLING_DOWN_FACTOR (5) | ||
| 60 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) | ||
| 61 | |||
| 62 | static void do_dbs_timer(void *data); | ||
| 63 | |||
| 64 | struct cpu_dbs_info_s { | ||
| 65 | struct cpufreq_policy *cur_policy; | ||
| 66 | unsigned int prev_cpu_idle_up; | ||
| 67 | unsigned int prev_cpu_idle_down; | ||
| 68 | unsigned int enable; | ||
| 69 | }; | ||
| 70 | static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); | ||
| 71 | |||
| 72 | static unsigned int dbs_enable; /* number of CPUs using this policy */ | ||
| 73 | |||
| 74 | static DECLARE_MUTEX (dbs_sem); | ||
| 75 | static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); | ||
| 76 | |||
| 77 | struct dbs_tuners { | ||
| 78 | unsigned int sampling_rate; | ||
| 79 | unsigned int sampling_down_factor; | ||
| 80 | unsigned int up_threshold; | ||
| 81 | unsigned int down_threshold; | ||
| 82 | unsigned int ignore_nice; | ||
| 83 | unsigned int freq_step; | ||
| 84 | }; | ||
| 85 | |||
| 86 | static struct dbs_tuners dbs_tuners_ins = { | ||
| 87 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, | ||
| 88 | .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, | ||
| 89 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, | ||
| 90 | }; | ||
| 91 | |||
| 92 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) | ||
| 93 | { | ||
| 94 | return kstat_cpu(cpu).cpustat.idle + | ||
| 95 | kstat_cpu(cpu).cpustat.iowait + | ||
| 96 | ( !dbs_tuners_ins.ignore_nice ? | ||
| 97 | kstat_cpu(cpu).cpustat.nice : | ||
| 98 | 0); | ||
| 99 | } | ||
| 100 | |||
| 101 | /************************** sysfs interface ************************/ | ||
| 102 | static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) | ||
| 103 | { | ||
| 104 | return sprintf (buf, "%u\n", MAX_SAMPLING_RATE); | ||
| 105 | } | ||
| 106 | |||
| 107 | static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf) | ||
| 108 | { | ||
| 109 | return sprintf (buf, "%u\n", MIN_SAMPLING_RATE); | ||
| 110 | } | ||
| 111 | |||
| 112 | #define define_one_ro(_name) \ | ||
| 113 | static struct freq_attr _name = \ | ||
| 114 | __ATTR(_name, 0444, show_##_name, NULL) | ||
| 115 | |||
| 116 | define_one_ro(sampling_rate_max); | ||
| 117 | define_one_ro(sampling_rate_min); | ||
| 118 | |||
| 119 | /* cpufreq_conservative Governor Tunables */ | ||
| 120 | #define show_one(file_name, object) \ | ||
| 121 | static ssize_t show_##file_name \ | ||
| 122 | (struct cpufreq_policy *unused, char *buf) \ | ||
| 123 | { \ | ||
| 124 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ | ||
| 125 | } | ||
| 126 | show_one(sampling_rate, sampling_rate); | ||
| 127 | show_one(sampling_down_factor, sampling_down_factor); | ||
| 128 | show_one(up_threshold, up_threshold); | ||
| 129 | show_one(down_threshold, down_threshold); | ||
| 130 | show_one(ignore_nice, ignore_nice); | ||
| 131 | show_one(freq_step, freq_step); | ||
| 132 | |||
| 133 | static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | ||
| 134 | const char *buf, size_t count) | ||
| 135 | { | ||
| 136 | unsigned int input; | ||
| 137 | int ret; | ||
| 138 | ret = sscanf (buf, "%u", &input); | ||
| 139 | if (ret != 1 ) | ||
| 140 | return -EINVAL; | ||
| 141 | |||
| 142 | down(&dbs_sem); | ||
| 143 | dbs_tuners_ins.sampling_down_factor = input; | ||
| 144 | up(&dbs_sem); | ||
| 145 | |||
| 146 | return count; | ||
| 147 | } | ||
| 148 | |||
| 149 | static ssize_t store_sampling_rate(struct cpufreq_policy *unused, | ||
| 150 | const char *buf, size_t count) | ||
| 151 | { | ||
| 152 | unsigned int input; | ||
| 153 | int ret; | ||
| 154 | ret = sscanf (buf, "%u", &input); | ||
| 155 | |||
| 156 | down(&dbs_sem); | ||
| 157 | if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) { | ||
| 158 | up(&dbs_sem); | ||
| 159 | return -EINVAL; | ||
| 160 | } | ||
| 161 | |||
| 162 | dbs_tuners_ins.sampling_rate = input; | ||
| 163 | up(&dbs_sem); | ||
| 164 | |||
| 165 | return count; | ||
| 166 | } | ||
| 167 | |||
| 168 | static ssize_t store_up_threshold(struct cpufreq_policy *unused, | ||
| 169 | const char *buf, size_t count) | ||
| 170 | { | ||
| 171 | unsigned int input; | ||
| 172 | int ret; | ||
| 173 | ret = sscanf (buf, "%u", &input); | ||
| 174 | |||
| 175 | down(&dbs_sem); | ||
| 176 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || | ||
| 177 | input < MIN_FREQUENCY_UP_THRESHOLD || | ||
| 178 | input <= dbs_tuners_ins.down_threshold) { | ||
| 179 | up(&dbs_sem); | ||
| 180 | return -EINVAL; | ||
| 181 | } | ||
| 182 | |||
| 183 | dbs_tuners_ins.up_threshold = input; | ||
| 184 | up(&dbs_sem); | ||
| 185 | |||
| 186 | return count; | ||
| 187 | } | ||
| 188 | |||
| 189 | static ssize_t store_down_threshold(struct cpufreq_policy *unused, | ||
| 190 | const char *buf, size_t count) | ||
| 191 | { | ||
| 192 | unsigned int input; | ||
| 193 | int ret; | ||
| 194 | ret = sscanf (buf, "%u", &input); | ||
| 195 | |||
| 196 | down(&dbs_sem); | ||
| 197 | if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || | ||
| 198 | input < MIN_FREQUENCY_DOWN_THRESHOLD || | ||
| 199 | input >= dbs_tuners_ins.up_threshold) { | ||
| 200 | up(&dbs_sem); | ||
| 201 | return -EINVAL; | ||
| 202 | } | ||
| 203 | |||
| 204 | dbs_tuners_ins.down_threshold = input; | ||
| 205 | up(&dbs_sem); | ||
| 206 | |||
| 207 | return count; | ||
| 208 | } | ||
| 209 | |||
| 210 | static ssize_t store_ignore_nice(struct cpufreq_policy *policy, | ||
| 211 | const char *buf, size_t count) | ||
| 212 | { | ||
| 213 | unsigned int input; | ||
| 214 | int ret; | ||
| 215 | |||
| 216 | unsigned int j; | ||
| 217 | |||
| 218 | ret = sscanf (buf, "%u", &input); | ||
| 219 | if ( ret != 1 ) | ||
| 220 | return -EINVAL; | ||
| 221 | |||
| 222 | if ( input > 1 ) | ||
| 223 | input = 1; | ||
| 224 | |||
| 225 | down(&dbs_sem); | ||
| 226 | if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ | ||
| 227 | up(&dbs_sem); | ||
| 228 | return count; | ||
| 229 | } | ||
| 230 | dbs_tuners_ins.ignore_nice = input; | ||
| 231 | |||
| 232 | /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */ | ||
| 233 | for_each_online_cpu(j) { | ||
| 234 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 235 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 236 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | ||
| 237 | j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; | ||
| 238 | } | ||
| 239 | up(&dbs_sem); | ||
| 240 | |||
| 241 | return count; | ||
| 242 | } | ||
| 243 | |||
| 244 | static ssize_t store_freq_step(struct cpufreq_policy *policy, | ||
| 245 | const char *buf, size_t count) | ||
| 246 | { | ||
| 247 | unsigned int input; | ||
| 248 | int ret; | ||
| 249 | |||
| 250 | ret = sscanf (buf, "%u", &input); | ||
| 251 | |||
| 252 | if ( ret != 1 ) | ||
| 253 | return -EINVAL; | ||
| 254 | |||
| 255 | if ( input > 100 ) | ||
| 256 | input = 100; | ||
| 257 | |||
| 258 | /* no need to test here if freq_step is zero as the user might actually | ||
| 259 | * want this, they would be crazy though :) */ | ||
| 260 | down(&dbs_sem); | ||
| 261 | dbs_tuners_ins.freq_step = input; | ||
| 262 | up(&dbs_sem); | ||
| 263 | |||
| 264 | return count; | ||
| 265 | } | ||
| 266 | |||
| 267 | #define define_one_rw(_name) \ | ||
| 268 | static struct freq_attr _name = \ | ||
| 269 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
| 270 | |||
| 271 | define_one_rw(sampling_rate); | ||
| 272 | define_one_rw(sampling_down_factor); | ||
| 273 | define_one_rw(up_threshold); | ||
| 274 | define_one_rw(down_threshold); | ||
| 275 | define_one_rw(ignore_nice); | ||
| 276 | define_one_rw(freq_step); | ||
| 277 | |||
| 278 | static struct attribute * dbs_attributes[] = { | ||
| 279 | &sampling_rate_max.attr, | ||
| 280 | &sampling_rate_min.attr, | ||
| 281 | &sampling_rate.attr, | ||
| 282 | &sampling_down_factor.attr, | ||
| 283 | &up_threshold.attr, | ||
| 284 | &down_threshold.attr, | ||
| 285 | &ignore_nice.attr, | ||
| 286 | &freq_step.attr, | ||
| 287 | NULL | ||
| 288 | }; | ||
| 289 | |||
| 290 | static struct attribute_group dbs_attr_group = { | ||
| 291 | .attrs = dbs_attributes, | ||
| 292 | .name = "conservative", | ||
| 293 | }; | ||
| 294 | |||
| 295 | /************************** sysfs end ************************/ | ||
| 296 | |||
| 297 | static void dbs_check_cpu(int cpu) | ||
| 298 | { | ||
| 299 | unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; | ||
| 300 | unsigned int freq_step; | ||
| 301 | unsigned int freq_down_sampling_rate; | ||
| 302 | static int down_skip[NR_CPUS]; | ||
| 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; | ||
| 309 | unsigned int j; | ||
| 310 | |||
| 311 | this_dbs_info = &per_cpu(cpu_dbs_info, cpu); | ||
| 312 | if (!this_dbs_info->enable) | ||
| 313 | return; | ||
| 314 | |||
| 315 | policy = this_dbs_info->cur_policy; | ||
| 316 | |||
| 317 | if ( init_flag == 0 ) { | ||
| 318 | for ( /* NULL */; init_flag < NR_CPUS; init_flag++ ) { | ||
| 319 | dbs_info = &per_cpu(cpu_dbs_info, init_flag); | ||
| 320 | requested_freq[cpu] = dbs_info->cur_policy->cur; | ||
| 321 | } | ||
| 322 | init_flag = 1; | ||
| 323 | } | ||
| 324 | |||
| 325 | /* | ||
| 326 | * The default safe range is 20% to 80% | ||
| 327 | * Every sampling_rate, we check | ||
| 328 | * - If current idle time is less than 20%, then we try to | ||
| 329 | * increase frequency | ||
| 330 | * Every sampling_rate*sampling_down_factor, we check | ||
| 331 | * - If current idle time is more than 80%, then we try to | ||
| 332 | * decrease frequency | ||
| 333 | * | ||
| 334 | * Any frequency increase takes it to the maximum frequency. | ||
| 335 | * Frequency reduction happens at minimum steps of | ||
| 336 | * 5% (default) of max_frequency | ||
| 337 | */ | ||
| 338 | |||
| 339 | /* Check for frequency increase */ | ||
| 340 | |||
| 341 | 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 | |||
| 346 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 347 | /* Check for frequency increase */ | ||
| 348 | total_idle_ticks = get_cpu_idle_time(j); | ||
| 349 | tmp_idle_ticks = total_idle_ticks - | ||
| 350 | j_dbs_info->prev_cpu_idle_up; | ||
| 351 | j_dbs_info->prev_cpu_idle_up = total_idle_ticks; | ||
| 352 | |||
| 353 | if (tmp_idle_ticks < idle_ticks) | ||
| 354 | idle_ticks = tmp_idle_ticks; | ||
| 355 | } | ||
| 356 | |||
| 357 | /* Scale idle ticks by 100 and compare with up and down ticks */ | ||
| 358 | idle_ticks *= 100; | ||
| 359 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * | ||
| 360 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); | ||
| 361 | |||
| 362 | if (idle_ticks < up_idle_ticks) { | ||
| 363 | down_skip[cpu] = 0; | ||
| 364 | for_each_cpu_mask(j, policy->cpus) { | ||
| 365 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 366 | |||
| 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 */ | ||
| 372 | if (requested_freq[cpu] == policy->max) | ||
| 373 | return; | ||
| 374 | |||
| 375 | freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; | ||
| 376 | |||
| 377 | /* max freq cannot be less than 100. But who knows.... */ | ||
| 378 | if (unlikely(freq_step == 0)) | ||
| 379 | freq_step = 5; | ||
| 380 | |||
| 381 | requested_freq[cpu] += freq_step; | ||
| 382 | if (requested_freq[cpu] > policy->max) | ||
| 383 | requested_freq[cpu] = policy->max; | ||
| 384 | |||
| 385 | __cpufreq_driver_target(policy, requested_freq[cpu], | ||
| 386 | CPUFREQ_RELATION_H); | ||
| 387 | return; | ||
| 388 | } | ||
| 389 | |||
| 390 | /* Check for frequency decrease */ | ||
| 391 | down_skip[cpu]++; | ||
| 392 | if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) | ||
| 393 | return; | ||
| 394 | |||
| 395 | idle_ticks = UINT_MAX; | ||
| 396 | for_each_cpu_mask(j, policy->cpus) { | ||
| 397 | unsigned int tmp_idle_ticks, total_idle_ticks; | ||
| 398 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 399 | |||
| 400 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 401 | total_idle_ticks = j_dbs_info->prev_cpu_idle_up; | ||
| 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 | |||
| 410 | /* Scale idle ticks by 100 and compare with up and down ticks */ | ||
| 411 | idle_ticks *= 100; | ||
| 412 | down_skip[cpu] = 0; | ||
| 413 | |||
| 414 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * | ||
| 415 | dbs_tuners_ins.sampling_down_factor; | ||
| 416 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * | ||
| 417 | usecs_to_jiffies(freq_down_sampling_rate); | ||
| 418 | |||
| 419 | if (idle_ticks > down_idle_ticks) { | ||
| 420 | /* 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 | ||
| 422 | * freq_step to be zero */ | ||
| 423 | if (requested_freq[cpu] == policy->min | ||
| 424 | || dbs_tuners_ins.freq_step == 0) | ||
| 425 | return; | ||
| 426 | |||
| 427 | freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; | ||
| 428 | |||
| 429 | /* max freq cannot be less than 100. But who knows.... */ | ||
| 430 | if (unlikely(freq_step == 0)) | ||
| 431 | freq_step = 5; | ||
| 432 | |||
| 433 | requested_freq[cpu] -= freq_step; | ||
| 434 | if (requested_freq[cpu] < policy->min) | ||
| 435 | requested_freq[cpu] = policy->min; | ||
| 436 | |||
| 437 | __cpufreq_driver_target(policy, | ||
| 438 | requested_freq[cpu], | ||
| 439 | CPUFREQ_RELATION_H); | ||
| 440 | return; | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | static void do_dbs_timer(void *data) | ||
| 445 | { | ||
| 446 | int i; | ||
| 447 | down(&dbs_sem); | ||
| 448 | for_each_online_cpu(i) | ||
| 449 | dbs_check_cpu(i); | ||
| 450 | schedule_delayed_work(&dbs_work, | ||
| 451 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); | ||
| 452 | up(&dbs_sem); | ||
| 453 | } | ||
| 454 | |||
| 455 | static inline void dbs_timer_init(void) | ||
| 456 | { | ||
| 457 | INIT_WORK(&dbs_work, do_dbs_timer, NULL); | ||
| 458 | schedule_delayed_work(&dbs_work, | ||
| 459 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); | ||
| 460 | return; | ||
| 461 | } | ||
| 462 | |||
| 463 | static inline void dbs_timer_exit(void) | ||
| 464 | { | ||
| 465 | cancel_delayed_work(&dbs_work); | ||
| 466 | return; | ||
| 467 | } | ||
| 468 | |||
| 469 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | ||
| 470 | unsigned int event) | ||
| 471 | { | ||
| 472 | unsigned int cpu = policy->cpu; | ||
| 473 | struct cpu_dbs_info_s *this_dbs_info; | ||
| 474 | unsigned int j; | ||
| 475 | |||
| 476 | this_dbs_info = &per_cpu(cpu_dbs_info, cpu); | ||
| 477 | |||
| 478 | switch (event) { | ||
| 479 | case CPUFREQ_GOV_START: | ||
| 480 | if ((!cpu_online(cpu)) || | ||
| 481 | (!policy->cur)) | ||
| 482 | return -EINVAL; | ||
| 483 | |||
| 484 | if (policy->cpuinfo.transition_latency > | ||
| 485 | (TRANSITION_LATENCY_LIMIT * 1000)) | ||
| 486 | return -EINVAL; | ||
| 487 | if (this_dbs_info->enable) /* Already enabled */ | ||
| 488 | break; | ||
| 489 | |||
| 490 | down(&dbs_sem); | ||
| 491 | for_each_cpu_mask(j, policy->cpus) { | ||
| 492 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 493 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 494 | j_dbs_info->cur_policy = policy; | ||
| 495 | |||
| 496 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | ||
| 497 | j_dbs_info->prev_cpu_idle_down | ||
| 498 | = j_dbs_info->prev_cpu_idle_up; | ||
| 499 | } | ||
| 500 | this_dbs_info->enable = 1; | ||
| 501 | sysfs_create_group(&policy->kobj, &dbs_attr_group); | ||
| 502 | dbs_enable++; | ||
| 503 | /* | ||
| 504 | * Start the timerschedule work, when this governor | ||
| 505 | * is used for first time | ||
| 506 | */ | ||
| 507 | if (dbs_enable == 1) { | ||
| 508 | unsigned int latency; | ||
| 509 | /* policy latency is in nS. Convert it to uS first */ | ||
| 510 | |||
| 511 | latency = policy->cpuinfo.transition_latency; | ||
| 512 | if (latency < 1000) | ||
| 513 | latency = 1000; | ||
| 514 | |||
| 515 | def_sampling_rate = (latency / 1000) * | ||
| 516 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; | ||
| 517 | dbs_tuners_ins.sampling_rate = def_sampling_rate; | ||
| 518 | dbs_tuners_ins.ignore_nice = 0; | ||
| 519 | dbs_tuners_ins.freq_step = 5; | ||
| 520 | |||
| 521 | dbs_timer_init(); | ||
| 522 | } | ||
| 523 | |||
| 524 | up(&dbs_sem); | ||
| 525 | break; | ||
| 526 | |||
| 527 | case CPUFREQ_GOV_STOP: | ||
| 528 | down(&dbs_sem); | ||
| 529 | this_dbs_info->enable = 0; | ||
| 530 | sysfs_remove_group(&policy->kobj, &dbs_attr_group); | ||
| 531 | dbs_enable--; | ||
| 532 | /* | ||
| 533 | * Stop the timerschedule work, when this governor | ||
| 534 | * is used for first time | ||
| 535 | */ | ||
| 536 | if (dbs_enable == 0) | ||
| 537 | dbs_timer_exit(); | ||
| 538 | |||
| 539 | up(&dbs_sem); | ||
| 540 | |||
| 541 | break; | ||
| 542 | |||
| 543 | case CPUFREQ_GOV_LIMITS: | ||
| 544 | down(&dbs_sem); | ||
| 545 | if (policy->max < this_dbs_info->cur_policy->cur) | ||
| 546 | __cpufreq_driver_target( | ||
| 547 | this_dbs_info->cur_policy, | ||
| 548 | policy->max, CPUFREQ_RELATION_H); | ||
| 549 | else if (policy->min > this_dbs_info->cur_policy->cur) | ||
| 550 | __cpufreq_driver_target( | ||
| 551 | this_dbs_info->cur_policy, | ||
| 552 | policy->min, CPUFREQ_RELATION_L); | ||
| 553 | up(&dbs_sem); | ||
| 554 | break; | ||
| 555 | } | ||
| 556 | return 0; | ||
| 557 | } | ||
| 558 | |||
| 559 | static struct cpufreq_governor cpufreq_gov_dbs = { | ||
| 560 | .name = "conservative", | ||
| 561 | .governor = cpufreq_governor_dbs, | ||
| 562 | .owner = THIS_MODULE, | ||
| 563 | }; | ||
| 564 | |||
| 565 | static int __init cpufreq_gov_dbs_init(void) | ||
| 566 | { | ||
| 567 | return cpufreq_register_governor(&cpufreq_gov_dbs); | ||
| 568 | } | ||
| 569 | |||
| 570 | static void __exit cpufreq_gov_dbs_exit(void) | ||
| 571 | { | ||
| 572 | /* Make sure that the scheduled work is indeed not running */ | ||
| 573 | flush_scheduled_work(); | ||
| 574 | |||
| 575 | cpufreq_unregister_governor(&cpufreq_gov_dbs); | ||
| 576 | } | ||
| 577 | |||
| 578 | |||
| 579 | MODULE_AUTHOR ("Alexander Clouter <alex-kernel@digriz.org.uk>"); | ||
| 580 | MODULE_DESCRIPTION ("'cpufreq_conservative' - A dynamic cpufreq governor for " | ||
| 581 | "Low Latency Frequency Transition capable processors " | ||
| 582 | "optimised for use in a battery environment"); | ||
| 583 | MODULE_LICENSE ("GPL"); | ||
| 584 | |||
| 585 | module_init(cpufreq_gov_dbs_init); | ||
| 586 | module_exit(cpufreq_gov_dbs_exit); | ||
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 8d83a21c6477..c1fc9c62bb51 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
| @@ -34,13 +34,9 @@ | |||
| 34 | */ | 34 | */ |
| 35 | 35 | ||
| 36 | #define DEF_FREQUENCY_UP_THRESHOLD (80) | 36 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
| 37 | #define MIN_FREQUENCY_UP_THRESHOLD (0) | 37 | #define MIN_FREQUENCY_UP_THRESHOLD (11) |
| 38 | #define MAX_FREQUENCY_UP_THRESHOLD (100) | 38 | #define MAX_FREQUENCY_UP_THRESHOLD (100) |
| 39 | 39 | ||
| 40 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) | ||
| 41 | #define MIN_FREQUENCY_DOWN_THRESHOLD (0) | ||
| 42 | #define MAX_FREQUENCY_DOWN_THRESHOLD (100) | ||
| 43 | |||
| 44 | /* | 40 | /* |
| 45 | * The polling frequency of this governor depends on the capability of | 41 | * The polling frequency of this governor depends on the capability of |
| 46 | * the processor. Default polling frequency is 1000 times the transition | 42 | * the processor. Default polling frequency is 1000 times the transition |
| @@ -55,9 +51,9 @@ static unsigned int def_sampling_rate; | |||
| 55 | #define MIN_SAMPLING_RATE (def_sampling_rate / 2) | 51 | #define MIN_SAMPLING_RATE (def_sampling_rate / 2) |
| 56 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | 52 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) |
| 57 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) | 53 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) |
| 58 | #define DEF_SAMPLING_DOWN_FACTOR (10) | 54 | #define DEF_SAMPLING_DOWN_FACTOR (1) |
| 55 | #define MAX_SAMPLING_DOWN_FACTOR (10) | ||
| 59 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) | 56 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) |
| 60 | #define sampling_rate_in_HZ(x) (((x * HZ) < (1000 * 1000))?1:((x * HZ) / (1000 * 1000))) | ||
| 61 | 57 | ||
| 62 | static void do_dbs_timer(void *data); | 58 | static void do_dbs_timer(void *data); |
| 63 | 59 | ||
| @@ -78,15 +74,23 @@ struct dbs_tuners { | |||
| 78 | unsigned int sampling_rate; | 74 | unsigned int sampling_rate; |
| 79 | unsigned int sampling_down_factor; | 75 | unsigned int sampling_down_factor; |
| 80 | unsigned int up_threshold; | 76 | unsigned int up_threshold; |
| 81 | unsigned int down_threshold; | 77 | unsigned int ignore_nice; |
| 82 | }; | 78 | }; |
| 83 | 79 | ||
| 84 | static struct dbs_tuners dbs_tuners_ins = { | 80 | static struct dbs_tuners dbs_tuners_ins = { |
| 85 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, | 81 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
| 86 | .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, | ||
| 87 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, | 82 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, |
| 88 | }; | 83 | }; |
| 89 | 84 | ||
| 85 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) | ||
| 86 | { | ||
| 87 | return kstat_cpu(cpu).cpustat.idle + | ||
| 88 | kstat_cpu(cpu).cpustat.iowait + | ||
| 89 | ( !dbs_tuners_ins.ignore_nice ? | ||
| 90 | kstat_cpu(cpu).cpustat.nice : | ||
| 91 | 0); | ||
| 92 | } | ||
| 93 | |||
| 90 | /************************** sysfs interface ************************/ | 94 | /************************** sysfs interface ************************/ |
| 91 | static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) | 95 | static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) |
| 92 | { | 96 | { |
| @@ -115,7 +119,7 @@ static ssize_t show_##file_name \ | |||
| 115 | show_one(sampling_rate, sampling_rate); | 119 | show_one(sampling_rate, sampling_rate); |
| 116 | show_one(sampling_down_factor, sampling_down_factor); | 120 | show_one(sampling_down_factor, sampling_down_factor); |
| 117 | show_one(up_threshold, up_threshold); | 121 | show_one(up_threshold, up_threshold); |
| 118 | show_one(down_threshold, down_threshold); | 122 | show_one(ignore_nice, ignore_nice); |
| 119 | 123 | ||
| 120 | static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | 124 | static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, |
| 121 | const char *buf, size_t count) | 125 | const char *buf, size_t count) |
| @@ -126,6 +130,9 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | |||
| 126 | if (ret != 1 ) | 130 | if (ret != 1 ) |
| 127 | return -EINVAL; | 131 | return -EINVAL; |
| 128 | 132 | ||
| 133 | if (input > MAX_SAMPLING_DOWN_FACTOR || input < 1) | ||
| 134 | return -EINVAL; | ||
| 135 | |||
| 129 | down(&dbs_sem); | 136 | down(&dbs_sem); |
| 130 | dbs_tuners_ins.sampling_down_factor = input; | 137 | dbs_tuners_ins.sampling_down_factor = input; |
| 131 | up(&dbs_sem); | 138 | up(&dbs_sem); |
| @@ -161,8 +168,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused, | |||
| 161 | 168 | ||
| 162 | down(&dbs_sem); | 169 | down(&dbs_sem); |
| 163 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || | 170 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
| 164 | input < MIN_FREQUENCY_UP_THRESHOLD || | 171 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
| 165 | input <= dbs_tuners_ins.down_threshold) { | ||
| 166 | up(&dbs_sem); | 172 | up(&dbs_sem); |
| 167 | return -EINVAL; | 173 | return -EINVAL; |
| 168 | } | 174 | } |
| @@ -173,22 +179,35 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused, | |||
| 173 | return count; | 179 | return count; |
| 174 | } | 180 | } |
| 175 | 181 | ||
| 176 | static ssize_t store_down_threshold(struct cpufreq_policy *unused, | 182 | static ssize_t store_ignore_nice(struct cpufreq_policy *policy, |
| 177 | const char *buf, size_t count) | 183 | const char *buf, size_t count) |
| 178 | { | 184 | { |
| 179 | unsigned int input; | 185 | unsigned int input; |
| 180 | int ret; | 186 | int ret; |
| 187 | |||
| 188 | unsigned int j; | ||
| 189 | |||
| 181 | ret = sscanf (buf, "%u", &input); | 190 | ret = sscanf (buf, "%u", &input); |
| 191 | if ( ret != 1 ) | ||
| 192 | return -EINVAL; | ||
| 182 | 193 | ||
| 194 | if ( input > 1 ) | ||
| 195 | input = 1; | ||
| 196 | |||
| 183 | down(&dbs_sem); | 197 | down(&dbs_sem); |
| 184 | if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || | 198 | if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ |
| 185 | input < MIN_FREQUENCY_DOWN_THRESHOLD || | ||
| 186 | input >= dbs_tuners_ins.up_threshold) { | ||
| 187 | up(&dbs_sem); | 199 | up(&dbs_sem); |
| 188 | return -EINVAL; | 200 | return count; |
| 189 | } | 201 | } |
| 202 | dbs_tuners_ins.ignore_nice = input; | ||
| 190 | 203 | ||
| 191 | dbs_tuners_ins.down_threshold = input; | 204 | /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */ |
| 205 | for_each_online_cpu(j) { | ||
| 206 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 207 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 208 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | ||
| 209 | j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; | ||
| 210 | } | ||
| 192 | up(&dbs_sem); | 211 | up(&dbs_sem); |
| 193 | 212 | ||
| 194 | return count; | 213 | return count; |
| @@ -201,7 +220,7 @@ __ATTR(_name, 0644, show_##_name, store_##_name) | |||
| 201 | define_one_rw(sampling_rate); | 220 | define_one_rw(sampling_rate); |
| 202 | define_one_rw(sampling_down_factor); | 221 | define_one_rw(sampling_down_factor); |
| 203 | define_one_rw(up_threshold); | 222 | define_one_rw(up_threshold); |
| 204 | define_one_rw(down_threshold); | 223 | define_one_rw(ignore_nice); |
| 205 | 224 | ||
| 206 | static struct attribute * dbs_attributes[] = { | 225 | static struct attribute * dbs_attributes[] = { |
| 207 | &sampling_rate_max.attr, | 226 | &sampling_rate_max.attr, |
| @@ -209,7 +228,7 @@ static struct attribute * dbs_attributes[] = { | |||
| 209 | &sampling_rate.attr, | 228 | &sampling_rate.attr, |
| 210 | &sampling_down_factor.attr, | 229 | &sampling_down_factor.attr, |
| 211 | &up_threshold.attr, | 230 | &up_threshold.attr, |
| 212 | &down_threshold.attr, | 231 | &ignore_nice.attr, |
| 213 | NULL | 232 | NULL |
| 214 | }; | 233 | }; |
| 215 | 234 | ||
| @@ -222,9 +241,8 @@ static struct attribute_group dbs_attr_group = { | |||
| 222 | 241 | ||
| 223 | static void dbs_check_cpu(int cpu) | 242 | static void dbs_check_cpu(int cpu) |
| 224 | { | 243 | { |
| 225 | unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; | 244 | unsigned int idle_ticks, up_idle_ticks, total_ticks; |
| 226 | unsigned int total_idle_ticks; | 245 | unsigned int freq_next; |
| 227 | unsigned int freq_down_step; | ||
| 228 | unsigned int freq_down_sampling_rate; | 246 | unsigned int freq_down_sampling_rate; |
| 229 | static int down_skip[NR_CPUS]; | 247 | static int down_skip[NR_CPUS]; |
| 230 | struct cpu_dbs_info_s *this_dbs_info; | 248 | struct cpu_dbs_info_s *this_dbs_info; |
| @@ -238,38 +256,25 @@ static void dbs_check_cpu(int cpu) | |||
| 238 | 256 | ||
| 239 | policy = this_dbs_info->cur_policy; | 257 | policy = this_dbs_info->cur_policy; |
| 240 | /* | 258 | /* |
| 241 | * The default safe range is 20% to 80% | 259 | * Every sampling_rate, we check, if current idle time is less |
| 242 | * Every sampling_rate, we check | 260 | * than 20% (default), then we try to increase frequency |
| 243 | * - If current idle time is less than 20%, then we try to | 261 | * Every sampling_rate*sampling_down_factor, we look for a the lowest |
| 244 | * increase frequency | 262 | * frequency which can sustain the load while keeping idle time over |
| 245 | * Every sampling_rate*sampling_down_factor, we check | 263 | * 30%. If such a frequency exist, we try to decrease to this frequency. |
| 246 | * - If current idle time is more than 80%, then we try to | ||
| 247 | * decrease frequency | ||
| 248 | * | 264 | * |
| 249 | * Any frequency increase takes it to the maximum frequency. | 265 | * Any frequency increase takes it to the maximum frequency. |
| 250 | * Frequency reduction happens at minimum steps of | 266 | * Frequency reduction happens at minimum steps of |
| 251 | * 5% of max_frequency | 267 | * 5% (default) of current frequency |
| 252 | */ | 268 | */ |
| 253 | 269 | ||
| 254 | /* Check for frequency increase */ | 270 | /* Check for frequency increase */ |
| 255 | total_idle_ticks = kstat_cpu(cpu).cpustat.idle + | 271 | idle_ticks = UINT_MAX; |
| 256 | kstat_cpu(cpu).cpustat.iowait; | ||
| 257 | idle_ticks = total_idle_ticks - | ||
| 258 | this_dbs_info->prev_cpu_idle_up; | ||
| 259 | this_dbs_info->prev_cpu_idle_up = total_idle_ticks; | ||
| 260 | |||
| 261 | |||
| 262 | for_each_cpu_mask(j, policy->cpus) { | 272 | for_each_cpu_mask(j, policy->cpus) { |
| 263 | unsigned int tmp_idle_ticks; | 273 | unsigned int tmp_idle_ticks, total_idle_ticks; |
| 264 | struct cpu_dbs_info_s *j_dbs_info; | 274 | struct cpu_dbs_info_s *j_dbs_info; |
| 265 | 275 | ||
| 266 | if (j == cpu) | ||
| 267 | continue; | ||
| 268 | |||
| 269 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 276 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
| 270 | /* Check for frequency increase */ | 277 | total_idle_ticks = get_cpu_idle_time(j); |
| 271 | total_idle_ticks = kstat_cpu(j).cpustat.idle + | ||
| 272 | kstat_cpu(j).cpustat.iowait; | ||
| 273 | tmp_idle_ticks = total_idle_ticks - | 278 | tmp_idle_ticks = total_idle_ticks - |
| 274 | j_dbs_info->prev_cpu_idle_up; | 279 | j_dbs_info->prev_cpu_idle_up; |
| 275 | j_dbs_info->prev_cpu_idle_up = total_idle_ticks; | 280 | j_dbs_info->prev_cpu_idle_up = total_idle_ticks; |
| @@ -281,13 +286,23 @@ static void dbs_check_cpu(int cpu) | |||
| 281 | /* Scale idle ticks by 100 and compare with up and down ticks */ | 286 | /* Scale idle ticks by 100 and compare with up and down ticks */ |
| 282 | idle_ticks *= 100; | 287 | idle_ticks *= 100; |
| 283 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * | 288 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * |
| 284 | sampling_rate_in_HZ(dbs_tuners_ins.sampling_rate); | 289 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| 285 | 290 | ||
| 286 | if (idle_ticks < up_idle_ticks) { | 291 | if (idle_ticks < up_idle_ticks) { |
| 292 | down_skip[cpu] = 0; | ||
| 293 | for_each_cpu_mask(j, policy->cpus) { | ||
| 294 | struct cpu_dbs_info_s *j_dbs_info; | ||
| 295 | |||
| 296 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
| 297 | j_dbs_info->prev_cpu_idle_down = | ||
| 298 | j_dbs_info->prev_cpu_idle_up; | ||
| 299 | } | ||
| 300 | /* if we are already at full speed then break out early */ | ||
| 301 | if (policy->cur == policy->max) | ||
| 302 | return; | ||
| 303 | |||
| 287 | __cpufreq_driver_target(policy, policy->max, | 304 | __cpufreq_driver_target(policy, policy->max, |
| 288 | CPUFREQ_RELATION_H); | 305 | CPUFREQ_RELATION_H); |
| 289 | down_skip[cpu] = 0; | ||
| 290 | this_dbs_info->prev_cpu_idle_down = total_idle_ticks; | ||
| 291 | return; | 306 | return; |
| 292 | } | 307 | } |
| 293 | 308 | ||
| @@ -296,23 +311,14 @@ static void dbs_check_cpu(int cpu) | |||
| 296 | if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) | 311 | if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) |
| 297 | return; | 312 | return; |
| 298 | 313 | ||
| 299 | total_idle_ticks = kstat_cpu(cpu).cpustat.idle + | 314 | idle_ticks = UINT_MAX; |
| 300 | kstat_cpu(cpu).cpustat.iowait; | ||
| 301 | idle_ticks = total_idle_ticks - | ||
| 302 | this_dbs_info->prev_cpu_idle_down; | ||
| 303 | this_dbs_info->prev_cpu_idle_down = total_idle_ticks; | ||
| 304 | |||
| 305 | for_each_cpu_mask(j, policy->cpus) { | 315 | for_each_cpu_mask(j, policy->cpus) { |
| 306 | unsigned int tmp_idle_ticks; | 316 | unsigned int tmp_idle_ticks, total_idle_ticks; |
| 307 | struct cpu_dbs_info_s *j_dbs_info; | 317 | struct cpu_dbs_info_s *j_dbs_info; |
| 308 | 318 | ||
| 309 | if (j == cpu) | ||
| 310 | continue; | ||
| 311 | |||
| 312 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 319 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
| 313 | /* Check for frequency increase */ | 320 | /* Check for frequency decrease */ |
| 314 | total_idle_ticks = kstat_cpu(j).cpustat.idle + | 321 | total_idle_ticks = j_dbs_info->prev_cpu_idle_up; |
| 315 | kstat_cpu(j).cpustat.iowait; | ||
| 316 | tmp_idle_ticks = total_idle_ticks - | 322 | tmp_idle_ticks = total_idle_ticks - |
| 317 | j_dbs_info->prev_cpu_idle_down; | 323 | j_dbs_info->prev_cpu_idle_down; |
| 318 | j_dbs_info->prev_cpu_idle_down = total_idle_ticks; | 324 | j_dbs_info->prev_cpu_idle_down = total_idle_ticks; |
| @@ -321,38 +327,37 @@ static void dbs_check_cpu(int cpu) | |||
| 321 | idle_ticks = tmp_idle_ticks; | 327 | idle_ticks = tmp_idle_ticks; |
| 322 | } | 328 | } |
| 323 | 329 | ||
| 324 | /* Scale idle ticks by 100 and compare with up and down ticks */ | ||
| 325 | idle_ticks *= 100; | ||
| 326 | down_skip[cpu] = 0; | 330 | down_skip[cpu] = 0; |
| 331 | /* if we cannot reduce the frequency anymore, break out early */ | ||
| 332 | if (policy->cur == policy->min) | ||
| 333 | return; | ||
| 327 | 334 | ||
| 335 | /* Compute how many ticks there are between two measurements */ | ||
| 328 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * | 336 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * |
| 329 | dbs_tuners_ins.sampling_down_factor; | 337 | dbs_tuners_ins.sampling_down_factor; |
| 330 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * | 338 | total_ticks = usecs_to_jiffies(freq_down_sampling_rate); |
| 331 | sampling_rate_in_HZ(freq_down_sampling_rate); | ||
| 332 | 339 | ||
| 333 | if (idle_ticks > down_idle_ticks ) { | 340 | /* |
| 334 | freq_down_step = (5 * policy->max) / 100; | 341 | * The optimal frequency is the frequency that is the lowest that |
| 335 | 342 | * can support the current CPU usage without triggering the up | |
| 336 | /* max freq cannot be less than 100. But who knows.... */ | 343 | * policy. To be safe, we focus 10 points under the threshold. |
| 337 | if (unlikely(freq_down_step == 0)) | 344 | */ |
| 338 | freq_down_step = 5; | 345 | freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks; |
| 346 | freq_next = (freq_next * policy->cur) / | ||
| 347 | (dbs_tuners_ins.up_threshold - 10); | ||
| 339 | 348 | ||
| 340 | __cpufreq_driver_target(policy, | 349 | if (freq_next <= ((policy->cur * 95) / 100)) |
| 341 | policy->cur - freq_down_step, | 350 | __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); |
| 342 | CPUFREQ_RELATION_H); | ||
| 343 | return; | ||
| 344 | } | ||
| 345 | } | 351 | } |
| 346 | 352 | ||
| 347 | static void do_dbs_timer(void *data) | 353 | static void do_dbs_timer(void *data) |
| 348 | { | 354 | { |
| 349 | int i; | 355 | int i; |
| 350 | down(&dbs_sem); | 356 | down(&dbs_sem); |
| 351 | for (i = 0; i < NR_CPUS; i++) | 357 | for_each_online_cpu(i) |
| 352 | if (cpu_online(i)) | 358 | dbs_check_cpu(i); |
| 353 | dbs_check_cpu(i); | ||
| 354 | schedule_delayed_work(&dbs_work, | 359 | schedule_delayed_work(&dbs_work, |
| 355 | sampling_rate_in_HZ(dbs_tuners_ins.sampling_rate)); | 360 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); |
| 356 | up(&dbs_sem); | 361 | up(&dbs_sem); |
| 357 | } | 362 | } |
| 358 | 363 | ||
| @@ -360,7 +365,7 @@ static inline void dbs_timer_init(void) | |||
| 360 | { | 365 | { |
| 361 | INIT_WORK(&dbs_work, do_dbs_timer, NULL); | 366 | INIT_WORK(&dbs_work, do_dbs_timer, NULL); |
| 362 | schedule_delayed_work(&dbs_work, | 367 | schedule_delayed_work(&dbs_work, |
| 363 | sampling_rate_in_HZ(dbs_tuners_ins.sampling_rate)); | 368 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); |
| 364 | return; | 369 | return; |
| 365 | } | 370 | } |
| 366 | 371 | ||
| @@ -397,12 +402,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 397 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 402 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
| 398 | j_dbs_info->cur_policy = policy; | 403 | j_dbs_info->cur_policy = policy; |
| 399 | 404 | ||
| 400 | j_dbs_info->prev_cpu_idle_up = | 405 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); |
| 401 | kstat_cpu(j).cpustat.idle + | 406 | j_dbs_info->prev_cpu_idle_down |
| 402 | kstat_cpu(j).cpustat.iowait; | 407 | = j_dbs_info->prev_cpu_idle_up; |
| 403 | j_dbs_info->prev_cpu_idle_down = | ||
| 404 | kstat_cpu(j).cpustat.idle + | ||
| 405 | kstat_cpu(j).cpustat.iowait; | ||
| 406 | } | 408 | } |
| 407 | this_dbs_info->enable = 1; | 409 | this_dbs_info->enable = 1; |
| 408 | sysfs_create_group(&policy->kobj, &dbs_attr_group); | 410 | sysfs_create_group(&policy->kobj, &dbs_attr_group); |
| @@ -422,6 +424,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 422 | def_sampling_rate = (latency / 1000) * | 424 | def_sampling_rate = (latency / 1000) * |
| 423 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; | 425 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; |
| 424 | dbs_tuners_ins.sampling_rate = def_sampling_rate; | 426 | dbs_tuners_ins.sampling_rate = def_sampling_rate; |
| 427 | dbs_tuners_ins.ignore_nice = 0; | ||
| 425 | 428 | ||
| 426 | dbs_timer_init(); | 429 | dbs_timer_init(); |
| 427 | } | 430 | } |
| @@ -461,12 +464,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
| 461 | return 0; | 464 | return 0; |
| 462 | } | 465 | } |
| 463 | 466 | ||
| 464 | struct cpufreq_governor cpufreq_gov_dbs = { | 467 | static struct cpufreq_governor cpufreq_gov_dbs = { |
| 465 | .name = "ondemand", | 468 | .name = "ondemand", |
| 466 | .governor = cpufreq_governor_dbs, | 469 | .governor = cpufreq_governor_dbs, |
| 467 | .owner = THIS_MODULE, | 470 | .owner = THIS_MODULE, |
| 468 | }; | 471 | }; |
| 469 | EXPORT_SYMBOL(cpufreq_gov_dbs); | ||
| 470 | 472 | ||
| 471 | static int __init cpufreq_gov_dbs_init(void) | 473 | static int __init cpufreq_gov_dbs_init(void) |
| 472 | { | 474 | { |
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 2084593937c6..741b6b191e6a 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <linux/percpu.h> | 19 | #include <linux/percpu.h> |
| 20 | #include <linux/kobject.h> | 20 | #include <linux/kobject.h> |
| 21 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
| 22 | #include <asm/cputime.h> | ||
| 22 | 23 | ||
| 23 | static spinlock_t cpufreq_stats_lock; | 24 | static spinlock_t cpufreq_stats_lock; |
| 24 | 25 | ||
| @@ -29,20 +30,14 @@ static struct freq_attr _attr_##_name = {\ | |||
| 29 | .show = _show,\ | 30 | .show = _show,\ |
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | static unsigned long | ||
| 33 | delta_time(unsigned long old, unsigned long new) | ||
| 34 | { | ||
| 35 | return (old > new) ? (old - new): (new + ~old + 1); | ||
| 36 | } | ||
| 37 | |||
| 38 | struct cpufreq_stats { | 33 | struct cpufreq_stats { |
| 39 | unsigned int cpu; | 34 | unsigned int cpu; |
| 40 | unsigned int total_trans; | 35 | unsigned int total_trans; |
| 41 | unsigned long long last_time; | 36 | unsigned long long last_time; |
| 42 | unsigned int max_state; | 37 | unsigned int max_state; |
| 43 | unsigned int state_num; | 38 | unsigned int state_num; |
| 44 | unsigned int last_index; | 39 | unsigned int last_index; |
| 45 | unsigned long long *time_in_state; | 40 | cputime64_t *time_in_state; |
| 46 | unsigned int *freq_table; | 41 | unsigned int *freq_table; |
| 47 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS | 42 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
| 48 | unsigned int *trans_table; | 43 | unsigned int *trans_table; |
| @@ -60,12 +55,16 @@ static int | |||
| 60 | cpufreq_stats_update (unsigned int cpu) | 55 | cpufreq_stats_update (unsigned int cpu) |
| 61 | { | 56 | { |
| 62 | struct cpufreq_stats *stat; | 57 | struct cpufreq_stats *stat; |
| 58 | unsigned long long cur_time; | ||
| 59 | |||
| 60 | cur_time = get_jiffies_64(); | ||
| 63 | spin_lock(&cpufreq_stats_lock); | 61 | spin_lock(&cpufreq_stats_lock); |
| 64 | stat = cpufreq_stats_table[cpu]; | 62 | stat = cpufreq_stats_table[cpu]; |
| 65 | if (stat->time_in_state) | 63 | if (stat->time_in_state) |
| 66 | stat->time_in_state[stat->last_index] += | 64 | stat->time_in_state[stat->last_index] = |
| 67 | delta_time(stat->last_time, jiffies); | 65 | cputime64_add(stat->time_in_state[stat->last_index], |
| 68 | stat->last_time = jiffies; | 66 | cputime_sub(cur_time, stat->last_time)); |
| 67 | stat->last_time = cur_time; | ||
| 69 | spin_unlock(&cpufreq_stats_lock); | 68 | spin_unlock(&cpufreq_stats_lock); |
| 70 | return 0; | 69 | return 0; |
| 71 | } | 70 | } |
| @@ -90,8 +89,8 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf) | |||
| 90 | return 0; | 89 | return 0; |
| 91 | cpufreq_stats_update(stat->cpu); | 90 | cpufreq_stats_update(stat->cpu); |
| 92 | for (i = 0; i < stat->state_num; i++) { | 91 | for (i = 0; i < stat->state_num; i++) { |
| 93 | len += sprintf(buf + len, "%u %llu\n", | 92 | len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], |
| 94 | stat->freq_table[i], stat->time_in_state[i]); | 93 | (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i])); |
| 95 | } | 94 | } |
| 96 | return len; | 95 | return len; |
| 97 | } | 96 | } |
| @@ -107,16 +106,30 @@ show_trans_table(struct cpufreq_policy *policy, char *buf) | |||
| 107 | if(!stat) | 106 | if(!stat) |
| 108 | return 0; | 107 | return 0; |
| 109 | cpufreq_stats_update(stat->cpu); | 108 | cpufreq_stats_update(stat->cpu); |
| 109 | len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); | ||
| 110 | len += snprintf(buf + len, PAGE_SIZE - len, " : "); | ||
| 111 | for (i = 0; i < stat->state_num; i++) { | ||
| 112 | if (len >= PAGE_SIZE) | ||
| 113 | break; | ||
| 114 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", | ||
| 115 | stat->freq_table[i]); | ||
| 116 | } | ||
| 117 | if (len >= PAGE_SIZE) | ||
| 118 | return len; | ||
| 119 | |||
| 120 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | ||
| 121 | |||
| 110 | for (i = 0; i < stat->state_num; i++) { | 122 | for (i = 0; i < stat->state_num; i++) { |
| 111 | if (len >= PAGE_SIZE) | 123 | if (len >= PAGE_SIZE) |
| 112 | break; | 124 | break; |
| 113 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u:\t", | 125 | |
| 126 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", | ||
| 114 | stat->freq_table[i]); | 127 | stat->freq_table[i]); |
| 115 | 128 | ||
| 116 | for (j = 0; j < stat->state_num; j++) { | 129 | for (j = 0; j < stat->state_num; j++) { |
| 117 | if (len >= PAGE_SIZE) | 130 | if (len >= PAGE_SIZE) |
| 118 | break; | 131 | break; |
| 119 | len += snprintf(buf + len, PAGE_SIZE - len, "%u\t", | 132 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", |
| 120 | stat->trans_table[i*stat->max_state+j]); | 133 | stat->trans_table[i*stat->max_state+j]); |
| 121 | } | 134 | } |
| 122 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | 135 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| @@ -197,7 +210,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, | |||
| 197 | count++; | 210 | count++; |
| 198 | } | 211 | } |
| 199 | 212 | ||
| 200 | alloc_size = count * sizeof(int) + count * sizeof(long long); | 213 | alloc_size = count * sizeof(int) + count * sizeof(cputime64_t); |
| 201 | 214 | ||
| 202 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS | 215 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
| 203 | alloc_size += count * count * sizeof(int); | 216 | alloc_size += count * count * sizeof(int); |
| @@ -224,7 +237,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, | |||
| 224 | } | 237 | } |
| 225 | stat->state_num = j; | 238 | stat->state_num = j; |
| 226 | spin_lock(&cpufreq_stats_lock); | 239 | spin_lock(&cpufreq_stats_lock); |
| 227 | stat->last_time = jiffies; | 240 | stat->last_time = get_jiffies_64(); |
| 228 | stat->last_index = freq_table_get_index(stat, policy->cur); | 241 | stat->last_index = freq_table_get_index(stat, policy->cur); |
| 229 | spin_unlock(&cpufreq_stats_lock); | 242 | spin_unlock(&cpufreq_stats_lock); |
| 230 | cpufreq_cpu_put(data); | 243 | cpufreq_cpu_put(data); |
