Skip to content

Commit 672917d

Browse files
czoccolotorvalds
authored andcommitted
cpuidle: menu governor: reduce latency on exit
Move the state residency accounting and statistics computation off the hot exit path. On exit, the need to recompute statistics is recorded, and new statistics will be computed when menu_select is called again. The expected effect is to reduce processor wakeup latency from sleep (C-states). We are speaking of few hundreds of cycles reduction out of a several microseconds latency (determined by the hardware transition), so it is difficult to measure. Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com> Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Cc: Len Brown <len.brown@intel.com> Cc: Adam Belay <abelay@novell.com Acked-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 69d2587 commit 672917d

File tree

1 file changed

+19
-1
lines changed
  • drivers/cpuidle/governors

1 file changed

+19
-1
lines changed

drivers/cpuidle/governors/menu.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
struct menu_device {
9898
int last_state_idx;
99+
int needs_update;
99100

100101
unsigned int expected_us;
101102
u64 predicted_us;
@@ -166,6 +167,8 @@ static inline int performance_multiplier(void)
166167

167168
static DEFINE_PER_CPU(struct menu_device, menu_devices);
168169

170+
static void menu_update(struct cpuidle_device *dev);
171+
169172
/**
170173
* menu_select - selects the next idle state to enter
171174
* @dev: the CPU
@@ -180,6 +183,11 @@ static int menu_select(struct cpuidle_device *dev)
180183
data->last_state_idx = 0;
181184
data->exit_us = 0;
182185

186+
if (data->needs_update) {
187+
menu_update(dev);
188+
data->needs_update = 0;
189+
}
190+
183191
/* Special case when user has set very strict latency requirement */
184192
if (unlikely(latency_req == 0))
185193
return 0;
@@ -231,13 +239,23 @@ static int menu_select(struct cpuidle_device *dev)
231239
}
232240

233241
/**
234-
* menu_reflect - attempts to guess what happened after entry
242+
* menu_reflect - records that data structures need update
235243
* @dev: the CPU
236244
*
237245
* NOTE: it's important to be fast here because this operation will add to
238246
* the overall exit latency.
239247
*/
240248
static void menu_reflect(struct cpuidle_device *dev)
249+
{
250+
struct menu_device *data = &__get_cpu_var(menu_devices);
251+
data->needs_update = 1;
252+
}
253+
254+
/**
255+
* menu_update - attempts to guess what happened after entry
256+
* @dev: the CPU
257+
*/
258+
static void menu_update(struct cpuidle_device *dev)
241259
{
242260
struct menu_device *data = &__get_cpu_var(menu_devices);
243261
int last_idx = data->last_state_idx;

0 commit comments

Comments
 (0)