From: George Anzinger <george@mvista.com>
To: bhavesh@avaya.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: 2.6.11 timeval_to_jiffies() wrong for ms resolution timers
Date: Wed, 25 May 2005 10:21:49 -0700 [thread overview]
Message-ID: <4294B42D.2020008@mvista.com> (raw)
In-Reply-To: <1116975555.2050.10.camel@cof110earth.dr.avaya.com>
Bhavesh P. Davda wrote:
> 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!
Well, I am already bald :)
What you are missing is that the PIT can not generate a 1ms tick. The best it
can do is 999849 nanoseconds. Given this we need to convert 20000 usec to not
less than 2000usec worth of jiffies (time MUST always be rounded up). 20
jiffies is 19.996980 usec so we need to use 21 (which is 20.996829 usec).
Note that TICK_NSEC and tick_nsec will both be 999849 nanoseconds.
If we do NOT account for this PIT issue, the result is a time drift that is
outside of what ntp can handle...
--
George Anzinger george@mvista.com
High-res-timers: http://sourceforge.net/projects/high-res-timers/
next prev parent reply other threads:[~2005-05-25 17:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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)
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=4294B42D.2020008@mvista.com \
--to=george@mvista.com \
--cc=bhavesh@avaya.com \
--cc=linux-kernel@vger.kernel.org \
/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 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.