]>
Commit | Line | Data |
---|---|---|
4f86d3a8 LB |
1 | /* |
2 | * cpuidle.c - core cpuidle infrastructure | |
3 | * | |
4 | * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> | |
5 | * Shaohua Li <shaohua.li@intel.com> | |
6 | * Adam Belay <abelay@novell.com> | |
7 | * | |
8 | * This code is licenced under the GPL. | |
9 | */ | |
10 | ||
b60e6a0e | 11 | #include <linux/clockchips.h> |
4f86d3a8 LB |
12 | #include <linux/kernel.h> |
13 | #include <linux/mutex.h> | |
14 | #include <linux/sched.h> | |
15 | #include <linux/notifier.h> | |
e8db0be1 | 16 | #include <linux/pm_qos.h> |
4f86d3a8 LB |
17 | #include <linux/cpu.h> |
18 | #include <linux/cpuidle.h> | |
9a0b8415 | 19 | #include <linux/ktime.h> |
2e94d1f7 | 20 | #include <linux/hrtimer.h> |
884b17e1 | 21 | #include <linux/module.h> |
288f023e | 22 | #include <trace/events/power.h> |
4f86d3a8 LB |
23 | |
24 | #include "cpuidle.h" | |
25 | ||
26 | DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices); | |
4c637b21 | 27 | DEFINE_PER_CPU(struct cpuidle_device, cpuidle_dev); |
4f86d3a8 LB |
28 | |
29 | DEFINE_MUTEX(cpuidle_lock); | |
30 | LIST_HEAD(cpuidle_detected_devices); | |
4f86d3a8 LB |
31 | |
32 | static int enabled_devices; | |
62027aea | 33 | static int off __read_mostly; |
a0bfa137 | 34 | static int initialized __read_mostly; |
62027aea LB |
35 | |
36 | int cpuidle_disabled(void) | |
37 | { | |
38 | return off; | |
39 | } | |
d91ee586 LB |
40 | void disable_cpuidle(void) |
41 | { | |
42 | off = 1; | |
43 | } | |
4f86d3a8 | 44 | |
1a022e3f BO |
45 | /** |
46 | * cpuidle_play_dead - cpu off-lining | |
47 | * | |
ee01e663 | 48 | * Returns in case of an error or no driver |
1a022e3f BO |
49 | */ |
50 | int cpuidle_play_dead(void) | |
51 | { | |
52 | struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); | |
bf4d1b5d | 53 | struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); |
8aef33a7 | 54 | int i; |
1a022e3f | 55 | |
ee01e663 TK |
56 | if (!drv) |
57 | return -ENODEV; | |
58 | ||
1a022e3f | 59 | /* Find lowest-power state that supports long-term idle */ |
8aef33a7 DL |
60 | for (i = drv->state_count - 1; i >= CPUIDLE_DRIVER_STATE_START; i--) |
61 | if (drv->states[i].enter_dead) | |
62 | return drv->states[i].enter_dead(dev, i); | |
1a022e3f BO |
63 | |
64 | return -ENODEV; | |
65 | } | |
66 | ||
56cfbf74 CC |
67 | /** |
68 | * cpuidle_enter_state - enter the state and update stats | |
69 | * @dev: cpuidle device for this cpu | |
70 | * @drv: cpuidle driver for this cpu | |
71 | * @next_state: index into drv->states of the state to enter | |
72 | */ | |
73 | int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, | |
554c06ba | 74 | int index) |
56cfbf74 CC |
75 | { |
76 | int entered_state; | |
77 | ||
554c06ba DL |
78 | struct cpuidle_state *target_state = &drv->states[index]; |
79 | ktime_t time_start, time_end; | |
80 | s64 diff; | |
81 | ||
82 | time_start = ktime_get(); | |
83 | ||
84 | entered_state = target_state->enter(dev, drv, index); | |
85 | ||
86 | time_end = ktime_get(); | |
87 | ||
88 | local_irq_enable(); | |
89 | ||
90 | diff = ktime_to_us(ktime_sub(time_end, time_start)); | |
91 | if (diff > INT_MAX) | |
92 | diff = INT_MAX; | |
93 | ||
94 | dev->last_residency = (int) diff; | |
56cfbf74 CC |
95 | |
96 | if (entered_state >= 0) { | |
97 | /* Update cpuidle counters */ | |
98 | /* This can be moved to within driver enter routine | |
99 | * but that results in multiple copies of same code. | |
100 | */ | |
a474a515 | 101 | dev->states_usage[entered_state].time += dev->last_residency; |
56cfbf74 CC |
102 | dev->states_usage[entered_state].usage++; |
103 | } else { | |
104 | dev->last_residency = 0; | |
105 | } | |
106 | ||
107 | return entered_state; | |
108 | } | |
109 | ||
4f86d3a8 LB |
110 | /** |
111 | * cpuidle_idle_call - the main idle loop | |
112 | * | |
113 | * NOTE: no locks or semaphores should be used here | |
a0bfa137 | 114 | * return non-zero on failure |
4f86d3a8 | 115 | */ |
a0bfa137 | 116 | int cpuidle_idle_call(void) |
4f86d3a8 | 117 | { |
4a6f4fe8 | 118 | struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); |
bf4d1b5d | 119 | struct cpuidle_driver *drv; |
e978aa7d | 120 | int next_state, entered_state; |
4f86d3a8 | 121 | |
a0bfa137 LB |
122 | if (off) |
123 | return -ENODEV; | |
124 | ||
125 | if (!initialized) | |
126 | return -ENODEV; | |
127 | ||
4f86d3a8 | 128 | /* check if the device is ready */ |
a0bfa137 LB |
129 | if (!dev || !dev->enabled) |
130 | return -EBUSY; | |
4f86d3a8 | 131 | |
bf4d1b5d DL |
132 | drv = cpuidle_get_cpu_driver(dev); |
133 | ||
4f86d3a8 | 134 | /* ask the governor for the next state */ |
46bcfad7 | 135 | next_state = cpuidle_curr_governor->select(drv, dev); |
246eb7f0 | 136 | if (need_resched()) { |
d73d68dc YS |
137 | dev->last_residency = 0; |
138 | /* give the governor an opportunity to reflect on the outcome */ | |
139 | if (cpuidle_curr_governor->reflect) | |
140 | cpuidle_curr_governor->reflect(dev, next_state); | |
246eb7f0 | 141 | local_irq_enable(); |
a0bfa137 | 142 | return 0; |
246eb7f0 KH |
143 | } |
144 | ||
76027ea8 | 145 | trace_cpu_idle_rcuidle(next_state, dev->cpu); |
f77cfe4e | 146 | |
b60e6a0e DL |
147 | if (drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP) |
148 | clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, | |
149 | &dev->cpu); | |
150 | ||
4126c019 CC |
151 | if (cpuidle_state_is_coupled(dev, drv, next_state)) |
152 | entered_state = cpuidle_enter_state_coupled(dev, drv, | |
153 | next_state); | |
154 | else | |
155 | entered_state = cpuidle_enter_state(dev, drv, next_state); | |
f77cfe4e | 156 | |
b60e6a0e DL |
157 | if (drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP) |
158 | clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, | |
159 | &dev->cpu); | |
160 | ||
76027ea8 | 161 | trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); |
f77cfe4e | 162 | |
4f86d3a8 LB |
163 | /* give the governor an opportunity to reflect on the outcome */ |
164 | if (cpuidle_curr_governor->reflect) | |
e978aa7d | 165 | cpuidle_curr_governor->reflect(dev, entered_state); |
a0bfa137 LB |
166 | |
167 | return 0; | |
4f86d3a8 LB |
168 | } |
169 | ||
170 | /** | |
171 | * cpuidle_install_idle_handler - installs the cpuidle idle loop handler | |
172 | */ | |
173 | void cpuidle_install_idle_handler(void) | |
174 | { | |
a0bfa137 | 175 | if (enabled_devices) { |
4f86d3a8 LB |
176 | /* Make sure all changes finished before we switch to new idle */ |
177 | smp_wmb(); | |
a0bfa137 | 178 | initialized = 1; |
4f86d3a8 LB |
179 | } |
180 | } | |
181 | ||
182 | /** | |
183 | * cpuidle_uninstall_idle_handler - uninstalls the cpuidle idle loop handler | |
184 | */ | |
185 | void cpuidle_uninstall_idle_handler(void) | |
186 | { | |
a0bfa137 LB |
187 | if (enabled_devices) { |
188 | initialized = 0; | |
4a162513 | 189 | kick_all_cpus_sync(); |
4f86d3a8 LB |
190 | } |
191 | } | |
192 | ||
193 | /** | |
194 | * cpuidle_pause_and_lock - temporarily disables CPUIDLE | |
195 | */ | |
196 | void cpuidle_pause_and_lock(void) | |
197 | { | |
198 | mutex_lock(&cpuidle_lock); | |
199 | cpuidle_uninstall_idle_handler(); | |
200 | } | |
201 | ||
202 | EXPORT_SYMBOL_GPL(cpuidle_pause_and_lock); | |
203 | ||
204 | /** | |
205 | * cpuidle_resume_and_unlock - resumes CPUIDLE operation | |
206 | */ | |
207 | void cpuidle_resume_and_unlock(void) | |
208 | { | |
209 | cpuidle_install_idle_handler(); | |
210 | mutex_unlock(&cpuidle_lock); | |
211 | } | |
212 | ||
213 | EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); | |
214 | ||
8651f97b PM |
215 | /* Currently used in suspend/resume path to suspend cpuidle */ |
216 | void cpuidle_pause(void) | |
217 | { | |
218 | mutex_lock(&cpuidle_lock); | |
219 | cpuidle_uninstall_idle_handler(); | |
220 | mutex_unlock(&cpuidle_lock); | |
221 | } | |
222 | ||
223 | /* Currently used in suspend/resume path to resume cpuidle */ | |
224 | void cpuidle_resume(void) | |
225 | { | |
226 | mutex_lock(&cpuidle_lock); | |
227 | cpuidle_install_idle_handler(); | |
228 | mutex_unlock(&cpuidle_lock); | |
229 | } | |
230 | ||
d8c216cf | 231 | #ifdef CONFIG_ARCH_HAS_CPU_RELAX |
46bcfad7 DD |
232 | static int poll_idle(struct cpuidle_device *dev, |
233 | struct cpuidle_driver *drv, int index) | |
d8c216cf RW |
234 | { |
235 | ktime_t t1, t2; | |
236 | s64 diff; | |
d8c216cf RW |
237 | |
238 | t1 = ktime_get(); | |
239 | local_irq_enable(); | |
240 | while (!need_resched()) | |
241 | cpu_relax(); | |
242 | ||
243 | t2 = ktime_get(); | |
244 | diff = ktime_to_us(ktime_sub(t2, t1)); | |
245 | if (diff > INT_MAX) | |
246 | diff = INT_MAX; | |
247 | ||
e978aa7d DD |
248 | dev->last_residency = (int) diff; |
249 | ||
250 | return index; | |
d8c216cf RW |
251 | } |
252 | ||
46bcfad7 | 253 | static void poll_idle_init(struct cpuidle_driver *drv) |
d8c216cf | 254 | { |
46bcfad7 | 255 | struct cpuidle_state *state = &drv->states[0]; |
d8c216cf | 256 | |
720f1c30 | 257 | snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); |
d8c216cf RW |
258 | snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); |
259 | state->exit_latency = 0; | |
260 | state->target_residency = 0; | |
261 | state->power_usage = -1; | |
d247632c | 262 | state->flags = 0; |
d8c216cf | 263 | state->enter = poll_idle; |
cbc9ef02 | 264 | state->disabled = false; |
d8c216cf RW |
265 | } |
266 | #else | |
46bcfad7 | 267 | static void poll_idle_init(struct cpuidle_driver *drv) {} |
d8c216cf RW |
268 | #endif /* CONFIG_ARCH_HAS_CPU_RELAX */ |
269 | ||
4f86d3a8 LB |
270 | /** |
271 | * cpuidle_enable_device - enables idle PM for a CPU | |
272 | * @dev: the CPU | |
273 | * | |
274 | * This function must be called between cpuidle_pause_and_lock and | |
275 | * cpuidle_resume_and_unlock when used externally. | |
276 | */ | |
277 | int cpuidle_enable_device(struct cpuidle_device *dev) | |
278 | { | |
5df0aa73 | 279 | int ret; |
bf4d1b5d | 280 | struct cpuidle_driver *drv; |
4f86d3a8 | 281 | |
1b0a0e9a SB |
282 | if (!dev) |
283 | return -EINVAL; | |
284 | ||
4f86d3a8 LB |
285 | if (dev->enabled) |
286 | return 0; | |
bf4d1b5d DL |
287 | |
288 | drv = cpuidle_get_cpu_driver(dev); | |
289 | ||
e1689795 | 290 | if (!drv || !cpuidle_curr_governor) |
4f86d3a8 | 291 | return -EIO; |
bf4d1b5d | 292 | |
10b9d3f8 DL |
293 | if (!dev->registered) |
294 | return -EINVAL; | |
295 | ||
4f86d3a8 | 296 | if (!dev->state_count) |
fc850f39 | 297 | dev->state_count = drv->state_count; |
4f86d3a8 | 298 | |
e1689795 | 299 | poll_idle_init(drv); |
d8c216cf | 300 | |
bf4d1b5d DL |
301 | ret = cpuidle_add_device_sysfs(dev); |
302 | if (ret) | |
4f86d3a8 LB |
303 | return ret; |
304 | ||
305 | if (cpuidle_curr_governor->enable && | |
e1689795 | 306 | (ret = cpuidle_curr_governor->enable(drv, dev))) |
4f86d3a8 LB |
307 | goto fail_sysfs; |
308 | ||
4f86d3a8 LB |
309 | smp_wmb(); |
310 | ||
311 | dev->enabled = 1; | |
312 | ||
313 | enabled_devices++; | |
314 | return 0; | |
315 | ||
316 | fail_sysfs: | |
bf4d1b5d | 317 | cpuidle_remove_device_sysfs(dev); |
4f86d3a8 LB |
318 | |
319 | return ret; | |
320 | } | |
321 | ||
322 | EXPORT_SYMBOL_GPL(cpuidle_enable_device); | |
323 | ||
324 | /** | |
325 | * cpuidle_disable_device - disables idle PM for a CPU | |
326 | * @dev: the CPU | |
327 | * | |
328 | * This function must be called between cpuidle_pause_and_lock and | |
329 | * cpuidle_resume_and_unlock when used externally. | |
330 | */ | |
331 | void cpuidle_disable_device(struct cpuidle_device *dev) | |
332 | { | |
bf4d1b5d DL |
333 | struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); |
334 | ||
cf31cd1a | 335 | if (!dev || !dev->enabled) |
4f86d3a8 | 336 | return; |
bf4d1b5d DL |
337 | |
338 | if (!drv || !cpuidle_curr_governor) | |
4f86d3a8 LB |
339 | return; |
340 | ||
341 | dev->enabled = 0; | |
342 | ||
343 | if (cpuidle_curr_governor->disable) | |
bf4d1b5d | 344 | cpuidle_curr_governor->disable(drv, dev); |
4f86d3a8 | 345 | |
bf4d1b5d | 346 | cpuidle_remove_device_sysfs(dev); |
4f86d3a8 LB |
347 | enabled_devices--; |
348 | } | |
349 | ||
350 | EXPORT_SYMBOL_GPL(cpuidle_disable_device); | |
351 | ||
f6bb51a5 DL |
352 | static void __cpuidle_unregister_device(struct cpuidle_device *dev) |
353 | { | |
354 | struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); | |
355 | ||
356 | list_del(&dev->device_list); | |
357 | per_cpu(cpuidle_devices, dev->cpu) = NULL; | |
358 | module_put(drv->owner); | |
359 | } | |
360 | ||
5df0aa73 DL |
361 | static int __cpuidle_device_init(struct cpuidle_device *dev) |
362 | { | |
363 | memset(dev->states_usage, 0, sizeof(dev->states_usage)); | |
364 | dev->last_residency = 0; | |
365 | ||
366 | return 0; | |
367 | } | |
368 | ||
4f86d3a8 | 369 | /** |
dcb84f33 VP |
370 | * __cpuidle_register_device - internal register function called before register |
371 | * and enable routines | |
4f86d3a8 | 372 | * @dev: the cpu |
dcb84f33 VP |
373 | * |
374 | * cpuidle_lock mutex must be held before this is called | |
4f86d3a8 | 375 | */ |
dcb84f33 | 376 | static int __cpuidle_register_device(struct cpuidle_device *dev) |
4f86d3a8 LB |
377 | { |
378 | int ret; | |
bf4d1b5d | 379 | struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); |
4f86d3a8 | 380 | |
bf4d1b5d | 381 | if (!try_module_get(drv->owner)) |
4f86d3a8 LB |
382 | return -EINVAL; |
383 | ||
4f86d3a8 LB |
384 | per_cpu(cpuidle_devices, dev->cpu) = dev; |
385 | list_add(&dev->device_list, &cpuidle_detected_devices); | |
4f86d3a8 | 386 | |
4126c019 | 387 | ret = cpuidle_coupled_register_device(dev); |
f6bb51a5 DL |
388 | if (ret) { |
389 | __cpuidle_unregister_device(dev); | |
390 | return ret; | |
391 | } | |
4f86d3a8 | 392 | |
dcb84f33 VP |
393 | dev->registered = 1; |
394 | return 0; | |
395 | } | |
396 | ||
397 | /** | |
398 | * cpuidle_register_device - registers a CPU's idle PM feature | |
399 | * @dev: the cpu | |
400 | */ | |
401 | int cpuidle_register_device(struct cpuidle_device *dev) | |
402 | { | |
403 | int ret; | |
404 | ||
1b0a0e9a SB |
405 | if (!dev) |
406 | return -EINVAL; | |
407 | ||
dcb84f33 VP |
408 | mutex_lock(&cpuidle_lock); |
409 | ||
5df0aa73 DL |
410 | ret = __cpuidle_device_init(dev); |
411 | if (ret) | |
412 | goto out_unlock; | |
413 | ||
f6bb51a5 DL |
414 | ret = __cpuidle_register_device(dev); |
415 | if (ret) | |
416 | goto out_unlock; | |
417 | ||
418 | ret = cpuidle_add_sysfs(dev); | |
419 | if (ret) | |
420 | goto out_unregister; | |
dcb84f33 | 421 | |
10b9d3f8 | 422 | ret = cpuidle_enable_device(dev); |
f6bb51a5 DL |
423 | if (ret) |
424 | goto out_sysfs; | |
10b9d3f8 | 425 | |
4f86d3a8 LB |
426 | cpuidle_install_idle_handler(); |
427 | ||
f6bb51a5 | 428 | out_unlock: |
4f86d3a8 LB |
429 | mutex_unlock(&cpuidle_lock); |
430 | ||
f6bb51a5 DL |
431 | return ret; |
432 | ||
433 | out_sysfs: | |
434 | cpuidle_remove_sysfs(dev); | |
435 | out_unregister: | |
436 | __cpuidle_unregister_device(dev); | |
437 | goto out_unlock; | |
4f86d3a8 LB |
438 | } |
439 | ||
440 | EXPORT_SYMBOL_GPL(cpuidle_register_device); | |
441 | ||
442 | /** | |
443 | * cpuidle_unregister_device - unregisters a CPU's idle PM feature | |
444 | * @dev: the cpu | |
445 | */ | |
446 | void cpuidle_unregister_device(struct cpuidle_device *dev) | |
447 | { | |
dcb84f33 VP |
448 | if (dev->registered == 0) |
449 | return; | |
450 | ||
4f86d3a8 LB |
451 | cpuidle_pause_and_lock(); |
452 | ||
453 | cpuidle_disable_device(dev); | |
454 | ||
1aef40e2 | 455 | cpuidle_remove_sysfs(dev); |
f6bb51a5 DL |
456 | |
457 | __cpuidle_unregister_device(dev); | |
4f86d3a8 | 458 | |
4126c019 CC |
459 | cpuidle_coupled_unregister_device(dev); |
460 | ||
4f86d3a8 | 461 | cpuidle_resume_and_unlock(); |
4f86d3a8 LB |
462 | } |
463 | ||
464 | EXPORT_SYMBOL_GPL(cpuidle_unregister_device); | |
465 | ||
1c192d04 | 466 | /** |
4c637b21 DL |
467 | * cpuidle_unregister: unregister a driver and the devices. This function |
468 | * can be used only if the driver has been previously registered through | |
469 | * the cpuidle_register function. | |
470 | * | |
471 | * @drv: a valid pointer to a struct cpuidle_driver | |
472 | */ | |
473 | void cpuidle_unregister(struct cpuidle_driver *drv) | |
474 | { | |
475 | int cpu; | |
476 | struct cpuidle_device *device; | |
477 | ||
82467a5a | 478 | for_each_cpu(cpu, drv->cpumask) { |
4c637b21 DL |
479 | device = &per_cpu(cpuidle_dev, cpu); |
480 | cpuidle_unregister_device(device); | |
481 | } | |
482 | ||
483 | cpuidle_unregister_driver(drv); | |
484 | } | |
485 | EXPORT_SYMBOL_GPL(cpuidle_unregister); | |
486 | ||
487 | /** | |
488 | * cpuidle_register: registers the driver and the cpu devices with the | |
489 | * coupled_cpus passed as parameter. This function is used for all common | |
490 | * initialization pattern there are in the arch specific drivers. The | |
491 | * devices is globally defined in this file. | |
492 | * | |
493 | * @drv : a valid pointer to a struct cpuidle_driver | |
494 | * @coupled_cpus: a cpumask for the coupled states | |
495 | * | |
496 | * Returns 0 on success, < 0 otherwise | |
497 | */ | |
498 | int cpuidle_register(struct cpuidle_driver *drv, | |
499 | const struct cpumask *const coupled_cpus) | |
500 | { | |
501 | int ret, cpu; | |
502 | struct cpuidle_device *device; | |
503 | ||
504 | ret = cpuidle_register_driver(drv); | |
505 | if (ret) { | |
506 | pr_err("failed to register cpuidle driver\n"); | |
507 | return ret; | |
508 | } | |
509 | ||
82467a5a | 510 | for_each_cpu(cpu, drv->cpumask) { |
4c637b21 DL |
511 | device = &per_cpu(cpuidle_dev, cpu); |
512 | device->cpu = cpu; | |
513 | ||
514 | #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED | |
515 | /* | |
516 | * On multiplatform for ARM, the coupled idle states could | |
517 | * enabled in the kernel even if the cpuidle driver does not | |
518 | * use it. Note, coupled_cpus is a struct copy. | |
519 | */ | |
520 | if (coupled_cpus) | |
521 | device->coupled_cpus = *coupled_cpus; | |
522 | #endif | |
523 | ret = cpuidle_register_device(device); | |
524 | if (!ret) | |
525 | continue; | |
526 | ||
527 | pr_err("Failed to register cpuidle device for cpu%d\n", cpu); | |
528 | ||
529 | cpuidle_unregister(drv); | |
530 | break; | |
531 | } | |
532 | ||
533 | return ret; | |
534 | } | |
535 | EXPORT_SYMBOL_GPL(cpuidle_register); | |
536 | ||
4f86d3a8 LB |
537 | #ifdef CONFIG_SMP |
538 | ||
539 | static void smp_callback(void *v) | |
540 | { | |
541 | /* we already woke the CPU up, nothing more to do */ | |
542 | } | |
543 | ||
544 | /* | |
545 | * This function gets called when a part of the kernel has a new latency | |
546 | * requirement. This means we need to get all processors out of their C-state, | |
547 | * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that | |
548 | * wakes them all right up. | |
549 | */ | |
550 | static int cpuidle_latency_notify(struct notifier_block *b, | |
551 | unsigned long l, void *v) | |
552 | { | |
8691e5a8 | 553 | smp_call_function(smp_callback, NULL, 1); |
4f86d3a8 LB |
554 | return NOTIFY_OK; |
555 | } | |
556 | ||
557 | static struct notifier_block cpuidle_latency_notifier = { | |
558 | .notifier_call = cpuidle_latency_notify, | |
559 | }; | |
560 | ||
d82b3518 MG |
561 | static inline void latency_notifier_init(struct notifier_block *n) |
562 | { | |
563 | pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, n); | |
564 | } | |
4f86d3a8 LB |
565 | |
566 | #else /* CONFIG_SMP */ | |
567 | ||
568 | #define latency_notifier_init(x) do { } while (0) | |
569 | ||
570 | #endif /* CONFIG_SMP */ | |
571 | ||
572 | /** | |
573 | * cpuidle_init - core initializer | |
574 | */ | |
575 | static int __init cpuidle_init(void) | |
576 | { | |
577 | int ret; | |
578 | ||
62027aea LB |
579 | if (cpuidle_disabled()) |
580 | return -ENODEV; | |
581 | ||
8a25a2fd | 582 | ret = cpuidle_add_interface(cpu_subsys.dev_root); |
4f86d3a8 LB |
583 | if (ret) |
584 | return ret; | |
585 | ||
586 | latency_notifier_init(&cpuidle_latency_notifier); | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
62027aea | 591 | module_param(off, int, 0444); |
4f86d3a8 | 592 | core_initcall(cpuidle_init); |