cpuidle: Time accounting fix
Subsystems (2)
cover cpuidle: Time accounting fix
As noted in PM minisummit notes here
http://lwn.net/Articles/292447/
Richard Woodruff <[email protected]> reported a bug
"the CPUIDLE bug that if target is avoided due to BM activity the original target state is still accounted the time."
Following provides a mechanism to fix the problem for all drivers and fixes the problem for acpi cpuidle driver.
PATCH 1/2 cpuidle: use last_state which can reflect the actual state entered
cpuidle accounts the idle time for the C-state it was trying to enter and not to the actual state that the driver eventually entered. The driver may select a different state than the one chosen by cpuidle due to constraints like bus-mastering, etc.
Change the time acounting code to look at the dev->last_state after returning from target_state->enter(). Driver can modify dev->last_state internally, inside the enter routine to reflect the actual C-state entered.
--- drivers/cpuidle/cpuidle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/cpuidle/cpuidle.c +4 -1
@@ -71,8 +71,11 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; + dev->last_residency = target_state->enter (dev, target_state); +if (dev->last_state) + target_state = dev->last_state; + target_state->time += (unsigned long long )dev->last_residency; target_state->usage++;
Re: [patch 1/2] cpuidle: use last_state which can reflect the actual state entered
Quoted 22 lines · Venkatesh Pallipadi
cpuidle accounts the idle time for the C-state it was trying to enter and not to the actual state that the driver eventually entered. The driver may select a different state than the one chosen by cpuidle due to constraints like bus-mastering, etc.
Change the time acounting code to look at the
dev->last_stateafter returning fromtarget_state->enter(). Driver can modifydev->last_stateinternally, inside the enter routine to reflect the actual C-state entered.Signed-off-by Venkatesh Pallipadi <[email protected]>--- drivers/cpuidle/cpuidle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
tip/drivers/cpuidle/cpuidle.c
===================================================================drivers/cpuidle/cpuidle.c +0
-0@@ -71,8 +71,11 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];
drivers/cpuidle/cpuidle.c static void cpuidle_idle_call(void) · line 80
Quoted 10 lines
drivers/cpuidle/cpuidle.c +4
-1/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; + dev->last_residency = target_state->enter (dev, target_state); +if (dev->last_state) + target_state = dev->last_state; + target_state->time += (unsigned long long )dev->last_residency; target_state->usage++;
Under what conditions would the enter hook set dev->last_sate to NULL? Having the check seems to indicate it's possilble.
A minor nit-pick... why not explicitly do the accounting using 'last_state' like below. While functionally the same as above, this makes it makes it more explicit when reading the code that the accounting is done using 'last_state' and not 'target_state.'
Kevin
drivers/cpuidle/cpuidle.c +3 -3
@@ -67,10 +67,10 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; - target_state->time += (unsigned long long )dev->last_residency; - target_state->usage++; + dev->last_residency = target_state->enter (dev, target_state); + dev->last_state->time += (unsigned long long )dev->last_residency; + dev->last_state->usage++;/* give the governor an opportunity to reflect on the outcome */ if (cpuidle_curr_governor->reflect)
Re: [patch 1/2] cpuidle: use last_state which can reflect the actual state entered
Quoted 40 lines
-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Wednesday, October 01, 2008 4:09 AM
To: Pallipadi, Venkatesh
Cc: [email protected]; [email protected]
Subject: Re: [linux-pm] [patch 1/2] cpuidle: uselast_statewhich can reflect the actual state enteredQuoted 1 line · Venkatesh Pallipadi
cpuidle accounts the idle time for the C-state it was trying
to enter and
Quoted 1 line
not to the actual state that the driver eventually entered.
The driver may
Quoted 5 lines
select a different state than the one chosen by cpuidle due to constraints like bus-mastering, etc.
Change the time acounting code to look at the
dev->last_stateafter returning fromtarget_state->enter(). Driver can modify
dev->last_stateQuoted 5 lines
internally, inside the enter routine to reflect the actual C-state entered.
Signed-off-by Venkatesh Pallipadi <[email protected]>Quoted 7 lines
--- drivers/cpuidle/cpuidle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
tip/drivers/cpuidle/cpuidle.c
===================================================================
---tip.orig/drivers/cpuidle/cpuidle.c2008-09-2313:52:59.000000000 -0700
Quoted 1 line
+++
tip/drivers/cpuidle/cpuidle.c2008-09-2314:22:43.000000000 -0700
Quoted 3 lines
drivers/cpuidle/cpuidle.c +0
-0@@ -71,8 +71,11 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];
Quoted 12 lines
Review static void cpuidle_idle_call(void) · line 80
Quoted 9 lines
(quoted diff) +4
-1/* enter the state and update stats */ - dev->last_residency = target_state->enter(dev, target_state); dev->last_state = target_state; + dev->last_residency = target_state->enter(dev, target_state); + if (dev->last_state) + target_state = dev->last_state; + target_state->time += (unsigned long long)dev->last_residency; target_state->usage++;Under what conditions would the enter hook set
dev->last_sateto NULL? Having the check seems to indicate it's possilble.
Sorry about the delayed response.
Yes. I added the check after finding out that last_state can be possibly NULL. That happens when the governor changes while one core is in idle and also during CPU offline/online.
Quoted 5 lines
A minor nit-pick... why not explicitly do the accounting using '
last_state' like below. While functionally the same as above, this makes it makes it more explicit when reading the code that the accounting is done using 'last_state' and not 'target_state.'
Yes. It is cleaner. But, we still have to check for last_state being NULL.
Quoted 21 lines
drivers/cpuidle/cpuidle.c +3
-3@@ -67,10 +67,10 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; - target_state->time += (unsigned long long )dev->last_residency; - target_state->usage++; + dev->last_residency = target_state->enter (dev, target_state); + dev->last_state->time += (unsigned long long )dev->last_residency; + dev->last_state->usage++;/* give the governor an opportunity to reflect on the outcome */
Quoted 2 lines
if (cpuidle_curr_governor->reflect)
Thanks,
Venki
Kevin Hilman
Tested-byRe: [patch 1/2] cpuidle: use last_state which can reflect the actual state entered
Quoted 43 lines · Venkatesh
Quoted 30 lines
Quoted 1 line · Venkatesh Pallipadi
cpuidle accounts the idle time for the C-state it was trying
to enter and
Quoted 1 line
not to the actual state that the driver eventually entered.
The driver may
Quoted 5 lines
select a different state than the one chosen by cpuidle due to constraints like bus-mastering, etc.
Change the time acounting code to look at the
dev->last_stateafter returning fromtarget_state->enter(). Driver can modify
dev->last_stateQuoted 5 lines
internally, inside the enter routine to reflect the actual C-state entered.
Signed-off-by Venkatesh Pallipadi <[email protected]>Quoted 7 lines
--- drivers/cpuidle/cpuidle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
tip/drivers/cpuidle/cpuidle.c
===================================================================
---tip.orig/drivers/cpuidle/cpuidle.c2008-09-2313:52:59.000000000 -0700
Quoted 1 line
+++
tip/drivers/cpuidle/cpuidle.c2008-09-2314:22:43.000000000 -0700
Quoted 3 lines
drivers/cpuidle/cpuidle.c +0
-0@@ -71,8 +71,11 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];Quoted 12 lines
Review static void cpuidle_idle_call(void) · line 80
Quoted 9 lines
(quoted diff) +4
-1/* enter the state and update stats */ - dev->last_residency = target_state->enter(dev, target_state); dev->last_state = target_state; + dev->last_residency = target_state->enter(dev, target_state); + if (dev->last_state) + target_state = dev->last_state; + target_state->time += (unsigned long long)dev->last_residency; target_state->usage++;Under what conditions would the enter hook set
dev->last_sateto NULL? Having the check seems to indicate it's possilble.
Quoted 5 lines
Sorry about the delayed response.
Yes. I added the check after finding out that
last_statecan be possibly NULL. That happens when the governor changes while one core is in idle and also during CPU offline/online.
OK, thanks for the clarification.
Quoted 7 lines
Quoted 5 lines
A minor nit-pick... why not explicitly do the accounting using '
last_state' like below. While functionally the same as above, this makes it makes it more explicit when reading the code that the accounting is done using 'last_state' and not 'target_state.'Yes. It is cleaner. But, we still have to check for
last_statebeing NULL.
Agreed.
I've switched to your version and tested this on OMAP3 and it's working well.
Quoted 26 lines
Quoted 21 lines
drivers/cpuidle/cpuidle.c +3
-3@@ -67,10 +67,10 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; - target_state->time += (unsigned long long )dev->last_residency; - target_state->usage++; + dev->last_residency = target_state->enter (dev, target_state); + dev->last_state->time += (unsigned long long )dev->last_residency; + dev->last_state->usage++;/* give the governor an opportunity to reflect on the outcome */
Quoted 2 lines
if (cpuidle_curr_governor->reflect)Thanks,
Venki
Len Brown
reviewerRe: [patch 1/2] cpuidle: use last_state which can reflect the actual state entered
In reply to Venkatesh Pallipadi1,2 applied.
thanks,
-len
Quoted 36 lines · Venkatesh Pallipadi
cpuidle accounts the idle time for the C-state it was trying to enter and not to the actual state that the driver eventually entered. The driver may select a different state than the one chosen by cpuidle due to constraints like bus-mastering, etc.
Change the time acounting code to look at the
dev->last_stateafter returning fromtarget_state->enter(). Driver can modifydev->last_stateinternally, inside the enter routine to reflect the actual C-state entered.Signed-off-by Venkatesh Pallipadi <[email protected]>--- drivers/cpuidle/cpuidle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
tip/drivers/cpuidle/cpuidle.c
===================================================================drivers/cpuidle/cpuidle.c +4
-1@@ -71,8 +71,11 @@ static void cpuidle_idle_call(void) target_state = &dev->states[next_state];/* enter the state and update stats */ - dev->last_residency = target_state->enter (dev, target_state); dev->last_state = target_state; + dev->last_residency = target_state->enter (dev, target_state); +if (dev->last_state) + target_state = dev->last_state; + target_state->time += (unsigned long long )dev->last_residency; target_state->usage++;Signature · 1 line
--
PATCH 2/2 cpuidle: update the last_state acpi cpuidle reflecting actual state entered
In reply to Venkatesh Pallipadireflect the actual state entered in dev->last_state, when actaul state entered is different from intended one.
--- drivers/acpi/processor_idle.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/processor_idle.c +1 -0
@@ -1587,6 +1587,7 @@ static int acpi_idle_enter_bm(struct cpuif (acpi_idle_bm_check ()) {if (dev->safe_state) { + dev->last_state = dev->safe_state;return dev->safe_state->enter (dev, dev->safe_state); }else {local_irq_disable ();