Skip to content

Commit d834e68

Browse files
committed
cpuidle: governors: teo: Simplify intercepts-based state lookup
Simplify the loop looking up a candidate idle state in the case when an intercept is likely to occur by adding a search for the state index limit if the tick is stopped before it. First, call tick_nohz_tick_stopped() just once and if it returns true, look for the shallowest state index below the current candidate one with target residency at least equal to the tick period length. Next, simply look for a state that is not shallower than the one found in the previous step and satisfies the intercepts majority condition (if there are no such states, the shallowest state that is not shallower than the one found in the previous step becomes the new candidate). Since teo_state_ok() has no callers any more after the above changes, drop it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Christian Loehle <christian.loehle@arm.com> [ rjw: Changelog clarification and code comment edit ] Link: https://patch.msgid.link/2418792.ElGaqSPkdT@rafael.j.wysocki Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 50db438 commit d834e68

1 file changed

Lines changed: 16 additions & 46 deletions

File tree

  • drivers/cpuidle/governors

drivers/cpuidle/governors/teo.c

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
256256
}
257257
}
258258

259-
static bool teo_state_ok(int i, struct cpuidle_driver *drv)
260-
{
261-
return !tick_nohz_tick_stopped() ||
262-
drv->states[i].target_residency_ns >= TICK_NSEC;
263-
}
264-
265259
/**
266260
* teo_find_shallower_state - Find shallower idle state matching given duration.
267261
* @drv: cpuidle driver containing state data.
@@ -383,7 +377,18 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
383377
* better choice.
384378
*/
385379
if (2 * idx_intercept_sum > cpu_data->total - idx_hit_sum) {
386-
int first_suitable_idx = idx;
380+
int min_idx = idx0;
381+
382+
if (tick_nohz_tick_stopped()) {
383+
/*
384+
* Look for the shallowest idle state below the current
385+
* candidate one whose target residency is at least
386+
* equal to the tick period length.
387+
*/
388+
while (min_idx < idx &&
389+
drv->states[min_idx].target_residency_ns < TICK_NSEC)
390+
min_idx++;
391+
}
387392

388393
/*
389394
* Look for the deepest idle state whose target residency had
@@ -393,49 +398,14 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
393398
* Take the possible duration limitation present if the tick
394399
* has been stopped already into account.
395400
*/
396-
intercept_sum = 0;
397-
398-
for (i = idx - 1; i >= 0; i--) {
399-
struct teo_bin *bin = &cpu_data->state_bins[i];
400-
401-
intercept_sum += bin->intercepts;
402-
403-
if (2 * intercept_sum > idx_intercept_sum) {
404-
/*
405-
* Use the current state unless it is too
406-
* shallow or disabled, in which case take the
407-
* first enabled state that is deep enough.
408-
*/
409-
if (teo_state_ok(i, drv) &&
410-
!dev->states_usage[i].disable) {
411-
idx = i;
412-
break;
413-
}
414-
idx = first_suitable_idx;
415-
break;
416-
}
401+
for (i = idx - 1, intercept_sum = 0; i >= min_idx; i--) {
402+
intercept_sum += cpu_data->state_bins[i].intercepts;
417403

418404
if (dev->states_usage[i].disable)
419405
continue;
420406

421-
if (teo_state_ok(i, drv)) {
422-
/*
423-
* The current state is deep enough, but still
424-
* there may be a better one.
425-
*/
426-
first_suitable_idx = i;
427-
continue;
428-
}
429-
430-
/*
431-
* The current state is too shallow, so if no suitable
432-
* states other than the initial candidate have been
433-
* found, give up (the remaining states to check are
434-
* shallower still), but otherwise the first suitable
435-
* state other than the initial candidate may turn out
436-
* to be preferable.
437-
*/
438-
if (first_suitable_idx == idx)
407+
idx = i;
408+
if (2 * intercept_sum > idx_intercept_sum)
439409
break;
440410
}
441411
}

0 commit comments

Comments
 (0)