From: Karsten Wiese <fzu@wemgehoertderstaat.de>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <johnstul@us.ibm.com>, Tim Ricketts <tr@earth.li>,
Michael Smith <msmith@xiph.org>,
LKML <linux-kernel@vger.kernel.org>,
Andy Wingo <wingo@fluendo.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: gettimeofday() jumping into the future
Date: Thu, 3 Apr 2008 00:57:31 +0100 [thread overview]
Message-ID: <200804030157.32086.fzu@wemgehoertderstaat.de> (raw)
In-Reply-To: <alpine.LFD.1.10.0804021254420.3219@apollo.tec.linutronix.de>
Am Mittwoch, 2. April 2008 schrieb Thomas Gleixner:
>
> Subject: x86: tsc prevent time going backwards
> From: Thomas Gleixner <tglx@linutronix.de>
> Date: Tue, 01 Apr 2008 19:45:18 +0200
>
> We already catch most of the TSC problems by sanity checks, but there
> is a subtle bug which has been in the code for ever. This can cause
> time jumps in the range of hours.
>
> This was reported in:
> http://lkml.org/lkml/2007/8/23/96
> and
> http://lkml.org/lkml/2008/3/31/23
>
> I was able to reproduce the problem with a gettimeofday loop test on a
> dual core and a quad core machine which both have sychronized
> TSCs. The TSCs seems not to be perfectly in sync though, but the
> kernel is not able to detect the slight delta in the bootup sync
> check. There exists an extremly small window where this delta can be
> observed with a real big time jump. So far I was only able to
> reproduce this with the vsyscall gettimeofday implementation, but in
> theory this might be observable with the syscall based version as
> well.
>
> CPU 0 updates the clock source variables under xtime/vyscall lock and
> CPU1, where the TSC is slighty behind CPU0, is reading the time right
> after the seqlock was unlocked.
>
> The clocksource reference data was updated with the TSC from CPU0 and
> the value which is read from TSC on CPU1 is less than the reference
> data. This results in a huge delta value due to the unsigned
> subtraction of the TSC value and the reference value. This algorithm
> can not be changed due to the support of wrapping clock sources like
> pm timer.
>
> The huge delta is converted to nanoseconds and added to xtime, which
> is then observable by the caller. The next gettimeofday call on CPU1
> will show the correct time again as now the TSC has advanced above the
> reference value.
>
> To prevent this TSC specific wreckage we need to compare the TSC value
> against the reference value and return the latter when it is larger
> than the actual TSC value.
Last paragraph IMO should be:
To prevent this TSC specific wreckage we need to substract the
reference value from the TSC value, interpret the result as
signed. If the interpreted result is negative, return the reference
value, else the TSC Value.
Your patch misses the corner case where TSC value is < reference _and_ valid
at TSC wrap around.
The access to the reference value needs a (the xtime ?) lock on 32bit, no?
Thanks,
Karsten
next prev parent reply other threads:[~2008-04-02 23:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-23 11:08 Michael Smith
2007-08-23 11:36 ` Gerald Britton
2007-08-23 13:03 ` Avi Kivity
2007-08-23 20:09 ` H. Peter Anvin
2007-08-23 20:07 ` H. Peter Anvin
2007-08-23 11:47 ` Peter Zijlstra
2007-08-23 12:20 ` Michael Smith
2007-08-23 18:47 ` john stultz
2007-08-25 16:44 ` Michael Smith
2008-03-30 21:17 ` Tim Ricketts
2008-03-31 7:18 ` Andi Kleen
2008-04-03 11:47 ` James Courtier-Dutton
2008-04-03 12:22 ` James Courtier-Dutton
2008-04-03 12:44 ` James Courtier-Dutton
2008-04-11 23:11 ` john stultz
2008-03-31 8:55 ` Thomas Gleixner
2008-03-31 16:03 ` John Stultz
2008-04-02 11:22 ` Thomas Gleixner
2008-04-02 23:57 ` Karsten Wiese [this message]
2008-04-03 6:28 ` Thomas Gleixner
2008-04-02 4:26 ` Mihai Donțu
2008-04-02 4:27 ` Mihai Donțu
[not found] <47F3F313.7030803@vmware.com>
2008-04-02 22:40 ` Tim Mann
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=200804030157.32086.fzu@wemgehoertderstaat.de \
--to=fzu@wemgehoertderstaat.de \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=msmith@xiph.org \
--cc=tglx@linutronix.de \
--cc=tr@earth.li \
--cc=wingo@fluendo.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
all inboxes | Powered by JetHome®