| To: | Andreas Dilger <adilger@xxxxxxxxxxxxx> |
|---|---|
| Subject: | Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup |
| From: | Linus Torvalds <torvalds@xxxxxxxxxxxxx> |
| Date: | Wed, 7 Nov 2001 17:22:35 -0800 (PST) |
| Cc: | "David S. Miller" <davem@xxxxxxxxxx>, <tim@xxxxxxxxxxxxxxxxxxxxxx>, <jgarzik@xxxxxxxxxxxxxxxx>, <andrewm@xxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>, <netdev@xxxxxxxxxxx>, <ak@xxxxxx>, <kuznet@xxxxxxxxxxxxx> |
| In-reply-to: | <20011107173626.S5922@xxxxxxx> |
| Sender: | owner-netdev@xxxxxxxxxxx |
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
|
| Previous by Date: | Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup, Tim Schmielau |
|---|---|
| Next by Date: | Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup, David S. Miller |
| Previous by Thread: | Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup, David S. Miller |
| Next by Thread: | Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup, kuznet |
| Indexes: | [Date] [Thread] [Top] [All Lists] |