Commit 85f6a17f authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 63f202e5
...@@ -202,6 +202,11 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) ...@@ -202,6 +202,11 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
cpu_data->interval_idx = 0; cpu_data->interval_idx = 0;
} }
static bool teo_time_ok(u64 interval_ns)
{
return !tick_nohz_tick_stopped() || interval_ns >= TICK_NSEC;
}
/** /**
* teo_find_shallower_state - Find shallower idle state matching given duration. * teo_find_shallower_state - Find shallower idle state matching given duration.
* @drv: cpuidle driver containing state data. * @drv: cpuidle driver containing state data.
...@@ -306,8 +311,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, ...@@ -306,8 +311,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
* check if the current candidate state is not too * check if the current candidate state is not too
* shallow for that role. * shallow for that role.
*/ */
if (!(tick_nohz_tick_stopped() && if (teo_time_ok(drv->states[idx].target_residency_ns)) {
drv->states[idx].target_residency_ns < TICK_NSEC)) {
prev_max_early_idx = max_early_idx; prev_max_early_idx = max_early_idx;
early_hits = cpu_data->states[i].early_hits; early_hits = cpu_data->states[i].early_hits;
max_early_idx = idx; max_early_idx = idx;
...@@ -333,8 +337,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, ...@@ -333,8 +337,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
misses = cpu_data->states[i].misses; misses = cpu_data->states[i].misses;
if (early_hits < cpu_data->states[i].early_hits && if (early_hits < cpu_data->states[i].early_hits &&
!(tick_nohz_tick_stopped() && teo_time_ok(drv->states[i].target_residency_ns)) {
drv->states[i].target_residency_ns < TICK_NSEC)) {
prev_max_early_idx = max_early_idx; prev_max_early_idx = max_early_idx;
early_hits = cpu_data->states[i].early_hits; early_hits = cpu_data->states[i].early_hits;
max_early_idx = i; max_early_idx = i;
...@@ -402,7 +405,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, ...@@ -402,7 +405,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
* Avoid spending too much time in an idle state that * Avoid spending too much time in an idle state that
* would be too shallow. * would be too shallow.
*/ */
if (!(tick_nohz_tick_stopped() && avg_ns < TICK_NSEC)) { if (teo_time_ok(avg_ns)) {
duration_ns = avg_ns; duration_ns = avg_ns;
if (drv->states[idx].target_residency_ns > avg_ns) if (drv->states[idx].target_residency_ns > avg_ns)
idx = teo_find_shallower_state(drv, dev, idx = teo_find_shallower_state(drv, dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment