Infrastructure

PTP or Die: Hardware Timestamping for Regulatory-Grade Time Sync

Why NTP is fundamentally broken for HFT compliance, and how we implemented IEEE 1588 PTPv2 with hardware timestamping to achieve sub-100ns accuracy on Solarflare NICs.

4 min
#ptp #time-sync #mifid2 #solarflare #latency #compliance

A MiFID II audit cost a trading firm I advised €2.3M in fines. Not for a trading violation-for clock drift.

Their order timestamps diverged from the exchange’s by 450µs. Under RTS 25, the legal limit is 100µs. The auditor’s forensic analysis was trivial: their logs were inadmissible evidence.

This post documents how to implement sub-100ns time synchronization using IEEE 1588 PTP with hardware timestamping.

1. The Physics of Software Clocks

Your server’s TSC (Time Stamp Counter) drifts. Silicon oscillators are affected by temperature, voltage, and manufacturing variance. A typical drift rate is 1-100 parts per million (PPM).

At 100 PPM, your clock drifts 8.6 seconds per day.

Why NTP Fails

NTP corrects drift by querying upstream servers over the network. The problem: asymmetric network jitter.

Client → t1 NTP Server → t2 Client Assumes Symmetric Path

NTP assumes the request and response take equal time. In reality, datacenter switches have asymmetric queuing. This introduces milliseconds of error-three orders of magnitude worse than MiFID II requires.

2. The Decision Matrix

ApproachAccuracyCostVerdict
A. NTP (Public Servers)±50msFreeNon-compliant. Rejected.
B. NTP (Private Stratum 1)±1ms$5KStill non-compliant.
C. PTP (Software Timestamping)±10µs$10KBorderline. Risky for audit.
D. PTP (Hardware Timestamping)±50ns$25KSelected. 1000x margin over regulation.

Why Hardware Timestamping? Software timestamping occurs in the kernel. By the time the kernel sees the packet, the NIC has already buffered it for ~10µs. Hardware timestamping stamps the packet at the PHY layer, before the kernel is involved.

3. The Kill: PTP on Solarflare

We use Solarflare X2522 NICs because they support hardware timestamping and have a dedicated PTP clock on the card.

Step 1: Configure the PTP Grandmaster

You need a GPS-disciplined PTP Grandmaster (e.g., Meinberg M1000). This device has an atomic clock and a GPS antenna. It broadcasts PTP packets to your network.

Step 2: Install and Configure ptp4l

# Install LinuxPTP
sudo apt install linuxptp

# Configure /etc/ptp4l.conf
# Key settings:
#   tx_timestamp_timeout: Increase for busy NICs
#   delay_mechanism: E2E for most setups
#   priority1: Lower = more likely to be elected master

Step 3: Run ptp4l in Slave Mode

sudo ptp4l -i enp3s0f0 -m -H
# -H = Hardware timestamping (mandatory)

Step 4: Discipline the System Clock with phc2sys

ptp4l synchronizes the NIC’s hardware clock (PHC). You must then discipline the system clock to the PHC.

sudo phc2sys -a -r -r -m

Verification:

cat /var/log/ptp4l.log
# Look for: "rms    5 max   12" (rms < 100ns = success)

4. The Tool: Auditing Time Sync State

Before an audit, verify your configuration programmatically.

pip install latency-audit && latency-audit --check ptp

This verifies that ptp4l is running, that the NIC supports hardware timestamping (ethtool -T), and that the offset is within tolerance.

5. Systems Thinking: The Trade-offs

  1. Single Point of Failure: Your Grandmaster is now critical infrastructure. Budget for a redundant pair.
  2. Network Topology: PTP requires symmetric network paths. Asymmetric hops (e.g., load balancers) destroy accuracy. Run PTP on a dedicated, flat VLAN.
  3. Observability: Standard monitoring tools don’t understand PTP. You need custom dashboards showing phc_offset_seconds from the PTP metrics.

6. The Philosophy

Time is not a feature. It is a physical constraint that determines the legality of your operation.

In financial markets, the order of events is legally binding. If your clock is wrong, your audit trail is fiction. A MiFID II fine is embarrassing. Criminal prosecution for market manipulation (where incorrect timestamps are evidence) is existential.

Invest in PTP like you invest in fire suppression: hoping you never need it, but certain you will.

Share: LinkedIn X