From: "Krishna Kumar" <kumarkr@us.ibm.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Andreas Dilger <adilger@turbolabs.com>,
ak@muc.de, andrewm@uow.edu.au,
"David S. Miller" <davem@redhat.com>,
jgarzik@mandrakesoft.com, kuznet@ms2.inr.ac.ru,
linux-kernel@vger.kernel.org, netdev@oss.sgi.com,
owner-netdev@oss.sgi.com, tim@physik3.uni-rostock.de
Subject: Re: [PATCH] net/ipv4/*, net/core/neighbour.c jiffies cleanup
Date: Thu, 8 Nov 2001 09:47:17 -0800 [thread overview]
Message-ID: <OFD59796BB.88D69925-ON88256AFE.006169C1@boulder.ibm.com> (raw)
Hi Linus,
Thanks for your clarification, it does make sense. I did only
the jiffies overflowing case, and missed the case where it
does not overflow.
Thanks,
- KK
-----------------------------------------------------------------------------
Ok.
Let's give an example. HZ is 100, and we started just before jiffies
wrapped, and we want to check that we're within one second.
So "start" equals 0xfffffff0, and "jiffies" equals 0xfffffff5.
The first if-statement will say
if (0xfffffff5 <= 0xfffffff0+100)
which is the same as
if (0xfffffff5 <= 0x54)
which is
if (0)
in short, the first statement will say that jiffies is _not_ within 100
ticks of "start", which is obviously wrong. Jiffies _is_ within 100 ticks,
it is in fact just 5 ticks after "start".
The second statement will say
if (0xfffffff5 - 0xfffffff0 <= 100)
which is
if (5 <= 100)
which is
if (1)
which is _correct_. We _are_ within 100 ticks.
See?
Ok, that was wrap-around one way: the "+HZ" wrapped. Let's see the other
case, which is that "jiffies" has wrapped: start is still 0xfffffff0, but
jiffies has wrapped around and is 0x00000001.
The first if-statement will say
if (0x00000001 <= 0xfffffff0+100)
which is
if (0x00000001 <= 0x54)
which is
if (1)
which is correct. The second one will say
if (0x00000001 - 0xfffffff0 <= 100)
which is
if (11 <= 100)
which is
if (1)
which is correct.
In short, the _correct_ one ALWAYS gets the right answer. Even when the
subtraction overflows.
While the first (and incorrect one) gets the wrong answer when the
addition overflows.
Do you see the difference now?
Linus
next reply other threads:[~2001-11-08 17:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-08 17:47 Krishna Kumar [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-11-08 16:55 Krishna Kumar
2001-11-08 17:10 ` Linus Torvalds
2001-11-08 18:01 ` Andreas Dilger
2001-11-09 10:43 ` Vino Thomas
2001-11-08 3:07 Krishna Kumar
2001-11-08 5:26 ` Linus Torvalds
2001-11-08 0:00 Tim Schmielau
2001-11-08 0:09 ` David S. Miller
2001-11-08 0:36 ` Andreas Dilger
2001-11-08 1:22 ` Linus Torvalds
2001-11-08 0:44 ` David S. Miller
2001-11-08 0:58 ` Tim Schmielau
2001-11-08 1:09 ` David S. Miller
2001-11-08 1:20 ` Tim Schmielau
2001-11-08 1:36 ` David S. Miller
2001-11-08 4:32 ` Andreas Dilger
2001-11-08 4:39 ` David S. Miller
2001-11-08 17:54 ` kuznet
2001-11-08 18:10 ` Tim Schmielau
2001-11-08 18:10 ` Andreas Dilger
2001-11-08 18:32 ` kuznet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=OFD59796BB.88D69925-ON88256AFE.006169C1@boulder.ibm.com \
--to=kumarkr@us.ibm.com \
--cc=adilger@turbolabs.com \
--cc=ak@muc.de \
--cc=andrewm@uow.edu.au \
--cc=davem@redhat.com \
--cc=jgarzik@mandrakesoft.com \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@oss.sgi.com \
--cc=owner-netdev@oss.sgi.com \
--cc=tim@physik3.uni-rostock.de \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®