linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][V2] cpuidle : use percpu cpuidle in the core code
@ 2012-04-02 12:48 Daniel Lezcano
       [not found] ` <1333370928-1930-1-git-send-email-daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2012-04-02 13:21 ` Srivatsa S. Bhat
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Lezcano @ 2012-04-02 12:48 UTC (permalink / raw)
  To: lenb; +Cc: linux-pm, linaro-dev, srivatsa.bhat, patches

The usual cpuidle initialization routines are to register the
driver, then register a cpuidle device per cpu.

With the device's state count default initialization with the
driver's state count, the code initialization remains mostly the
same in the different drivers.

We can then add a new function 'cpuidle_register' where we register
the driver and the devices. These devices can be defined in a global
static variable in cpuidle.c. We will be able to factor out and
remove a lot of duplicate lines of code.

As we still have some drivers, with different initialization routines,
we keep 'cpuidle_register_driver' and 'cpuidle_register_device' as low
level initialization routines to do some specific operations on the
cpuidle devices.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/cpuidle/cpuidle.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/cpuidle.h   |    3 +++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 87411ce..151c55a 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -23,6 +23,7 @@
 #include "cpuidle.h"
 
 DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
+DEFINE_PER_CPU(struct cpuidle_device, cpuidle_device);
 
 DEFINE_MUTEX(cpuidle_lock);
 LIST_HEAD(cpuidle_detected_devices);
@@ -419,6 +420,47 @@ int cpuidle_register_device(struct cpuidle_device *dev)
 
 EXPORT_SYMBOL_GPL(cpuidle_register_device);
 
+/*
+ * cpuidle_register : register cpuidle driver and devices
+ * Note this function must be called after smp_init.
+ * @drv : the cpuidle driver
+ * Returns 0 on success, < 0 otherwise
+ */
+int cpuidle_register(struct cpuidle_driver *drv)
+{
+	int ret, cpu, i;
+	struct cpuidle_device *dev;
+
+	ret = cpuidle_register_driver(drv);
+	if (ret)
+		return ret;
+
+	for_each_online_cpu(cpu) {
+		dev = &per_cpu(cpuidle_device, cpu);
+		dev->cpu = cpu;
+
+		ret = cpuidle_register_device(dev);
+		if (ret)
+			goto out_unregister;
+	}
+
+out:
+	return ret;
+
+out_unregister:
+	for_each_online_cpu(i) {
+		if (i == cpu)
+			break;
+		dev = &per_cpu(cpuidle_device, cpu);
+		cpuidle_unregister_device(dev);
+	}
+
+	cpuidle_unregister_driver(drv);
+
+	goto out;
+}
+EXPORT_SYMBOL_GPL(cpuidle_register);
+
 /**
  * cpuidle_unregister_device - unregisters a CPU's idle PM feature
  * @dev: the cpu
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index 6c26a3d..3475294 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -135,6 +135,7 @@ struct cpuidle_driver {
 #ifdef CONFIG_CPU_IDLE
 extern void disable_cpuidle(void);
 extern int cpuidle_idle_call(void);
+extern int cpuidle_register(struct cpuidle_driver *drv);
 extern int cpuidle_register_driver(struct cpuidle_driver *drv);
 struct cpuidle_driver *cpuidle_get_driver(void);
 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
@@ -154,6 +155,8 @@ extern int cpuidle_play_dead(void);
 #else
 static inline void disable_cpuidle(void) { }
 static inline int cpuidle_idle_call(void) { return -ENODEV; }
+static inline int cpuidle_register(struct cpuidle_driver *drv)
+{return -ENODEV; }
 static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
 {return -ENODEV; }
 static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][V2] cpuidle : use percpu cpuidle in the core code
       [not found] ` <1333370928-1930-1-git-send-email-daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2012-04-02 12:59   ` Amit Kucheria
  0 siblings, 0 replies; 4+ messages in thread
From: Amit Kucheria @ 2012-04-02 12:59 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: linux-pm-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	patches-QSEj5FYQhm4dnm+yROfE0A, linaro-dev-cunTk1MwBs8s++Sfvej+rw,
	srivatsa.bhat-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	lenb-DgEjT+Ai2ygdnm+yROfE0A

On Mon, Apr 2, 2012 at 3:48 PM, Daniel Lezcano
<daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> The usual cpuidle initialization routines are to register the

s/are to//

> driver, then register a cpuidle device per cpu.
>
> With the device's state count default initialization with the
> driver's state count, the code initialization remains mostly the
> same in the different drivers.

The following is a bit easier to read and captures your point, I think:

By default, most drivers initialize the device state count with the
driver state count.

> We can then add a new function 'cpuidle_register' where we register
> the driver and the devices. These devices can be defined in a global
> static variable in cpuidle.c. We will be able to factor out and
> remove a lot of duplicate lines of code.
>
> As we still have some drivers, with different initialization routines,
> we keep 'cpuidle_register_driver' and 'cpuidle_register_device' as low
> level initialization routines to do some specific operations on the
> cpuidle devices.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
>  drivers/cpuidle/cpuidle.c |   42 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/cpuidle.h   |    3 +++
>  2 files changed, 45 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index 87411ce..151c55a 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -23,6 +23,7 @@
>  #include "cpuidle.h"
>
>  DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
> +DEFINE_PER_CPU(struct cpuidle_device, cpuidle_device);
>
>  DEFINE_MUTEX(cpuidle_lock);
>  LIST_HEAD(cpuidle_detected_devices);
> @@ -419,6 +420,47 @@ int cpuidle_register_device(struct cpuidle_device *dev)
>
>  EXPORT_SYMBOL_GPL(cpuidle_register_device);
>
> +/*
> + * cpuidle_register : register cpuidle driver and devices
> + * Note this function must be called after smp_init.
> + * @drv : the cpuidle driver
> + * Returns 0 on success, < 0 otherwise
> + */
> +int cpuidle_register(struct cpuidle_driver *drv)
> +{
> +       int ret, cpu, i;
> +       struct cpuidle_device *dev;
> +
> +       ret = cpuidle_register_driver(drv);
> +       if (ret)
> +               return ret;
> +
> +       for_each_online_cpu(cpu) {
> +               dev = &per_cpu(cpuidle_device, cpu);
> +               dev->cpu = cpu;
> +
> +               ret = cpuidle_register_device(dev);
> +               if (ret)
> +                       goto out_unregister;
> +       }
> +
> +out:
> +       return ret;
> +
> +out_unregister:
> +       for_each_online_cpu(i) {
> +               if (i == cpu)
> +                       break;
> +               dev = &per_cpu(cpuidle_device, cpu);
> +               cpuidle_unregister_device(dev);
> +       }
> +
> +       cpuidle_unregister_driver(drv);
> +
> +       goto out;
> +}
> +EXPORT_SYMBOL_GPL(cpuidle_register);
> +
>  /**
>  * cpuidle_unregister_device - unregisters a CPU's idle PM feature
>  * @dev: the cpu
> diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
> index 6c26a3d..3475294 100644
> --- a/include/linux/cpuidle.h
> +++ b/include/linux/cpuidle.h
> @@ -135,6 +135,7 @@ struct cpuidle_driver {
>  #ifdef CONFIG_CPU_IDLE
>  extern void disable_cpuidle(void);
>  extern int cpuidle_idle_call(void);
> +extern int cpuidle_register(struct cpuidle_driver *drv);
>  extern int cpuidle_register_driver(struct cpuidle_driver *drv);
>  struct cpuidle_driver *cpuidle_get_driver(void);
>  extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
> @@ -154,6 +155,8 @@ extern int cpuidle_play_dead(void);
>  #else
>  static inline void disable_cpuidle(void) { }
>  static inline int cpuidle_idle_call(void) { return -ENODEV; }
> +static inline int cpuidle_register(struct cpuidle_driver *drv)
> +{return -ENODEV; }
>  static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
>  {return -ENODEV; }
>  static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
> --
> 1.7.5.4
>
>
> _______________________________________________
> linaro-dev mailing list
> linaro-dev-cunTk1MwBs8s++Sfvej+rw@public.gmane.org
> http://lists.linaro.org/mailman/listinfo/linaro-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][V2] cpuidle : use percpu cpuidle in the core code
  2012-04-02 12:48 [PATCH][V2] cpuidle : use percpu cpuidle in the core code Daniel Lezcano
       [not found] ` <1333370928-1930-1-git-send-email-daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2012-04-02 13:21 ` Srivatsa S. Bhat
  2012-04-02 13:46   ` Daniel Lezcano
  1 sibling, 1 reply; 4+ messages in thread
From: Srivatsa S. Bhat @ 2012-04-02 13:21 UTC (permalink / raw)
  To: Daniel Lezcano; +Cc: linux-pm, patches, linaro-dev, amit.kucheria

On 04/02/2012 06:18 PM, Daniel Lezcano wrote:

> The usual cpuidle initialization routines are to register the
> driver, then register a cpuidle device per cpu.
> 
> With the device's state count default initialization with the
> driver's state count, the code initialization remains mostly the
> same in the different drivers.
> 
> We can then add a new function 'cpuidle_register' where we register
> the driver and the devices. These devices can be defined in a global
> static variable in cpuidle.c. We will be able to factor out and
> remove a lot of duplicate lines of code.
> 
> As we still have some drivers, with different initialization routines,
> we keep 'cpuidle_register_driver' and 'cpuidle_register_device' as low
> level initialization routines to do some specific operations on the
> cpuidle devices.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

> +/*
> + * cpuidle_register : register cpuidle driver and devices
> + * Note this function must be called after smp_init.
> + * @drv : the cpuidle driver
> + * Returns 0 on success, < 0 otherwise
> + */
> +int cpuidle_register(struct cpuidle_driver *drv)
> +{
> +	int ret, cpu, i;
> +	struct cpuidle_device *dev;
> +
> +	ret = cpuidle_register_driver(drv);
> +	if (ret)
> +		return ret;
> +
> +	for_each_online_cpu(cpu) {
> +		dev = &per_cpu(cpuidle_device, cpu);
> +		dev->cpu = cpu;
> +
> +		ret = cpuidle_register_device(dev);
> +		if (ret)
> +			goto out_unregister;
> +	}
> +
> +out:
> +	return ret;
> +
> +out_unregister:
> +	for_each_online_cpu(i) {
> +		if (i == cpu)
> +			break;
> +		dev = &per_cpu(cpuidle_device, cpu);


					       ^^^
That must have been "i" instead of "cpu"...

> +		cpuidle_unregister_device(dev);
> +	}
> +
> +	cpuidle_unregister_driver(drv);
> +
> +	goto out;
> +}
> +EXPORT_SYMBOL_GPL(cpuidle_register);
> +



Regards,
Srivatsa S. Bhat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][V2] cpuidle : use percpu cpuidle in the core code
  2012-04-02 13:21 ` Srivatsa S. Bhat
@ 2012-04-02 13:46   ` Daniel Lezcano
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Lezcano @ 2012-04-02 13:46 UTC (permalink / raw)
  To: Srivatsa S. Bhat; +Cc: linux-pm, patches, linaro-dev, amit.kucheria

On 04/02/2012 03:21 PM, Srivatsa S. Bhat wrote:
> On 04/02/2012 06:18 PM, Daniel Lezcano wrote:
>
>> The usual cpuidle initialization routines are to register the
>> driver, then register a cpuidle device per cpu.
>>
>> With the device's state count default initialization with the
>> driver's state count, the code initialization remains mostly the
>> same in the different drivers.
>>
>> We can then add a new function 'cpuidle_register' where we register
>> the driver and the devices. These devices can be defined in a global
>> static variable in cpuidle.c. We will be able to factor out and
>> remove a lot of duplicate lines of code.
>>
>> As we still have some drivers, with different initialization routines,
>> we keep 'cpuidle_register_driver' and 'cpuidle_register_device' as low
>> level initialization routines to do some specific operations on the
>> cpuidle devices.
>>
>> Signed-off-by: Daniel Lezcano<daniel.lezcano@linaro.org>
>
>> +/*
>> + * cpuidle_register : register cpuidle driver and devices
>> + * Note this function must be called after smp_init.
>> + * @drv : the cpuidle driver
>> + * Returns 0 on success,<  0 otherwise
>> + */
>> +int cpuidle_register(struct cpuidle_driver *drv)
>> +{
>> +	int ret, cpu, i;
>> +	struct cpuidle_device *dev;
>> +
>> +	ret = cpuidle_register_driver(drv);
>> +	if (ret)
>> +		return ret;
>> +
>> +	for_each_online_cpu(cpu) {
>> +		dev =&per_cpu(cpuidle_device, cpu);
>> +		dev->cpu = cpu;
>> +
>> +		ret = cpuidle_register_device(dev);
>> +		if (ret)
>> +			goto out_unregister;
>> +	}
>> +
>> +out:
>> +	return ret;
>> +
>> +out_unregister:
>> +	for_each_online_cpu(i) {
>> +		if (i == cpu)
>> +			break;
>> +		dev =&per_cpu(cpuidle_device, cpu);
>
>
> 					^^^
> That must have been "i" instead of "cpu"...

Oops, right ! Good catch.

Thanks

   -- Daniel



-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-02 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-02 12:48 [PATCH][V2] cpuidle : use percpu cpuidle in the core code Daniel Lezcano
     [not found] ` <1333370928-1930-1-git-send-email-daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-04-02 12:59   ` Amit Kucheria
2012-04-02 13:21 ` Srivatsa S. Bhat
2012-04-02 13:46   ` Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).