Skip to content

pps: time synchronization over LPT

Alexander Gordeev lkml 2 versions – NAK

Status from this message: Nak.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 13 repliesNAK
  2. v15 patches 6 repliesSuperseded

Changes in v2 from the cover letter

* fix issues pointed out by John Stultz:
* style fixes
* add a about the authorship of the original code
* replace timespec with pps_normtime struct where timespec is used in a wrong way
* fix seqlock usage in hardpps()
* unbind kernel consumer on device removal
* send raw timestamp instead of the last difference to hardpps() which simplifies the code and is less error-prone
* update comments in the kernel consumer code to match the reality
* split the patch that adds MONOTONIC_RAW timestmaps into two
* other small fixes

Patches in v2

#Subject and filesSizeRepliesApplied
1/6ntp: add hardpps implementationdrivers/pps/Kconfig include/linux/timex.h kernel/time/Kconfig +1 more+414 -152 replies
2/6pps: unify timestamp gatheringdrivers/pps/kapi.c include/linux/pps_kernel.h+31 -71 reply
3/6pps: capture MONOTONIC_RAW timestamps as wellinclude/linux/pps_kernel.h include/linux/time.h kernel/time/timekeeping.c+38 -11 reply
4/6pps: add kernel consumer supportDocumentation/ioctl/ioctl-number.txt drivers/pps/kapi.c drivers/pps/pps.c +2 more+106 -22 replies
5/6pps: add parallel port PPS signal generatordrivers/pps/Kconfig drivers/pps/Makefile drivers/pps/generators/Kconfig +2 more+293 -02 replies
6/6pps: add parallel port PPS clientdrivers/pps/Kconfig drivers/pps/Makefile drivers/pps/clients/Kconfig +2 more+239 -11 reply

Reviews trailers per patch

3 of 6 patches have a Reviewed-by or Acked-by.

PatchRodolfo Giometti
1/6
2/6A-b
3/6A-b
4/6A-b
5/6
6/6

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCHv2 0/6] pps: time synchronization over LPT

This patchset adds a complete solution (well, the kernel part) for fast high-precision time synchronization between computers using their LPT ports. My tests show that it is able to achieve synchronization in the order of 1-2 microseconds and keep it for as long as needed. We are using this facility in my company for distributed real-time simulation.

The idea is to have a single master computer whose local clock is used as a standard. It then provides time information through both PPS high-precision signal over LPT and NTP over network. Then any other computer can combine these two time sources (this is what ntpd can do). Client-side ntpd constantly checks that the local time divergence from the master's time is less then 128ms. If this is true it uses PPS signal to further decrease the difference. ntpd can try to do itself but it's too slow and imprecise. This is really a job for the kernel.

All stuff related to the PPS signals in Linux kernel is handled by the code from LinuxPPS project. It can be controlled from user-space through PPSAPI (RFC 2783) and ntpd can use it to pass control over synchronization to the kernel. Unfortunately this is an optional feature of PPSAPI and it was not implemented. Also Linux code from NTPv4 reference model was missing all the pieces that deal with PPS. This patchset closes both gaps to achieve the highest precision and speed. It:

* adds missing hardpps() function to the NTPv4 Linux kernel code

* adds getnstime_raw_and_real() to atomically get both MONOTONIC_RAW and REALTIME clock timestamps for hardpps()

* adds missing optional PPSAPI method to bind the particular PPS source to feed information to the time subsystem through hardpps()

Also it adds the actual parallel port PPS generator and client.

This patchset is tested against the vanilla 2.6.32.9 kernel. But we are actually using it on 2.6.31.12-rt20 rt-preempt kernel most of the time. Also there is a version which should be applied on top of LinuxPPS out of tree patches (i.e. all clients and low-level irq timestamps stuff). Those who are interested in other versions of the patchset can find them in my git repository:
http://lvk.cs.msu.su/~lasaine/timesync/linux-2.6-timesync.git

There is one problem however: hardpps() works bad when used on top of 2.6.33-rc* with CONFIG_NO_HZ enabled. The reason for this is commit a092ff0f90cae22b2ac8028ecd2c6f6c1a9e4601. Without it hardpps() is able to sync to 1us precision in about 10 seconds. With it

Changelog
v1 -> v2:
* fix issues pointed out by John Stultz:
* style fixes
* add a about the authorship of the original code
* replace timespec with pps_normtime struct where timespec is used in a wrong way
* fix seqlock usage in hardpps()
* unbind kernel consumer on device removal
* send raw timestamp instead of the last difference to hardpps() which simplifies the code and is less error-prone
* update comments in the kernel consumer code to match the reality
* split the patch that adds MONOTONIC_RAW timestmaps into two
* other small fixes

Alexander Gordeev (6):
ntp: add hardpps implementation
pps: unify timestamp gathering
pps: capture MONOTONIC_RAW timestamps as well
pps: add kernel consumer support
pps: add parallel port PPS signal generator
pps: add parallel port PPS client

 Documentation/ioctl/ioctl-number.txt     |    2 +-
 drivers/pps/Kconfig                      |    5 +
 drivers/pps/Makefile                     |    1 +
 drivers/pps/clients/Kconfig              |   16 ++
 drivers/pps/clients/Makefile             |    9 +
 drivers/pps/clients/pps_parport.c        |  211 +++++++++++++++
 drivers/pps/generators/Kconfig           |   17 ++
 drivers/pps/generators/Makefile          |    9 +
 drivers/pps/generators/pps_gen_parport.c |  264 +++++++++++++++++++
 drivers/pps/kapi.c                       |   41 +++-
 drivers/pps/pps.c                        |   67 +++++-
 include/linux/pps.h                      |    7 +
 include/linux/pps_kernel.h               |   30 ++-
 include/linux/time.h                     |    2 +
 include/linux/timex.h                    |    1 +
 kernel/time/Kconfig                      |    7 +
 kernel/time/ntp.c                        |  420 ++++++++++++++++++++++++++++-
 kernel/time/timekeeping.c                |   34 +++
 18 files changed, 1119 insertions(+), 24 deletions(-)
 create mode 100644 drivers/pps/clients/Kconfig
 create mode 100644 drivers/pps/clients/Makefile
 create mode 100644 drivers/pps/clients/pps_parport.c
 create mode 100644 drivers/pps/generators/Kconfig
 create mode 100644 drivers/pps/generators/Makefile
 create mode 100644 drivers/pps/generators/pps_gen_parport.c