提交 3b99669b 编写于 作者: R Rasmus Villemoes 提交者: Rafael J. Wysocki

cpuidle: menu: help gcc generate slightly better code

We know that the avg variable actually ends up holding a 32 bit
quantity, since it's an average of such numbers. It is only a u64
because it is temporarily used to hold the sum. Making it an actual
u32 allows gcc to generate slightly better code, e.g. when computing
the square, it can do a 32x32->64 multiply.
Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 7024b18c
...@@ -199,8 +199,8 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); ...@@ -199,8 +199,8 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
static void get_typical_interval(struct menu_device *data) static void get_typical_interval(struct menu_device *data)
{ {
int i, divisor; int i, divisor;
unsigned int max, thresh; unsigned int max, thresh, avg;
uint64_t avg, variance; uint64_t sum, variance;
thresh = UINT_MAX; /* Discard outliers above this value */ thresh = UINT_MAX; /* Discard outliers above this value */
...@@ -208,28 +208,28 @@ static void get_typical_interval(struct menu_device *data) ...@@ -208,28 +208,28 @@ static void get_typical_interval(struct menu_device *data)
/* First calculate the average of past intervals */ /* First calculate the average of past intervals */
max = 0; max = 0;
avg = 0; sum = 0;
divisor = 0; divisor = 0;
for (i = 0; i < INTERVALS; i++) { for (i = 0; i < INTERVALS; i++) {
unsigned int value = data->intervals[i]; unsigned int value = data->intervals[i];
if (value <= thresh) { if (value <= thresh) {
avg += value; sum += value;
divisor++; divisor++;
if (value > max) if (value > max)
max = value; max = value;
} }
} }
if (divisor == INTERVALS) if (divisor == INTERVALS)
avg >>= INTERVAL_SHIFT; avg = sum >> INTERVAL_SHIFT;
else else
do_div(avg, divisor); avg = div_u64(sum, divisor);
/* Then try to determine variance */ /* Then try to determine variance */
variance = 0; variance = 0;
for (i = 0; i < INTERVALS; i++) { for (i = 0; i < INTERVALS; i++) {
unsigned int value = data->intervals[i]; unsigned int value = data->intervals[i];
if (value <= thresh) { if (value <= thresh) {
int64_t diff = value - avg; int64_t diff = (int64_t)value - avg;
variance += diff * diff; variance += diff * diff;
} }
} }
...@@ -251,7 +251,7 @@ static void get_typical_interval(struct menu_device *data) ...@@ -251,7 +251,7 @@ static void get_typical_interval(struct menu_device *data)
* Use this result only if there is no timer to wake us up sooner. * Use this result only if there is no timer to wake us up sooner.
*/ */
if (likely(variance <= U64_MAX/36)) { if (likely(variance <= U64_MAX/36)) {
if (((avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3)) if ((((u64)avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3))
|| variance <= 400) { || variance <= 400) {
if (data->next_timer_us > avg) if (data->next_timer_us > avg)
data->predicted_us = avg; data->predicted_us = avg;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册