aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/governors
diff options
context:
space:
mode:
authorAi Li <aili@codeaurora.org>2010-08-09 20:20:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-09 23:45:04 -0400
commit71abbbf856a0e70ca478782505c800891260ba84 (patch)
tree00ae494afd2868056753984035e1bfc0c2040257 /drivers/cpuidle/governors
parentd2997b1042ec150616c1963b5e5e919ffd0b0ebf (diff)
cpuidle: extend cpuidle and menu governor to handle dynamic states
On some SoC chips, HW resources may be in use during any particular idle period. As a consequence, the cpuidle states that the SoC is safe to enter can change from idle period to idle period. In addition, the latency and threshold of each cpuidle state can vary, depending on the operating condition when the CPU becomes idle, e.g. the current cpu frequency, the current state of the HW blocks, etc. cpuidle core and the menu governor, in the current form, are geared towards cpuidle states that are static, i.e. the availabiltiy of the states, their latencies, their thresholds are non-changing during run time. cpuidle does not provide any hook that cpuidle drivers can use to adjust those values on the fly for the current idle period before the menu governor selects the target cpuidle state. This patch extends cpuidle core and the menu governor to handle states that are dynamic. There are three additions in the patch and the patch maintains backwards-compatibility with existing cpuidle drivers. 1) add prepare() to struct cpuidle_device. A cpuidle driver can hook into the callback and cpuidle will call prepare() before calling the governor's select function. The callback gives the cpuidle driver a chance to update the dynamic information of the cpuidle states for the current idle period, e.g. state availability, latencies, thresholds, power values, etc. 2) add CPUIDLE_FLAG_IGNORE as one of the state flags. In the prepare() function, a cpuidle driver can set/clear the flag to indicate to the menu governor whether a cpuidle state should be ignored, i.e. not available, during the current idle period. 3) add power_specified bit to struct cpuidle_device. The menu governor currently assumes that the cpuidle states are arranged in the order of increasing latency, threshold, and power savings. This is true or can be made true for static states. Once the state parameters are dynamic, the latencies, thresholds, and power savings for the cpuidle states can increase or decrease by different amounts from idle period to idle period. So the assumption of increasing latency, threshold, and power savings from Cn to C(n+1) can no longer be guaranteed. It can be straightforward to calculate the power consumption of each available state and to specify it in power_usage for the idle period. Using the power_usage fields, the menu governor then selects the state that has the lowest power consumption and that still satisfies all other critieria. The power_specified bit defaults to 0. For existing cpuidle drivers, cpuidle detects that power_specified is 0 and fills in a dummy set of power_usage values. Signed-off-by: Ai Li <aili@codeaurora.org> Cc: Len Brown <len.brown@intel.com> Acked-by: Arjan van de Ven <arjan@linux.intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Venkatesh Pallipadi <venki@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/cpuidle/governors')
-rw-r--r--drivers/cpuidle/governors/menu.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 1b128702d300..c2408bbe9c2e 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -234,6 +234,7 @@ static int menu_select(struct cpuidle_device *dev)
234{ 234{
235 struct menu_device *data = &__get_cpu_var(menu_devices); 235 struct menu_device *data = &__get_cpu_var(menu_devices);
236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); 236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
237 unsigned int power_usage = -1;
237 int i; 238 int i;
238 int multiplier; 239 int multiplier;
239 240
@@ -278,19 +279,27 @@ static int menu_select(struct cpuidle_device *dev)
278 if (data->expected_us > 5) 279 if (data->expected_us > 5)
279 data->last_state_idx = CPUIDLE_DRIVER_STATE_START; 280 data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
280 281
281 282 /*
282 /* find the deepest idle state that satisfies our constraints */ 283 * Find the idle state with the lowest power while satisfying
284 * our constraints.
285 */
283 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { 286 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) {
284 struct cpuidle_state *s = &dev->states[i]; 287 struct cpuidle_state *s = &dev->states[i];
285 288
289 if (s->flags & CPUIDLE_FLAG_IGNORE)
290 continue;
286 if (s->target_residency > data->predicted_us) 291 if (s->target_residency > data->predicted_us)
287 break; 292 continue;
288 if (s->exit_latency > latency_req) 293 if (s->exit_latency > latency_req)
289 break; 294 continue;
290 if (s->exit_latency * multiplier > data->predicted_us) 295 if (s->exit_latency * multiplier > data->predicted_us)
291 break; 296 continue;
292 data->exit_us = s->exit_latency; 297
293 data->last_state_idx = i; 298 if (s->power_usage < power_usage) {
299 power_usage = s->power_usage;
300 data->last_state_idx = i;
301 data->exit_us = s->exit_latency;
302 }
294 } 303 }
295 304
296 return data->last_state_idx; 305 return data->last_state_idx;