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
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.