Subject: Re: Problem with clock_gettime()
To: None <tech-kern@netbsd.org>
From: None <wolfgang+gnus20031124T054217@dailyplanet.dontspam.wsrcc.com>
List: tech-kern
Date: 11/24/2003 05:52:45
ianm@cat.co.za (Ian McIntosh) writes:
> When doing this I have noticed some strange behaviour
> with clock_gettime(). I can call clock_gettime() and 
> store the result in a temporary variable and then 
> when I call it again the time returned is before 
> the time in the temporary variable (indicating that 
> time has gone backwards????). 

This is an old problem.  PR 14100  (and probably others)

     http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=14100

As an aside, if you need to measure delay-time you probably want to
use the TSC if you have one in your processor.  You get much finer
granularity time in units of your processor's internal clock speed.
(eg. 3.2 Ghz clock ticks on a 3.2Ghz CPU.)

 /* x86 stub for reading the CPU's tick counter */

 typedef unsigned long long u64;

 inline          u64
 getTick64(void)
 {
     u64             ticks;
     asm             volatile("rdtsc":"=A"(ticks));
     return ticks;
 }

-wolfgang
-- 
Wolfgang S. Rupprecht 		     http://www.wsrcc.com/wolfgang/
       The above "From:" address is valid.  Don't mess with it.