Skip to content

Commit 6da8f9b

Browse files
committed
cpuidle: teo: Skip tick_nohz_get_sleep_length() call in some cases
Make teo_select() avoid calling tick_nohz_get_sleep_length() if the candidate idle state to return is state 0 or if state 0 is a polling one and the target residency of the current candidate one is below a certain threshold, in which cases it may be assumed that the CPU will be woken up immediately by a non-timer wakeup source and the timers are not likely to matter. Signed-off-by: Rafael J. Wysocki <[email protected]> Tested-by: Kajetan Puchalski <[email protected]> Tested-by: Anna-Maria Behnsen <[email protected]>
1 parent 21d28cd commit 6da8f9b

File tree

1 file changed

+22
-0
lines changed
  • drivers/cpuidle/governors

1 file changed

+22
-0
lines changed

drivers/cpuidle/governors/teo.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@
166166
*/
167167
#define NR_RECENT 9
168168

169+
/*
170+
* Idle state target residency threshold used for deciding whether or not to
171+
* check the time till the closest expected timer event.
172+
*/
173+
#define RESIDENCY_THRESHOLD_NS (15 * NSEC_PER_USEC)
174+
169175
/**
170176
* struct teo_bin - Metrics used by the TEO cpuidle governor.
171177
* @intercepts: The "intercepts" metric.
@@ -542,6 +548,22 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
542548
idx = i;
543549
}
544550

551+
/*
552+
* Skip the timers check if state 0 is the current candidate one,
553+
* because an immediate non-timer wakeup is expected in that case.
554+
*/
555+
if (!idx)
556+
goto out_tick;
557+
558+
/*
559+
* If state 0 is a polling one, check if the target residency of
560+
* the current candidate state is low enough and skip the timers
561+
* check in that case too.
562+
*/
563+
if ((drv->states[0].flags & CPUIDLE_FLAG_POLLING) &&
564+
drv->states[idx].target_residency_ns < RESIDENCY_THRESHOLD_NS)
565+
goto out_tick;
566+
545567
duration_ns = tick_nohz_get_sleep_length(&delta_tick);
546568
cpu_data->sleep_length_ns = duration_ns;
547569

0 commit comments

Comments
 (0)