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