mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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: Wed, 7 Nov 2001 19:07:47 -0800	[thread overview]
Message-ID: <OF80A3FFE5.FC1D4628-ON88256AFE.0010957E@boulder.ibm.com> (raw)


> 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


             reply	other threads:[~2001-11-08  3:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-08  3:07 Krishna Kumar [this message]
2001-11-08  5:26 ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2001-11-08 17:47 Krishna Kumar
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  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=OF80A3FFE5.FC1D4628-ON88256AFE.0010957E@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®