[PATCH] nomadik: prevent sched_clock() wraparound

Linus Walleij linus.ml.walleij at gmail.com
Wed Nov 17 04:26:53 EST 2010


2010/11/17 Linus Walleij <linus.ml.walleij at gmail.com>:

> Hm! Then in this code in plat-orion/timer.c:
>
> #define TCLK2NS_SCALE_FACTOR 8
> static unsigned long tclk2ns_scale;
>
> unsigned long long sched_clock(void)
> {
>        unsigned long long v = cnt32_to_63(0xffffffff - readl(TIMER0_VAL));
>        return (v * tclk2ns_scale) >> TCLK2NS_SCALE_FACTOR;
> }

Looking at this again it seems the Orion is implicitly
loosing bits - so this code will work and multiply out some of the
63 bits so it just wraps around earlier.

Would be nice to have these kind of things explicit though,
it's a bit hard to determine when this counter will wrap.

Linus Walleij



More information about the linux-arm-kernel mailing list