time() vs gettimeofday()

Vernon Schryver vjs at rhyolite.wpd.sgi.com
Sun Sep 9 08:10:12 AEST 1990


In article <1990Sep8.085849.5096 at odin.corp.sgi.com>, olson at anchor.esd.sgi.com (Dave Olson) writes:
> 
> gettimeofday() will get you down to the system clock resolution,
> which is 10 ms by default, but which can be changed to ~1 ms (exact
> value depends on the model) by kernel configuration or the ftimer
> command.  time() will only give you 1 second resolution.


The resolution of gettimeofday() is limited to the frequency of clock
interrupts, which is either 10 or 1 ms.  However, you should not expect the
tv_usec field of the structure returned by gettimeofday() to contain a
multiple of 10,000 or 1,000.  Any fractions of a clock tick from the
adjtime() system call are slopped into the current time.  In addition, the
syssgi() system call can be used to adjust the clock rate, periodically
adding or subtracting a number of nanoseconds to the current time, thereby
jiggling the least significant bits of the current time.

The deamons described in timed(1M) and timeslave(1M) use both mechanisms.
A port of ntp or xntp would also use them.


Gettimeofday() and time() should be used for time stamps.  The timers used
by select() and other things are based on "lbolt", the "hz counter" that is
returned by times().  Times() should be used if you want a relatively
constant tick.


vjs



More information about the Comp.sys.sgi mailing list