From: "lk" <linux_kernel@patni.com>
To: "jeff shia" <tshxiayu@gmail.com>, <linux-kernel@vger.kernel.org>,
"robert love" <rml@novell.com>
Subject: Re: something about jiffies wraparound overflow
Date: Tue, 27 Dec 2005 14:24:03 +0530 [thread overview]
Message-ID: <003201c60ac3$16692d90$5e91a8c0@patni.com> (raw)
In-Reply-To: 7cd5d4b40512262046w6f7a8161jfaf1e618e5722b4@mail.gmail.com
As you mentioned the code for comparison:
> /* code 2*/
> unsigned long timeout = jiffies + HZ/2;
the code has no problem with jiffies wrapping around
as long as the values are compared in a right way.
For a 32 bit platform the counter wraps around only once every 50 day
when the value of HZ 1000. so if your code is prepared to face this event
it will work fine.
> 2.Is there any other possibilities for the "code 2" to overflow
> except the jiffies overflow?
No.
The better option would be to use the inline macros:
> #define time_after(a,b) \
> (typecheck(unsigned long, a) && \
> typecheck(unsigned long, b) && \
> ((long)(b) - (long)(a) < 0))
> #define time_before(a,b) time_after(b,a)
>
> #define time_after_eq(a,b) \
> (typecheck(unsigned long, a) && \
> typecheck(unsigned long, b) && \
> ((long)(a) - (long)(b) >= 0))
> #define time_before_eq(a,b) time_after_eq(b,a)
>
> But I cannot understand it has some differences comparing with the
> following code.
> 1.why the macros of time_after can solve the jiffies
> wraparound problem?
As it is clear that time_after evaluates true,
when a, as a snapshot of jiffies, represents a time after b,
These inlines deals with the timer wrapping correctly, because
if the timer wrap changes in the future , you won't have to alter the driver
code.
Typechecks are performed at the compiled time, that variables are of the
same type.
the code works by first converting the values to unsigned long, subtracting
them and then comparing the result.
so it is the safe way and most encoraged..
If you need to know the difference
between two instances of jiffies in a safe way, you can use the same trick:
diff = (long)t2 - (long)t1;.
regards
lk.
next prev parent reply other threads:[~2005-12-27 8:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-27 4:46 something about jiffies wraparound overflow jeff shia
2005-12-27 8:54 ` lk [this message]
2005-12-27 9:05 ` Con Kolivas
2005-12-27 14:54 ` Ben Collins
[not found] <5oeWK-5Od-11@gated-at.bofh.it>
2005-12-27 10:06 ` Bodo Eggert
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='003201c60ac3$16692d90$5e91a8c0@patni.com' \
--to=linux_kernel@patni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rml@novell.com \
--cc=tshxiayu@gmail.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