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