cpuidle: fix finding state with min power_usage
PATCH 1/2 cpuidle: fix finding state with min power_usage
Since cpuidle_state.power_usage is a signed value, use INT_MAX (instead of -1) to init the local copies so that functions that tries to find cpuidle states with minimum power usage works correctly even if they use non-negative values.
--- drivers/cpuidle/cpuidle.c | 2 +- drivers/cpuidle/governors/menu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle.c +1 -1
@@ -70,7 +70,7 @@ int cpuidle_play_dead(void)struct cpuidle_device *dev =__this_cpu_read (cpuidle_devices);struct cpuidle_driver *drv =cpuidle_get_cpu_driver (dev);int i, dead_state =-1 ; -int power_usage =-1 ; +int power_usage =INT_MAX ;if (!drv)return -ENODEV ;
drivers/cpuidle/governors/menu.c +1 -1
@@ -312,7 +312,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) {struct menu_device *data = &__get_cpu_var (menu_devices);int latency_req =pm_qos_request (PM_QOS_CPU_DMA_LATENCY ); -int power_usage =-1 ; +int power_usage =INT_MAX ;int i;int multiplier;struct timespec t;
Signature · 1 line
1.7.9.5
PATCH 2/2 cpuidle: fix sysfs output for power_usage
cpuidle_state->power_usage is signed; so change the corresponding sysfs ops to output signed value instead of unsigned.
--- drivers/cpuidle/sysfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/cpuidle/sysfs.c +8 -1
@@ -232,6 +232,13 @@ static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store) static ssize_t show_state_##_name(struct cpuidle_state *state, \struct cpuidle_state_usage *state_usage,char *buf) \ { \ +return sprintf (buf,"%d\n" , state->_name);\ +} + +#define define_show_state_u_function (_name) \ +static ssize_t show_state_##_name(struct cpuidle_state *state, \ + struct cpuidle_state_usage *state_usage, char *buf) \ +{ \ return sprintf(buf, "%u\n", state->_name);\ }
@@ -270,7 +277,7 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, \return sprintf (buf,"%s\n" , state->_name);\ } -define_show_state_function(exit_latency) +define_show_state_u_function(exit_latency) define_show_state_function(power_usage) define_show_state_ull_function(usage) define_show_state_ull_function(time)
Signature · 1 line
1.7.9.5
Re: [PATCH 2/2] cpuidle: fix sysfs output for power_usage
Quoted 2 lines · Sivaram Nair
cpuidle_state->power_usageis signed; so change the corresponding sysfs ops to output signed value instead of unsigned.
What's actually wrong with printing it as an unsigned int?
Rafael
Quoted 33 lines
Signed-off-by Sivaram Nair <[email protected]>--- drivers/cpuidle/sysfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/cpuidle/sysfs.c +8
-1@@ -232,6 +232,13 @@ static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store) static ssize_t show_state_##_name(struct cpuidle_state *state, \struct cpuidle_state_usage *state_usage,char *buf) \ { \ +return sprintf (buf,"%d\n" , state->_name);\ +} + +#define define_show_state_u_function (_name) \ +static ssize_t show_state_##_name(struct cpuidle_state *state, \ + struct cpuidle_state_usage *state_usage, char *buf) \ +{ \ return sprintf(buf, "%u\n", state->_name);\ }@@ -270,7 +277,7 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, \return sprintf (buf,"%s\n" , state->_name);\ } -define_show_state_function(exit_latency) +define_show_state_u_function(exit_latency) define_show_state_function(power_usage) define_show_state_ull_function(usage) define_show_state_ull_function(time)
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 2/2] cpuidle: fix sysfs output for power_usage
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Sivaram Nair
cpuidle_state->power_usageis signed; so change the corresponding sysfs ops to output signed value instead of unsigned.What's actually wrong with printing it as an unsigned int?
power_usage could have negative values (for example cpuidle/driver.c inits this value to -1, -2 etc. when drv->power_specified is not set) and these shows up badly in the sysfs output.
regards,
Sivaram
Re: [PATCH 2/2] cpuidle: fix sysfs output for power_usage
Quoted 10 lines · Sivaram Nair
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Sivaram Nair
cpuidle_state->power_usageis signed; so change the corresponding sysfs ops to output signed value instead of unsigned.What's actually wrong with printing it as an unsigned int?
power_usagecould have negative values (for examplecpuidle/driver.cinits this value to -1, -2 etc. whendrv->power_specifiedis not set) and these shows up badly in the sysfs output.
Does "badly" mean "as big positive numbers"?
Should we actually print them at all in those case? Perhaps it'll be better to make the file appear empty then?
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 2/2] cpuidle: fix sysfs output for power_usage
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Sivaram Nair
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Sivaram Nair
cpuidle_state->power_usageis signed; so change the corresponding sysfs ops to output signed value instead of unsigned.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
What's actually wrong with printing it as an unsigned int?
power_usagecould have negative values (for examplecpuidle/driver.cinits this value to -1, -2 etc. whendrv->power_specifiedis not set) and these shows up badly in the sysfs output.Does "badly" mean "as big positive numbers"?
Yes (sorry for not being clearer).
Quoted 3 lines
Should we actually print them at all in those case? Perhaps it'll be better to make the file appear empty then?
May be, but why is power_usage signed in the first place? I also noticed Daniel Lezcano's patches that reduces the scope of this variable. So, perhaps we can just ignore this change.
-Sivaram
Re: [PATCH 2/2] cpuidle: fix sysfs output for power_usage
Quoted 15 lines · Sivaram Nair
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Sivaram Nair
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Sivaram Nair
cpuidle_state->power_usageis signed; so change the corresponding sysfs ops to output signed value instead of unsigned.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
What's actually wrong with printing it as an unsigned int?
power_usagecould have negative values (for examplecpuidle/driver.cinits this value to -1, -2 etc. whendrv->power_specifiedis not set) and these shows up badly in the sysfs output.Does "badly" mean "as big positive numbers"?
Quoted 7 lines
Yes (sorry for not being clearer).
Quoted 3 lines
Should we actually print them at all in those case? Perhaps it'll be better to make the file appear empty then?
May be, but why is
power_usagesigned in the first place?
Please read the comment in driver.c:set_power_states() for the answer. :-)
Quoted 3 lines
I also noticed
Daniel Lezcano's patches that reduces the scope of this variable. So, perhaps we can just ignore this change.
OK
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 6 lines · Sivaram Nair
Since cpuidle_state.power_usage is a signed value, use
INT_MAX(instead of -1) to init the local copies so that functions that tries to find cpuidle states with minimum power usage works correctly even if they use non-negative values.Signed-off-by Sivaram Nair <[email protected]>
Signature · 1 line
All rights reversed
Quoted 4 lines · Sivaram Nair
Since cpuidle_state.power_usage is a signed value, use
INT_MAX(instead of -1) to init the local copies so that functions that tries to find cpuidle states with minimum power usage works correctly even if they use non-negative values.
I'm queuing this up for submission as v3.8 material.
Thanks,
Rafael
Quoted 33 lines
Signed-off-by Sivaram Nair <[email protected]>--- drivers/cpuidle/cpuidle.c | 2 +- drivers/cpuidle/governors/menu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/cpuidle/cpuidle.c +1
-1@@ -70,7 +70,7 @@ int cpuidle_play_dead(void)struct cpuidle_device *dev =__this_cpu_read (cpuidle_devices);struct cpuidle_driver *drv =cpuidle_get_cpu_driver (dev);int i, dead_state =-1 ; -int power_usage =-1 ; +int power_usage =INT_MAX ;if (!drv)return -ENODEV ;drivers/cpuidle/governors/menu.c +1
-1@@ -312,7 +312,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) {struct menu_device *data = &__get_cpu_var (menu_devices);int latency_req =pm_qos_request (PM_QOS_CPU_DMA_LATENCY ); -int power_usage =-1 ; +int power_usage =INT_MAX ;int i;int multiplier;struct timespec t;
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.