aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/cpuidle/governors/menu.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index beef7ae123ba..27fc733cb5b9 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -199,8 +199,8 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
199static void get_typical_interval(struct menu_device *data) 199static void get_typical_interval(struct menu_device *data)
200{ 200{
201 int i, divisor; 201 int i, divisor;
202 unsigned int max, thresh; 202 unsigned int max, thresh, avg;
203 uint64_t avg, variance; 203 uint64_t sum, variance;
204 204
205 thresh = UINT_MAX; /* Discard outliers above this value */ 205 thresh = UINT_MAX; /* Discard outliers above this value */
206 206
@@ -208,28 +208,28 @@ again:
208 208
209 /* First calculate the average of past intervals */ 209 /* First calculate the average of past intervals */
210 max = 0; 210 max = 0;
211 avg = 0; 211 sum = 0;
212 divisor = 0; 212 divisor = 0;
213 for (i = 0; i < INTERVALS; i++) { 213 for (i = 0; i < INTERVALS; i++) {
214 unsigned int value = data->intervals[i]; 214 unsigned int value = data->intervals[i];
215 if (value <= thresh) { 215 if (value <= thresh) {
216 avg += value; 216 sum += value;
217 divisor++; 217 divisor++;
218 if (value > max) 218 if (value > max)
219 max = value; 219 max = value;
220 } 220 }
221 } 221 }
222 if (divisor == INTERVALS) 222 if (divisor == INTERVALS)
223 avg >>= INTERVAL_SHIFT; 223 avg = sum >> INTERVAL_SHIFT;
224 else 224 else
225 do_div(avg, divisor); 225 avg = div_u64(sum, divisor);
226 226
227 /* Then try to determine variance */ 227 /* Then try to determine variance */
228 variance = 0; 228 variance = 0;
229 for (i = 0; i < INTERVALS; i++) { 229 for (i = 0; i < INTERVALS; i++) {
230 unsigned int value = data->intervals[i]; 230 unsigned int value = data->intervals[i];
231 if (value <= thresh) { 231 if (value <= thresh) {
232 int64_t diff = value - avg; 232 int64_t diff = (int64_t)value - avg;
233 variance += diff * diff; 233 variance += diff * diff;
234 } 234 }
235 } 235 }
@@ -251,7 +251,7 @@ again:
251 * Use this result only if there is no timer to wake us up sooner. 251 * Use this result only if there is no timer to wake us up sooner.
252 */ 252 */
253 if (likely(variance <= U64_MAX/36)) { 253 if (likely(variance <= U64_MAX/36)) {
254 if (((avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3)) 254 if ((((u64)avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3))
255 || variance <= 400) { 255 || variance <= 400) {
256 if (data->next_timer_us > avg) 256 if (data->next_timer_us > avg)
257 data->predicted_us = avg; 257 data->predicted_us = avg;