[LinuxPPS] [PATCH] synchronizing several linux computers over parallel port with microsecond precision

Alexander Gordeev lasaine at lvk.cs.msu.su
Thu Aug 20 18:34:44 CEST 2009


Hi All!

I've recently got a task to make subj. Yes, we do need an ultimate
precision! After some researching I had this scheme in mind:
 * one of the computers is a master, it "exports" time information
   using both ntpd and PPS signal through the STROBE pin of a parallel
   port
 * other computers are slaves, they sync to the master ntpd server and
   the provided PPS signal over an ACK pin, which causes an interrupt

1. PPS signal generator and client
----------------------------------
Since the interrupt handling needs several microseconds at best so the
assert edge can not be used.
On the other hand reading parallel port status port takes nearly 1
microsecond so the clear edge can be determined with nearly microsecond
precision with simple parport status polling until the signal on ACK
pin is lost.

I've written two kernel modules: pps_gen_parport and pps_parport. The
former is PPS signal generator and the latter is PPS signal receiver or
PPS client. I didn't like the existing parallel port client which is a
set of parport and lp hacks so I decided to write it from scratch. Both
modules are not completely finished yet, but they already do the job
well and I decided to publish them now to get your comments. The patch
is attached. Please comment :)
I'd like them to become a part of LinuxPPS and, of course, LinuxPPS to
get mainline.

pps_gen_parport uses hrtimers to wake up shortly before the beginning
of a second. Then it waits for the right time for an assert edge in a
busy loop, then sets the signal, waits for the right time for a clear
edge and unsets the signal.

pps_parport waits for a parport interrupt, picks the timestamp for the
assert edge, polls the parport status until the signal is unset and
then gets the timestamp for the clear edge.

Both modules try to calibrate getnstimeofday, port read/write times.
The current implementation calculates expected time and dispersion for
all of them using getnstimeofday. The dispersion is calculated mostly
for debugging. I'm not sure if this implementation is good. Maybe
someone can suggest a better calibration solution?

Some other issues are listed in the TODO sections in the beginning of
each module.

2. Synchronization issues
-------------------------
When both modules were good enough I tried to actually sync two
computers using ntpd+PPS. I've set up client to use the ATOM driver and
an external ntp server. BTW, I had to recompile ntpd with both
/usr/include/timepps.h and /usr/include/linux/pps.h installed. This is
not, well, emphasized in the wiki that the recompilation is necessary
to use the ATOM driver.

Also I had to stop ntpd on the master in order to stop adjusting the
master's local time. This was causing high jitter of the PPS signal.
Well, this is not a big problem, but it would be good to have the
master's clock showing the right time.

The big problem is that ntpd needs at least 10 hours to synchronize!
And even after several days the offset is about +-5 microseconds. I
think that the offset can be reduced if ntpd polls every second. Is
there a way to configure ntpd to synchronize faster and better? I mean
in minutes, not in hours.

Maybe the (currently missing) hardpps implementation can do the
synchronization faster and better then ntpd?

I'll be happy to provide any additional details of the setup if needed
so please ask.

-- 
  Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parport.patch
Type: text/x-patch
Size: 25328 bytes
Desc: not available
Url : http://ml.enneenne.com/pipermail/linuxpps/attachments/20090820/48cae9e6/attachment-0001.bin 


More information about the LinuxPPS mailing list