public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.co.uk>
To: Andi Kleen <andi@firstfloor.org>
Cc: Tim Ricketts <tr@earth.li>, Michael Smith <msmith@xiph.org>,
	linux-kernel@vger.kernel.org, Andy Wingo <wingo@fluendo.com>,
	tglx@linutronix.de
Subject: Re: gettimeofday() jumping into the future
Date: Thu, 03 Apr 2008 12:47:14 +0100	[thread overview]
Message-ID: <47F4C3C2.8030004@superbug.co.uk> (raw)
In-Reply-To: <87r6dr8iq3.fsf@basil.nowhere.org>


>> On Thu, 23 Aug 2007, Michael Smith wrote:
>>
>>     
> [...]
>   
>> +static inline u64 __get_nsec_offset(void)
>>   {
>>   	cycle_t cycle_now, cycle_delta;
>> -	s64 ns_offset;
>> +	u64 ns_offset;
>>
>>   	/* read clocksource: */
>>   	cycle_now = clocksource_read(clock);
>>
>> +	if (cycle_now < clock->cycle_last)
>> +		return 0;
>>     


That does not work as cycle_now can go backwards as well as wrap around.
The only way to catch all edge cases is to be able to make an assumption
on the maximum acceptable difference between cycle_now and cycle_last,
where difference is the shortest distance between values if they were
pointers into a ring buffer. If this maximum difference value is less
than half of the max value cycle_now can have, one can take a very
simple approach.
Treat the cycle_now, cycle_last value as signed.
If they have same sign, do the comparison as unsigned.
If they have different signs, do the comparision as signed.

James



  reply	other threads:[~2008-04-03 10:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-23 11:08 gettimeofday() jumping into the future 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 [this message]
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
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=47F4C3C2.8030004@superbug.co.uk \
    --to=james@superbug.co.uk \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --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