BlueZero (BØ)
Middleware for distributed applications
Time Synchronization

This page describes how time synchronization works.

The objective of time synchronization is to coordinate otherwise independent clocks. Even when initially set accurately, real clocks will differ after some amount of time due to clock drift, caused by clocks counting time at slightly different rates.

timesync_plot1.png
Example of two drifting clocks

There is one master clock node, which usualy coincides with the resolver node, and every other node instance will try to synchronize its clock to the master clock, while maintaining a guarrantee on some properties:

Time synchronization never changes the computer's hardware clock. It rather computes an offset to add to the hardware clock.

The method Node::timeUSec() returns the value of the hardware clock corrected by the required offset, while the method Node::hardwareTimeUSec() will return the hardware clock actual value.

Each time a new time is received from master clock (tipically in the heartbeat message) the method Node::updateTime() is called, and a new offset is computed.

timesync_plot2.png
Example time series of the offset, which is computed as the difference between local time and remote time. Note that is not required that the offset is received at fixed intervals, and in fact in this example it is not the case.

If we look at the offset as a function of time we see that is discontinuous. This is bad because just adding the offset to the hardware clock would cause arbitrarily big jumps and even jump backwards in time, thus violating the two properties stated before.

timesync_plot3.png
The adjusted time obtained by adding the offset to local time

To fix this, the offset function is smoothed so that it is continuous, and limited in its rate of change (max slope). It is important that the max slope is always greater than zero, so as to produce an actual change, and strictly less than 1, so as to not cause time to stop or go backwards.

timesync_plot4.png
The smoothed offset. In this example we used a max slope of 0.5, such that the time adjustment is at most half second per second.
timesync_plot5.png
The resulting adjusted time