TimeStamp Class

Tim Rowledge tim at sumeru.stanford.edu
Mon Apr 11 05:11:18 UTC 2005


John M McIntosh <johnmci at smalltalkconsulting.com> wrote:

> Well most modern CPU have counters tied to Ghz/Mhz cycles so that you  
> can calculate a nano-second time value if you know the multiplers  
> values to use,
> some operating systems actually provide calls to get that information.
Unfortunately you can't really trust such counters, at least not over longer
timespans like 30mins or so. The problem is that the timing crystals used
commercially are not terribly precise. They are prone to
a) not be quite the x.yz MHz it says on the tin and
b) drift with temperature - and goodness knows temps drift in most computers.

As an example, my machine has a nominal 200MHz crystal clock. To prevent the
system interval ticker from drifting too far from the RTC, the OS will check
with an ntp server every 30 minutes and work out if the ticker is getting ahead
or behind, then alter the number of xtal ticks per millisec to slowly
compensate (instead of jumping around) by changing the countdown register
reload value. So for example if the ticker is a tad behind it might change the
nominal 200,000 reload value to 199,750 thus speeding up the tick by an eighth
of a percent.

Any arithmetic you do on the raw value has to be able to compensate for any
such fudging (think modulo arithmetic for example) and to do that you have to
be able to discover the amount of fudging and not all hardware allows that.
There are such things as write only hardware registers for example which can
really cramp your style.

The answer is to lean back, relax, not care too much and decide to run on
Island Time, mon.


tim - on a Pacific Island :-)
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Useful random insult:- Went to the dentist to have his cranial cavity filled.



More information about the Squeak-dev mailing list