Path: utzoo!utgpu!watserv1!watmath!att!pacbell!pacbell.com!decwrl!sgi!vjs@rhyolite.wpd.sgi.com From: vjs@rhyolite.wpd.sgi.com (Vernon Schryver) Newsgroups: comp.sys.sgi Subject: Re: time() vs gettimeofday() Message-ID: <68830@sgi.sgi.com> Date: 8 Sep 90 22:10:12 GMT References: <9009080837.AA06570@mcirps2.med.nyu.edu> <1990Sep8.085849.5096@odin.corp.sgi.com> Sender: guest@sgi.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 28 In article <1990Sep8.085849.5096@odin.corp.sgi.com>, olson@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