remote-lab.net learn by doing

The Poor Man's PTP Grandmaster: GNSS Time in My Home Lab

One long-standing item on my home lab list was time synchronization. In this experiment I wanted to explore how Precision Time Protocol (PTP) works and what it takes to bring a more accurate time reference to my network.

Since commercial PTP grandmasters are dedicated and quite expensive appliances, for this exercise I wanted to build one with hardware I already had and a few additional parts. A Lenovo m920q mini PC, one Intel I210 network card and a GNSS timing receiver turned out to be enough to make a useful home-lab grandmaster.

The hardware

The setup uses:

Close-up of the SparkFun GNSS timing breakout and its u-blox ZED-F9T module
Close-up of the SparkFun timing breakout with the ZED-F9T receiver.
Lenovo m920q opened to show the Intel I210 NIC and GNSS timing breakout wired inside
The m920q with the I210 NIC and GNSS timing breakout installed

The m920q’s PCIe riser makes room for the I210 card. The GNSS breakout needed a header soldered onto it; after that, a pair of jumper wires connected its 1PPS output to the NIC’s external timestamp input. The receiver connects to the host over the USB-C port, providing the time-of-day data. The u-blox ANN-MB1 connects to the SparkFun breakout’s SMA port via its built-in coax cable and sits near a window/outdoors for a clean GNSS signal.

The ANN-MB1 GNSS antenna and its coiled coax cable beside the Lenovo m920q
The ANN-MB1 antenna and its cable beside the m920q with the cover on top

The PTP client runs in a CentOS Stream VM on a separate host with its own I210 NIC passed through. That NIC is directly connected to the grandmaster I210 port.

How the clocks fit together

The SparkFun board combines the ZED-F9T GNSS timing receiver with the antenna connection. GNSS satellites transmit timing and navigation signals, which the receiver uses to establish its time reference. For this setup, the receiver provides two useful outputs:

  • 1PPS: one pulse per second. Its edge gives the NIC a precise second boundary to timestamp.
  • NMEA time-of-day: the Recommended Minimum Specific GNSS Data (RMC) sentence labels which second that pulse represents.

A pulse on its own does not identify the second: it marks a boundary, but does not say whether that boundary is 12:00:00 or 12:00:01. LinuxPTP’s ts2phc combines the pulse timestamp captured by the NIC with the NMEA time information and disciplines the I210’s PHC. LinuxPTP supports NMEA RMC as the time-of-day source for an external PPS signal (ts2phc documentation).

There are three clocks to keep track of:

  1. GNSS time, provided by the receiver
  2. The NIC’s PHC, disciplined from the GNSS pulse and used for hardware packet timestamps
  3. The Linux system clock, CLOCK_REALTIME, which applications normally use

On the grandmaster, ptp4l advertises the NIC’s clock to PTP clients. On the client, another I210 receives hardware timestamps and ptp4l uses PTP messages to synchronize its PHC with the grandmaster. phc2sys then synchronizes the client’s system clock to its PHC.

Diagram showing GNSS 1PPS and NMEA disciplining the grandmaster PHC, PTP synchronizing the client PHC, and phc2sys synchronizing the client system clock
The timing path from the GNSS receiver to the grandmaster and client system clocks.

Checking the ZED-F9T’s reported status

Before starting ts2phc check if the receiver is reporting a GNSS fix by reading its NMEA output:

cat /dev/ttyACM0

The useful status fields from one sample look like this (the coordinates are masked):

$GNRMC,163537.00,A,<latitude>,N,<longitude>,E,0.113,,021226,...
$GNGGA,163537.00,<latitude>,N,<longitude>,E,1,12,1.31,76.2,M,34.8,M,,
$GNGSA,A,3,...

In the RMC sentence, A means the data is valid. The GGA quality value 1 indicates an autonomous GNSS fix; 12 is the number of satellites used and 1.31 is the reported HDOP. The GSA mode 3 indicates a 3D fix. These are useful checks that the receiver has a position solution, but they do not measure the absolute accuracy of the timing output. See the u-blox ZED-F9T Interface Description for the NMEA field definitions.

Configuration used

These are snapshots of the LinuxPTP configuration used in this experiment. The interface names and ZED-F9T serial path are specific to these machines, so replace them with the names present on your own hosts if adapting the examples.

Grandmaster: ts2phc

On compute03, ts2phc reads the ZED-F9T’s NMEA RMC time over USB and captures external timestamps on enp1s0. The pulse width is configured as 100 ms, with channel 0 and pin 0 used for the external timestamp input.

[global]
use_syslog 0
verbose 1
logging_level 6
leapfile /usr/share/zoneinfo/leap-seconds.list
ts2phc.tod_source nmea
ts2phc.nmea_serialport /dev/serial/by-id/usb-u-blox_AG_-_www.u-blox.com_u-blox_GNSS_receiver-if00
ts2phc.nmea_baudrate 38400
ts2phc.pulsewidth 100000000

[enp1s0]
ts2phc.channel 0
ts2phc.extts_polarity both
ts2phc.pin_index 0

Grandmaster: ptp4l

The grandmaster runs hardware timestamping over Ethernet Layer 2 and uses end-to-end delay measurement:

[global]
domainNumber 0
clientOnly 0
time_stamping hardware
network_transport L2
delay_mechanism E2E
twoStepFlag 1
clockClass 6
clockAccuracy 0xFE
offsetScaledLogVariance 0xFFFF
timeSource 0x20
utc_offset 37
logging_level 6
summary_interval 0

[enp1s0]

Client: ptp4l and phc2sys

The client VM uses its passed-through I210 interface and runs as client-only:

[global]
domainNumber 0
clientOnly 1
time_stamping hardware
network_transport L2
delay_mechanism E2E
logging_level 6
summary_interval 0

[enp4s0]

See the ts2phc, ptp4l and phc2sys documentation for the available options.

Watching the clocks

To see how the system behaves over time I set up exporters on the grandmaster and client, scrape the metrics with Prometheus and display them in Grafana. The dashboard tracks GNSS-to-PHC offset, client offset from the master and the offset between the client PHC and its system clock.

Grafana time series showing GNSS-to-PHC and PHC-to-system offsets
GNSS-to-PHC offset on the grandmaster and PHC-to-system offset on the client.
Grafana time series showing the client PTP offset from the grandmaster over time
The client PTP offset from the grandmaster

What I got out of it

The result is a compact GNSS-backed PTP grandmaster assembled around a mini PC I already had. More than anything, it gave me a hands-on way to follow time from the GNSS receiver, into a NIC’s hardware clock, across a PTP link and into another machine’s system clock.

References

comments powered by Disqus