blob: f38359f64cc6bea50783fc603da274c0fff43fbd [file] [log] [blame]
Len Brown4f86d3a2007-10-03 18:58:00 -04001/*
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
Daniel Lezcanob60e6a02013-03-21 12:21:31 +000011#include <linux/clockchips.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040012#include <linux/kernel.h>
13#include <linux/mutex.h>
14#include <linux/sched.h>
15#include <linux/notifier.h>
Jean Pihete8db0be2011-08-25 15:35:03 +020016#include <linux/pm_qos.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040017#include <linux/cpu.h>
18#include <linux/cpuidle.h>
venkatesh.pallipadi@intel.com9a0b8412008-01-31 17:35:06 -080019#include <linux/ktime.h>
Arjan van de Ven2e94d1f2008-09-10 16:06:00 -070020#include <linux/hrtimer.h>
Paul Gortmaker884b17e2011-08-29 17:52:39 -040021#include <linux/module.h>
Arjan van de Ven288f0232009-09-19 13:35:33 +020022#include <trace/events/power.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040023
24#include "cpuidle.h"
25
26DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
Daniel Lezcano4c637b22013-04-23 08:54:33 +000027DEFINE_PER_CPU(struct cpuidle_device, cpuidle_dev);
Len Brown4f86d3a2007-10-03 18:58:00 -040028
29DEFINE_MUTEX(cpuidle_lock);
30LIST_HEAD(cpuidle_detected_devices);
Len Brown4f86d3a2007-10-03 18:58:00 -040031
32static int enabled_devices;
Len Brown62027ae2011-04-01 18:13:10 -040033static int off __read_mostly;
Len Browna0bfa132011-04-01 19:34:59 -040034static int initialized __read_mostly;
Len Brown62027ae2011-04-01 18:13:10 -040035
36int cpuidle_disabled(void)
37{
38 return off;
39}
Len Brownd91ee582011-04-01 18:28:35 -040040void disable_cpuidle(void)
41{
42 off = 1;
43}
Len Brown4f86d3a2007-10-03 18:58:00 -040044
45/**
Boris Ostrovsky1a022e32012-03-13 19:55:09 +010046 * cpuidle_play_dead - cpu off-lining
47 *
Toshi Kaniee01e662012-03-31 21:37:02 -060048 * Returns in case of an error or no driver
Boris Ostrovsky1a022e32012-03-13 19:55:09 +010049 */
50int cpuidle_play_dead(void)
51{
52 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +000053 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
Daniel Lezcano8aef33a2013-01-15 14:18:04 +010054 int i;
Boris Ostrovsky1a022e32012-03-13 19:55:09 +010055
Toshi Kaniee01e662012-03-31 21:37:02 -060056 if (!drv)
57 return -ENODEV;
58
Boris Ostrovsky1a022e32012-03-13 19:55:09 +010059 /* Find lowest-power state that supports long-term idle */
Daniel Lezcano8aef33a2013-01-15 14:18:04 +010060 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);
Boris Ostrovsky1a022e32012-03-13 19:55:09 +010063
64 return -ENODEV;
65}
66
67/**
Colin Cross56cfbf72012-05-07 17:57:39 -070068 * 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 */
73int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
Daniel Lezcano554c06b2013-04-23 08:54:31 +000074 int index)
Colin Cross56cfbf72012-05-07 17:57:39 -070075{
76 int entered_state;
77
Daniel Lezcano554c06b2013-04-23 08:54:31 +000078 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
Paul Burton0b89e9a2014-03-06 11:02:01 +000088 if (!cpuidle_state_is_coupled(dev, drv, entered_state))
89 local_irq_enable();
Daniel Lezcano554c06b2013-04-23 08:54:31 +000090
91 diff = ktime_to_us(ktime_sub(time_end, time_start));
92 if (diff > INT_MAX)
93 diff = INT_MAX;
94
95 dev->last_residency = (int) diff;
Colin Cross56cfbf72012-05-07 17:57:39 -070096
97 if (entered_state >= 0) {
98 /* Update cpuidle counters */
99 /* This can be moved to within driver enter routine
100 * but that results in multiple copies of same code.
101 */
Julius Wernera474a512012-11-27 14:17:58 +0100102 dev->states_usage[entered_state].time += dev->last_residency;
Colin Cross56cfbf72012-05-07 17:57:39 -0700103 dev->states_usage[entered_state].usage++;
104 } else {
105 dev->last_residency = 0;
106 }
107
108 return entered_state;
109}
110
111/**
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100112 * cpuidle_select - ask the cpuidle framework to choose an idle state
Len Brown4f86d3a2007-10-03 18:58:00 -0400113 *
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100114 * @drv: the cpuidle driver
115 * @dev: the cpuidle device
116 *
117 * Returns the index of the idle state.
Len Brown4f86d3a2007-10-03 18:58:00 -0400118 */
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100119int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
Len Brown4f86d3a2007-10-03 18:58:00 -0400120{
Rafael J. Wysocki52c324f2014-05-01 00:13:47 +0200121 if (off || !initialized)
122 return -ENODEV;
123
124 if (!drv || !dev || !dev->enabled)
125 return -EBUSY;
126
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100127 return cpuidle_curr_governor->select(drv, dev);
128}
Len Brown4f86d3a2007-10-03 18:58:00 -0400129
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100130/**
131 * cpuidle_enter - enter into the specified idle state
132 *
133 * @drv: the cpuidle driver tied with the cpu
134 * @dev: the cpuidle device
135 * @index: the index in the idle state table
136 *
137 * Returns the index in the idle state, < 0 in case of error.
138 * The error code depends on the backend driver
139 */
140int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev,
141 int index)
142{
143 if (cpuidle_state_is_coupled(dev, drv, index))
144 return cpuidle_enter_state_coupled(dev, drv, index);
145 return cpuidle_enter_state(dev, drv, index);
146}
Len Browna0bfa132011-04-01 19:34:59 -0400147
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100148/**
149 * cpuidle_reflect - tell the underlying governor what was the state
150 * we were in
151 *
152 * @dev : the cpuidle device
153 * @index: the index in the idle state table
154 *
155 */
156void cpuidle_reflect(struct cpuidle_device *dev, int index)
157{
Len Brown4f86d3a2007-10-03 18:58:00 -0400158 if (cpuidle_curr_governor->reflect)
Daniel Lezcano907e30f2014-03-03 08:48:50 +0100159 cpuidle_curr_governor->reflect(dev, index);
Len Brown4f86d3a2007-10-03 18:58:00 -0400160}
161
162/**
163 * cpuidle_install_idle_handler - installs the cpuidle idle loop handler
164 */
165void cpuidle_install_idle_handler(void)
166{
Len Browna0bfa132011-04-01 19:34:59 -0400167 if (enabled_devices) {
Len Brown4f86d3a2007-10-03 18:58:00 -0400168 /* Make sure all changes finished before we switch to new idle */
169 smp_wmb();
Len Browna0bfa132011-04-01 19:34:59 -0400170 initialized = 1;
Len Brown4f86d3a2007-10-03 18:58:00 -0400171 }
172}
173
174/**
175 * cpuidle_uninstall_idle_handler - uninstalls the cpuidle idle loop handler
176 */
177void cpuidle_uninstall_idle_handler(void)
178{
Len Browna0bfa132011-04-01 19:34:59 -0400179 if (enabled_devices) {
180 initialized = 0;
Thomas Gleixner4a162512012-05-07 17:59:48 +0000181 kick_all_cpus_sync();
Len Brown4f86d3a2007-10-03 18:58:00 -0400182 }
183}
184
185/**
186 * cpuidle_pause_and_lock - temporarily disables CPUIDLE
187 */
188void cpuidle_pause_and_lock(void)
189{
190 mutex_lock(&cpuidle_lock);
191 cpuidle_uninstall_idle_handler();
192}
193
194EXPORT_SYMBOL_GPL(cpuidle_pause_and_lock);
195
196/**
197 * cpuidle_resume_and_unlock - resumes CPUIDLE operation
198 */
199void cpuidle_resume_and_unlock(void)
200{
201 cpuidle_install_idle_handler();
202 mutex_unlock(&cpuidle_lock);
203}
204
205EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
206
Preeti U Murthy8651f972012-07-09 10:12:56 +0200207/* Currently used in suspend/resume path to suspend cpuidle */
208void cpuidle_pause(void)
209{
210 mutex_lock(&cpuidle_lock);
211 cpuidle_uninstall_idle_handler();
212 mutex_unlock(&cpuidle_lock);
213}
214
215/* Currently used in suspend/resume path to resume cpuidle */
216void cpuidle_resume(void)
217{
218 mutex_lock(&cpuidle_lock);
219 cpuidle_install_idle_handler();
220 mutex_unlock(&cpuidle_lock);
221}
222
Len Brown4f86d3a2007-10-03 18:58:00 -0400223/**
224 * cpuidle_enable_device - enables idle PM for a CPU
225 * @dev: the CPU
226 *
227 * This function must be called between cpuidle_pause_and_lock and
228 * cpuidle_resume_and_unlock when used externally.
229 */
230int cpuidle_enable_device(struct cpuidle_device *dev)
231{
Daniel Lezcano5df0aa72013-06-12 15:08:54 +0200232 int ret;
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000233 struct cpuidle_driver *drv;
Len Brown4f86d3a2007-10-03 18:58:00 -0400234
Srivatsa S. Bhat1b0a0e92012-05-04 14:06:02 -0700235 if (!dev)
236 return -EINVAL;
237
Len Brown4f86d3a2007-10-03 18:58:00 -0400238 if (dev->enabled)
239 return 0;
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000240
241 drv = cpuidle_get_cpu_driver(dev);
242
Robert Leee1689792012-03-20 15:22:42 -0500243 if (!drv || !cpuidle_curr_governor)
Len Brown4f86d3a2007-10-03 18:58:00 -0400244 return -EIO;
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000245
Daniel Lezcano10b9d3f2013-06-12 15:08:49 +0200246 if (!dev->registered)
247 return -EINVAL;
248
Len Brown4f86d3a2007-10-03 18:58:00 -0400249 if (!dev->state_count)
Daniel Lezcanofc850f32012-03-26 14:51:26 +0200250 dev->state_count = drv->state_count;
Len Brown4f86d3a2007-10-03 18:58:00 -0400251
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000252 ret = cpuidle_add_device_sysfs(dev);
253 if (ret)
Len Brown4f86d3a2007-10-03 18:58:00 -0400254 return ret;
255
256 if (cpuidle_curr_governor->enable &&
Robert Leee1689792012-03-20 15:22:42 -0500257 (ret = cpuidle_curr_governor->enable(drv, dev)))
Len Brown4f86d3a2007-10-03 18:58:00 -0400258 goto fail_sysfs;
259
Len Brown4f86d3a2007-10-03 18:58:00 -0400260 smp_wmb();
261
262 dev->enabled = 1;
263
264 enabled_devices++;
265 return 0;
266
267fail_sysfs:
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000268 cpuidle_remove_device_sysfs(dev);
Len Brown4f86d3a2007-10-03 18:58:00 -0400269
270 return ret;
271}
272
273EXPORT_SYMBOL_GPL(cpuidle_enable_device);
274
275/**
276 * cpuidle_disable_device - disables idle PM for a CPU
277 * @dev: the CPU
278 *
279 * This function must be called between cpuidle_pause_and_lock and
280 * cpuidle_resume_and_unlock when used externally.
281 */
282void cpuidle_disable_device(struct cpuidle_device *dev)
283{
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000284 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
285
Srivatsa S. Bhatcf31cd12012-10-08 13:43:08 +0530286 if (!dev || !dev->enabled)
Len Brown4f86d3a2007-10-03 18:58:00 -0400287 return;
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000288
289 if (!drv || !cpuidle_curr_governor)
Len Brown4f86d3a2007-10-03 18:58:00 -0400290 return;
291
292 dev->enabled = 0;
293
294 if (cpuidle_curr_governor->disable)
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000295 cpuidle_curr_governor->disable(drv, dev);
Len Brown4f86d3a2007-10-03 18:58:00 -0400296
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000297 cpuidle_remove_device_sysfs(dev);
Len Brown4f86d3a2007-10-03 18:58:00 -0400298 enabled_devices--;
299}
300
301EXPORT_SYMBOL_GPL(cpuidle_disable_device);
302
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200303static void __cpuidle_unregister_device(struct cpuidle_device *dev)
304{
305 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
306
307 list_del(&dev->device_list);
308 per_cpu(cpuidle_devices, dev->cpu) = NULL;
309 module_put(drv->owner);
310}
311
Viresh Kumar267d4bf2013-10-03 21:26:43 +0530312static void __cpuidle_device_init(struct cpuidle_device *dev)
Daniel Lezcano5df0aa72013-06-12 15:08:54 +0200313{
314 memset(dev->states_usage, 0, sizeof(dev->states_usage));
315 dev->last_residency = 0;
Daniel Lezcano5df0aa72013-06-12 15:08:54 +0200316}
317
Len Brown4f86d3a2007-10-03 18:58:00 -0400318/**
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400319 * __cpuidle_register_device - internal register function called before register
320 * and enable routines
Len Brown4f86d3a2007-10-03 18:58:00 -0400321 * @dev: the cpu
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400322 *
323 * cpuidle_lock mutex must be held before this is called
Len Brown4f86d3a2007-10-03 18:58:00 -0400324 */
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400325static int __cpuidle_register_device(struct cpuidle_device *dev)
Len Brown4f86d3a2007-10-03 18:58:00 -0400326{
327 int ret;
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000328 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
Len Brown4f86d3a2007-10-03 18:58:00 -0400329
Daniel Lezcanobf4d1b52012-10-31 16:44:48 +0000330 if (!try_module_get(drv->owner))
Len Brown4f86d3a2007-10-03 18:58:00 -0400331 return -EINVAL;
332
Len Brown4f86d3a2007-10-03 18:58:00 -0400333 per_cpu(cpuidle_devices, dev->cpu) = dev;
334 list_add(&dev->device_list, &cpuidle_detected_devices);
Len Brown4f86d3a2007-10-03 18:58:00 -0400335
Colin Cross4126c012012-05-07 17:57:41 -0700336 ret = cpuidle_coupled_register_device(dev);
Viresh Kumar47182662013-10-03 21:26:46 +0530337 if (ret)
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200338 __cpuidle_unregister_device(dev);
Viresh Kumar47182662013-10-03 21:26:46 +0530339 else
340 dev->registered = 1;
Len Brown4f86d3a2007-10-03 18:58:00 -0400341
Viresh Kumar47182662013-10-03 21:26:46 +0530342 return ret;
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400343}
344
345/**
346 * cpuidle_register_device - registers a CPU's idle PM feature
347 * @dev: the cpu
348 */
349int cpuidle_register_device(struct cpuidle_device *dev)
350{
Daniel Lezcanoc878a522013-06-12 15:08:55 +0200351 int ret = -EBUSY;
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400352
Srivatsa S. Bhat1b0a0e92012-05-04 14:06:02 -0700353 if (!dev)
354 return -EINVAL;
355
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400356 mutex_lock(&cpuidle_lock);
357
Daniel Lezcanoc878a522013-06-12 15:08:55 +0200358 if (dev->registered)
359 goto out_unlock;
360
Viresh Kumar267d4bf2013-10-03 21:26:43 +0530361 __cpuidle_device_init(dev);
Daniel Lezcano5df0aa72013-06-12 15:08:54 +0200362
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200363 ret = __cpuidle_register_device(dev);
364 if (ret)
365 goto out_unlock;
366
367 ret = cpuidle_add_sysfs(dev);
368 if (ret)
369 goto out_unregister;
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400370
Daniel Lezcano10b9d3f2013-06-12 15:08:49 +0200371 ret = cpuidle_enable_device(dev);
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200372 if (ret)
373 goto out_sysfs;
Daniel Lezcano10b9d3f2013-06-12 15:08:49 +0200374
Len Brown4f86d3a2007-10-03 18:58:00 -0400375 cpuidle_install_idle_handler();
376
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200377out_unlock:
Len Brown4f86d3a2007-10-03 18:58:00 -0400378 mutex_unlock(&cpuidle_lock);
379
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200380 return ret;
381
382out_sysfs:
383 cpuidle_remove_sysfs(dev);
384out_unregister:
385 __cpuidle_unregister_device(dev);
386 goto out_unlock;
Len Brown4f86d3a2007-10-03 18:58:00 -0400387}
388
389EXPORT_SYMBOL_GPL(cpuidle_register_device);
390
391/**
392 * cpuidle_unregister_device - unregisters a CPU's idle PM feature
393 * @dev: the cpu
394 */
395void cpuidle_unregister_device(struct cpuidle_device *dev)
396{
Konrad Rzeszutek Wilk813e8e32013-12-03 10:59:58 -0500397 if (!dev || dev->registered == 0)
Venkatesh Pallipadidcb84f32008-05-19 19:09:27 -0400398 return;
399
Len Brown4f86d3a2007-10-03 18:58:00 -0400400 cpuidle_pause_and_lock();
401
402 cpuidle_disable_device(dev);
403
Daniel Lezcano1aef40e2012-10-26 12:26:24 +0200404 cpuidle_remove_sysfs(dev);
Daniel Lezcanof6bb51a2013-06-12 15:08:53 +0200405
406 __cpuidle_unregister_device(dev);
Len Brown4f86d3a2007-10-03 18:58:00 -0400407
Colin Cross4126c012012-05-07 17:57:41 -0700408 cpuidle_coupled_unregister_device(dev);
409
Len Brown4f86d3a2007-10-03 18:58:00 -0400410 cpuidle_resume_and_unlock();
Len Brown4f86d3a2007-10-03 18:58:00 -0400411}
412
413EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
414
Daniel Lezcano1c192d02013-04-23 15:28:44 +0000415/**
Daniel Lezcano4c637b22013-04-23 08:54:33 +0000416 * cpuidle_unregister: unregister a driver and the devices. This function
417 * can be used only if the driver has been previously registered through
418 * the cpuidle_register function.
419 *
420 * @drv: a valid pointer to a struct cpuidle_driver
421 */
422void cpuidle_unregister(struct cpuidle_driver *drv)
423{
424 int cpu;
425 struct cpuidle_device *device;
426
Daniel Lezcano82467a52013-06-07 21:53:09 +0000427 for_each_cpu(cpu, drv->cpumask) {
Daniel Lezcano4c637b22013-04-23 08:54:33 +0000428 device = &per_cpu(cpuidle_dev, cpu);
429 cpuidle_unregister_device(device);
430 }
431
432 cpuidle_unregister_driver(drv);
433}
434EXPORT_SYMBOL_GPL(cpuidle_unregister);
435
436/**
437 * cpuidle_register: registers the driver and the cpu devices with the
438 * coupled_cpus passed as parameter. This function is used for all common
439 * initialization pattern there are in the arch specific drivers. The
440 * devices is globally defined in this file.
441 *
442 * @drv : a valid pointer to a struct cpuidle_driver
443 * @coupled_cpus: a cpumask for the coupled states
444 *
445 * Returns 0 on success, < 0 otherwise
446 */
447int cpuidle_register(struct cpuidle_driver *drv,
448 const struct cpumask *const coupled_cpus)
449{
450 int ret, cpu;
451 struct cpuidle_device *device;
452
453 ret = cpuidle_register_driver(drv);
454 if (ret) {
455 pr_err("failed to register cpuidle driver\n");
456 return ret;
457 }
458
Daniel Lezcano82467a52013-06-07 21:53:09 +0000459 for_each_cpu(cpu, drv->cpumask) {
Daniel Lezcano4c637b22013-04-23 08:54:33 +0000460 device = &per_cpu(cpuidle_dev, cpu);
461 device->cpu = cpu;
462
463#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
464 /*
Viresh Kumarcaf4a362013-10-03 21:26:41 +0530465 * On multiplatform for ARM, the coupled idle states could be
Daniel Lezcano4c637b22013-04-23 08:54:33 +0000466 * enabled in the kernel even if the cpuidle driver does not
467 * use it. Note, coupled_cpus is a struct copy.
468 */
469 if (coupled_cpus)
470 device->coupled_cpus = *coupled_cpus;
471#endif
472 ret = cpuidle_register_device(device);
473 if (!ret)
474 continue;
475
476 pr_err("Failed to register cpuidle device for cpu%d\n", cpu);
477
478 cpuidle_unregister(drv);
479 break;
480 }
481
482 return ret;
483}
484EXPORT_SYMBOL_GPL(cpuidle_register);
485
Len Brown4f86d3a2007-10-03 18:58:00 -0400486#ifdef CONFIG_SMP
487
488static void smp_callback(void *v)
489{
490 /* we already woke the CPU up, nothing more to do */
491}
492
493/*
494 * This function gets called when a part of the kernel has a new latency
495 * requirement. This means we need to get all processors out of their C-state,
496 * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
497 * wakes them all right up.
498 */
499static int cpuidle_latency_notify(struct notifier_block *b,
500 unsigned long l, void *v)
501{
Jens Axboe8691e5a2008-06-06 11:18:06 +0200502 smp_call_function(smp_callback, NULL, 1);
Len Brown4f86d3a2007-10-03 18:58:00 -0400503 return NOTIFY_OK;
504}
505
506static struct notifier_block cpuidle_latency_notifier = {
507 .notifier_call = cpuidle_latency_notify,
508};
509
Mark Grossd82b3512008-02-04 22:30:08 -0800510static inline void latency_notifier_init(struct notifier_block *n)
511{
512 pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, n);
513}
Len Brown4f86d3a2007-10-03 18:58:00 -0400514
515#else /* CONFIG_SMP */
516
517#define latency_notifier_init(x) do { } while (0)
518
519#endif /* CONFIG_SMP */
520
521/**
522 * cpuidle_init - core initializer
523 */
524static int __init cpuidle_init(void)
525{
526 int ret;
527
Len Brown62027ae2011-04-01 18:13:10 -0400528 if (cpuidle_disabled())
529 return -ENODEV;
530
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800531 ret = cpuidle_add_interface(cpu_subsys.dev_root);
Len Brown4f86d3a2007-10-03 18:58:00 -0400532 if (ret)
533 return ret;
534
535 latency_notifier_init(&cpuidle_latency_notifier);
536
537 return 0;
538}
539
Len Brown62027ae2011-04-01 18:13:10 -0400540module_param(off, int, 0444);
Len Brown4f86d3a2007-10-03 18:58:00 -0400541core_initcall(cpuidle_init);