Re: FreeBSD driver for the OCP TAP Time Card

From: John Hay <john_at_sanren.ac.za>
Date: Wed, 08 May 2024 06:36:53 UTC
Hi Poul-Henning,

On Wed, 8 May 2024 at 07:35, Poul-Henning Kamp <phk@phk.freebsd.dk> wrote:

> --------
> John Hay writes:
>
> > I have been working on a FreeBSD driver for the Open Compute Project
> (OCP)
> > Time Appliance Project (TAP) Time Card. The card consists of three main
> > parts, a clock module, a GNSS module and a FPGA module. The firmware for
> > the FPGA implements a counter that is synchronized to TAI using the GNSS
> > module and the clock module. The counter is implemented as two 32-bit
> > registers, seconds and nanoseconds, like struct timespec, and make that
> > available on the pci-e bus.
>
> That is /precisely/ the kind of hardware timecounters were designed for :-)
>

True, it did make it a lot easier. :-) Working close to the nanosecond does
seem to push things close to the limits though. :-)

There are a few things I wish could be handled differently. Maybe there are
ways, and I just did not find them. :-)

One is that you cannot just feed timecounters with a timespec value. It
assumes the hardware counter is in binary, while in this case, the
nanoseconds rolls over at 1 second, so for every tc_get_timecount(), you
have to multiply the seconds register value by 10^9 and then add the
nanosecond register value. Not a big deal and reading the registers over
the pci-e bus is the slowest part by far.

The other is that the conversion from the above value to bintime and later
back to what is used elsewhere, seems to lose a little precision. The
comments in sys/kern/kern_tc.c also note that.

In the pps code, I wished that one could provide a timestamp with
pps_capture(). It uses the time at which it handled the interrupt. The card
latch the counter values when the pps happens, so it knows the correct
time. Currently I hack around it by twiddling sc->sc_pps_state.capcount
directly.

Regards

John