Highly accurate system time

On Time for All Time

Article from Issue 203/2017
Author(s):

After the idea of procuring an atomic clock failed to thrill the other members of Charly's household, our intrepid columnist simply decided to tap into the timekeeping of a GPS satellite. In doing so, he ensured the kind of punctuality at home that only large data centers actually need. Precisely.

The network time protocol (NTP) is one of the easiest server-based services to configure. The ntp.conf file requires minimal configuration; just one line with a source from which to tell the time.

pool de.pool.ntp.org iburst

You usually specify more than one source. The NTP daemon (ntpd) queries it cyclically and tries to compute running time differences caused by network latency. My local NTP service runs on a Raspberry Pi (Rasp Pi), otherwise employed full-time in driving the garden irrigation system, and has a time imprecision of 30 to 40msec.

This may be almost indecently accurate for my always slightly chaotic household, but logging with millisecond accuracy is a genuine requirement for data centers. How far can I take this newly inspired punctuality madness?

First of all, I need to reduce the stratum. A highly accurate time source that makes its time signal available to the public is a stratum-0 device. A server that requests the time from it, and distributes the results, is a stratum-1 server, and so on.

The obvious idea of buying an atomic clock strangely failed to meet approval in our family council. This prompted me to provide my Rasp Pi with a GPS receiver – any GPS satellite is a stratum-0 time source. The GPS daemon, included in the scope of most distributions, provides the time signal to the NTP server via a virtual interface. I then added two lines to the ntp.conf file to introduce the NTP daemon to the address:

server 127.127.28.0 minpoll4 noselect
fudge 127.127.28.0 time1 0.0 refid GPS

That's better; however, you can achieve even more precision, because transporting the data through the serial interface can still produce slight variations. You can compute these yourself: GPS satellites do not just transmit the time, but also a pulse per second (PPS) signal. These are short, high-precision pulses output every second.

A small tool named rpi_gpio_ntp [1] by programmer Folkert van Heusden makes the PPS signal accessible to the time server. Again, a virtual IP is used for this, which I entered in my ntp.conf:

server 127.127.28.1 minpoll 4 prefer
fudge 127.127.28.1 refid UPPS

This was amazingly successful. My Munin graph in Figure 1, which shows the fluctuations of the time signal, flattens out to a smooth line after firing up the GPS-PPS combination – not bad for a stratum-1 time server.

Figure 1: Diagram with the system time skew measured on Charly's Rasp Pi.

Time To Go Time

Ntpd is currently dying out on clients in the wake of systemd, replace by timesyncd. Although timesyncd is leaner, it does not propagate to the clients. I configured it in my /etc/systemd/timesyncd.conf file so that it primarily uses my irrigation Rasp Pi and only turns into Internet time servers in an emergency:

NTP=gpspi
FallBackNTP=de.pool.ntp.org 0.pool.ntp.org 1.pool.ntp.org

If the day ever comes when I have accumulated enough hardware to require high-precision logging, now I'm prepared.

The Author

Charly Kühnast manages Unix systems in the data center in the Lower Rhine region of Germany. His responsibilities include ensuring the security and availability of firewalls and the DMZ.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Admin Workshop: NTP

    Networks often require very accurate timekeeping. The Network Time Protocol provides the time with precision.

  • Tempus Fugit

    Charly Kühnast, sys admin columnist for 15 years, is searching for lost microseconds.

  • Charly's Column

    On vacation we may be happy just to check the position of the sun,but computers need a more accurate measure of time. Luckily, there are atomic clocks that can receive time signals by radio and off the Internet.

  • chrony

    The chrony implementation of the network time protocol provides an alternative to the familiar NTP daemon.

  • Charly's Column: Ntpd

    The Network Time Protocol keeps Charly up to date at all times. To put all of this punctuality in the service of the common good, he even exports the time signal.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News