aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/cpuidle.c
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2012-10-31 12:44:48 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:34:23 -0500
commitbf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 (patch)
tree36ec1f061372f6a8cfe7b3326036f06aa3a5067c /drivers/cpuidle/cpuidle.c
parent13dd52f11a04e616900f565d6a1e5138e58d579f (diff)
cpuidle: support multiple drivers
With the tegra3 and the big.LITTLE [1] new architectures, several cpus with different characteristics (latencies and states) can co-exists on the system. The cpuidle framework has the limitation of handling only identical cpus. This patch removes this limitation by introducing the multiple driver support for cpuidle. This option is configurable at compile time and should be enabled for the architectures mentioned above. So there is no impact for the other platforms if the option is disabled. The option defaults to 'n'. Note the multiple drivers support is also compatible with the existing drivers, even if just one driver is needed, all the cpu will be tied to this driver using an extra small chunk of processor memory. The multiple driver support use a per-cpu driver pointer instead of a global variable and the accessor to this variable are done from a cpu context. In order to keep the compatibility with the existing drivers, the function 'cpuidle_register_driver' and 'cpuidle_unregister_driver' will register the specified driver for all the cpus. The semantic for the output of /sys/devices/system/cpu/cpuidle/current_driver remains the same except the driver name will be related to the current cpu. The /sys/devices/system/cpu/cpu[0-9]/cpuidle/driver/name files are added allowing to read the per cpu driver name. [1] http://lwn.net/Articles/481055/ Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Peter De Schrijver <pdeschrijver@nvidia.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpuidle/cpuidle.c')
-rw-r--r--drivers/cpuidle/cpuidle.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index ce4cac706dd1..711dd83fd3ba 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -68,7 +68,7 @@ static cpuidle_enter_t cpuidle_enter_ops;
68int cpuidle_play_dead(void) 68int cpuidle_play_dead(void)
69{ 69{
70 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); 70 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
71 struct cpuidle_driver *drv = cpuidle_get_driver(); 71 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
72 int i, dead_state = -1; 72 int i, dead_state = -1;
73 int power_usage = -1; 73 int power_usage = -1;
74 74
@@ -128,7 +128,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
128int cpuidle_idle_call(void) 128int cpuidle_idle_call(void)
129{ 129{
130 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); 130 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
131 struct cpuidle_driver *drv = cpuidle_get_driver(); 131 struct cpuidle_driver *drv;
132 int next_state, entered_state; 132 int next_state, entered_state;
133 133
134 if (off) 134 if (off)
@@ -141,6 +141,8 @@ int cpuidle_idle_call(void)
141 if (!dev || !dev->enabled) 141 if (!dev || !dev->enabled)
142 return -EBUSY; 142 return -EBUSY;
143 143
144 drv = cpuidle_get_cpu_driver(dev);
145
144 /* ask the governor for the next state */ 146 /* ask the governor for the next state */
145 next_state = cpuidle_curr_governor->select(drv, dev); 147 next_state = cpuidle_curr_governor->select(drv, dev);
146 if (need_resched()) { 148 if (need_resched()) {
@@ -312,15 +314,19 @@ static void poll_idle_init(struct cpuidle_driver *drv) {}
312int cpuidle_enable_device(struct cpuidle_device *dev) 314int cpuidle_enable_device(struct cpuidle_device *dev)
313{ 315{
314 int ret, i; 316 int ret, i;
315 struct cpuidle_driver *drv = cpuidle_get_driver(); 317 struct cpuidle_driver *drv;
316 318
317 if (!dev) 319 if (!dev)
318 return -EINVAL; 320 return -EINVAL;
319 321
320 if (dev->enabled) 322 if (dev->enabled)
321 return 0; 323 return 0;
324
325 drv = cpuidle_get_cpu_driver(dev);
326
322 if (!drv || !cpuidle_curr_governor) 327 if (!drv || !cpuidle_curr_governor)
323 return -EIO; 328 return -EIO;
329
324 if (!dev->state_count) 330 if (!dev->state_count)
325 dev->state_count = drv->state_count; 331 dev->state_count = drv->state_count;
326 332
@@ -335,7 +341,8 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
335 341
336 poll_idle_init(drv); 342 poll_idle_init(drv);
337 343
338 if ((ret = cpuidle_add_state_sysfs(dev))) 344 ret = cpuidle_add_device_sysfs(dev);
345 if (ret)
339 return ret; 346 return ret;
340 347
341 if (cpuidle_curr_governor->enable && 348 if (cpuidle_curr_governor->enable &&
@@ -356,7 +363,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
356 return 0; 363 return 0;
357 364
358fail_sysfs: 365fail_sysfs:
359 cpuidle_remove_state_sysfs(dev); 366 cpuidle_remove_device_sysfs(dev);
360 367
361 return ret; 368 return ret;
362} 369}
@@ -372,17 +379,20 @@ EXPORT_SYMBOL_GPL(cpuidle_enable_device);
372 */ 379 */
373void cpuidle_disable_device(struct cpuidle_device *dev) 380void cpuidle_disable_device(struct cpuidle_device *dev)
374{ 381{
382 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
383
375 if (!dev || !dev->enabled) 384 if (!dev || !dev->enabled)
376 return; 385 return;
377 if (!cpuidle_get_driver() || !cpuidle_curr_governor) 386
387 if (!drv || !cpuidle_curr_governor)
378 return; 388 return;
379 389
380 dev->enabled = 0; 390 dev->enabled = 0;
381 391
382 if (cpuidle_curr_governor->disable) 392 if (cpuidle_curr_governor->disable)
383 cpuidle_curr_governor->disable(cpuidle_get_driver(), dev); 393 cpuidle_curr_governor->disable(drv, dev);
384 394
385 cpuidle_remove_state_sysfs(dev); 395 cpuidle_remove_device_sysfs(dev);
386 enabled_devices--; 396 enabled_devices--;
387} 397}
388 398
@@ -398,9 +408,9 @@ EXPORT_SYMBOL_GPL(cpuidle_disable_device);
398static int __cpuidle_register_device(struct cpuidle_device *dev) 408static int __cpuidle_register_device(struct cpuidle_device *dev)
399{ 409{
400 int ret; 410 int ret;
401 struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver(); 411 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
402 412
403 if (!try_module_get(cpuidle_driver->owner)) 413 if (!try_module_get(drv->owner))
404 return -EINVAL; 414 return -EINVAL;
405 415
406 per_cpu(cpuidle_devices, dev->cpu) = dev; 416 per_cpu(cpuidle_devices, dev->cpu) = dev;
@@ -421,7 +431,7 @@ err_coupled:
421err_sysfs: 431err_sysfs:
422 list_del(&dev->device_list); 432 list_del(&dev->device_list);
423 per_cpu(cpuidle_devices, dev->cpu) = NULL; 433 per_cpu(cpuidle_devices, dev->cpu) = NULL;
424 module_put(cpuidle_driver->owner); 434 module_put(drv->owner);
425 return ret; 435 return ret;
426} 436}
427 437
@@ -460,7 +470,7 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device);
460 */ 470 */
461void cpuidle_unregister_device(struct cpuidle_device *dev) 471void cpuidle_unregister_device(struct cpuidle_device *dev)
462{ 472{
463 struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver(); 473 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
464 474
465 if (dev->registered == 0) 475 if (dev->registered == 0)
466 return; 476 return;
@@ -477,7 +487,7 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)
477 487
478 cpuidle_resume_and_unlock(); 488 cpuidle_resume_and_unlock();
479 489
480 module_put(cpuidle_driver->owner); 490 module_put(drv->owner);
481} 491}
482 492
483EXPORT_SYMBOL_GPL(cpuidle_unregister_device); 493EXPORT_SYMBOL_GPL(cpuidle_unregister_device);