Highly accurate system time
On Time for All Time
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.
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.
Infos
- rpi_gpio_ntp: https://vanheusden.com/time/rpi_gpio_ntp/
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs