Time for Pi

Building a Stratum-1 NTP Server with a Raspberry Pi 3 or 4

While plenty others have posted their Raspberry Pi based NTP server builds, here's my take on it (this post and github [1]).


Picture 1, Precision timepiece


Why do I need accurate and precise time on my network?

Many organizations, not just the smaller ones, do not take the time to really get time right (pun intended). Some believe that their Active Directory PDC emulator on top of the AD Hierarchy (at least time-wise) provide accurate and precise time.
Others just assign a single random Network Time Protocol (NTP) server as the time source (some Cisco equipment only allow one, some only two, some vendors even rely on - the horror - SNTP) which is another fallacy. As Segals law state “A man with one watch always knows what time it is. A man with two watches is never sure.” which helps to illustrate the need for multiple sources of accurate time - NTP does exactly that, by utilizing many time sources.
This build use a GPS/PPS based source combined with a number of public Stratum-1 servers, but with 4 or more internal time sources internet connectivity isn't required. Precision Time Protocol (PTP) is a totally different beast, achieving nanosecond- or even picosecond-level precision, where NTP "only" provide microsecond or, depending on Stratum, millisecond-level precision. NTP is likely more than accurate enough, but for even better precision and accuracy PTP is required. PTP is way out of scope for this post, so let's get back on track with NTP.

Precise and accurate time is important for many reasons, including
  • Log file accuracy, auditing & monitoring
  • Trouble shooting and recovery
  • File time stamps
  • Directory services
  • Access security and authentication (i.e. Kerberos in AD)
  • Distributed computing
  • Transactions (not least financial)

There's also legal requirements to be aware of for many industries - far more than you might think - some requiring accurate timestamps on all logs. However the benefits of keeping accurate time alone is reason enough to do it.


NTP Server Hardware

A few Raspberry Pi's with cheap GPS boards and external antennas* should be within reach for most - even home networks. With internet access you could get away with one or two Pi's adding publicly available time servers to reach the sweet spot of 5-7 time sources. With no internet access 5 Pi's won't break the bank either, and you'd even have enough redundancy to swap the inevitable worn out sd-card and update them regularly.

* I Put the cheap indoor antennas inside outdoor electrical boxes like the one in picture 2, and mounted them outside with a clear view of the sky. They did work in the window sill, however with less satellites seen.

Picture 2, Electrical Box


It would also be within reach of many organizations to buy a cheaper NTP server, such as the LeoNTP [2] or the Meinberg M200 [3], then supplement with a few Raspberry Pi's for extra sources.

A lot of different GPS Boards are available, including some complete hats that can be mounted directly on the 40 Pin GPIO on the Pi, however it's easy to connect a breakout board with 5 pieces of wire.

Picture 3, GPS Board


Chrony vs NTPD

Using chrony may increase precision, including using hardware timestamping (like PTP), however Raspberry Pi NICs do not support hw timestamping, as evidenced by the command "ethtool -T eth0".

Time stamping parameters for eth0:
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none

Chrony may replace NTPD in future versions of this build if my testing show increased precision - but please note that smarter people with better tools have shown this to be the case [4], so why am I waiting?

Precision versus accuracy

While I may have used accuracy and precision loosely above, here's a definition lifted off the Internet:
Accuracy refers to how close a measurement is to the true or accepted value.
Precision refers to how close measurements of the same item are to each other.
That means it is possible to be very precise but not very accurate, and it is also possible to be accurate without being precise.

When it comes to timestamps we want them to be both accurate and precise, however achieving good precision across all systems on your network at least allow you to work with the timestamps you've got, and understanding the delta in accuracy even to correlate with data from other, more accurate, systems.

[4] Building a more accurate time service at Facebook scale: https://engineering.fb.com/2020/03/18/production-engineering/ntp-service/

No comments: