[Asterisk-Dev] what's the value of a jiffie in zaptel driver ?
Derek Smithies
derek at indranet.co.nz
Mon Nov 22 14:09:23 MST 2004
Hi,
In the 2.4 series there are a bundle of macros,
time_after,
time_before,
time_after_eq,
time_before_eq
from include/linux/timer.h
In 2.6.9, these marcos are in include/linux/jiffies.h
pasting from this file,
/*
* These inlines deal with timer wrapping correctly. You are
* strongly encouraged to use them
* 1. Because people otherwise forget
* 2. Because if the timer wrap changes in future you won't have to
* alter your driver code.
*
* time_after(a,b) returns true if the time a is after time b.
*
* Do this with "<0" and ">=0" to only test the sign of the result. A
* good compiler would generate better code (and a really good compiler
* wouldn't care). Gcc is currently neither.
*/
#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)
Derek.
On Mon, 22 Nov 2004, Peter Svensson wrote:
> On Mon, 22 Nov 2004, Gilad Ben-Yossef wrote:
>
> > Dinesh Nair wrote:
> > > origjiffies=jiffies;
> > > while((jiffies-origjiffies)<4);
>
> [snip]
> > One issue that is very important to consider is "jiffie warp". The
> > jiffie is a 32 bit value, which means it will wrap around somewhere
> > after a year for kernel 2.4/x86 and much sooner for 2.6 kernels or on
> > the powerpc.
> >
> > In the 2.6 series a jiffie_64 (or something similar, I don't remember)
> > symbol exists, but on 32 bit arch's like the x86 it is not possible to
> > read this value atomically without holding a lock. The regular jiffies
> > symbols is really the 32 bit LSB of 64 bit jiffies value.
> >
> > What all this means is the code snippet above is broken and will fail
> > when the jiffies will wrap around causing untold damage to your machine,
> > life and telephony equipment, but maybe not in that order... :-)
>
> Actually it works nicely event at wrap around time, as long as the result
> of the subtraction is a signed operation. Actually, I think there are
> macros in the kernel that make sure the variables are cast correctly.
>
> Peter
>
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-dev
>
>
>
--
Derek Smithies Ph.D. This PC runs pine on linux for email
IndraNet Technologies Ltd. If you find a virus apparently from me, it has
Email: derek at indranet.co.nz forged the e-mail headers on someone else's machine
ph +64 3 365 6485 Please do not notify me when (apparently) receiving a
Web: http://www.indranet-technologies.com/ windows virus from me......
More information about the asterisk-dev
mailing list