2 * drivers/cpufreq/cpufreq_interactive.c
4 * Copyright (C) 2010 Google, Inc.
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.
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.
15 * Author: Mike Chan (mike@android.com)
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>
36 #define CREATE_TRACE_POINTS
37 #include <trace/events/cpufreq_interactive.h>
39 static atomic_t active_count = ATOMIC_INIT(0);
41 struct cpufreq_interactive_cpuinfo {
42 struct timer_list cpu_timer;
44 spinlock_t load_lock; /* protects the next 4 fields */
46 u64 time_in_idle_timestamp;
48 u64 cputime_speedadj_timestamp;
49 struct cpufreq_policy *policy;
50 struct cpufreq_frequency_table *freq_table;
51 unsigned int target_freq;
52 unsigned int floor_freq;
53 u64 floor_validate_time;
54 u64 hispeed_validate_time;
58 static DEFINE_PER_CPU(struct cpufreq_interactive_cpuinfo, cpuinfo);
60 /* realtime thread handles frequency scaling */
61 static struct task_struct *speedchange_task;
62 static cpumask_t speedchange_cpumask;
63 static spinlock_t speedchange_cpumask_lock;
65 /* Hi speed to bump to from lo speed when load burst (default max) */
66 static unsigned int hispeed_freq;
68 /* Go to hi speed when CPU load at or above this value. */
69 #define DEFAULT_GO_HISPEED_LOAD 85
70 static unsigned long go_hispeed_load;
72 /* Target load. Lower values result in higher CPU speeds. */
73 #define DEFAULT_TARGET_LOAD 90
74 static unsigned int default_target_loads[] = {DEFAULT_TARGET_LOAD};
75 static spinlock_t target_loads_lock;
76 static unsigned int *target_loads = default_target_loads;
77 static int ntarget_loads = ARRAY_SIZE(default_target_loads);
80 * The minimum amount of time to spend at a frequency before we can ramp down.
82 #define DEFAULT_MIN_SAMPLE_TIME (80 * USEC_PER_MSEC)
83 static unsigned long min_sample_time;
86 * The sample rate of the timer used to increase frequency
88 #define DEFAULT_TIMER_RATE (20 * USEC_PER_MSEC)
89 static unsigned long timer_rate;
92 * Wait this long before raising speed above hispeed, by default a single
95 #define DEFAULT_ABOVE_HISPEED_DELAY DEFAULT_TIMER_RATE
96 static unsigned long above_hispeed_delay_val;
98 /* Non-zero means indefinite speed boost active */
100 /* Duration of a boot pulse in usecs */
101 static int boostpulse_duration_val = DEFAULT_MIN_SAMPLE_TIME;
102 /* End time of boost pulse in ktime converted to usecs */
103 static u64 boostpulse_endtime;
105 static bool governidle;
106 module_param(governidle, bool, S_IWUSR | S_IRUGO);
107 MODULE_PARM_DESC(governidle,
108 "Set to 1 to wake up CPUs from idle to reduce speed (default 0)");
110 static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
113 #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
116 struct cpufreq_governor cpufreq_gov_interactive = {
117 .name = "interactive",
118 .governor = cpufreq_governor_interactive,
119 .max_transition_latency = 10000000,
120 .owner = THIS_MODULE,
123 static void cpufreq_interactive_timer_resched(
124 struct cpufreq_interactive_cpuinfo *pcpu)
126 mod_timer_pinned(&pcpu->cpu_timer,
127 jiffies + usecs_to_jiffies(timer_rate));
128 spin_lock(&pcpu->load_lock);
130 get_cpu_idle_time_us(smp_processor_id(),
131 &pcpu->time_in_idle_timestamp);
132 pcpu->cputime_speedadj = 0;
133 pcpu->cputime_speedadj_timestamp = pcpu->time_in_idle_timestamp;
134 spin_unlock(&pcpu->load_lock);
137 static unsigned int freq_to_targetload(unsigned int freq)
142 spin_lock(&target_loads_lock);
144 for (i = 0; i < ntarget_loads - 1 && freq >= target_loads[i+1]; i += 2)
147 ret = target_loads[i];
148 spin_unlock(&target_loads_lock);
153 * If increasing frequencies never map to a lower target load then
154 * choose_freq() will find the minimum frequency that does not exceed its
155 * target load given the current load.
158 static unsigned int choose_freq(
159 struct cpufreq_interactive_cpuinfo *pcpu, unsigned int loadadjfreq)
161 unsigned int freq = pcpu->policy->cur;
162 unsigned int prevfreq, freqmin, freqmax;
171 tl = freq_to_targetload(freq);
174 * Find the lowest frequency where the computed load is less
175 * than or equal to the target load.
178 cpufreq_frequency_table_target(
179 pcpu->policy, pcpu->freq_table, loadadjfreq / tl,
180 CPUFREQ_RELATION_L, &index);
181 freq = pcpu->freq_table[index].frequency;
183 if (freq > prevfreq) {
184 /* The previous frequency is too low. */
187 if (freq >= freqmax) {
189 * Find the highest frequency that is less
192 cpufreq_frequency_table_target(
193 pcpu->policy, pcpu->freq_table,
194 freqmax - 1, CPUFREQ_RELATION_H,
196 freq = pcpu->freq_table[index].frequency;
198 if (freq == freqmin) {
200 * The first frequency below freqmax
201 * has already been found to be too
202 * low. freqmax is the lowest speed
203 * we found that is fast enough.
209 } else if (freq < prevfreq) {
210 /* The previous frequency is high enough. */
213 if (freq <= freqmin) {
215 * Find the lowest frequency that is higher
218 cpufreq_frequency_table_target(
219 pcpu->policy, pcpu->freq_table,
220 freqmin + 1, CPUFREQ_RELATION_L,
222 freq = pcpu->freq_table[index].frequency;
225 * If freqmax is the first frequency above
226 * freqmin then we have already found that
227 * this speed is fast enough.
234 /* If same frequency chosen as previous then done. */
235 } while (freq != prevfreq);
240 static u64 update_load(int cpu)
242 struct cpufreq_interactive_cpuinfo *pcpu = &per_cpu(cpuinfo, cpu);
245 unsigned int delta_idle;
246 unsigned int delta_time;
249 now_idle = get_cpu_idle_time_us(cpu, &now);
250 delta_idle = (unsigned int)(now_idle - pcpu->time_in_idle);
251 delta_time = (unsigned int)(now - pcpu->time_in_idle_timestamp);
252 active_time = delta_time - delta_idle;
253 pcpu->cputime_speedadj += active_time * pcpu->policy->cur;
255 pcpu->time_in_idle = now_idle;
256 pcpu->time_in_idle_timestamp = now;
260 static void cpufreq_interactive_timer(unsigned long data)
263 unsigned int delta_time;
264 u64 cputime_speedadj;
266 struct cpufreq_interactive_cpuinfo *pcpu =
267 &per_cpu(cpuinfo, data);
268 unsigned int new_freq;
269 unsigned int loadadjfreq;
276 if (!pcpu->governor_enabled)
279 spin_lock(&pcpu->load_lock);
280 now = update_load(data);
281 delta_time = (unsigned int)(now - pcpu->cputime_speedadj_timestamp);
282 cputime_speedadj = pcpu->cputime_speedadj;
283 spin_unlock(&pcpu->load_lock);
285 if (WARN_ON_ONCE(!delta_time))
288 do_div(cputime_speedadj, delta_time);
289 loadadjfreq = (unsigned int)cputime_speedadj * 100;
290 cpu_load = loadadjfreq / pcpu->target_freq;
291 boosted = boost_val || now < boostpulse_endtime;
293 if ((cpu_load >= go_hispeed_load || boosted) &&
294 pcpu->target_freq < hispeed_freq)
295 new_freq = hispeed_freq;
297 new_freq = choose_freq(pcpu, loadadjfreq);
299 if (pcpu->target_freq >= hispeed_freq &&
300 new_freq > pcpu->target_freq &&
301 now - pcpu->hispeed_validate_time < above_hispeed_delay_val) {
302 trace_cpufreq_interactive_notyet(
303 data, cpu_load, pcpu->target_freq,
304 pcpu->policy->cur, new_freq);
308 pcpu->hispeed_validate_time = now;
310 if (cpufreq_frequency_table_target(pcpu->policy, pcpu->freq_table,
311 new_freq, CPUFREQ_RELATION_L,
313 pr_warn_once("timer %d: cpufreq_frequency_table_target error\n",
318 new_freq = pcpu->freq_table[index].frequency;
321 * Do not scale below floor_freq unless we have been at or above the
322 * floor frequency for the minimum sample time since last validated.
324 if (new_freq < pcpu->floor_freq) {
325 if (now - pcpu->floor_validate_time < min_sample_time) {
326 trace_cpufreq_interactive_notyet(
327 data, cpu_load, pcpu->target_freq,
328 pcpu->policy->cur, new_freq);
334 * Update the timestamp for checking whether speed has been held at
335 * or above the selected frequency for a minimum of min_sample_time,
336 * if not boosted to hispeed_freq. If boosted to hispeed_freq then we
337 * allow the speed to drop as soon as the boostpulse duration expires
338 * (or the indefinite boost is turned off).
341 if (!boosted || new_freq > hispeed_freq) {
342 pcpu->floor_freq = new_freq;
343 pcpu->floor_validate_time = now;
346 if (pcpu->target_freq == new_freq) {
347 trace_cpufreq_interactive_already(
348 data, cpu_load, pcpu->target_freq,
349 pcpu->policy->cur, new_freq);
350 goto rearm_if_notmax;
353 trace_cpufreq_interactive_target(data, cpu_load, pcpu->target_freq,
354 pcpu->policy->cur, new_freq);
356 pcpu->target_freq = new_freq;
357 spin_lock_irqsave(&speedchange_cpumask_lock, flags);
358 cpumask_set_cpu(data, &speedchange_cpumask);
359 spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
360 wake_up_process(speedchange_task);
364 * Already set max speed and don't see a need to change that,
365 * wait until next idle to re-evaluate, don't need timer.
367 if (pcpu->target_freq == pcpu->policy->max)
371 if (!timer_pending(&pcpu->cpu_timer)) {
373 * If governing speed in idle and already at min, cancel the
374 * timer if that CPU goes idle. We don't need to re-evaluate
375 * speed until the next idle exit.
377 if (governidle && pcpu->target_freq == pcpu->policy->min)
378 pcpu->timer_idlecancel = 1;
380 cpufreq_interactive_timer_resched(pcpu);
387 static void cpufreq_interactive_idle_start(void)
389 struct cpufreq_interactive_cpuinfo *pcpu =
390 &per_cpu(cpuinfo, smp_processor_id());
393 if (!pcpu->governor_enabled)
396 pending = timer_pending(&pcpu->cpu_timer);
398 if (pcpu->target_freq != pcpu->policy->min) {
400 * Entering idle while not at lowest speed. On some
401 * platforms this can hold the other CPU(s) at that speed
402 * even though the CPU is idle. Set a timer to re-evaluate
403 * speed so this idle CPU doesn't hold the other CPUs above
404 * min indefinitely. This should probably be a quirk of
405 * the CPUFreq driver.
408 pcpu->timer_idlecancel = 0;
409 cpufreq_interactive_timer_resched(pcpu);
411 } else if (governidle) {
413 * If at min speed and entering idle after load has
414 * already been evaluated, and a timer has been set just in
415 * case the CPU suddenly goes busy, cancel that timer. The
416 * CPU didn't go busy; we'll recheck things upon idle exit.
418 if (pending && pcpu->timer_idlecancel) {
419 del_timer(&pcpu->cpu_timer);
420 pcpu->timer_idlecancel = 0;
426 static void cpufreq_interactive_idle_end(void)
428 struct cpufreq_interactive_cpuinfo *pcpu =
429 &per_cpu(cpuinfo, smp_processor_id());
431 if (!pcpu->governor_enabled)
434 /* Arm the timer for 1-2 ticks later if not already. */
435 if (!timer_pending(&pcpu->cpu_timer)) {
436 pcpu->timer_idlecancel = 0;
437 cpufreq_interactive_timer_resched(pcpu);
438 } else if (!governidle &&
439 time_after_eq(jiffies, pcpu->cpu_timer.expires)) {
440 del_timer(&pcpu->cpu_timer);
441 cpufreq_interactive_timer(smp_processor_id());
445 static int cpufreq_interactive_speedchange_task(void *data)
450 struct cpufreq_interactive_cpuinfo *pcpu;
453 set_current_state(TASK_INTERRUPTIBLE);
454 spin_lock_irqsave(&speedchange_cpumask_lock, flags);
456 if (cpumask_empty(&speedchange_cpumask)) {
457 spin_unlock_irqrestore(&speedchange_cpumask_lock,
461 if (kthread_should_stop())
464 spin_lock_irqsave(&speedchange_cpumask_lock, flags);
467 set_current_state(TASK_RUNNING);
468 tmp_mask = speedchange_cpumask;
469 cpumask_clear(&speedchange_cpumask);
470 spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
472 for_each_cpu(cpu, &tmp_mask) {
474 unsigned int max_freq = 0;
476 pcpu = &per_cpu(cpuinfo, cpu);
479 if (!pcpu->governor_enabled)
482 for_each_cpu(j, pcpu->policy->cpus) {
483 struct cpufreq_interactive_cpuinfo *pjcpu =
484 &per_cpu(cpuinfo, j);
486 if (pjcpu->target_freq > max_freq)
487 max_freq = pjcpu->target_freq;
490 if (max_freq != pcpu->policy->cur)
491 __cpufreq_driver_target(pcpu->policy,
494 trace_cpufreq_interactive_setspeed(cpu,
503 static void cpufreq_interactive_boost(void)
508 struct cpufreq_interactive_cpuinfo *pcpu;
510 spin_lock_irqsave(&speedchange_cpumask_lock, flags);
512 for_each_online_cpu(i) {
513 pcpu = &per_cpu(cpuinfo, i);
515 if (pcpu->target_freq < hispeed_freq) {
516 pcpu->target_freq = hispeed_freq;
517 cpumask_set_cpu(i, &speedchange_cpumask);
518 pcpu->hispeed_validate_time =
519 ktime_to_us(ktime_get());
524 * Set floor freq and (re)start timer for when last
528 pcpu->floor_freq = hispeed_freq;
529 pcpu->floor_validate_time = ktime_to_us(ktime_get());
532 spin_unlock_irqrestore(&speedchange_cpumask_lock, flags);
535 wake_up_process(speedchange_task);
538 static int cpufreq_interactive_notifier(
539 struct notifier_block *nb, unsigned long val, void *data)
541 struct cpufreq_freqs *freq = data;
542 struct cpufreq_interactive_cpuinfo *pcpu;
545 if (val == CPUFREQ_POSTCHANGE) {
546 pcpu = &per_cpu(cpuinfo, freq->cpu);
548 for_each_cpu(cpu, pcpu->policy->cpus) {
549 struct cpufreq_interactive_cpuinfo *pjcpu =
550 &per_cpu(cpuinfo, cpu);
551 spin_lock(&pjcpu->load_lock);
553 spin_unlock(&pjcpu->load_lock);
560 static struct notifier_block cpufreq_notifier_block = {
561 .notifier_call = cpufreq_interactive_notifier,
564 static ssize_t show_target_loads(
565 struct kobject *kobj, struct attribute *attr, char *buf)
570 spin_lock(&target_loads_lock);
572 for (i = 0; i < ntarget_loads; i++)
573 ret += sprintf(buf + ret, "%u%s", target_loads[i],
574 i & 0x1 ? ":" : " ");
576 ret += sprintf(buf + ret, "\n");
577 spin_unlock(&target_loads_lock);
581 static ssize_t store_target_loads(
582 struct kobject *kobj, struct attribute *attr, const char *buf,
587 unsigned int *new_target_loads = NULL;
592 while ((cp = strpbrk(cp + 1, " :")))
595 if (!(ntokens & 0x1))
598 new_target_loads = kmalloc(ntokens * sizeof(unsigned int), GFP_KERNEL);
599 if (!new_target_loads) {
606 while (i < ntokens) {
607 if (sscanf(cp, "%u", &new_target_loads[i++]) != 1)
610 cp = strpbrk(cp, " :");
619 spin_lock(&target_loads_lock);
620 if (target_loads != default_target_loads)
622 target_loads = new_target_loads;
623 ntarget_loads = ntokens;
624 spin_unlock(&target_loads_lock);
630 kfree(new_target_loads);
634 static struct global_attr target_loads_attr =
635 __ATTR(target_loads, S_IRUGO | S_IWUSR,
636 show_target_loads, store_target_loads);
638 static ssize_t show_hispeed_freq(struct kobject *kobj,
639 struct attribute *attr, char *buf)
641 return sprintf(buf, "%u\n", hispeed_freq);
644 static ssize_t store_hispeed_freq(struct kobject *kobj,
645 struct attribute *attr, const char *buf,
649 long unsigned int val;
651 ret = strict_strtoul(buf, 0, &val);
658 static struct global_attr hispeed_freq_attr = __ATTR(hispeed_freq, 0644,
659 show_hispeed_freq, store_hispeed_freq);
662 static ssize_t show_go_hispeed_load(struct kobject *kobj,
663 struct attribute *attr, char *buf)
665 return sprintf(buf, "%lu\n", go_hispeed_load);
668 static ssize_t store_go_hispeed_load(struct kobject *kobj,
669 struct attribute *attr, const char *buf, size_t count)
674 ret = strict_strtoul(buf, 0, &val);
677 go_hispeed_load = val;
681 static struct global_attr go_hispeed_load_attr = __ATTR(go_hispeed_load, 0644,
682 show_go_hispeed_load, store_go_hispeed_load);
684 static ssize_t show_min_sample_time(struct kobject *kobj,
685 struct attribute *attr, char *buf)
687 return sprintf(buf, "%lu\n", min_sample_time);
690 static ssize_t store_min_sample_time(struct kobject *kobj,
691 struct attribute *attr, const char *buf, size_t count)
696 ret = strict_strtoul(buf, 0, &val);
699 min_sample_time = val;
703 static struct global_attr min_sample_time_attr = __ATTR(min_sample_time, 0644,
704 show_min_sample_time, store_min_sample_time);
706 static ssize_t show_above_hispeed_delay(struct kobject *kobj,
707 struct attribute *attr, char *buf)
709 return sprintf(buf, "%lu\n", above_hispeed_delay_val);
712 static ssize_t store_above_hispeed_delay(struct kobject *kobj,
713 struct attribute *attr,
714 const char *buf, size_t count)
719 ret = strict_strtoul(buf, 0, &val);
722 above_hispeed_delay_val = val;
726 define_one_global_rw(above_hispeed_delay);
728 static ssize_t show_timer_rate(struct kobject *kobj,
729 struct attribute *attr, char *buf)
731 return sprintf(buf, "%lu\n", timer_rate);
734 static ssize_t store_timer_rate(struct kobject *kobj,
735 struct attribute *attr, const char *buf, size_t count)
740 ret = strict_strtoul(buf, 0, &val);
747 static struct global_attr timer_rate_attr = __ATTR(timer_rate, 0644,
748 show_timer_rate, store_timer_rate);
750 static ssize_t show_boost(struct kobject *kobj, struct attribute *attr,
753 return sprintf(buf, "%d\n", boost_val);
756 static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
757 const char *buf, size_t count)
762 ret = kstrtoul(buf, 0, &val);
769 trace_cpufreq_interactive_boost("on");
770 cpufreq_interactive_boost();
772 trace_cpufreq_interactive_unboost("off");
778 define_one_global_rw(boost);
780 static ssize_t store_boostpulse(struct kobject *kobj, struct attribute *attr,
781 const char *buf, size_t count)
786 ret = kstrtoul(buf, 0, &val);
790 boostpulse_endtime = ktime_to_us(ktime_get()) + boostpulse_duration_val;
791 trace_cpufreq_interactive_boost("pulse");
792 cpufreq_interactive_boost();
796 static struct global_attr boostpulse =
797 __ATTR(boostpulse, 0200, NULL, store_boostpulse);
799 static ssize_t show_boostpulse_duration(
800 struct kobject *kobj, struct attribute *attr, char *buf)
802 return sprintf(buf, "%d\n", boostpulse_duration_val);
805 static ssize_t store_boostpulse_duration(
806 struct kobject *kobj, struct attribute *attr, const char *buf,
812 ret = kstrtoul(buf, 0, &val);
816 boostpulse_duration_val = val;
820 define_one_global_rw(boostpulse_duration);
822 static struct attribute *interactive_attributes[] = {
823 &target_loads_attr.attr,
824 &hispeed_freq_attr.attr,
825 &go_hispeed_load_attr.attr,
826 &above_hispeed_delay.attr,
827 &min_sample_time_attr.attr,
828 &timer_rate_attr.attr,
831 &boostpulse_duration.attr,
835 static struct attribute_group interactive_attr_group = {
836 .attrs = interactive_attributes,
837 .name = "interactive",
840 static int cpufreq_interactive_idle_notifier(struct notifier_block *nb,
846 cpufreq_interactive_idle_start();
849 cpufreq_interactive_idle_end();
856 static struct notifier_block cpufreq_interactive_idle_nb = {
857 .notifier_call = cpufreq_interactive_idle_notifier,
860 static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
865 struct cpufreq_interactive_cpuinfo *pcpu;
866 struct cpufreq_frequency_table *freq_table;
869 case CPUFREQ_GOV_START:
870 if (!cpu_online(policy->cpu))
874 cpufreq_frequency_get_table(policy->cpu);
876 hispeed_freq = policy->max;
878 for_each_cpu(j, policy->cpus) {
879 pcpu = &per_cpu(cpuinfo, j);
880 pcpu->policy = policy;
881 pcpu->target_freq = policy->cur;
882 pcpu->freq_table = freq_table;
883 pcpu->floor_freq = pcpu->target_freq;
884 pcpu->floor_validate_time =
885 ktime_to_us(ktime_get());
886 pcpu->hispeed_validate_time =
887 pcpu->floor_validate_time;
888 pcpu->governor_enabled = 1;
890 pcpu->cpu_timer.expires =
891 jiffies + usecs_to_jiffies(timer_rate);
892 add_timer_on(&pcpu->cpu_timer, j);
896 * Do not register the idle hook and create sysfs
897 * entries if we have already done so.
899 if (atomic_inc_return(&active_count) > 1)
902 rc = sysfs_create_group(cpufreq_global_kobject,
903 &interactive_attr_group);
907 idle_notifier_register(&cpufreq_interactive_idle_nb);
908 cpufreq_register_notifier(
909 &cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
912 case CPUFREQ_GOV_STOP:
913 for_each_cpu(j, policy->cpus) {
914 pcpu = &per_cpu(cpuinfo, j);
915 pcpu->governor_enabled = 0;
917 del_timer_sync(&pcpu->cpu_timer);
920 if (atomic_dec_return(&active_count) > 0)
923 cpufreq_unregister_notifier(
924 &cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
925 idle_notifier_unregister(&cpufreq_interactive_idle_nb);
926 sysfs_remove_group(cpufreq_global_kobject,
927 &interactive_attr_group);
931 case CPUFREQ_GOV_LIMITS:
932 if (policy->max < policy->cur)
933 __cpufreq_driver_target(policy,
934 policy->max, CPUFREQ_RELATION_H);
935 else if (policy->min > policy->cur)
936 __cpufreq_driver_target(policy,
937 policy->min, CPUFREQ_RELATION_L);
943 static int __init cpufreq_interactive_init(void)
946 struct cpufreq_interactive_cpuinfo *pcpu;
947 struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
949 go_hispeed_load = DEFAULT_GO_HISPEED_LOAD;
950 min_sample_time = DEFAULT_MIN_SAMPLE_TIME;
951 above_hispeed_delay_val = DEFAULT_ABOVE_HISPEED_DELAY;
952 timer_rate = DEFAULT_TIMER_RATE;
954 /* Initalize per-cpu timers */
955 for_each_possible_cpu(i) {
956 pcpu = &per_cpu(cpuinfo, i);
958 init_timer(&pcpu->cpu_timer);
960 init_timer_deferrable(&pcpu->cpu_timer);
961 pcpu->cpu_timer.function = cpufreq_interactive_timer;
962 pcpu->cpu_timer.data = i;
963 spin_lock_init(&pcpu->load_lock);
966 spin_lock_init(&target_loads_lock);
967 spin_lock_init(&speedchange_cpumask_lock);
969 kthread_create(cpufreq_interactive_speedchange_task, NULL,
971 if (IS_ERR(speedchange_task))
972 return PTR_ERR(speedchange_task);
974 sched_setscheduler_nocheck(speedchange_task, SCHED_FIFO, ¶m);
975 get_task_struct(speedchange_task);
977 /* NB: wake up so the thread does not look hung to the freezer */
978 wake_up_process(speedchange_task);
980 return cpufreq_register_governor(&cpufreq_gov_interactive);
983 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE
984 fs_initcall(cpufreq_interactive_init);
986 module_init(cpufreq_interactive_init);
989 static void __exit cpufreq_interactive_exit(void)
991 cpufreq_unregister_governor(&cpufreq_gov_interactive);
992 kthread_stop(speedchange_task);
993 put_task_struct(speedchange_task);
996 module_exit(cpufreq_interactive_exit);
998 MODULE_AUTHOR("Mike Chan <mike@android.com>");
999 MODULE_DESCRIPTION("'cpufreq_interactive' - A cpufreq governor for "
1000 "Latency sensitive workloads");
1001 MODULE_LICENSE("GPL");