Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel
gettimeofday() jumping into the future
 

Index | Next | Previous | View Flat


msmith at xiph

Aug 23, 2007, 4:08 AM


Views: 23502
Permalink
gettimeofday() jumping into the future

Hi,

We've been seeing some strange behaviour on some of our applications
recently. I've tracked this down to gettimeofday() returning spurious
values occasionally.

Specifically, gettimeofday() will suddenly, for a single call, return
a value about 4398 seconds (~1 hour 13 minutes) in the future. The
following call goes back to a normal value.

This seems to be occurring when the clock source goes slightly
backwards for a single call. In
kernel/time/timekeeping.c:__get_nsec_offset(), we have this:
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;

So a small decrease in time here will (this is all unsigned
arithmetic) give us a very large cycle_delta. cyc2ns() then multiplies
this by some value, then right shifts by 22. The resulting value (in
nanoseconds) is approximately 4398 seconds; this gets added on to the
xtime value, giving us our jump into the future. The next call to
gettimeofday() returns to normal as we don't have this huge nanosecond
offset.

This system is a 2-socket core 2 quad machine (8 cpus), running 32 bit
mode. It's a dell poweredge 1950. The kernel selects the TSC as the
clock source, having determined that the tsc runs synchronously on
this system. Switching the systems to use a different time source
seems to make the problem go away (which is fine for us, but we'd like
to get this fixed properly upstream).

We've also seen this behaviour with a synthetic test program (which
just runs 4 threads all calling gettimeofday() in a loop as fast as
possible and testing that it doesn't jump) on an older machine, a dell
poweredge SC1425 with two p4 hyperthreaded xeons.

Can anyone advise on what's going wrong here? I can't find much in the
way of documentation on whether the TSC is guaranteed to be
monotonically increasing on intel systems. Should the code choose not
to use the TSC? Or should the TSC reading code ensure that the
returned values are monotonic?

Is there any more information that would be useful? I'll be on a plane
for most of tomorrow, so might be a little slow responding.

Thanks,

Mike
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Subject User Time
gettimeofday() jumping into the future msmith at xiph Aug 23, 2007, 4:08 AM
    Re: gettimeofday() jumping into the future gbritton at doomcom Aug 23, 2007, 4:36 AM
        Re: gettimeofday() jumping into the future avi at argo Aug 23, 2007, 6:03 AM
            Re: gettimeofday() jumping into the future hpa at zytor Aug 23, 2007, 1:09 PM
        Re: gettimeofday() jumping into the future hpa at zytor Aug 23, 2007, 1:07 PM
    Re: gettimeofday() jumping into the future peterz at infradead Aug 23, 2007, 4:47 AM
        Re: gettimeofday() jumping into the future msmith at xiph Aug 23, 2007, 5:20 AM
    Re: gettimeofday() jumping into the future johnstul at us Aug 23, 2007, 11:47 AM
        Re: gettimeofday() jumping into the future msmith at xiph Aug 25, 2007, 9:44 AM
    Re: gettimeofday() jumping into the future tr at earth Mar 30, 2008, 2:17 PM
        Re: gettimeofday() jumping into the future andi at firstfloor Mar 31, 2008, 12:18 AM
            Re: gettimeofday() jumping into the future James at superbug Apr 3, 2008, 4:29 AM
                Re: gettimeofday() jumping into the future James at superbug Apr 3, 2008, 4:29 AM
                    Re: gettimeofday() jumping into the future James at superbug Apr 3, 2008, 5:44 AM
                        Re: gettimeofday() jumping into the future johnstul at us Apr 11, 2008, 4:11 PM
        Re: gettimeofday() jumping into the future tglx at linutronix Mar 31, 2008, 1:55 AM
        Re: gettimeofday() jumping into the future mihai.dontu at gmail Apr 1, 2008, 9:26 PM
            Re: gettimeofday() jumping into the future mihai.dontu at gmail Apr 1, 2008, 9:27 PM
    Re: gettimeofday() jumping into the future johnstul at us Mar 31, 2008, 9:03 AM
        Re: gettimeofday() jumping into the future tglx at linutronix Apr 2, 2008, 4:22 AM
    Re: gettimeofday() jumping into the future mann at vmware Apr 2, 2008, 3:40 PM
    Re: gettimeofday() jumping into the future fzu at wemgehoertderstaat Apr 2, 2008, 4:57 PM
        Re: gettimeofday() jumping into the future tglx at linutronix Apr 2, 2008, 11:28 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.