Skip to content

Commit 85f6a17

Browse files
committed
cpuidle: teo: Avoid code duplication in conditionals
There are three places in teo_select() where a given amount of time is compared with TICK_NSEC if tick_nohz_tick_stopped() returns true, which is a bit of duplicated code. Avoid that code duplication by defining a helper function to do the check and using it in all of the places in question. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 63f202e commit 85f6a17

File tree

1 file changed

+8
-5
lines changed
  • drivers/cpuidle/governors

1 file changed

+8
-5
lines changed

drivers/cpuidle/governors/teo.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
202202
cpu_data->interval_idx = 0;
203203
}
204204

205+
static bool teo_time_ok(u64 interval_ns)
206+
{
207+
return !tick_nohz_tick_stopped() || interval_ns >= TICK_NSEC;
208+
}
209+
205210
/**
206211
* teo_find_shallower_state - Find shallower idle state matching given duration.
207212
* @drv: cpuidle driver containing state data.
@@ -306,8 +311,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
306311
* check if the current candidate state is not too
307312
* shallow for that role.
308313
*/
309-
if (!(tick_nohz_tick_stopped() &&
310-
drv->states[idx].target_residency_ns < TICK_NSEC)) {
314+
if (teo_time_ok(drv->states[idx].target_residency_ns)) {
311315
prev_max_early_idx = max_early_idx;
312316
early_hits = cpu_data->states[i].early_hits;
313317
max_early_idx = idx;
@@ -333,8 +337,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
333337
misses = cpu_data->states[i].misses;
334338

335339
if (early_hits < cpu_data->states[i].early_hits &&
336-
!(tick_nohz_tick_stopped() &&
337-
drv->states[i].target_residency_ns < TICK_NSEC)) {
340+
teo_time_ok(drv->states[i].target_residency_ns)) {
338341
prev_max_early_idx = max_early_idx;
339342
early_hits = cpu_data->states[i].early_hits;
340343
max_early_idx = i;
@@ -402,7 +405,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
402405
* Avoid spending too much time in an idle state that
403406
* would be too shallow.
404407
*/
405-
if (!(tick_nohz_tick_stopped() && avg_ns < TICK_NSEC)) {
408+
if (teo_time_ok(avg_ns)) {
406409
duration_ns = avg_ns;
407410
if (drv->states[idx].target_residency_ns > avg_ns)
408411
idx = teo_find_shallower_state(drv, dev,

0 commit comments

Comments
 (0)