Skip to contentSkip to conversation

cpuidle: enter_state: Don't needlessly calculate diff time

PATCH Applied Fieah Lim 2 participants 2 messages Sep 10, 2018 – Oct 3, 2018 CPU idle time management framework

lore
Share & tools
lore

Fieah Lim

author
#0 lore raw

PATCH v3 1/1 cpuidle: enter_state: Don't needlessly calculate diff time

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.

---
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(-)
drivers/cpuidle/cpuidle.c +7 -8
index 6df894d65d9e..40442c3631ce 100644
@@ -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 {
Signature · 1 line
2.18.0
#1 lore raw
Quoted 40 lines · CEST 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.

---
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(-)
drivers/cpuidle/cpuidle.c +2 -8
index 6df894d65d9e..40442c3631ce 100644
@@ -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,

drivers/cpuidle/cpuidle.c int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, · line 262

Quoted 10 lines
drivers/cpuidle/cpuidle.c +5 -0
 		 * 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!