Re: Jiffies Wraparound (was Re: interrupt counts)
Tyson D Sawyer (tyson@rwii.com)
Wed, 21 Aug 1996 23:48:26 -0400 (EDT)
> > IMHO, we either should forget about it and wait for Merced or anything
> > else to move us out of the 32 bit world ... or we should completely avoid
> > comparing "jiffies" to variables. We could do this the following way:
> >
> > #define IS_TIMED_OUT(timeout) (jiffies>timeout) || \
> > (timeout-jiffies>MAX_JIFFIES/2)
>
> Just rewriting tests from
>
> timeout = jiffies + delay;
> while (jifies < timeout) continue;
>
> to
>
> start = jiffies;
> while (jiffies - start < delay) continue;
>
> solves the problem, and is much faster.
>
>
> r~
That is more genericly solved like this:
timeout = jiffies + delay;
while ((int)timeout-(int)jiffies>0) {stuff};
This form can be put into a macro that requires only a single argument:
#define TIMED_OUT(timeout) ((int)timeout-(int)jiffies<0)
timeout = jiffies + delay;
while (!TIMED_OUT(timeout)) {stuff;};
Ty