Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup

From: Linus Torvalds (torvalds@transmeta.com)
Date: Wed Nov 07 2001 - 20:22:35 EST


On Wed, 7 Nov 2001, Andreas Dilger wrote:
>
> No, only a limited number of them cast to a signed value, which means
> that a large number of them get the comparison wrong in the case of
> jiffies wrap (where the difference is a large unsigned value, and not
> a small negative number).

No.

Unsigned arithmetic is fine. The _correct_ way to test whether something
is in within

        [ start , start+HZ ]

is to do

        if (jiffies - start <= HZ)

try it. The C language guarantees that unsigned arithmetic works in a
"modulo power of two" fashion, which means that it _is_ ok to do
arithmetic on unsigned longs, and jiffy wrapping does not matter. No need
to cast to "signed" or anything else.

In short: It is wrong to do

        if (jiffies <= start+HZ)

and it is _right_ to do

        if (jiffies - start <= HZ)

(as long as "start" is "unsigned long" like jiffies).

                Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Nov 07 2001 - 21:00:37 EST