Skip to contentSkip to conversation

cpuidle: Fix incorrect optimization

PATCH New Arjan van de Ven 1 participant 1 message May 8, 2010 CPU idle time management framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuidle: Fix incorrect optimization

Quoted 1 line

From 264ad94308de7c120a2c2b15acdb2973304c51c9 Mon Sep 17 00:00:00 2001

From: Arjan van de Ven <[email protected]>
Date: Sat, 8 May 2010 15:47:37 -0700
Subject: [PATCH] cpuidle: Fix incorrect optimization

commit 672917dcc781ead7652a8b11b1fba14e38ac15b8 added an optimization, where the analysis on the past idle period moved from the end of idle, to the beginning of the new idle.

Unfortunately, this optimization had a bug where it zeroed one key variable for new use, that is needed for the analysis. The fix is simple, zero the variable after doing the work from the previous idle.

During the audit of the code that found this issue, another issue was also found; the ->measured_us data structure member is never set, a local variable is always used instead.

Cc Corrado Zoccolo <[email protected]>
---
 drivers/cpuidle/governors/menu.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
drivers/cpuidle/governors/menu.c +4 -5
index 1aea715..f8e57c6 100644
@@ -100,7 +100,6 @@ struct menu_device {
 	int             needs_update;
 
 	unsigned int	expected_us;
-	unsigned int	measured_us;
 	u64		predicted_us;
 	unsigned int	exit_us;
 	unsigned int	bucket;
@@ -187,14 +186,14 @@ static int menu_select(struct cpuidle_device *dev)
 	int i;
 	int multiplier;
 
-	data->last_state_idx = 0;
-	data->exit_us = 0;
-
 	if (data->needs_update) {
 		menu_update(dev);
 		data->needs_update = 0;
 	}
 
+	data->last_state_idx = 0;
+	data->exit_us = 0;
+
 	/* Special case when user has set very strict latency requirement */
 	if (unlikely(latency_req == 0))
 		return 0;
@@ -294,7 +293,7 @@ static void menu_update(struct cpuidle_device *dev)
 	new_factor = data->correction_factor[data->bucket]
 			* (DECAY - 1) / DECAY;
 
-	if (data->expected_us > 0 && data->measured_us < MAX_INTERESTING)
+	if (data->expected_us > 0 && measured_us < MAX_INTERESTING)
 		new_factor += RESOLUTION * measured_us / data->expected_us;
 	else
 		/*
Signature · 1 line
1.6.2.5