netdev
[Top] [All Lists]

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

To: Linus Torvalds <torvalds@xxxxxxxxxxxxx>
Subject: Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup
From: "Krishna Kumar" <kumarkr@xxxxxxxxxx>
Date: Wed, 7 Nov 2001 19:07:47 -0800
Cc: Andreas Dilger <adilger@xxxxxxxxxxxxx>, ak@xxxxxx, andrewm@xxxxxxxxxx, "David S. Miller" <davem@xxxxxxxxxx>, jgarzik@xxxxxxxxxxxxxxxx, kuznet@xxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxx, owner-netdev@xxxxxxxxxxx, tim@xxxxxxxxxxxxxxxxxxxxxx
Sender: owner-netdev@xxxxxxxxxxx
> 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)

Actually this last part is wrong, isn't it ? jiffies <= start + HZ is also
a correct way to do it, since start+HZ will overflow to the current value
of
jiffies when HZ time elapses. So the above two statements are IDENTICAL. I
agree with the rest of the statements, and especially that you don't need
to worry about wrapping using unsigned numbers.

Regards,

- KK

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


<Prev in Thread] Current Thread [Next in Thread>