aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/sysfs.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/sysfs.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/sysfs.c')
-rw-r--r--drivers/cpuidle/sysfs.c174
1 files changed, 168 insertions, 6 deletions
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 49b1f4bcc1b3..340942946106 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -364,17 +364,17 @@ static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
364} 364}
365 365
366/** 366/**
367 * cpuidle_add_driver_sysfs - adds driver-specific sysfs attributes 367 * cpuidle_add_state_sysfs - adds cpuidle states sysfs attributes
368 * @device: the target device 368 * @device: the target device
369 */ 369 */
370int cpuidle_add_state_sysfs(struct cpuidle_device *device) 370static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
371{ 371{
372 int i, ret = -ENOMEM; 372 int i, ret = -ENOMEM;
373 struct cpuidle_state_kobj *kobj; 373 struct cpuidle_state_kobj *kobj;
374 struct cpuidle_driver *drv = cpuidle_get_driver(); 374 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(device);
375 375
376 /* state statistics */ 376 /* state statistics */
377 for (i = 0; i < device->state_count; i++) { 377 for (i = 0; i < drv->state_count; i++) {
378 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL); 378 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
379 if (!kobj) 379 if (!kobj)
380 goto error_state; 380 goto error_state;
@@ -401,10 +401,10 @@ error_state:
401} 401}
402 402
403/** 403/**
404 * cpuidle_remove_driver_sysfs - removes driver-specific sysfs attributes 404 * cpuidle_remove_driver_sysfs - removes the cpuidle states sysfs attributes
405 * @device: the target device 405 * @device: the target device
406 */ 406 */
407void cpuidle_remove_state_sysfs(struct cpuidle_device *device) 407static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
408{ 408{
409 int i; 409 int i;
410 410
@@ -412,6 +412,168 @@ void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
412 cpuidle_free_state_kobj(device, i); 412 cpuidle_free_state_kobj(device, i);
413} 413}
414 414
415#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
416#define kobj_to_driver_kobj(k) container_of(k, struct cpuidle_driver_kobj, kobj)
417#define attr_to_driver_attr(a) container_of(a, struct cpuidle_driver_attr, attr)
418
419#define define_one_driver_ro(_name, show) \
420 static struct cpuidle_driver_attr attr_driver_##_name = \
421 __ATTR(_name, 0644, show, NULL)
422
423struct cpuidle_driver_kobj {
424 struct cpuidle_driver *drv;
425 struct completion kobj_unregister;
426 struct kobject kobj;
427};
428
429struct cpuidle_driver_attr {
430 struct attribute attr;
431 ssize_t (*show)(struct cpuidle_driver *, char *);
432 ssize_t (*store)(struct cpuidle_driver *, const char *, size_t);
433};
434
435static ssize_t show_driver_name(struct cpuidle_driver *drv, char *buf)
436{
437 ssize_t ret;
438
439 spin_lock(&cpuidle_driver_lock);
440 ret = sprintf(buf, "%s\n", drv ? drv->name : "none");
441 spin_unlock(&cpuidle_driver_lock);
442
443 return ret;
444}
445
446static void cpuidle_driver_sysfs_release(struct kobject *kobj)
447{
448 struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
449 complete(&driver_kobj->kobj_unregister);
450}
451
452static ssize_t cpuidle_driver_show(struct kobject *kobj, struct attribute * attr,
453 char * buf)
454{
455 int ret = -EIO;
456 struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
457 struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);
458
459 if (dattr->show)
460 ret = dattr->show(driver_kobj->drv, buf);
461
462 return ret;
463}
464
465static ssize_t cpuidle_driver_store(struct kobject *kobj, struct attribute *attr,
466 const char *buf, size_t size)
467{
468 int ret = -EIO;
469 struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
470 struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);
471
472 if (dattr->store)
473 ret = dattr->store(driver_kobj->drv, buf, size);
474
475 return ret;
476}
477
478define_one_driver_ro(name, show_driver_name);
479
480static const struct sysfs_ops cpuidle_driver_sysfs_ops = {
481 .show = cpuidle_driver_show,
482 .store = cpuidle_driver_store,
483};
484
485static struct attribute *cpuidle_driver_default_attrs[] = {
486 &attr_driver_name.attr,
487 NULL
488};
489
490static struct kobj_type ktype_driver_cpuidle = {
491 .sysfs_ops = &cpuidle_driver_sysfs_ops,
492 .default_attrs = cpuidle_driver_default_attrs,
493 .release = cpuidle_driver_sysfs_release,
494};
495
496/**
497 * cpuidle_add_driver_sysfs - adds the driver name sysfs attribute
498 * @device: the target device
499 */
500static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
501{
502 struct cpuidle_driver_kobj *kdrv;
503 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
504 int ret;
505
506 kdrv = kzalloc(sizeof(*kdrv), GFP_KERNEL);
507 if (!kdrv)
508 return -ENOMEM;
509
510 kdrv->drv = drv;
511 init_completion(&kdrv->kobj_unregister);
512
513 ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
514 &dev->kobj, "driver");
515 if (ret) {
516 kfree(kdrv);
517 return ret;
518 }
519
520 kobject_uevent(&kdrv->kobj, KOBJ_ADD);
521 dev->kobj_driver = kdrv;
522
523 return ret;
524}
525
526/**
527 * cpuidle_remove_driver_sysfs - removes the driver name sysfs attribute
528 * @device: the target device
529 */
530static void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
531{
532 struct cpuidle_driver_kobj *kdrv = dev->kobj_driver;
533 kobject_put(&kdrv->kobj);
534 wait_for_completion(&kdrv->kobj_unregister);
535 kfree(kdrv);
536}
537#else
538static inline int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
539{
540 return 0;
541}
542
543static inline void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
544{
545 ;
546}
547#endif
548
549/**
550 * cpuidle_add_device_sysfs - adds device specific sysfs attributes
551 * @device: the target device
552 */
553int cpuidle_add_device_sysfs(struct cpuidle_device *device)
554{
555 int ret;
556
557 ret = cpuidle_add_state_sysfs(device);
558 if (ret)
559 return ret;
560
561 ret = cpuidle_add_driver_sysfs(device);
562 if (ret)
563 cpuidle_remove_state_sysfs(device);
564 return ret;
565}
566
567/**
568 * cpuidle_remove_device_sysfs : removes device specific sysfs attributes
569 * @device : the target device
570 */
571void cpuidle_remove_device_sysfs(struct cpuidle_device *device)
572{
573 cpuidle_remove_driver_sysfs(device);
574 cpuidle_remove_state_sysfs(device);
575}
576
415/** 577/**
416 * cpuidle_add_sysfs - creates a sysfs instance for the target device 578 * cpuidle_add_sysfs - creates a sysfs instance for the target device
417 * @dev: the target device 579 * @dev: the target device