A CLOCK_MONOTONIC-to-PHC offset held constant between samples drifts by microseconds
Symptom#
Events stamped with CLOCK_MONOTONIC are mapped onto a shared NIC hardware clock (PHC) timeline with an offset phc - mono that a daemon measures once per second. Cross-node checks built on the CPU stamps show a clock error of 1 to 3 us that changes from run to run and from rep to rep, while the same check on NIC hardware stamps reads about 0. The offset samples themselves are accurate: two different ways to read them agree within a few ns.
Cause#
CLOCK_MONOTONIC is steered by the time daemon (chrony or ntpd adjust its frequency); a PHC that nothing disciplines runs free. So phc - mono is not a constant: it moves at the frequency difference, here -1.2 to +2.4 us per second, with a different sign on each node. Held constant between two samples, it puts a stamp off by that rate times the age of the sample, up to one second's worth, and two nodes drift apart in opposite directions.
Fix#
- Fit the offset's rate over the last few samples (least squares over 8 samples at 1 Hz is enough) and publish it with the time of the sample.
- Map a stamp with
phc = mono + offset + rate * (mono - t_sample). - Record the rate and the sample time with the trace, so an analysis can undo or redo the mapping.
- Remember that a published struct copied field by field silently drops any new field until the copy is updated.
Evidence#
Seen in dpucrumbs E2 on BlueField-3 DPUs on 2026-09-30. Arm C (CPU stamps on the synced timeline) read +2.56 us with the server on one DPU and -1.15 us with the roles swapped; arm D (NIC stamps) read 0.00 both ways. After the rate fix (datacrumbs-utils 50c2664), arm C read -0.13 and -0.38 us, and the node-dependent part fell from 1.5 to 1.9 us to 0.06 to 0.13 us. PTP_SYS_OFFSET_PRECISE was not supported, and PTP_SYS_OFFSET agreed with the tightest PTP_SYS_OFFSET_EXTENDED sample within 6 ns.
Also found by searching
- arm C clock error 1 to 3 us while NIC hardware stamps read 0
- CPU timestamps drift apart between nodes on a PHC timeline
- how do I map CLOCK_MONOTONIC onto a PTP hardware clock accurately
- mono to PHC offset held constant between samples
- cross-node clock error 1-3 us on CPU timestamps mapped to PHC via phc - CLOCK_MONOTONIC offset sampled each second
- timestamps converted to the NIC hardware clock drift by microseconds between offset samples, but NIC stamps agree
- how do I convert CLOCK_MONOTONIC timestamps to a PTP hardware clock timeline accurately
- chrony steering monotonic clock frequency vs free running PHC, interpolate offset instead of holding it constant