blob: 2fc514fb68d2bf5bb1c259253d0f23713cefa29d [file] [log] [blame]
Mike Chan9d49b702010-06-22 11:26:45 -07001/*
2 * drivers/cpufreq/cpufreq_interactive.c
3 *
4 * Copyright (C) 2010 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * Author: Mike Chan (mike@android.com)
16 *
17 */
18
19#include <linux/cpu.h>
20#include <linux/cpumask.h>
21#include <linux/cpufreq.h>
22#include <linux/module.h>
23#include <linux/mutex.h>
24#include <linux/sched.h>
25#include <linux/tick.h>
26#include <linux/time.h>
27#include <linux/timer.h>
28#include <linux/workqueue.h>
29#include <linux/kthread.h>
30#include <linux/mutex.h>
31
Todd Poynora1e19512012-02-16 16:27:59 -080032#define CREATE_TRACE_POINTS
33#include <trace/events/cpufreq_interactive.h>
34
Mike Chan9d49b702010-06-22 11:26:45 -070035#include <asm/cputime.h>
36
37static atomic_t active_count = ATOMIC_INIT(0);
38
39struct cpufreq_interactive_cpuinfo {
40 struct timer_list cpu_timer;
41 int timer_idlecancel;
42 u64 time_in_idle;
43 u64 idle_exit_time;
44 u64 timer_run_time;
45 int idling;
Todd Poynor0a92d482012-04-06 19:59:36 -070046 u64 target_set_time;
47 u64 target_set_time_in_idle;
Mike Chan9d49b702010-06-22 11:26:45 -070048 struct cpufreq_policy *policy;
49 struct cpufreq_frequency_table *freq_table;
50 unsigned int target_freq;
51 int governor_enabled;
52};
53
54static DEFINE_PER_CPU(struct cpufreq_interactive_cpuinfo, cpuinfo);
55
56/* Workqueues handle frequency scaling */
57static struct task_struct *up_task;
58static struct workqueue_struct *down_wq;
59static struct work_struct freq_scale_down_work;
60static cpumask_t up_cpumask;
61static spinlock_t up_cpumask_lock;
62static cpumask_t down_cpumask;
63static spinlock_t down_cpumask_lock;
64static struct mutex set_speed_lock;
65
66/* Hi speed to bump to from lo speed when load burst (default max) */
67static u64 hispeed_freq;
68
69/* Go to hi speed when CPU load at or above this value. */
70#define DEFAULT_GO_HISPEED_LOAD 95
71static unsigned long go_hispeed_load;
72
73/*
74 * The minimum amount of time to spend at a frequency before we can ramp down.
75 */
76#define DEFAULT_MIN_SAMPLE_TIME 20 * USEC_PER_MSEC
77static unsigned long min_sample_time;
78
79/*
80 * The sample rate of the timer used to increase frequency
81 */
82#define DEFAULT_TIMER_RATE 20 * USEC_PER_MSEC
83static unsigned long timer_rate;
84
85static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
86 unsigned int event);
87
88#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
89static
90#endif
91struct cpufreq_governor cpufreq_gov_interactive = {
92 .name = "interactive",
93 .governor = cpufreq_governor_interactive,
94 .max_transition_latency = 10000000,
95 .owner = THIS_MODULE,
96};
97
98static void cpufreq_interactive_timer(unsigned long data)
99{
100 unsigned int delta_idle;
101 unsigned int delta_time;
102 int cpu_load;
103 int load_since_change;
104 u64 time_in_idle;
105 u64 idle_exit_time;
106 struct cpufreq_interactive_cpuinfo *pcpu =
107 &per_cpu(cpuinfo, data);
108 u64 now_idle;
109 unsigned int new_freq;
110 unsigned int index;
111 unsigned long flags;
112
113 smp_rmb();
114
115 if (!pcpu->governor_enabled)
116 goto exit;
117
118 /*
119 * Once pcpu->timer_run_time is updated to >= pcpu->idle_exit_time,
120 * this lets idle exit know the current idle time sample has
121 * been processed, and idle exit can generate a new sample and
122 * re-arm the timer. This prevents a concurrent idle
123 * exit on that CPU from writing a new set of info at the same time
124 * the timer function runs (the timer function can't use that info
125 * until more time passes).
126 */
127 time_in_idle = pcpu->time_in_idle;
128 idle_exit_time = pcpu->idle_exit_time;
129 now_idle = get_cpu_idle_time_us(data, &pcpu->timer_run_time);
130 smp_wmb();
131
132 /* If we raced with cancelling a timer, skip. */
133 if (!idle_exit_time)
134 goto exit;
135
136 delta_idle = (unsigned int)(now_idle - time_in_idle);
137 delta_time = (unsigned int)(pcpu->timer_run_time - idle_exit_time);
138
139 /*
140 * If timer ran less than 1ms after short-term sample started, retry.
141 */
142 if (delta_time < 1000)
143 goto rearm;
144
145 if (delta_idle > delta_time)
146 cpu_load = 0;
147 else
148 cpu_load = 100 * (delta_time - delta_idle) / delta_time;
149
Todd Poynor0a92d482012-04-06 19:59:36 -0700150 delta_idle = (unsigned int)(now_idle - pcpu->target_set_time_in_idle);
151 delta_time = (unsigned int)(pcpu->timer_run_time -
152 pcpu->target_set_time);
Mike Chan9d49b702010-06-22 11:26:45 -0700153
154 if ((delta_time == 0) || (delta_idle > delta_time))
155 load_since_change = 0;
156 else
157 load_since_change =
158 100 * (delta_time - delta_idle) / delta_time;
159
160 /*
161 * Choose greater of short-term load (since last idle timer
162 * started or timer function re-armed itself) or long-term load
163 * (since last frequency change).
164 */
165 if (load_since_change > cpu_load)
166 cpu_load = load_since_change;
167
168 if (cpu_load >= go_hispeed_load) {
Todd Poynor8dc352c2012-04-06 19:50:12 -0700169 if (pcpu->policy->cur == pcpu->policy->min) {
Mike Chan9d49b702010-06-22 11:26:45 -0700170 new_freq = hispeed_freq;
Todd Poynor8dc352c2012-04-06 19:50:12 -0700171 } else {
Mike Chan9d49b702010-06-22 11:26:45 -0700172 new_freq = pcpu->policy->max * cpu_load / 100;
Todd Poynor8dc352c2012-04-06 19:50:12 -0700173
174 if (new_freq < hispeed_freq)
175 new_freq = hispeed_freq;
176 }
Mike Chan9d49b702010-06-22 11:26:45 -0700177 } else {
Todd Poynor1f53ef22012-04-06 01:13:09 -0700178 new_freq = pcpu->policy->max * cpu_load / 100;
Mike Chan9d49b702010-06-22 11:26:45 -0700179 }
180
181 if (cpufreq_frequency_table_target(pcpu->policy, pcpu->freq_table,
182 new_freq, CPUFREQ_RELATION_H,
183 &index)) {
184 pr_warn_once("timer %d: cpufreq_frequency_table_target error\n",
185 (int) data);
186 goto rearm;
187 }
188
189 new_freq = pcpu->freq_table[index].frequency;
190
Mike Chan9d49b702010-06-22 11:26:45 -0700191 /*
192 * Do not scale down unless we have been at this frequency for the
193 * minimum sample time.
194 */
195 if (new_freq < pcpu->target_freq) {
Todd Poynor0a92d482012-04-06 19:59:36 -0700196 if (pcpu->timer_run_time - pcpu->target_set_time
Todd Poynora1e19512012-02-16 16:27:59 -0800197 < min_sample_time) {
198 trace_cpufreq_interactive_notyet(data, cpu_load,
199 pcpu->target_freq, new_freq);
Mike Chan9d49b702010-06-22 11:26:45 -0700200 goto rearm;
Todd Poynora1e19512012-02-16 16:27:59 -0800201 }
Mike Chan9d49b702010-06-22 11:26:45 -0700202 }
203
Todd Poynor0a92d482012-04-06 19:59:36 -0700204 pcpu->target_set_time_in_idle = now_idle;
205 pcpu->target_set_time = pcpu->timer_run_time;
206
207 if (pcpu->target_freq == new_freq) {
208 trace_cpufreq_interactive_already(data, cpu_load,
209 pcpu->target_freq, new_freq);
210 goto rearm_if_notmax;
211 }
212
Todd Poynora1e19512012-02-16 16:27:59 -0800213 trace_cpufreq_interactive_target(data, cpu_load, pcpu->target_freq,
214 new_freq);
215
Mike Chan9d49b702010-06-22 11:26:45 -0700216 if (new_freq < pcpu->target_freq) {
217 pcpu->target_freq = new_freq;
218 spin_lock_irqsave(&down_cpumask_lock, flags);
219 cpumask_set_cpu(data, &down_cpumask);
220 spin_unlock_irqrestore(&down_cpumask_lock, flags);
221 queue_work(down_wq, &freq_scale_down_work);
222 } else {
223 pcpu->target_freq = new_freq;
224 spin_lock_irqsave(&up_cpumask_lock, flags);
225 cpumask_set_cpu(data, &up_cpumask);
226 spin_unlock_irqrestore(&up_cpumask_lock, flags);
227 wake_up_process(up_task);
228 }
229
230rearm_if_notmax:
231 /*
232 * Already set max speed and don't see a need to change that,
233 * wait until next idle to re-evaluate, don't need timer.
234 */
235 if (pcpu->target_freq == pcpu->policy->max)
236 goto exit;
237
238rearm:
239 if (!timer_pending(&pcpu->cpu_timer)) {
240 /*
241 * If already at min: if that CPU is idle, don't set timer.
242 * Else cancel the timer if that CPU goes idle. We don't
243 * need to re-evaluate speed until the next idle exit.
244 */
245 if (pcpu->target_freq == pcpu->policy->min) {
246 smp_rmb();
247
248 if (pcpu->idling)
249 goto exit;
250
251 pcpu->timer_idlecancel = 1;
252 }
253
254 pcpu->time_in_idle = get_cpu_idle_time_us(
255 data, &pcpu->idle_exit_time);
256 mod_timer(&pcpu->cpu_timer,
257 jiffies + usecs_to_jiffies(timer_rate));
258 }
259
260exit:
261 return;
262}
263
264static void cpufreq_interactive_idle_start(void)
265{
266 struct cpufreq_interactive_cpuinfo *pcpu =
267 &per_cpu(cpuinfo, smp_processor_id());
268 int pending;
269
270 if (!pcpu->governor_enabled)
271 return;
272
273 pcpu->idling = 1;
274 smp_wmb();
275 pending = timer_pending(&pcpu->cpu_timer);
276
277 if (pcpu->target_freq != pcpu->policy->min) {
278#ifdef CONFIG_SMP
279 /*
280 * Entering idle while not at lowest speed. On some
281 * platforms this can hold the other CPU(s) at that speed
282 * even though the CPU is idle. Set a timer to re-evaluate
283 * speed so this idle CPU doesn't hold the other CPUs above
284 * min indefinitely. This should probably be a quirk of
285 * the CPUFreq driver.
286 */
287 if (!pending) {
288 pcpu->time_in_idle = get_cpu_idle_time_us(
289 smp_processor_id(), &pcpu->idle_exit_time);
290 pcpu->timer_idlecancel = 0;
291 mod_timer(&pcpu->cpu_timer,
292 jiffies + usecs_to_jiffies(timer_rate));
293 }
294#endif
295 } else {
296 /*
297 * If at min speed and entering idle after load has
298 * already been evaluated, and a timer has been set just in
299 * case the CPU suddenly goes busy, cancel that timer. The
300 * CPU didn't go busy; we'll recheck things upon idle exit.
301 */
302 if (pending && pcpu->timer_idlecancel) {
303 del_timer(&pcpu->cpu_timer);
304 /*
305 * Ensure last timer run time is after current idle
306 * sample start time, so next idle exit will always
307 * start a new idle sampling period.
308 */
309 pcpu->idle_exit_time = 0;
310 pcpu->timer_idlecancel = 0;
311 }
312 }
313
314}
315
316static void cpufreq_interactive_idle_end(void)
317{
318 struct cpufreq_interactive_cpuinfo *pcpu =
319 &per_cpu(cpuinfo, smp_processor_id());
320
321 pcpu->idling = 0;
322 smp_wmb();
323
324 /*
325 * Arm the timer for 1-2 ticks later if not already, and if the timer
326 * function has already processed the previous load sampling
327 * interval. (If the timer is not pending but has not processed
328 * the previous interval, it is probably racing with us on another
329 * CPU. Let it compute load based on the previous sample and then
330 * re-arm the timer for another interval when it's done, rather
331 * than updating the interval start time to be "now", which doesn't
332 * give the timer function enough time to make a decision on this
333 * run.)
334 */
335 if (timer_pending(&pcpu->cpu_timer) == 0 &&
336 pcpu->timer_run_time >= pcpu->idle_exit_time &&
337 pcpu->governor_enabled) {
338 pcpu->time_in_idle =
339 get_cpu_idle_time_us(smp_processor_id(),
340 &pcpu->idle_exit_time);
341 pcpu->timer_idlecancel = 0;
342 mod_timer(&pcpu->cpu_timer,
343 jiffies + usecs_to_jiffies(timer_rate));
344 }
345
346}
347
348static int cpufreq_interactive_up_task(void *data)
349{
350 unsigned int cpu;
351 cpumask_t tmp_mask;
352 unsigned long flags;
353 struct cpufreq_interactive_cpuinfo *pcpu;
354
355 while (1) {
356 set_current_state(TASK_INTERRUPTIBLE);
357 spin_lock_irqsave(&up_cpumask_lock, flags);
358
359 if (cpumask_empty(&up_cpumask)) {
360 spin_unlock_irqrestore(&up_cpumask_lock, flags);
361 schedule();
362
363 if (kthread_should_stop())
364 break;
365
366 spin_lock_irqsave(&up_cpumask_lock, flags);
367 }
368
369 set_current_state(TASK_RUNNING);
370 tmp_mask = up_cpumask;
371 cpumask_clear(&up_cpumask);
372 spin_unlock_irqrestore(&up_cpumask_lock, flags);
373
374 for_each_cpu(cpu, &tmp_mask) {
375 unsigned int j;
376 unsigned int max_freq = 0;
377
378 pcpu = &per_cpu(cpuinfo, cpu);
379 smp_rmb();
380
381 if (!pcpu->governor_enabled)
382 continue;
383
384 mutex_lock(&set_speed_lock);
385
386 for_each_cpu(j, pcpu->policy->cpus) {
387 struct cpufreq_interactive_cpuinfo *pjcpu =
388 &per_cpu(cpuinfo, j);
389
390 if (pjcpu->target_freq > max_freq)
391 max_freq = pjcpu->target_freq;
392 }
393
394 if (max_freq != pcpu->policy->cur)
395 __cpufreq_driver_target(pcpu->policy,
396 max_freq,
397 CPUFREQ_RELATION_H);
398 mutex_unlock(&set_speed_lock);
Todd Poynora1e19512012-02-16 16:27:59 -0800399 trace_cpufreq_interactive_up(cpu, pcpu->target_freq,
400 pcpu->policy->cur);
Mike Chan9d49b702010-06-22 11:26:45 -0700401 }
402 }
403
404 return 0;
405}
406
407static void cpufreq_interactive_freq_down(struct work_struct *work)
408{
409 unsigned int cpu;
410 cpumask_t tmp_mask;
411 unsigned long flags;
412 struct cpufreq_interactive_cpuinfo *pcpu;
413
414 spin_lock_irqsave(&down_cpumask_lock, flags);
415 tmp_mask = down_cpumask;
416 cpumask_clear(&down_cpumask);
417 spin_unlock_irqrestore(&down_cpumask_lock, flags);
418
419 for_each_cpu(cpu, &tmp_mask) {
420 unsigned int j;
421 unsigned int max_freq = 0;
422
423 pcpu = &per_cpu(cpuinfo, cpu);
424 smp_rmb();
425
426 if (!pcpu->governor_enabled)
427 continue;
428
429 mutex_lock(&set_speed_lock);
430
431 for_each_cpu(j, pcpu->policy->cpus) {
432 struct cpufreq_interactive_cpuinfo *pjcpu =
433 &per_cpu(cpuinfo, j);
434
435 if (pjcpu->target_freq > max_freq)
436 max_freq = pjcpu->target_freq;
437 }
438
439 if (max_freq != pcpu->policy->cur)
440 __cpufreq_driver_target(pcpu->policy, max_freq,
441 CPUFREQ_RELATION_H);
442
443 mutex_unlock(&set_speed_lock);
Todd Poynora1e19512012-02-16 16:27:59 -0800444 trace_cpufreq_interactive_down(cpu, pcpu->target_freq,
445 pcpu->policy->cur);
Mike Chan9d49b702010-06-22 11:26:45 -0700446 }
447}
448
449static ssize_t show_hispeed_freq(struct kobject *kobj,
450 struct attribute *attr, char *buf)
451{
452 return sprintf(buf, "%llu\n", hispeed_freq);
453}
454
455static ssize_t store_hispeed_freq(struct kobject *kobj,
456 struct attribute *attr, const char *buf,
457 size_t count)
458{
459 int ret;
460 u64 val;
461
462 ret = strict_strtoull(buf, 0, &val);
463 if (ret < 0)
464 return ret;
465 hispeed_freq = val;
466 return count;
467}
468
469static struct global_attr hispeed_freq_attr = __ATTR(hispeed_freq, 0644,
470 show_hispeed_freq, store_hispeed_freq);
471
472
473static ssize_t show_go_hispeed_load(struct kobject *kobj,
474 struct attribute *attr, char *buf)
475{
476 return sprintf(buf, "%lu\n", go_hispeed_load);
477}
478
479static ssize_t store_go_hispeed_load(struct kobject *kobj,
480 struct attribute *attr, const char *buf, size_t count)
481{
482 int ret;
483 unsigned long val;
484
485 ret = strict_strtoul(buf, 0, &val);
486 if (ret < 0)
487 return ret;
488 go_hispeed_load = val;
489 return count;
490}
491
492static struct global_attr go_hispeed_load_attr = __ATTR(go_hispeed_load, 0644,
493 show_go_hispeed_load, store_go_hispeed_load);
494
495static ssize_t show_min_sample_time(struct kobject *kobj,
496 struct attribute *attr, char *buf)
497{
498 return sprintf(buf, "%lu\n", min_sample_time);
499}
500
501static ssize_t store_min_sample_time(struct kobject *kobj,
502 struct attribute *attr, const char *buf, size_t count)
503{
504 int ret;
505 unsigned long val;
506
507 ret = strict_strtoul(buf, 0, &val);
508 if (ret < 0)
509 return ret;
510 min_sample_time = val;
511 return count;
512}
513
514static struct global_attr min_sample_time_attr = __ATTR(min_sample_time, 0644,
515 show_min_sample_time, store_min_sample_time);
516
517static ssize_t show_timer_rate(struct kobject *kobj,
518 struct attribute *attr, char *buf)
519{
520 return sprintf(buf, "%lu\n", timer_rate);
521}
522
523static ssize_t store_timer_rate(struct kobject *kobj,
524 struct attribute *attr, const char *buf, size_t count)
525{
526 int ret;
527 unsigned long val;
528
529 ret = strict_strtoul(buf, 0, &val);
530 if (ret < 0)
531 return ret;
532 timer_rate = val;
533 return count;
534}
535
536static struct global_attr timer_rate_attr = __ATTR(timer_rate, 0644,
537 show_timer_rate, store_timer_rate);
538
539static struct attribute *interactive_attributes[] = {
540 &hispeed_freq_attr.attr,
541 &go_hispeed_load_attr.attr,
542 &min_sample_time_attr.attr,
543 &timer_rate_attr.attr,
544 NULL,
545};
546
547static struct attribute_group interactive_attr_group = {
548 .attrs = interactive_attributes,
549 .name = "interactive",
550};
551
552static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
553 unsigned int event)
554{
555 int rc;
556 unsigned int j;
557 struct cpufreq_interactive_cpuinfo *pcpu;
558 struct cpufreq_frequency_table *freq_table;
559
560 switch (event) {
561 case CPUFREQ_GOV_START:
562 if (!cpu_online(policy->cpu))
563 return -EINVAL;
564
565 freq_table =
566 cpufreq_frequency_get_table(policy->cpu);
567
568 for_each_cpu(j, policy->cpus) {
569 pcpu = &per_cpu(cpuinfo, j);
570 pcpu->policy = policy;
571 pcpu->target_freq = policy->cur;
572 pcpu->freq_table = freq_table;
Todd Poynor0a92d482012-04-06 19:59:36 -0700573 pcpu->target_set_time_in_idle =
Mike Chan9d49b702010-06-22 11:26:45 -0700574 get_cpu_idle_time_us(j,
Todd Poynor0a92d482012-04-06 19:59:36 -0700575 &pcpu->target_set_time);
Mike Chan9d49b702010-06-22 11:26:45 -0700576 pcpu->governor_enabled = 1;
577 smp_wmb();
578 }
579
580 if (!hispeed_freq)
581 hispeed_freq = policy->max;
582
583 /*
584 * Do not register the idle hook and create sysfs
585 * entries if we have already done so.
586 */
587 if (atomic_inc_return(&active_count) > 1)
588 return 0;
589
590 rc = sysfs_create_group(cpufreq_global_kobject,
591 &interactive_attr_group);
592 if (rc)
593 return rc;
594
595 break;
596
597 case CPUFREQ_GOV_STOP:
598 for_each_cpu(j, policy->cpus) {
599 pcpu = &per_cpu(cpuinfo, j);
600 pcpu->governor_enabled = 0;
601 smp_wmb();
602 del_timer_sync(&pcpu->cpu_timer);
603
604 /*
605 * Reset idle exit time since we may cancel the timer
606 * before it can run after the last idle exit time,
607 * to avoid tripping the check in idle exit for a timer
608 * that is trying to run.
609 */
610 pcpu->idle_exit_time = 0;
611 }
612
613 flush_work(&freq_scale_down_work);
614 if (atomic_dec_return(&active_count) > 0)
615 return 0;
616
617 sysfs_remove_group(cpufreq_global_kobject,
618 &interactive_attr_group);
619
620 break;
621
622 case CPUFREQ_GOV_LIMITS:
623 if (policy->max < policy->cur)
624 __cpufreq_driver_target(policy,
625 policy->max, CPUFREQ_RELATION_H);
626 else if (policy->min > policy->cur)
627 __cpufreq_driver_target(policy,
628 policy->min, CPUFREQ_RELATION_L);
629 break;
630 }
631 return 0;
632}
633
634static int cpufreq_interactive_idle_notifier(struct notifier_block *nb,
635 unsigned long val,
636 void *data)
637{
638 switch (val) {
639 case IDLE_START:
640 cpufreq_interactive_idle_start();
641 break;
642 case IDLE_END:
643 cpufreq_interactive_idle_end();
644 break;
645 }
646
647 return 0;
648}
649
650static struct notifier_block cpufreq_interactive_idle_nb = {
651 .notifier_call = cpufreq_interactive_idle_notifier,
652};
653
654static int __init cpufreq_interactive_init(void)
655{
656 unsigned int i;
657 struct cpufreq_interactive_cpuinfo *pcpu;
658 struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
659
660 go_hispeed_load = DEFAULT_GO_HISPEED_LOAD;
661 min_sample_time = DEFAULT_MIN_SAMPLE_TIME;
662 timer_rate = DEFAULT_TIMER_RATE;
663
664 /* Initalize per-cpu timers */
665 for_each_possible_cpu(i) {
666 pcpu = &per_cpu(cpuinfo, i);
667 init_timer(&pcpu->cpu_timer);
668 pcpu->cpu_timer.function = cpufreq_interactive_timer;
669 pcpu->cpu_timer.data = i;
670 }
671
672 up_task = kthread_create(cpufreq_interactive_up_task, NULL,
673 "kinteractiveup");
674 if (IS_ERR(up_task))
675 return PTR_ERR(up_task);
676
677 sched_setscheduler_nocheck(up_task, SCHED_FIFO, &param);
678 get_task_struct(up_task);
679
680 /* No rescuer thread, bind to CPU queuing the work for possibly
681 warm cache (probably doesn't matter much). */
682 down_wq = alloc_workqueue("knteractive_down", 0, 1);
683
684 if (!down_wq)
685 goto err_freeuptask;
686
687 INIT_WORK(&freq_scale_down_work,
688 cpufreq_interactive_freq_down);
689
690 spin_lock_init(&up_cpumask_lock);
691 spin_lock_init(&down_cpumask_lock);
692 mutex_init(&set_speed_lock);
693
694 idle_notifier_register(&cpufreq_interactive_idle_nb);
695
696 return cpufreq_register_governor(&cpufreq_gov_interactive);
697
698err_freeuptask:
699 put_task_struct(up_task);
700 return -ENOMEM;
701}
702
703#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
704fs_initcall(cpufreq_interactive_init);
705#else
706module_init(cpufreq_interactive_init);
707#endif
708
709static void __exit cpufreq_interactive_exit(void)
710{
711 cpufreq_unregister_governor(&cpufreq_gov_interactive);
712 kthread_stop(up_task);
713 put_task_struct(up_task);
714 destroy_workqueue(down_wq);
715}
716
717module_exit(cpufreq_interactive_exit);
718
719MODULE_AUTHOR("Mike Chan <mike@android.com>");
720MODULE_DESCRIPTION("'cpufreq_interactive' - A cpufreq governor for "
721 "Latency sensitive workloads");
722MODULE_LICENSE("GPL");