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