linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] cpuidle: enter_state: Don't needlessly calculate diff time
@ 2018-09-10 21:47 Fieah Lim
  2018-10-03  9:42 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Fieah Lim @ 2018-09-10 21:47 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, open list:CPUIDLE DRIVERS, open list
  Cc: Fieah Lim

Currently we use ktime_us_delta() to calculate last residency and
state usage unconditionally, it makes no sense to do this calculation
when we fails to enter any idle state.
It can be optimize by moving the calculation after entered_state >= 0

While at it, merge those comment blocks into one and remove a
space between type casting of diff.

This patch has no functional changes.

Signed-off-by: Fieah Lim <kw@fieahl.im>
---
Changes from v1:
 - Rewrite changelog as Rafael J. Wysocki suggested
Changes from v2:
 - Minor adjustment
---
 drivers/cpuidle/cpuidle.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 6df894d65d9e..40442c3631ce 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -247,17 +247,16 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
 	if (!cpuidle_state_is_coupled(drv, index))
 		local_irq_enable();
 
-	diff = ktime_us_delta(time_end, time_start);
-	if (diff > INT_MAX)
-		diff = INT_MAX;
-
-	dev->last_residency = (int) diff;
-
 	if (entered_state >= 0) {
-		/* Update cpuidle counters */
-		/* This can be moved to within driver enter routine
+		/* Update cpuidle counters
+		 * This can be moved to within driver enter routine,
 		 * but that results in multiple copies of same code.
 		 */
+		diff = ktime_us_delta(time_end, time_start);
+		if (diff > INT_MAX)
+			diff = INT_MAX;
+
+		dev->last_residency = (int)diff;
 		dev->states_usage[entered_state].time += dev->last_residency;
 		dev->states_usage[entered_state].usage++;
 	} else {
-- 
2.18.0


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

* Re: [PATCH v3] cpuidle: enter_state: Don't needlessly calculate diff time
  2018-09-10 21:47 [PATCH v3] cpuidle: enter_state: Don't needlessly calculate diff time Fieah Lim
@ 2018-10-03  9:42 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2018-10-03  9:42 UTC (permalink / raw)
  To: Fieah Lim; +Cc: Daniel Lezcano, open list:CPUIDLE DRIVERS, open list

On Monday, September 10, 2018 11:47:25 PM CEST Fieah Lim wrote:
> Currently we use ktime_us_delta() to calculate last residency and
> state usage unconditionally, it makes no sense to do this calculation
> when we fails to enter any idle state.
> It can be optimize by moving the calculation after entered_state >= 0
> 
> While at it, merge those comment blocks into one and remove a
> space between type casting of diff.
> 
> This patch has no functional changes.
> 
> Signed-off-by: Fieah Lim <kw@fieahl.im>
> ---
> Changes from v1:
>  - Rewrite changelog as Rafael J. Wysocki suggested
> Changes from v2:
>  - Minor adjustment
> ---
>  drivers/cpuidle/cpuidle.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index 6df894d65d9e..40442c3631ce 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -247,17 +247,16 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
>  	if (!cpuidle_state_is_coupled(drv, index))
>  		local_irq_enable();
>  
> -	diff = ktime_us_delta(time_end, time_start);
> -	if (diff > INT_MAX)
> -		diff = INT_MAX;
> -
> -	dev->last_residency = (int) diff;
> -
>  	if (entered_state >= 0) {
> -		/* Update cpuidle counters */
> -		/* This can be moved to within driver enter routine
> +		/* Update cpuidle counters
> +		 * This can be moved to within driver enter routine,
>  		 * but that results in multiple copies of same code.
>  		 */
> +		diff = ktime_us_delta(time_end, time_start);
> +		if (diff > INT_MAX)
> +			diff = INT_MAX;
> +
> +		dev->last_residency = (int)diff;
>  		dev->states_usage[entered_state].time += dev->last_residency;
>  		dev->states_usage[entered_state].usage++;
>  	} else {
> 

Applied, thanks!



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

end of thread, other threads:[~2018-10-03  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10 21:47 [PATCH v3] cpuidle: enter_state: Don't needlessly calculate diff time Fieah Lim
2018-10-03  9:42 ` Rafael J. Wysocki

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).