Re: [PATCH 2/2] cpuidle: Add a repeating pattern detector to themenu governor

From: Andrew Morton
Date: Mon May 10 2010 - 17:39:10 EST


On Sun, 9 May 2010 16:04:44 -0700
Arjan van de Ven <arjan@xxxxxxxxxxxxx> wrote:

> +static void detect_repeating_patterns(struct menu_device *data)
> +{
> + int i;
> + uint64_t avg = 0;
> + uint64_t stddev = 0; /* contains the square of the std deviation */
> +
> + /* first calculate average and standard deviation of the past */
> + for (i = 0; i < INTERVALS; i++)
> + avg += data->intervals[i];
> +
> + /* if the avg is beyond the known next tick, it's worthless */
> + if (avg > data->expected_us)
> + return;
> +
> + avg = avg / INTERVALS;
> + for (i = 0; i < INTERVALS; i++)
> + stddev += (data->intervals[i] - avg) *
> + (data->intervals[i] - avg);
> +
> + stddev = stddev / INTERVALS;
> +
> + /*
> + * now.. if stddev is small.. then assume we have a
> + * repeating pattern and predict we keep doing this.
> + */
> +
> + if (avg && stddev < STDDEV_THRESH)
> + data->predicted_us = avg;
> +}

You got lucky there, because INTERVALS is a power of two. If someone
changes INTERVALS to 7, this code will ask for __udivdi3 and won't link
on i364.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/