All of lore.kernel.org
 help / color / mirror / Atom feed
* 2.6.11 timeval_to_jiffies() wrong for ms resolution timers
@ 2005-05-24 22:59 Bhavesh P. Davda
  2005-05-25 17:21 ` George Anzinger
  0 siblings, 1 reply; 14+ messages in thread
From: Bhavesh P. Davda @ 2005-05-24 22:59 UTC (permalink / raw)
  To: linux-kernel

setitimer for 20ms was firing at 21ms, so I wrote a simple debug module
for 2.6.11.10 kernel on i386 to do something like this:

struct timeval tv;
unsigned long jif;

tv.tv_usec = 20000;
tv.tv_sec = 0;

jif = timeval_to_jiffies(&tv);
printk("%lu usec = %lu jiffies\n", tv.tv_usec, jif);

This yields:

20000 usec = 21 jiffies

Egad!

I looked at the timeval_to_jiffies() inline function in
include/linux/jiffies.h, and after pulling my hair for a few minutes
(okay almost an hour), I decided to ask much smarter people than myself
on why it is behaving this way, and what it would take to fix it so that
"20000 usec = 20 jiffies".

I got as far as this in figuring it out for i386:

HZ=1000
SEC_CONVERSION=4194941632
USEC_CONVERSION=2199357558
USEC_ROUND=2199023255551
USEC_JIFFIE_SC=41
SEC_JIFFIE_SC=22

Thanks in advance for saving me from going bald!

- Bhavesh

-- 
Bhavesh P. Davda | Distinguished Member of Technical Staff | Avaya |
1300 West 120th Avenue | B3-B03 | Westminster, CO 80234 | U.S.A. |
Voice/Fax: 303.538.4438 | bhavesh@avaya.com

^ permalink raw reply	[flat|nested] 14+ messages in thread
* RE: 2.6.11 timeval_to_jiffies() wrong for ms resolution timers
@ 2005-05-25 19:06 Davda, Bhavesh P (Bhavesh)
  2005-05-25 20:02 ` George Anzinger
  0 siblings, 1 reply; 14+ messages in thread
From: Davda, Bhavesh P (Bhavesh) @ 2005-05-25 19:06 UTC (permalink / raw)
  To: Chris Friesen, george; +Cc: linux-kernel

> -----Original Message-----
> From: Chris Friesen [mailto:cfriesen@nortel.com] 
> Sent: Wednesday, May 25, 2005 12:08 PM
> To: george@mvista.com
> Cc: Davda, Bhavesh P (Bhavesh); linux-kernel@vger.kernel.org
> Subject: Re: 2.6.11 timeval_to_jiffies() wrong for ms 
> resolution timers
> 
> George Anzinger wrote:
> > Chris Friesen wrote:
> 
> >> What about telling it to wake up a jiffy earlier, then checking 
> >> whether the scheduling lag was enough to cause it to have 
> waited the 
> >> full specified time.  If not, put it to sleep for another jiffy.
> 
> > The user is, of course, free to do what ever they would like.  
> 
> I actually meant doing this in the kernel.

Ditto.

> 
>  > For a
> > more complete solution you might be interested in HRT (High Res 
> > Timers).  See my signature below.
> 
> Yep.  One more patch to apply and worry about versions and 
> maintenance. 
>   Not enough of a demand for us to be able to use it, at 
> least at this 
> point.
> 
> Chris

Ditto ditto :)

BTW, this reminds me an aweful lot of TH2GT2G, and Deep Thought taking 7.5 million years to come up with the answer "42!"

Me: Hey Deep Thought! What's 20 us converted into jiffies?

Deep Thought: Let's see: after accounting for all kinds of underflow and overflow possibilities, and extending the operands to 64-bit to retain the best precision, and crunching through a few complex macros, the answer you're looking for is... Is... Is... "21!" The real problem is: You didn't ask me the right question. You should have asked me "What's 19 us converted into jiffies?"

On a more serious note: what is a real-time (read SCHED_FIFO/SCHED_RR) task to use to get millisecond accuracy wakeup timing services from the kernel? i.e. what are the alternatives to setitimer() that wake up the task exactly at the interval that is requested of it? You mention high-res timers as a possibility, but in the form of a patch. What's available in mainline unpatched?

Thanks

- Bhavesh



Bhavesh P. Davda | Distinguished Member of Technical Staff | Avaya |
1300 West 120th Avenue | B3-B03 | Westminster, CO 80234, U.S.A. |
Voice/Fax: (303) 538-4438 | bhavesh@avaya.com 

^ permalink raw reply	[flat|nested] 14+ messages in thread
* RE: 2.6.11 timeval_to_jiffies() wrong for ms resolution timers
@ 2005-05-25 19:16 Davda, Bhavesh P (Bhavesh)
  0 siblings, 0 replies; 14+ messages in thread
From: Davda, Bhavesh P (Bhavesh) @ 2005-05-25 19:16 UTC (permalink / raw)
  To: Chris Friesen, george; +Cc: linux-kernel

Awefully sorry about the line-breaks (or absence thereof!)

Stupid Outlook that corporate IT forces us to use!

And I meant 20 ms, not 20 us, of course...

- Bhavesh

Bhavesh P. Davda | Distinguished Member of Technical Staff | Avaya |
1300 West 120th Avenue | B3-B03 | Westminster, CO 80234, U.S.A. |
Voice/Fax: (303) 538-4438 | bhavesh@avaya.com

 

> -----Original Message-----
> From: Davda, Bhavesh P (Bhavesh) 
> Sent: Wednesday, May 25, 2005 1:07 PM
> To: 'Chris Friesen'; 'george@mvista.com'
> Cc: 'linux-kernel@vger.kernel.org'
> Subject: RE: 2.6.11 timeval_to_jiffies() wrong for ms 
> resolution timers
> 
> > -----Original Message-----
> > From: Chris Friesen [mailto:cfriesen@nortel.com] 
> > Sent: Wednesday, May 25, 2005 12:08 PM
> > To: george@mvista.com
> > Cc: Davda, Bhavesh P (Bhavesh); linux-kernel@vger.kernel.org
> > Subject: Re: 2.6.11 timeval_to_jiffies() wrong for ms 
> > resolution timers
> > 
> > George Anzinger wrote:
> > > Chris Friesen wrote:
> > 
> > >> What about telling it to wake up a jiffy earlier, then checking 
> > >> whether the scheduling lag was enough to cause it to have 
> > waited the 
> > >> full specified time.  If not, put it to sleep for another jiffy.
> > 
> > > The user is, of course, free to do what ever they would like.  
> > 
> > I actually meant doing this in the kernel.
> 
> Ditto.
> 
> > 
> >  > For a
> > > more complete solution you might be interested in HRT (High Res 
> > > Timers).  See my signature below.
> > 
> > Yep.  One more patch to apply and worry about versions and 
> > maintenance. 
> >   Not enough of a demand for us to be able to use it, at 
> > least at this 
> > point.
> > 
> > Chris
> 
> Ditto ditto :)
> 
> BTW, this reminds me an aweful lot of TH2GT2G, and Deep 
> Thought taking 7.5 million years to come up with the answer "42!"
> 
> Me: Hey Deep Thought! What's 20 us converted into jiffies?
> 
> Deep Thought: Let's see: after accounting for all kinds of 
> underflow and overflow possibilities, and extending the 
> operands to 64-bit to retain the best precision, and 
> crunching through a few complex macros, the answer you're 
> looking for is... Is... Is... "21!" The real problem is: You 
> didn't ask me the right question. You should have asked me 
> "What's 19 us converted into jiffies?"
> 
> On a more serious note: what is a real-time (read 
> SCHED_FIFO/SCHED_RR) task to use to get millisecond accuracy 
> wakeup timing services from the kernel? i.e. what are the 
> alternatives to setitimer() that wake up the task exactly at 
> the interval that is requested of it? You mention high-res 
> timers as a possibility, but in the form of a patch. What's 
> available in mainline unpatched?
> 
> Thanks
> 
> - Bhavesh
> 
> 
> 
> Bhavesh P. Davda | Distinguished Member of Technical Staff | Avaya |
> 1300 West 120th Avenue | B3-B03 | Westminster, CO 80234, U.S.A. |
> Voice/Fax: (303) 538-4438 | bhavesh@avaya.com 
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-05-26 19:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-24 22:59 2.6.11 timeval_to_jiffies() wrong for ms resolution timers Bhavesh P. Davda
2005-05-25 17:21 ` George Anzinger
2005-05-25 17:37   ` Chris Friesen
2005-05-25 17:54     ` George Anzinger
2005-05-25 18:07       ` Chris Friesen
  -- strict thread matches above, loose matches on Subject: below --
2005-05-25 19:06 Davda, Bhavesh P (Bhavesh)
2005-05-25 20:02 ` George Anzinger
2005-05-25 21:41   ` Thomas Gleixner
2005-05-26 17:04   ` Olivier Croquette
2005-05-26 18:10     ` Richard B. Johnson
2005-05-26 18:19       ` Lee Revell
2005-05-26 19:24         ` George Anzinger
2005-05-26 19:32           ` Lee Revell
2005-05-25 19:16 Davda, Bhavesh P (Bhavesh)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.