[time-nuts] FreeBSD, NetBSD, or Minix-III?

Lux, James P james.p.lux at jpl.nasa.gov
Mon May 18 13:18:25 UTC 2009




On 5/18/09 1:12 AM, "Hal Murray" <hmurray at megapathdsl.net> wrote:

> 
> 
> stanley_reynolds at yahoo.com said:
>> I need to go back and read what you are trying to measure with your
>> clock. Is it internal to the computer or an external event ?
> 
> I was thinking of a FPGA on a PCI bus.  It has to be PCI rather than USB in
> order to get reasonable timings.
> 
> I was going to put the Unix clock in the FPGA.  It's a pair of 32 bit words.
> The high word is seconds since some magic date/time.  The low word is
> nano-seconds within this second.
> 

I would make that "magic time" the time when power was applied.  Do the
transformation from "hardware time" to "Unix time" in software (since it
requires just arithmetic.. An add (offset between the two time zeros) and a
multiply (for the scale factor between "unix time" and your hardware
counter)

If you have a solution where you "jam" the hardware counter to "set it", you
always have a question about the latency of that set operation.  It's pretty
easy in hardware (FPGA) to arrange an "atomic" read of an arbitrarily long
counter into a holding register, which software then reads.

> 
> 
> I was planning to drive that with a stable external clock, say a GPSDO.  So if
> things were setup properly, it should be a very good clock.
> 
> The typical Unix clock is implemented by looking at the TSC.   I think that's
> Intel's term for a register that counts each CPU cycle, Time Stamp Counter.
> The CPU comes from an inexpensive crystal.  The frequency of that crystal
> varies (wildly) with temperature.  The temperature varies with activity.

I don't know about wildly.  Certainly in time-nuts land, a few tens of ppm
is wild variation, but in the overall scheme of things, it's still
reasonably good.



> 
> The basic idea is that you maintain a reference time and TSC value.  To get
> the current time, you read the TSC, subtract off the reference TSC.  That
> gives you the number of CPU clock ticks since the reference time.  Convert
> that to nanoseconds, add on the reference time, and normalize.  You have to
> update the reference info periodically, in particular before that subtract
> will over/underflow.
> 
> 





More information about the Time-nuts_lists.febo.com mailing list