Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/cpufreq/cpufreq_ondemand.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 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/cpufreq.h> |
Andrew Morton | 138a0128 | 2006-06-23 03:31:19 -0700 | [diff] [blame] | 17 | #include <linux/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/jiffies.h> |
| 19 | #include <linux/kernel_stat.h> |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * dbs is used in this file as a shortform for demandbased switching |
| 24 | * It helps to keep variable names smaller, simpler |
| 25 | */ |
| 26 | |
| 27 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 28 | #define MIN_FREQUENCY_UP_THRESHOLD (11) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #define MAX_FREQUENCY_UP_THRESHOLD (100) |
| 30 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 31 | /* |
| 32 | * The polling frequency of this governor depends on the capability of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * the processor. Default polling frequency is 1000 times the transition |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 34 | * latency of the processor. The governor will work on any processor with |
| 35 | * transition latency <= 10mS, using appropriate sampling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * rate. |
| 37 | * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL) |
| 38 | * this governor will not work. |
| 39 | * All times here are in uS. |
| 40 | */ |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 41 | static unsigned int def_sampling_rate; |
Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 42 | #define MIN_SAMPLING_RATE_RATIO (2) |
| 43 | /* for correct statistics, we need at least 10 ticks between each measure */ |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 44 | #define MIN_STAT_SAMPLING_RATE \ |
| 45 | (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) |
| 46 | #define MIN_SAMPLING_RATE \ |
| 47 | (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) |
| 49 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 50 | #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 52 | static void do_dbs_timer(struct work_struct *work); |
| 53 | |
| 54 | /* Sampling types */ |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 55 | enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | struct cpu_dbs_info_s { |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 58 | cputime64_t prev_cpu_idle; |
| 59 | cputime64_t prev_cpu_wall; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 60 | struct cpufreq_policy *cur_policy; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 61 | struct delayed_work work; |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 62 | struct cpufreq_frequency_table *freq_table; |
| 63 | unsigned int freq_lo; |
| 64 | unsigned int freq_lo_jiffies; |
| 65 | unsigned int freq_hi_jiffies; |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 66 | int cpu; |
| 67 | unsigned int enable:1, |
| 68 | sample_type:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Venkatesh Pallipadi | 4ec223d | 2006-06-21 15:18:34 -0700 | [diff] [blame] | 74 | /* |
| 75 | * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug |
| 76 | * lock and dbs_mutex. cpu_hotplug lock should always be held before |
| 77 | * dbs_mutex. If any function that can potentially take cpu_hotplug lock |
| 78 | * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then |
| 79 | * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock |
| 80 | * is recursive for the same process. -Venki |
| 81 | */ |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 82 | static DEFINE_MUTEX(dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 84 | static struct workqueue_struct *kondemand_wq; |
Andi Kleen | 6810b54 | 2006-05-08 15:17:31 +0200 | [diff] [blame] | 85 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 86 | static struct dbs_tuners { |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 87 | unsigned int sampling_rate; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 88 | unsigned int up_threshold; |
| 89 | unsigned int ignore_nice; |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 90 | unsigned int powersave_bias; |
| 91 | } dbs_tuners_ins = { |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 92 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
Eric Piel | 9cbad61 | 2006-03-10 11:35:27 +0200 | [diff] [blame] | 93 | .ignore_nice = 0, |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 94 | .powersave_bias = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 97 | static inline cputime64_t get_cpu_idle_time(unsigned int cpu) |
Dave Jones | dac1c1a | 2005-05-31 19:03:49 -0700 | [diff] [blame] | 98 | { |
Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 99 | cputime64_t idle_time; |
| 100 | cputime64_t cur_jiffies; |
| 101 | cputime64_t busy_time; |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 102 | |
Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 103 | cur_jiffies = jiffies64_to_cputime64(get_jiffies_64()); |
| 104 | busy_time = cputime64_add(kstat_cpu(cpu).cpustat.user, |
| 105 | kstat_cpu(cpu).cpustat.system); |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 106 | |
Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 107 | busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.irq); |
| 108 | busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.softirq); |
| 109 | busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.steal); |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 110 | |
Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 111 | if (!dbs_tuners_ins.ignore_nice) { |
| 112 | busy_time = cputime64_add(busy_time, |
| 113 | kstat_cpu(cpu).cpustat.nice); |
| 114 | } |
| 115 | |
| 116 | idle_time = cputime64_sub(cur_jiffies, busy_time); |
| 117 | return idle_time; |
Dave Jones | dac1c1a | 2005-05-31 19:03:49 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 120 | /* |
| 121 | * Find right freq to be set now with powersave_bias on. |
| 122 | * Returns the freq_hi to be used right now and will set freq_hi_jiffies, |
| 123 | * freq_lo, and freq_lo_jiffies in percpu area for averaging freqs. |
| 124 | */ |
Adrian Bunk | b5ecf60 | 2006-08-13 23:00:08 +0200 | [diff] [blame] | 125 | static unsigned int powersave_bias_target(struct cpufreq_policy *policy, |
| 126 | unsigned int freq_next, |
| 127 | unsigned int relation) |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 128 | { |
| 129 | unsigned int freq_req, freq_reduc, freq_avg; |
| 130 | unsigned int freq_hi, freq_lo; |
| 131 | unsigned int index = 0; |
| 132 | unsigned int jiffies_total, jiffies_hi, jiffies_lo; |
| 133 | struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, policy->cpu); |
| 134 | |
| 135 | if (!dbs_info->freq_table) { |
| 136 | dbs_info->freq_lo = 0; |
| 137 | dbs_info->freq_lo_jiffies = 0; |
| 138 | return freq_next; |
| 139 | } |
| 140 | |
| 141 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_next, |
| 142 | relation, &index); |
| 143 | freq_req = dbs_info->freq_table[index].frequency; |
| 144 | freq_reduc = freq_req * dbs_tuners_ins.powersave_bias / 1000; |
| 145 | freq_avg = freq_req - freq_reduc; |
| 146 | |
| 147 | /* Find freq bounds for freq_avg in freq_table */ |
| 148 | index = 0; |
| 149 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg, |
| 150 | CPUFREQ_RELATION_H, &index); |
| 151 | freq_lo = dbs_info->freq_table[index].frequency; |
| 152 | index = 0; |
| 153 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg, |
| 154 | CPUFREQ_RELATION_L, &index); |
| 155 | freq_hi = dbs_info->freq_table[index].frequency; |
| 156 | |
| 157 | /* Find out how long we have to be in hi and lo freqs */ |
| 158 | if (freq_hi == freq_lo) { |
| 159 | dbs_info->freq_lo = 0; |
| 160 | dbs_info->freq_lo_jiffies = 0; |
| 161 | return freq_lo; |
| 162 | } |
| 163 | jiffies_total = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| 164 | jiffies_hi = (freq_avg - freq_lo) * jiffies_total; |
| 165 | jiffies_hi += ((freq_hi - freq_lo) / 2); |
| 166 | jiffies_hi /= (freq_hi - freq_lo); |
| 167 | jiffies_lo = jiffies_total - jiffies_hi; |
| 168 | dbs_info->freq_lo = freq_lo; |
| 169 | dbs_info->freq_lo_jiffies = jiffies_lo; |
| 170 | dbs_info->freq_hi_jiffies = jiffies_hi; |
| 171 | return freq_hi; |
| 172 | } |
| 173 | |
| 174 | static void ondemand_powersave_bias_init(void) |
| 175 | { |
| 176 | int i; |
| 177 | for_each_online_cpu(i) { |
| 178 | struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, i); |
| 179 | dbs_info->freq_table = cpufreq_frequency_get_table(i); |
| 180 | dbs_info->freq_lo = 0; |
| 181 | } |
| 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /************************** sysfs interface ************************/ |
| 185 | static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) |
| 186 | { |
| 187 | return sprintf (buf, "%u\n", MAX_SAMPLING_RATE); |
| 188 | } |
| 189 | |
| 190 | static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf) |
| 191 | { |
| 192 | return sprintf (buf, "%u\n", MIN_SAMPLING_RATE); |
| 193 | } |
| 194 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 195 | #define define_one_ro(_name) \ |
| 196 | static struct freq_attr _name = \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | __ATTR(_name, 0444, show_##_name, NULL) |
| 198 | |
| 199 | define_one_ro(sampling_rate_max); |
| 200 | define_one_ro(sampling_rate_min); |
| 201 | |
| 202 | /* cpufreq_ondemand Governor Tunables */ |
| 203 | #define show_one(file_name, object) \ |
| 204 | static ssize_t show_##file_name \ |
| 205 | (struct cpufreq_policy *unused, char *buf) \ |
| 206 | { \ |
| 207 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ |
| 208 | } |
| 209 | show_one(sampling_rate, sampling_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | show_one(up_threshold, up_threshold); |
Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 211 | show_one(ignore_nice_load, ignore_nice); |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 212 | show_one(powersave_bias, powersave_bias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 214 | static ssize_t store_sampling_rate(struct cpufreq_policy *unused, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | const char *buf, size_t count) |
| 216 | { |
| 217 | unsigned int input; |
| 218 | int ret; |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 219 | ret = sscanf(buf, "%u", &input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 221 | mutex_lock(&dbs_mutex); |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 222 | if (ret != 1 || input > MAX_SAMPLING_RATE |
| 223 | || input < MIN_SAMPLING_RATE) { |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 224 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | } |
| 227 | |
| 228 | dbs_tuners_ins.sampling_rate = input; |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 229 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | return count; |
| 232 | } |
| 233 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 234 | static ssize_t store_up_threshold(struct cpufreq_policy *unused, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | const char *buf, size_t count) |
| 236 | { |
| 237 | unsigned int input; |
| 238 | int ret; |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 239 | ret = sscanf(buf, "%u", &input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 241 | mutex_lock(&dbs_mutex); |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 242 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 243 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 244 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | dbs_tuners_ins.up_threshold = input; |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 249 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | return count; |
| 252 | } |
| 253 | |
Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 254 | static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy, |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 255 | const char *buf, size_t count) |
| 256 | { |
| 257 | unsigned int input; |
| 258 | int ret; |
| 259 | |
| 260 | unsigned int j; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 261 | |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 262 | ret = sscanf(buf, "%u", &input); |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 263 | if ( ret != 1 ) |
| 264 | return -EINVAL; |
| 265 | |
| 266 | if ( input > 1 ) |
| 267 | input = 1; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 268 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 269 | mutex_lock(&dbs_mutex); |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 270 | if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 271 | mutex_unlock(&dbs_mutex); |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 272 | return count; |
| 273 | } |
| 274 | dbs_tuners_ins.ignore_nice = input; |
| 275 | |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 276 | /* we need to re-evaluate prev_cpu_idle */ |
Dave Jones | dac1c1a | 2005-05-31 19:03:49 -0700 | [diff] [blame] | 277 | for_each_online_cpu(j) { |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 278 | struct cpu_dbs_info_s *dbs_info; |
| 279 | dbs_info = &per_cpu(cpu_dbs_info, j); |
| 280 | dbs_info->prev_cpu_idle = get_cpu_idle_time(j); |
| 281 | dbs_info->prev_cpu_wall = get_jiffies_64(); |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 282 | } |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 283 | mutex_unlock(&dbs_mutex); |
Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 284 | |
| 285 | return count; |
| 286 | } |
| 287 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 288 | static ssize_t store_powersave_bias(struct cpufreq_policy *unused, |
| 289 | const char *buf, size_t count) |
| 290 | { |
| 291 | unsigned int input; |
| 292 | int ret; |
| 293 | ret = sscanf(buf, "%u", &input); |
| 294 | |
| 295 | if (ret != 1) |
| 296 | return -EINVAL; |
| 297 | |
| 298 | if (input > 1000) |
| 299 | input = 1000; |
| 300 | |
| 301 | mutex_lock(&dbs_mutex); |
| 302 | dbs_tuners_ins.powersave_bias = input; |
| 303 | ondemand_powersave_bias_init(); |
| 304 | mutex_unlock(&dbs_mutex); |
| 305 | |
| 306 | return count; |
| 307 | } |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #define define_one_rw(_name) \ |
| 310 | static struct freq_attr _name = \ |
| 311 | __ATTR(_name, 0644, show_##_name, store_##_name) |
| 312 | |
| 313 | define_one_rw(sampling_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | define_one_rw(up_threshold); |
Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 315 | define_one_rw(ignore_nice_load); |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 316 | define_one_rw(powersave_bias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | static struct attribute * dbs_attributes[] = { |
| 319 | &sampling_rate_max.attr, |
| 320 | &sampling_rate_min.attr, |
| 321 | &sampling_rate.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | &up_threshold.attr, |
Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 323 | &ignore_nice_load.attr, |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 324 | &powersave_bias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | NULL |
| 326 | }; |
| 327 | |
| 328 | static struct attribute_group dbs_attr_group = { |
| 329 | .attrs = dbs_attributes, |
| 330 | .name = "ondemand", |
| 331 | }; |
| 332 | |
| 333 | /************************** sysfs end ************************/ |
| 334 | |
Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 335 | static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 337 | unsigned int max_load_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | struct cpufreq_policy *policy; |
| 340 | unsigned int j; |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (!this_dbs_info->enable) |
| 343 | return; |
| 344 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 345 | this_dbs_info->freq_lo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | policy = this_dbs_info->cur_policy; |
Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 347 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 348 | /* |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 349 | * Every sampling_rate, we check, if current idle time is less |
| 350 | * than 20% (default), then we try to increase frequency |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 351 | * Every sampling_rate, we look for a the lowest |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 352 | * frequency which can sustain the load while keeping idle time over |
| 353 | * 30%. If such a frequency exist, we try to decrease to this frequency. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | * |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 355 | * Any frequency increase takes it to the maximum frequency. |
| 356 | * Frequency reduction happens at minimum steps of |
| 357 | * 5% (default) of current frequency |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | */ |
| 359 | |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 360 | /* Get Absolute Load - in terms of freq */ |
| 361 | max_load_freq = 0; |
| 362 | |
Mike Travis | 068b127 | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 363 | for_each_cpu_mask_nr(j, policy->cpus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | struct cpu_dbs_info_s *j_dbs_info; |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 365 | cputime64_t cur_wall_time, cur_idle_time; |
| 366 | unsigned int idle_time, wall_time; |
| 367 | unsigned int load, load_freq; |
| 368 | int freq_avg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 371 | cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); |
| 372 | wall_time = (unsigned int) cputime64_sub(cur_wall_time, |
| 373 | j_dbs_info->prev_cpu_wall); |
| 374 | j_dbs_info->prev_cpu_wall = cur_wall_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 376 | cur_idle_time = get_cpu_idle_time(j); |
| 377 | idle_time = (unsigned int) cputime64_sub(cur_idle_time, |
| 378 | j_dbs_info->prev_cpu_idle); |
| 379 | j_dbs_info->prev_cpu_idle = cur_idle_time; |
| 380 | |
| 381 | if (unlikely(wall_time <= idle_time || |
| 382 | (cputime_to_msecs(wall_time) < |
| 383 | dbs_tuners_ins.sampling_rate / (2 * 1000)))) { |
| 384 | continue; |
| 385 | } |
| 386 | |
| 387 | load = 100 * (wall_time - idle_time) / wall_time; |
| 388 | |
| 389 | freq_avg = __cpufreq_driver_getavg(policy, j); |
| 390 | if (freq_avg <= 0) |
| 391 | freq_avg = policy->cur; |
| 392 | |
| 393 | load_freq = load * freq_avg; |
| 394 | if (load_freq > max_load_freq) |
| 395 | max_load_freq = load_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 398 | /* Check for frequency increase */ |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 399 | if (max_load_freq > dbs_tuners_ins.up_threshold * policy->cur) { |
Dave Jones | c11420a | 2005-05-31 19:03:48 -0700 | [diff] [blame] | 400 | /* if we are already at full speed then break out early */ |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 401 | if (!dbs_tuners_ins.powersave_bias) { |
| 402 | if (policy->cur == policy->max) |
| 403 | return; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 404 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 405 | __cpufreq_driver_target(policy, policy->max, |
| 406 | CPUFREQ_RELATION_H); |
| 407 | } else { |
| 408 | int freq = powersave_bias_target(policy, policy->max, |
| 409 | CPUFREQ_RELATION_H); |
| 410 | __cpufreq_driver_target(policy, freq, |
| 411 | CPUFREQ_RELATION_L); |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
| 416 | /* Check for frequency decrease */ |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 417 | /* if we cannot reduce the frequency anymore, break out early */ |
| 418 | if (policy->cur == policy->min) |
| 419 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 421 | /* |
| 422 | * The optimal frequency is the frequency that is the lowest that |
| 423 | * can support the current CPU usage without triggering the up |
| 424 | * policy. To be safe, we focus 10 points under the threshold. |
| 425 | */ |
venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame^] | 426 | if (max_load_freq < (dbs_tuners_ins.up_threshold - 10) * policy->cur) { |
| 427 | unsigned int freq_next; |
| 428 | freq_next = max_load_freq / (dbs_tuners_ins.up_threshold - 10); |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 429 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 430 | if (!dbs_tuners_ins.powersave_bias) { |
| 431 | __cpufreq_driver_target(policy, freq_next, |
| 432 | CPUFREQ_RELATION_L); |
| 433 | } else { |
| 434 | int freq = powersave_bias_target(policy, freq_next, |
| 435 | CPUFREQ_RELATION_L); |
| 436 | __cpufreq_driver_target(policy, freq, |
| 437 | CPUFREQ_RELATION_L); |
| 438 | } |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 442 | static void do_dbs_timer(struct work_struct *work) |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 443 | { |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 444 | struct cpu_dbs_info_s *dbs_info = |
| 445 | container_of(work, struct cpu_dbs_info_s, work.work); |
| 446 | unsigned int cpu = dbs_info->cpu; |
| 447 | int sample_type = dbs_info->sample_type; |
| 448 | |
Alexey Starikovskiy | 1ce28d6 | 2006-07-31 22:25:20 +0400 | [diff] [blame] | 449 | /* We want all CPUs to do sampling nearly on same jiffy */ |
| 450 | int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 451 | |
Alexey Starikovskiy | 1ce28d6 | 2006-07-31 22:25:20 +0400 | [diff] [blame] | 452 | delay -= jiffies % delay; |
Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 453 | |
Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 454 | if (lock_policy_rwsem_write(cpu) < 0) |
Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 455 | return; |
Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 456 | |
| 457 | if (!dbs_info->enable) { |
| 458 | unlock_policy_rwsem_write(cpu); |
| 459 | return; |
| 460 | } |
| 461 | |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 462 | /* Common NORMAL_SAMPLE setup */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 463 | dbs_info->sample_type = DBS_NORMAL_SAMPLE; |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 464 | if (!dbs_tuners_ins.powersave_bias || |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 465 | sample_type == DBS_NORMAL_SAMPLE) { |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 466 | dbs_check_cpu(dbs_info); |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 467 | if (dbs_info->freq_lo) { |
| 468 | /* Setup timer for SUB_SAMPLE */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 469 | dbs_info->sample_type = DBS_SUB_SAMPLE; |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 470 | delay = dbs_info->freq_hi_jiffies; |
| 471 | } |
| 472 | } else { |
| 473 | __cpufreq_driver_target(dbs_info->cur_policy, |
| 474 | dbs_info->freq_lo, |
| 475 | CPUFREQ_RELATION_H); |
| 476 | } |
Alexey Starikovskiy | 1ce28d6 | 2006-07-31 22:25:20 +0400 | [diff] [blame] | 477 | queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay); |
Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 478 | unlock_policy_rwsem_write(cpu); |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 481 | static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Alexey Starikovskiy | 1ce28d6 | 2006-07-31 22:25:20 +0400 | [diff] [blame] | 483 | /* We want all CPUs to do sampling nearly on same jiffy */ |
| 484 | int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| 485 | delay -= jiffies % delay; |
Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 486 | |
Dave Jones | c18a148 | 2007-02-10 20:03:51 -0500 | [diff] [blame] | 487 | dbs_info->enable = 1; |
Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 488 | ondemand_powersave_bias_init(); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 489 | dbs_info->sample_type = DBS_NORMAL_SAMPLE; |
Venki Pallipadi | 2828703 | 2007-05-08 00:27:47 -0700 | [diff] [blame] | 490 | INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer); |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 491 | queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work, |
| 492 | delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 495 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 497 | dbs_info->enable = 0; |
| 498 | cancel_delayed_work(&dbs_info->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
| 502 | unsigned int event) |
| 503 | { |
| 504 | unsigned int cpu = policy->cpu; |
| 505 | struct cpu_dbs_info_s *this_dbs_info; |
| 506 | unsigned int j; |
Jeff Garzik | 914f7c3 | 2006-10-20 14:31:00 -0700 | [diff] [blame] | 507 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | this_dbs_info = &per_cpu(cpu_dbs_info, cpu); |
| 510 | |
| 511 | switch (event) { |
| 512 | case CPUFREQ_GOV_START: |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 513 | if ((!cpu_online(cpu)) || (!policy->cur)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | return -EINVAL; |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (this_dbs_info->enable) /* Already enabled */ |
| 517 | break; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 518 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 519 | mutex_lock(&dbs_mutex); |
Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 520 | dbs_enable++; |
Jeff Garzik | 914f7c3 | 2006-10-20 14:31:00 -0700 | [diff] [blame] | 521 | |
| 522 | rc = sysfs_create_group(&policy->kobj, &dbs_attr_group); |
| 523 | if (rc) { |
Jeff Garzik | 914f7c3 | 2006-10-20 14:31:00 -0700 | [diff] [blame] | 524 | dbs_enable--; |
| 525 | mutex_unlock(&dbs_mutex); |
| 526 | return rc; |
| 527 | } |
| 528 | |
Mike Travis | 068b127 | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 529 | for_each_cpu_mask_nr(j, policy->cpus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | struct cpu_dbs_info_s *j_dbs_info; |
| 531 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
| 532 | j_dbs_info->cur_policy = policy; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 533 | |
Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 534 | j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j); |
| 535 | j_dbs_info->prev_cpu_wall = get_jiffies_64(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 537 | this_dbs_info->cpu = cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | /* |
| 539 | * Start the timerschedule work, when this governor |
| 540 | * is used for first time |
| 541 | */ |
| 542 | if (dbs_enable == 1) { |
| 543 | unsigned int latency; |
| 544 | /* policy latency is in nS. Convert it to uS first */ |
Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 545 | latency = policy->cpuinfo.transition_latency / 1000; |
| 546 | if (latency == 0) |
| 547 | latency = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 549 | def_sampling_rate = latency * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; |
Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 551 | |
| 552 | if (def_sampling_rate < MIN_STAT_SAMPLING_RATE) |
| 553 | def_sampling_rate = MIN_STAT_SAMPLING_RATE; |
| 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | dbs_tuners_ins.sampling_rate = def_sampling_rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 557 | dbs_timer_init(this_dbs_info); |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 558 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 559 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | case CPUFREQ_GOV_STOP: |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 563 | mutex_lock(&dbs_mutex); |
Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 564 | dbs_timer_exit(this_dbs_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | sysfs_remove_group(&policy->kobj, &dbs_attr_group); |
| 566 | dbs_enable--; |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 567 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | break; |
| 570 | |
| 571 | case CPUFREQ_GOV_LIMITS: |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 572 | mutex_lock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (policy->max < this_dbs_info->cur_policy->cur) |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 574 | __cpufreq_driver_target(this_dbs_info->cur_policy, |
| 575 | policy->max, |
| 576 | CPUFREQ_RELATION_H); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | else if (policy->min > this_dbs_info->cur_policy->cur) |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 578 | __cpufreq_driver_target(this_dbs_info->cur_policy, |
| 579 | policy->min, |
| 580 | CPUFREQ_RELATION_L); |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 581 | mutex_unlock(&dbs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | break; |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 587 | struct cpufreq_governor cpufreq_gov_ondemand = { |
| 588 | .name = "ondemand", |
| 589 | .governor = cpufreq_governor_dbs, |
| 590 | .max_transition_latency = TRANSITION_LATENCY_LIMIT, |
| 591 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | }; |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 593 | EXPORT_SYMBOL(cpufreq_gov_ondemand); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | static int __init cpufreq_gov_dbs_init(void) |
| 596 | { |
Akinobu Mita | 888a794 | 2008-07-14 12:00:45 +0900 | [diff] [blame] | 597 | int err; |
| 598 | |
Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 599 | kondemand_wq = create_workqueue("kondemand"); |
| 600 | if (!kondemand_wq) { |
| 601 | printk(KERN_ERR "Creation of kondemand failed\n"); |
| 602 | return -EFAULT; |
| 603 | } |
Akinobu Mita | 888a794 | 2008-07-14 12:00:45 +0900 | [diff] [blame] | 604 | err = cpufreq_register_governor(&cpufreq_gov_ondemand); |
| 605 | if (err) |
| 606 | destroy_workqueue(kondemand_wq); |
| 607 | |
| 608 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static void __exit cpufreq_gov_dbs_exit(void) |
| 612 | { |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 613 | cpufreq_unregister_governor(&cpufreq_gov_ondemand); |
Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 614 | destroy_workqueue(kondemand_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 618 | MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>"); |
| 619 | MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>"); |
| 620 | MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for " |
| 621 | "Low Latency Frequency Transition capable processors"); |
| 622 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 624 | #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND |
| 625 | fs_initcall(cpufreq_gov_dbs_init); |
| 626 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | module_init(cpufreq_gov_dbs_init); |
Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 628 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | module_exit(cpufreq_gov_dbs_exit); |