An mlx5 CQE timestamp needs its own device's clock fit; another device's fit lands seconds off
Symptom#
Completion timestamps from one host are far off a synchronized clock: send and receive legs between the host and a peer read about +26.75 s one way and about the opposite the other way, with every message paired correctly. A second host is off by about 59 ms. Stamps from other nodes are fine.
Cause#
A CQE timestamp counts the free-running counter of the device that owns the CQ. The converter fitted one device per node (the clock sync daemon's chosen raw device) and pushed every CQE through that one tuple. On the DPUs the application used that same device, so the stamps were right. On the hosts the application used a different card with its own counter, so its counts went through another counter's tuple.
Fix#
Convert each CQE through its own device's clock:
- Keep the CQ's
ibv_contextwhen the CQ is created. - Read that device's
mlx5dv_get_clock_info(ctx, &ci)(dlsym it fromlibmlx5.so.1) and refresh it about every 100 ms, well inside the counter's wrap bound. - Test whether it is the fitted device's counter: convert the device's own
ci.last_cyclesthrough the fitted tuple. If that lands within 1 ms ofci.nsec, it is the same counter; keep the fitted path. - Otherwise convert the raw count to ns with the device's own tuple (
nsec,last_cycles,frac,mult,shift,mask), which gives time on that device's PHC, then move it to the synchronized clock with the PHC-to-global map. - Read the clock info only while the context is alive; in a reader thread that sweeps CQs, read it under the lock that keeps the context alive.
Evidence#
Seen in dpucrumbs' ibverbs completion shim on BlueField-3 host PFs (the host app on mlx5_0, the daemon fitting mlx5_2, a different card). Before: +26.75 s on one host and +59 ms on the other. After: no completion stamp earlier than the CPU poll that returned it on the DPUs and one host; the other host still ran up to about 4 us late, most likely the offset between the two cards' PHCs, which the daemon measures once a second (not proven). DPU-to-DPU message legs did not change (4.4 to 5.7 us).
Also found by searching
- RDMA completion timestamps are seconds off on one host
- CQE hardware timestamp converted with the wrong device clock
- how do I convert an mlx5 CQE timestamp to wall time on a host with two NICs
- message legs read +26 s one way and -26 s the other