Commit f1c8e410 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

cpuidle: menu: Avoid computations when result will be discarded

If the minimum interval taken into account in the average computation
loop in get_typical_interval() is less than the expected idle
duration determined so far, the resultant average cannot be greater
than that value as well and the entire return result of the function
is going to be discarded anyway going forward.

In that case, it is a waste of time to carry out the remaining
computations in get_typical_interval(), so avoid that by returning
early if the minimum interval is not below the expected idle duration.

No intentional changes of behavior.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 12b65ead
...@@ -196,10 +196,11 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); ...@@ -196,10 +196,11 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
* of points is below a threshold. If it is... then use the * of points is below a threshold. If it is... then use the
* average of these 8 points as the estimated value. * average of these 8 points as the estimated value.
*/ */
static unsigned int get_typical_interval(struct menu_device *data) static unsigned int get_typical_interval(struct menu_device *data,
unsigned int predicted_us)
{ {
int i, divisor; int i, divisor;
unsigned int max, thresh, avg; unsigned int min, max, thresh, avg;
uint64_t sum, variance; uint64_t sum, variance;
thresh = UINT_MAX; /* Discard outliers above this value */ thresh = UINT_MAX; /* Discard outliers above this value */
...@@ -207,6 +208,7 @@ static unsigned int get_typical_interval(struct menu_device *data) ...@@ -207,6 +208,7 @@ static unsigned int get_typical_interval(struct menu_device *data)
again: again:
/* First calculate the average of past intervals */ /* First calculate the average of past intervals */
min = UINT_MAX;
max = 0; max = 0;
sum = 0; sum = 0;
divisor = 0; divisor = 0;
...@@ -217,8 +219,19 @@ static unsigned int get_typical_interval(struct menu_device *data) ...@@ -217,8 +219,19 @@ static unsigned int get_typical_interval(struct menu_device *data)
divisor++; divisor++;
if (value > max) if (value > max)
max = value; max = value;
if (value < min)
min = value;
} }
} }
/*
* If the result of the computation is going to be discarded anyway,
* avoid the computation altogether.
*/
if (min >= predicted_us)
return UINT_MAX;
if (divisor == INTERVALS) if (divisor == INTERVALS)
avg = sum >> INTERVAL_SHIFT; avg = sum >> INTERVAL_SHIFT;
else else
...@@ -325,7 +338,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, ...@@ -325,7 +338,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
/* /*
* Use the lowest expected idle interval to pick the idle state. * Use the lowest expected idle interval to pick the idle state.
*/ */
predicted_us = min(predicted_us, get_typical_interval(data)); predicted_us = min(predicted_us, get_typical_interval(data, predicted_us));
if (tick_nohz_tick_stopped()) { if (tick_nohz_tick_stopped()) {
/* /*
......
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