From: Daniel Lezcano <hidden> Date: 2012-11-12 20:27:04
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
@@ -69,24 +69,15 @@ int cpuidle_play_dead(void){structcpuidle_device*dev=__this_cpu_read(cpuidle_devices);structcpuidle_driver*drv=cpuidle_get_cpu_driver(dev);-inti,dead_state=-1;-intpower_usage=-1;+inti;if(!drv)return-ENODEV;/* Find lowest-power state that supports long-term idle */-for(i=CPUIDLE_DRIVER_STATE_START;i<drv->state_count;i++){-structcpuidle_state*s=&drv->states[i];--if(s->power_usage<power_usage&&s->enter_dead){-power_usage=s->power_usage;-dead_state=i;-}-}--if(dead_state!=-1)-returndrv->states[dead_state].enter_dead(dev,dead_state);+for(i=drv->state_count;i>=CPUIDLE_DRIVER_STATE_START;i--)+if(drv->states[i].play_dead)+returndrv->states[i].enter_dead(dev,i);return-ENODEV;}
@@ -126,9 +126,9 @@ struct cpuidle_driver {structmodule*owner;intrefcnt;-unsignedintpower_specified:1;/* set to 1 to use the core cpuidle time keeping (for all states). */unsignedinten_core_tk_irqen:1;+/* states array must be ordered in decreasing power consumption */structcpuidle_statestates[CPUIDLE_STATE_MAX];intstate_count;intsafe_state_index;
From: Julius Werner <jwerner@chromium.org> Date: 2012-11-12 21:09:43
Thanks for moving this along, Daniel. I think this is the right
approach... the cpuidle driver shouldn't be more complex than
necessary.
Note that you are starting your loop too high in cpuidle_play_dead...
states[state_count] is not an actual state anymore, it should start at
state_count - 1. Also, I think you can go ahead and do the same
last-to-first loop transformation with immediate return in the menu
governor, for an extra tiny bit of performance.
On Mon, Nov 12, 2012 at 12:26 PM, Daniel Lezcano
[off-list ref] wrote:
quoted hunk
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
@@ -69,24 +69,15 @@ int cpuidle_play_dead(void){structcpuidle_device*dev=__this_cpu_read(cpuidle_devices);structcpuidle_driver*drv=cpuidle_get_cpu_driver(dev);-inti,dead_state=-1;-intpower_usage=-1;+inti;if(!drv)return-ENODEV;/* Find lowest-power state that supports long-term idle */-for(i=CPUIDLE_DRIVER_STATE_START;i<drv->state_count;i++){-structcpuidle_state*s=&drv->states[i];--if(s->power_usage<power_usage&&s->enter_dead){-power_usage=s->power_usage;-dead_state=i;-}-}--if(dead_state!=-1)-returndrv->states[dead_state].enter_dead(dev,dead_state);+for(i=drv->state_count;i>=CPUIDLE_DRIVER_STATE_START;i--)+if(drv->states[i].play_dead)+returndrv->states[i].enter_dead(dev,i);return-ENODEV;}
@@ -126,9 +126,9 @@ struct cpuidle_driver {structmodule*owner;intrefcnt;-unsignedintpower_specified:1;/* set to 1 to use the core cpuidle time keeping (for all states). */unsignedinten_core_tk_irqen:1;+/* states array must be ordered in decreasing power consumption */structcpuidle_statestates[CPUIDLE_STATE_MAX];intstate_count;intsafe_state_index;--
From: Daniel Lezcano <hidden> Date: 2012-11-12 22:08:27
On 11/12/2012 10:09 PM, Julius Werner wrote:
Thanks for moving this along, Daniel. I think this is the right
approach... the cpuidle driver shouldn't be more complex than
necessary.
Note that you are starting your loop too high in cpuidle_play_dead...
states[state_count] is not an actual state anymore, it should start at
state_count - 1.
Yep. Thanks for catching this.
Also, I think you can go ahead and do the same
last-to-first loop transformation with immediate return in the menu
governor, for an extra tiny bit of performance.
Yes, that makes sense.
Thanks for the review.
-- Daniel
On Mon, Nov 12, 2012 at 12:26 PM, Daniel Lezcano
[off-list ref] wrote:
quoted
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
@@ -69,24 +69,15 @@ int cpuidle_play_dead(void){structcpuidle_device*dev=__this_cpu_read(cpuidle_devices);structcpuidle_driver*drv=cpuidle_get_cpu_driver(dev);-inti,dead_state=-1;-intpower_usage=-1;+inti;if(!drv)return-ENODEV;/* Find lowest-power state that supports long-term idle */-for(i=CPUIDLE_DRIVER_STATE_START;i<drv->state_count;i++){-structcpuidle_state*s=&drv->states[i];--if(s->power_usage<power_usage&&s->enter_dead){-power_usage=s->power_usage;-dead_state=i;-}-}--if(dead_state!=-1)-returndrv->states[dead_state].enter_dead(dev,dead_state);+for(i=drv->state_count;i>=CPUIDLE_DRIVER_STATE_START;i--)+if(drv->states[i].play_dead)+returndrv->states[i].enter_dead(dev,i);return-ENODEV;}
@@ -126,9 +126,9 @@ struct cpuidle_driver {structmodule*owner;intrefcnt;-unsignedintpower_specified:1;/* set to 1 to use the core cpuidle time keeping (for all states). */unsignedinten_core_tk_irqen:1;+/* states array must be ordered in decreasing power consumption */structcpuidle_statestates[CPUIDLE_STATE_MAX];intstate_count;intsafe_state_index;--
From: Francesco Lavra <hidden> Date: 2012-11-18 08:41:55
Hi,
On 11/12/2012 09:26 PM, Daniel Lezcano wrote:
quoted hunk
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
@@ -69,24 +69,15 @@ int cpuidle_play_dead(void){structcpuidle_device*dev=__this_cpu_read(cpuidle_devices);structcpuidle_driver*drv=cpuidle_get_cpu_driver(dev);-inti,dead_state=-1;-intpower_usage=-1;+inti;if(!drv)return-ENODEV;/* Find lowest-power state that supports long-term idle */-for(i=CPUIDLE_DRIVER_STATE_START;i<drv->state_count;i++){-structcpuidle_state*s=&drv->states[i];--if(s->power_usage<power_usage&&s->enter_dead){-power_usage=s->power_usage;-dead_state=i;-}-}--if(dead_state!=-1)-returndrv->states[dead_state].enter_dead(dev,dead_state);+for(i=drv->state_count;i>=CPUIDLE_DRIVER_STATE_START;i--)+if(drv->states[i].play_dead)
From: Daniel Lezcano <hidden> Date: 2012-11-18 09:17:53
On 11/18/2012 09:40 AM, Francesco Lavra wrote:
Hi,
On 11/12/2012 09:26 PM, Daniel Lezcano wrote:
quoted
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
@@ -69,24 +69,15 @@ int cpuidle_play_dead(void){structcpuidle_device*dev=__this_cpu_read(cpuidle_devices);structcpuidle_driver*drv=cpuidle_get_cpu_driver(dev);-inti,dead_state=-1;-intpower_usage=-1;+inti;if(!drv)return-ENODEV;/* Find lowest-power state that supports long-term idle */-for(i=CPUIDLE_DRIVER_STATE_START;i<drv->state_count;i++){-structcpuidle_state*s=&drv->states[i];--if(s->power_usage<power_usage&&s->enter_dead){-power_usage=s->power_usage;-dead_state=i;-}-}--if(dead_state!=-1)-returndrv->states[dead_state].enter_dead(dev,dead_state);+for(i=drv->state_count;i>=CPUIDLE_DRIVER_STATE_START;i--)+if(drv->states[i].play_dead)
From: Julius Werner <jwerner@chromium.org> Date: 2012-12-10 19:10:03
Hi,
What is the current status of this? Daniel, do you think you have got
enough feedback to submit a definitive patch for this? Rafael, would
you approve of such a change?
The bug with dynamically added C-states that is tied to this still
hurts the battery life for some users across all distros every day, so
I think it would be valuable to get a consistent solution into the
mainline soon before everyone has to roll their own.
On 11/12/2012 09:26 PM, Daniel Lezcano wrote:
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
From: Rafael J. Wysocki <hidden> Date: 2012-12-10 22:36:57
On Monday, December 10, 2012 11:09:58 AM Julius Werner wrote:
Hi,
What is the current status of this? Daniel, do you think you have got
enough feedback to submit a definitive patch for this? Rafael, would
you approve of such a change?
I need to talk to Len about that before I give you a reliable answer.
Thanks,
Rafael
The bug with dynamically added C-states that is tied to this still
hurts the battery life for some users across all distros every day, so
I think it would be valuable to get a consistent solution into the
mainline soon before everyone has to roll their own.
On 11/12/2012 09:26 PM, Daniel Lezcano wrote:
quoted
This patch follows the discussion about reinitializing the power usage
when a C-state is added/removed.
https://lkml.org/lkml/2012/10/16/518
We realized the power usage field is never filled and when it is
filled for tegra, the power_specified flag is not set making all these
values to be resetted when the driver is initialized with the set_power_state
function.
Julius and I feel this is over-engineered and the power_specified
flag could be simply removed and continue assuming the states are
backward sorted.
The menu governor select function is simplified as the power is ordered.
Actually the condition is always true with the current code.
The cpuidle_play_dead function is also simplified by doing a reverse lookup
on the array.
The set_power_states function is removed as it does no make sense anymore.
Signed-off-by: Daniel Lezcano <redacted>
---
drivers/cpuidle/cpuidle.c | 17 ++++-------------
drivers/cpuidle/driver.c | 25 -------------------------
drivers/cpuidle/governors/menu.c | 8 ++------
include/linux/cpuidle.h | 2 +-
4 files changed, 7 insertions(+), 45 deletions(-)
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.