cpufreq: interactive: kick timer on idle exit past expiry
[firefly-linux-kernel-4.4.55.git] / drivers / cpufreq / cpufreq_interactive.c
1 /*
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/moduleparam.h>
24 #include <linux/mutex.h>
25 #include <linux/sched.h>
26 #include <linux/sched/rt.h>
27 #include <linux/tick.h>
28 #include <linux/time.h>
29 #include <linux/timer.h>
30 #include <linux/workqueue.h>
31 #include <linux/kthread.h>
32 #include <linux/mutex.h>
33 #include <linux/slab.h>
34 #include <asm/cputime.h>
35
36 #define CREATE_TRACE_POINTS
37 #include <trace/events/cpufreq_interactive.h>
38
39 static atomic_t active_count = ATOMIC_INIT(0);
40
41 struct cpufreq_interactive_cpuinfo {
42         struct timer_list cpu_timer;
43         int timer_idlecancel;
44         u64 time_in_idle;
45         u64 time_in_idle_timestamp;
46         u64 target_set_time;
47         u64 target_set_time_in_idle;
48         struct cpufreq_policy *policy;
49         struct cpufreq_frequency_table *freq_table;
50         unsigned int target_freq;
51         unsigned int floor_freq;
52         u64 floor_validate_time;
53         u64 hispeed_validate_time;
54         int governor_enabled;
55 };
56
57 static DEFINE_PER_CPU(struct cpufreq_interactive_cpuinfo, cpuinfo);
58
59 /* realtime thread handles frequency scaling */
60 static struct task_struct *speedchange_task;
61 static cpumask_t speedchange_cpumask;
62 static spinlock_t speedchange_cpumask_lock;
63
64 /* Hi speed to bump to from lo speed when load burst (default max) */
65 static unsigned int hispeed_freq;
66
67 /* Go to hi speed when CPU load at or above this value. */
68 #define DEFAULT_GO_HISPEED_LOAD 85
69 static unsigned long go_hispeed_load;
70
71 /*
72  * The minimum amount of time to spend at a frequency before we can ramp down.
73  */
74 #define DEFAULT_MIN_SAMPLE_TIME (80 * USEC_PER_MSEC)
75 static unsigned long min_sample_time;
76
77 /*
78  * The sample rate of the timer used to increase frequency
79  */
80 #define DEFAULT_TIMER_RATE (20 * USEC_PER_MSEC)
81 static unsigned long timer_rate;
82
83 /*
84  * Wait this long before raising speed above hispeed, by default a single
85  * timer interval.
86  */
87 #define DEFAULT_ABOVE_HISPEED_DELAY DEFAULT_TIMER_RATE
88 static unsigned long above_hispeed_delay_val;
89
90 /*
91  * Non-zero means longer-term speed boost active.
92  */
93
94 static int boost_val;
95
96 static bool governidle;
97 module_param(governidle, bool, S_IWUSR | S_IRUGO);
98 MODULE_PARM_DESC(governidle,
99         "Set to 1 to wake up CPUs from idle to reduce speed (default 0)");
100
101 static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
102                 unsigned int event);
103
104 #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
105 static
106 #endif
107 struct cpufreq_governor cpufreq_gov_interactive = {
108         .name = "interactive",
109         .governor = cpufreq_governor_interactive,
110         .max_transition_latency = 10000000,
111         .owner = THIS_MODULE,
112 };
113
114 static void cpufreq_interactive_timer_resched(
115         struct cpufreq_interactive_cpuinfo *pcpu)
116 {
117         mod_timer_pinned(&pcpu->cpu_timer,
118                          jiffies + usecs_to_jiffies(timer_rate));
119         pcpu->time_in_idle =
120                 get_cpu_idle_time_us(smp_processor_id(),
121                                      &pcpu->time_in_idle_timestamp);
122 }
123
124 static void cpufreq_interactive_timer(unsigned long data)
125 {
126         u64 now;
127         unsigned int delta_idle;
128         unsigned int delta_time;
129         int cpu_load;
130         int load_since_change;
131         struct cpufreq_interactive_cpuinfo *pcpu =
132                 &per_cpu(cpuinfo, data);
133         u64 now_idle;
134         unsigned int new_freq;
135         unsigned int index;
136         unsigned long flags;
137
138         smp_rmb();
139
140         if (!pcpu->governor_enabled)
141                 goto exit;
142
143         now_idle = get_cpu_idle_time_us(data, &now);
144         delta_idle = (unsigned int)(now_idle - pcpu->time_in_idle);
145         delta_time = (unsigned int)(now - pcpu->time_in_idle_timestamp);
146
147         /*
148          * If timer ran less than 1ms after short-term sample started, retry.
149          */
150         if (delta_time < 1000)
151                 goto rearm;
152
153         if (delta_idle > delta_time)
154                 cpu_load = 0;
155         else
156                 cpu_load = 100 * (delta_time - delta_idle) / delta_time;
157
158         delta_idle = (unsigned int)(now_idle - pcpu->target_set_time_in_idle);
159         delta_time = (unsigned int)(now - pcpu->target_set_time);
160
161         if ((delta_time == 0) || (delta_idle > delta_time))
162                 load_since_change = 0;
163         else
164                 load_since_change =
165                         100 * (delta_time - delta_idle) / delta_time;
166
167         /*
168          * Choose greater of short-term load (since last idle timer
169          * started or timer function re-armed itself) or long-term load
170          * (since last frequency change).
171          */
172         if (load_since_change > cpu_load)
173                 cpu_load = load_since_change;
174
175         if (cpu_load >= go_hispeed_load || boost_val) {
176                 if (pcpu->target_freq < hispeed_freq &&
177                     hispeed_freq < pcpu->policy->max) {
178                         new_freq = hispeed_freq;
179                 } else {
180                         new_freq = pcpu->policy->max * cpu_load / 100;
181
182                         if (new_freq < hispeed_freq)
183                                 new_freq = hispeed_freq;
184
185                         if (pcpu->target_freq == hispeed_freq &&
186                             new_freq > hispeed_freq &&
187                             now - pcpu->hispeed_validate_time
188                             < above_hispeed_delay_val) {
189                                 trace_cpufreq_interactive_notyet(data, cpu_load,
190                                                                  pcpu->target_freq,
191                                                                  new_freq);
192                                 goto rearm;
193                         }
194                 }
195         } else {
196                 new_freq = hispeed_freq * cpu_load / 100;
197         }
198
199         if (new_freq <= hispeed_freq)
200                 pcpu->hispeed_validate_time = now;
201
202         if (cpufreq_frequency_table_target(pcpu->policy, pcpu->freq_table,
203                                            new_freq, CPUFREQ_RELATION_H,
204                                            &index)) {
205                 pr_warn_once("timer %d: cpufreq_frequency_table_target error\n",
206                              (int) data);
207                 goto rearm;
208         }
209
210         new_freq = pcpu->freq_table[index].frequency;
211
212         /*
213          * Do not scale below floor_freq unless we have been at or above the
214          * floor frequency for the minimum sample time since last validated.
215          */
216         if (new_freq < pcpu->floor_freq) {
217                 if (now - pcpu->floor_validate_time < min_sample_time) {
218                         trace_cpufreq_interactive_notyet(data, cpu_load,
219                                          pcpu->target_freq, new_freq);
220                         goto rearm;
221                 }
222         }
223
224         pcpu->floor_freq = new_freq;
225         pcpu->floor_validate_time = now;
226
227         if (pcpu->target_freq == new_freq) {
228                 trace_cpufreq_interactive_already(data, cpu_load,
229                                                   pcpu->target_freq, new_freq);
230                 goto rearm_if_notmax;
231         }
232
233         trace_cpufreq_interactive_target(data, cpu_load, pcpu->target_freq,
234                                          new_freq);
235         pcpu->target_set_time_in_idle = now_idle;
236         pcpu->target_set_time = now;
237
238         pcpu->target_freq = new_freq;
239         spin_lock_irqsave(&speedchange_cpumask_lock, flags);
240         cpumask_set_cpu(data, &speedchange_cpumask);
241         spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
242         wake_up_process(speedchange_task);
243
244 rearm_if_notmax:
245         /*
246          * Already set max speed and don't see a need to change that,
247          * wait until next idle to re-evaluate, don't need timer.
248          */
249         if (pcpu->target_freq == pcpu->policy->max)
250                 goto exit;
251
252 rearm:
253         if (!timer_pending(&pcpu->cpu_timer)) {
254                 /*
255                  * If governing speed in idle and already at min, cancel the
256                  * timer if that CPU goes idle.  We don't need to re-evaluate
257                  * speed until the next idle exit.
258                  */
259                 if (governidle && pcpu->target_freq == pcpu->policy->min)
260                         pcpu->timer_idlecancel = 1;
261
262                 cpufreq_interactive_timer_resched(pcpu);
263         }
264
265 exit:
266         return;
267 }
268
269 static void cpufreq_interactive_idle_start(void)
270 {
271         struct cpufreq_interactive_cpuinfo *pcpu =
272                 &per_cpu(cpuinfo, smp_processor_id());
273         int pending;
274
275         if (!pcpu->governor_enabled)
276                 return;
277
278         pending = timer_pending(&pcpu->cpu_timer);
279
280         if (pcpu->target_freq != pcpu->policy->min) {
281                 /*
282                  * Entering idle while not at lowest speed.  On some
283                  * platforms this can hold the other CPU(s) at that speed
284                  * even though the CPU is idle. Set a timer to re-evaluate
285                  * speed so this idle CPU doesn't hold the other CPUs above
286                  * min indefinitely.  This should probably be a quirk of
287                  * the CPUFreq driver.
288                  */
289                 if (!pending) {
290                         pcpu->timer_idlecancel = 0;
291                         cpufreq_interactive_timer_resched(pcpu);
292                 }
293         } else if (governidle) {
294                 /*
295                  * If at min speed and entering idle after load has
296                  * already been evaluated, and a timer has been set just in
297                  * case the CPU suddenly goes busy, cancel that timer.  The
298                  * CPU didn't go busy; we'll recheck things upon idle exit.
299                  */
300                 if (pending && pcpu->timer_idlecancel) {
301                         del_timer(&pcpu->cpu_timer);
302                         pcpu->timer_idlecancel = 0;
303                 }
304         }
305
306 }
307
308 static void cpufreq_interactive_idle_end(void)
309 {
310         struct cpufreq_interactive_cpuinfo *pcpu =
311                 &per_cpu(cpuinfo, smp_processor_id());
312
313         if (!pcpu->governor_enabled)
314                 return;
315
316         /* Arm the timer for 1-2 ticks later if not already. */
317         if (!timer_pending(&pcpu->cpu_timer)) {
318                 pcpu->timer_idlecancel = 0;
319                 cpufreq_interactive_timer_resched(pcpu);
320         } else if (!governidle &&
321                    time_after_eq(jiffies, pcpu->cpu_timer.expires)) {
322                 del_timer(&pcpu->cpu_timer);
323                 cpufreq_interactive_timer(smp_processor_id());
324         }
325 }
326
327 static int cpufreq_interactive_speedchange_task(void *data)
328 {
329         unsigned int cpu;
330         cpumask_t tmp_mask;
331         unsigned long flags;
332         struct cpufreq_interactive_cpuinfo *pcpu;
333
334         while (1) {
335                 set_current_state(TASK_INTERRUPTIBLE);
336                 spin_lock_irqsave(&speedchange_cpumask_lock, flags);
337
338                 if (cpumask_empty(&speedchange_cpumask)) {
339                         spin_unlock_irqrestore(&speedchange_cpumask_lock,
340                                                flags);
341                         schedule();
342
343                         if (kthread_should_stop())
344                                 break;
345
346                         spin_lock_irqsave(&speedchange_cpumask_lock, flags);
347                 }
348
349                 set_current_state(TASK_RUNNING);
350                 tmp_mask = speedchange_cpumask;
351                 cpumask_clear(&speedchange_cpumask);
352                 spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
353
354                 for_each_cpu(cpu, &tmp_mask) {
355                         unsigned int j;
356                         unsigned int max_freq = 0;
357
358                         pcpu = &per_cpu(cpuinfo, cpu);
359                         smp_rmb();
360
361                         if (!pcpu->governor_enabled)
362                                 continue;
363
364                         for_each_cpu(j, pcpu->policy->cpus) {
365                                 struct cpufreq_interactive_cpuinfo *pjcpu =
366                                         &per_cpu(cpuinfo, j);
367
368                                 if (pjcpu->target_freq > max_freq)
369                                         max_freq = pjcpu->target_freq;
370                         }
371
372                         if (max_freq != pcpu->policy->cur)
373                                 __cpufreq_driver_target(pcpu->policy,
374                                                         max_freq,
375                                                         CPUFREQ_RELATION_H);
376                         trace_cpufreq_interactive_setspeed(cpu,
377                                                      pcpu->target_freq,
378                                                      pcpu->policy->cur);
379                 }
380         }
381
382         return 0;
383 }
384
385 static void cpufreq_interactive_boost(void)
386 {
387         int i;
388         int anyboost = 0;
389         unsigned long flags;
390         struct cpufreq_interactive_cpuinfo *pcpu;
391
392         spin_lock_irqsave(&speedchange_cpumask_lock, flags);
393
394         for_each_online_cpu(i) {
395                 pcpu = &per_cpu(cpuinfo, i);
396
397                 if (pcpu->target_freq < hispeed_freq) {
398                         pcpu->target_freq = hispeed_freq;
399                         cpumask_set_cpu(i, &speedchange_cpumask);
400                         pcpu->target_set_time_in_idle =
401                                 get_cpu_idle_time_us(i, &pcpu->target_set_time);
402                         pcpu->hispeed_validate_time = pcpu->target_set_time;
403                         anyboost = 1;
404                 }
405
406                 /*
407                  * Set floor freq and (re)start timer for when last
408                  * validated.
409                  */
410
411                 pcpu->floor_freq = hispeed_freq;
412                 pcpu->floor_validate_time = ktime_to_us(ktime_get());
413         }
414
415         spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
416
417         if (anyboost)
418                 wake_up_process(speedchange_task);
419 }
420
421 static ssize_t show_hispeed_freq(struct kobject *kobj,
422                                  struct attribute *attr, char *buf)
423 {
424         return sprintf(buf, "%u\n", hispeed_freq);
425 }
426
427 static ssize_t store_hispeed_freq(struct kobject *kobj,
428                                   struct attribute *attr, const char *buf,
429                                   size_t count)
430 {
431         int ret;
432         long unsigned int val;
433
434         ret = strict_strtoul(buf, 0, &val);
435         if (ret < 0)
436                 return ret;
437         hispeed_freq = val;
438         return count;
439 }
440
441 static struct global_attr hispeed_freq_attr = __ATTR(hispeed_freq, 0644,
442                 show_hispeed_freq, store_hispeed_freq);
443
444
445 static ssize_t show_go_hispeed_load(struct kobject *kobj,
446                                      struct attribute *attr, char *buf)
447 {
448         return sprintf(buf, "%lu\n", go_hispeed_load);
449 }
450
451 static ssize_t store_go_hispeed_load(struct kobject *kobj,
452                         struct attribute *attr, const char *buf, size_t count)
453 {
454         int ret;
455         unsigned long val;
456
457         ret = strict_strtoul(buf, 0, &val);
458         if (ret < 0)
459                 return ret;
460         go_hispeed_load = val;
461         return count;
462 }
463
464 static struct global_attr go_hispeed_load_attr = __ATTR(go_hispeed_load, 0644,
465                 show_go_hispeed_load, store_go_hispeed_load);
466
467 static ssize_t show_min_sample_time(struct kobject *kobj,
468                                 struct attribute *attr, char *buf)
469 {
470         return sprintf(buf, "%lu\n", min_sample_time);
471 }
472
473 static ssize_t store_min_sample_time(struct kobject *kobj,
474                         struct attribute *attr, const char *buf, size_t count)
475 {
476         int ret;
477         unsigned long val;
478
479         ret = strict_strtoul(buf, 0, &val);
480         if (ret < 0)
481                 return ret;
482         min_sample_time = val;
483         return count;
484 }
485
486 static struct global_attr min_sample_time_attr = __ATTR(min_sample_time, 0644,
487                 show_min_sample_time, store_min_sample_time);
488
489 static ssize_t show_above_hispeed_delay(struct kobject *kobj,
490                                         struct attribute *attr, char *buf)
491 {
492         return sprintf(buf, "%lu\n", above_hispeed_delay_val);
493 }
494
495 static ssize_t store_above_hispeed_delay(struct kobject *kobj,
496                                          struct attribute *attr,
497                                          const char *buf, size_t count)
498 {
499         int ret;
500         unsigned long val;
501
502         ret = strict_strtoul(buf, 0, &val);
503         if (ret < 0)
504                 return ret;
505         above_hispeed_delay_val = val;
506         return count;
507 }
508
509 define_one_global_rw(above_hispeed_delay);
510
511 static ssize_t show_timer_rate(struct kobject *kobj,
512                         struct attribute *attr, char *buf)
513 {
514         return sprintf(buf, "%lu\n", timer_rate);
515 }
516
517 static ssize_t store_timer_rate(struct kobject *kobj,
518                         struct attribute *attr, const char *buf, size_t count)
519 {
520         int ret;
521         unsigned long val;
522
523         ret = strict_strtoul(buf, 0, &val);
524         if (ret < 0)
525                 return ret;
526         timer_rate = val;
527         return count;
528 }
529
530 static struct global_attr timer_rate_attr = __ATTR(timer_rate, 0644,
531                 show_timer_rate, store_timer_rate);
532
533 static ssize_t show_boost(struct kobject *kobj, struct attribute *attr,
534                           char *buf)
535 {
536         return sprintf(buf, "%d\n", boost_val);
537 }
538
539 static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
540                            const char *buf, size_t count)
541 {
542         int ret;
543         unsigned long val;
544
545         ret = kstrtoul(buf, 0, &val);
546         if (ret < 0)
547                 return ret;
548
549         boost_val = val;
550
551         if (boost_val) {
552                 trace_cpufreq_interactive_boost("on");
553                 cpufreq_interactive_boost();
554         } else {
555                 trace_cpufreq_interactive_unboost("off");
556         }
557
558         return count;
559 }
560
561 define_one_global_rw(boost);
562
563 static ssize_t store_boostpulse(struct kobject *kobj, struct attribute *attr,
564                                 const char *buf, size_t count)
565 {
566         int ret;
567         unsigned long val;
568
569         ret = kstrtoul(buf, 0, &val);
570         if (ret < 0)
571                 return ret;
572
573         trace_cpufreq_interactive_boost("pulse");
574         cpufreq_interactive_boost();
575         return count;
576 }
577
578 static struct global_attr boostpulse =
579         __ATTR(boostpulse, 0200, NULL, store_boostpulse);
580
581 static struct attribute *interactive_attributes[] = {
582         &hispeed_freq_attr.attr,
583         &go_hispeed_load_attr.attr,
584         &above_hispeed_delay.attr,
585         &min_sample_time_attr.attr,
586         &timer_rate_attr.attr,
587         &boost.attr,
588         &boostpulse.attr,
589         NULL,
590 };
591
592 static struct attribute_group interactive_attr_group = {
593         .attrs = interactive_attributes,
594         .name = "interactive",
595 };
596
597 static int cpufreq_interactive_idle_notifier(struct notifier_block *nb,
598                                              unsigned long val,
599                                              void *data)
600 {
601         switch (val) {
602         case IDLE_START:
603                 cpufreq_interactive_idle_start();
604                 break;
605         case IDLE_END:
606                 cpufreq_interactive_idle_end();
607                 break;
608         }
609
610         return 0;
611 }
612
613 static struct notifier_block cpufreq_interactive_idle_nb = {
614         .notifier_call = cpufreq_interactive_idle_notifier,
615 };
616
617 static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
618                 unsigned int event)
619 {
620         int rc;
621         unsigned int j;
622         struct cpufreq_interactive_cpuinfo *pcpu;
623         struct cpufreq_frequency_table *freq_table;
624
625         switch (event) {
626         case CPUFREQ_GOV_START:
627                 if (!cpu_online(policy->cpu))
628                         return -EINVAL;
629
630                 freq_table =
631                         cpufreq_frequency_get_table(policy->cpu);
632                 if (!hispeed_freq)
633                         hispeed_freq = policy->max;
634
635                 for_each_cpu(j, policy->cpus) {
636                         pcpu = &per_cpu(cpuinfo, j);
637                         pcpu->policy = policy;
638                         pcpu->target_freq = policy->cur;
639                         pcpu->freq_table = freq_table;
640                         pcpu->target_set_time_in_idle =
641                                 get_cpu_idle_time_us(j,
642                                              &pcpu->target_set_time);
643                         pcpu->floor_freq = pcpu->target_freq;
644                         pcpu->floor_validate_time =
645                                 pcpu->target_set_time;
646                         pcpu->hispeed_validate_time =
647                                 pcpu->target_set_time;
648                         pcpu->governor_enabled = 1;
649                         smp_wmb();
650                         pcpu->cpu_timer.expires =
651                                 jiffies + usecs_to_jiffies(timer_rate);
652                         add_timer_on(&pcpu->cpu_timer, j);
653                 }
654
655                 /*
656                  * Do not register the idle hook and create sysfs
657                  * entries if we have already done so.
658                  */
659                 if (atomic_inc_return(&active_count) > 1)
660                         return 0;
661
662                 rc = sysfs_create_group(cpufreq_global_kobject,
663                                 &interactive_attr_group);
664                 if (rc)
665                         return rc;
666
667                 idle_notifier_register(&cpufreq_interactive_idle_nb);
668                 break;
669
670         case CPUFREQ_GOV_STOP:
671                 for_each_cpu(j, policy->cpus) {
672                         pcpu = &per_cpu(cpuinfo, j);
673                         pcpu->governor_enabled = 0;
674                         smp_wmb();
675                         del_timer_sync(&pcpu->cpu_timer);
676                 }
677
678                 if (atomic_dec_return(&active_count) > 0)
679                         return 0;
680
681                 idle_notifier_unregister(&cpufreq_interactive_idle_nb);
682                 sysfs_remove_group(cpufreq_global_kobject,
683                                 &interactive_attr_group);
684
685                 break;
686
687         case CPUFREQ_GOV_LIMITS:
688                 if (policy->max < policy->cur)
689                         __cpufreq_driver_target(policy,
690                                         policy->max, CPUFREQ_RELATION_H);
691                 else if (policy->min > policy->cur)
692                         __cpufreq_driver_target(policy,
693                                         policy->min, CPUFREQ_RELATION_L);
694                 break;
695         }
696         return 0;
697 }
698
699 static int __init cpufreq_interactive_init(void)
700 {
701         unsigned int i;
702         struct cpufreq_interactive_cpuinfo *pcpu;
703         struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
704
705         go_hispeed_load = DEFAULT_GO_HISPEED_LOAD;
706         min_sample_time = DEFAULT_MIN_SAMPLE_TIME;
707         above_hispeed_delay_val = DEFAULT_ABOVE_HISPEED_DELAY;
708         timer_rate = DEFAULT_TIMER_RATE;
709
710         /* Initalize per-cpu timers */
711         for_each_possible_cpu(i) {
712                 pcpu = &per_cpu(cpuinfo, i);
713                 if (governidle)
714                         init_timer(&pcpu->cpu_timer);
715                 else
716                         init_timer_deferrable(&pcpu->cpu_timer);
717                 pcpu->cpu_timer.function = cpufreq_interactive_timer;
718                 pcpu->cpu_timer.data = i;
719         }
720
721         spin_lock_init(&speedchange_cpumask_lock);
722         speedchange_task =
723                 kthread_create(cpufreq_interactive_speedchange_task, NULL,
724                                "cfinteractive");
725         if (IS_ERR(speedchange_task))
726                 return PTR_ERR(speedchange_task);
727
728         sched_setscheduler_nocheck(speedchange_task, SCHED_FIFO, &param);
729         get_task_struct(speedchange_task);
730
731         /* NB: wake up so the thread does not look hung to the freezer */
732         wake_up_process(speedchange_task);
733
734         return cpufreq_register_governor(&cpufreq_gov_interactive);
735 }
736
737 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
738 fs_initcall(cpufreq_interactive_init);
739 #else
740 module_init(cpufreq_interactive_init);
741 #endif
742
743 static void __exit cpufreq_interactive_exit(void)
744 {
745         cpufreq_unregister_governor(&cpufreq_gov_interactive);
746         kthread_stop(speedchange_task);
747         put_task_struct(speedchange_task);
748 }
749
750 module_exit(cpufreq_interactive_exit);
751
752 MODULE_AUTHOR("Mike Chan <mike@android.com>");
753 MODULE_DESCRIPTION("'cpufreq_interactive' - A cpufreq governor for "
754         "Latency sensitive workloads");
755 MODULE_LICENSE("GPL");