From: george anzinger <george@mvista.com>
To: root@chaos.analogic.com
Cc: Christopher Friesen <cfriesen@nortelnetworks.com>,
John Being <olonho@hotmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: strange nonmonotonic behavior of gettimeoftheday -- seen similar problem on PPC
Date: Fri, 02 Mar 2001 10:25:13 -0800 [thread overview]
Message-ID: <3A9FE589.610D5220@mvista.com> (raw)
In-Reply-To: <Pine.LNX.3.95.1010302103506.1920A-100000@chaos.analogic.com>
"Richard B. Johnson" wrote:
>
> On Fri, 2 Mar 2001, Christopher Friesen wrote:
>
> > John Being wrote:
> >
> > > gives following result on box in question
> > > root@******:# ./clo
> > > Leap found: -1687 msec
> > > and prints nothing on all other my boxes.
> > > This gives me bunch of troubles with occasional hang ups and I found nothing
> > > in kernel archives at
> > > http://www.uwsg.indiana.edu/hypermail/linux/kernel/index.html
> > > just some notes about smth like this for SMP boxes with ntp. Is this issue
> > > known, and how can I fix it?
> >
> > I've run into non-monotonic gettimeofday() on a PPC system with 2.2.17, but it
> > always seemed to be almost exactly a jiffy out, as though it was getting
> > hundredths of a second from the old tick, and microseconds from the new tick.
> > Your leap seems to be more unusual, and the first one I've seen on an x86 box.
> >
> > Have you considered storing the results to see what happens on the next call?
> > Does it make up the difference, or do you just lose that time?
> >
> > Chris
>
> I think it's a math problem in the test code. Try this:
>
> #include <stdio.h>
> #include <sys/time.h>
>
> #define DEB(f)
>
> int main()
> {
> struct timeval t;
> double start_us;
> double stop_us;
> for(;;)
> {
> gettimeofday(&t, NULL);
> start_us = (double) t.tv_sec * 1e6;
> start_us += (double) t.tv_usec;
> gettimeofday(&t, NULL);
> stop_us = (double) t.tv_sec * 1e6;
> stop_us += (double) t.tv_usec;
> if(stop_us <= start_us)
> break;
> DEB(fprintf(stdout, "Start = %f, Stop = %f\n", start_us, stop_us));
> }
> fprintf(stderr, "Start = %f, Stop = %f\n", start_us, stop_us);
> return 0;
> }
>
> Note that two subsequent calls to gettimeofday() must not return the
> same time even if your CPU runs infinitely fast. I haven't seen any
> kernel in the past few years that fails this test.
Oh! With only micro second resolution how is this avoided? The only
"legal" thing to do to avoid this is for the fast boxes to loop until
the requirement is satisfied. Is this really done?
George
next prev parent reply other threads:[~2001-03-02 18:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-02 5:30 strange nonmonotonic behavior of gettimeoftheday John Being
2001-03-02 15:07 ` Eli Carter
2001-03-02 15:08 ` strange nonmonotonic behavior of gettimeoftheday -- seen similar problem on PPC Christopher Friesen
2001-03-02 15:40 ` Richard B. Johnson
2001-03-02 18:25 ` george anzinger [this message]
2001-03-02 19:14 ` Richard B. Johnson
2001-03-02 20:09 ` george anzinger
2001-03-03 7:42 ` Mike Galbraith
2001-03-03 22:40 ` dean gaudet
-- strict thread matches above, loose matches on Subject: below --
2001-03-03 4:22 Doug Siebert
2001-03-03 13:18 ` Alan Cox
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=3A9FE589.610D5220@mvista.com \
--to=george@mvista.com \
--cc=cfriesen@nortelnetworks.com \
--cc=linux-kernel@vger.kernel.org \
--cc=olonho@hotmail.com \
--cc=root@chaos.analogic.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