ES - 05 Clock Synchronization
ES - 05 Clock Synchronization
Embedded Systems
2
Outline
Ø Time and Clocks
Ø Time Measurement
Ø DenseTime versus SparseTime
Ø Internal Clock Synchronization
Ø External Clock Synchronization
RealTime
p q r
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
4
Durations
and Events
Ø A section of the time line is called a duration.
Ø An event is a happening at an instant of time.
Ø An event does not have a duration.
Ø If two events occur at an identical instant, then the two
events are said to occur simultaneously.
Ø Instants are totally ordered, while events are only partially
ordered, since simultaneous events are not in the order
relation.
Ø Events can be totally ordered if another criterion is
introduced to order events that occur simultaneously (e.g.,
in a distributed computer system the node number can be
used to order simultaneous events).
Causal Order
Ø Definition of causality by a mark method without
reference to time: "If event 𝑒1 is a cause of event 𝑒2,
then a small variation (a mark) in 𝑒1 is associated with
small variation in 𝑒2, whereas small variations in 𝑒2 are
not necessarily associated with small variations in 𝑒1."
Ø Example: Suppose there are two events 𝑒1 and 𝑒2:
Ø 𝑒1 Somebody enters a room.
Ø 𝑒2 The telephone starts to ring.
Ø Consider the following two cases
Ø (i) 𝑒2 occurs after𝑒1
Ø (ii) 𝑒1 occurs after 𝑒2
Alarm Analysis
Ø A primary alarm event leads to a shower of secondary
alarm events (alarm shower).
Ø If the (partial) temporal order between alarm events
has been established, it is possible to exclude an alarm
event that definitely occurred later than other alarm
events from being the primary event.
Ø A precise global time-base helps to determine the
event set that is in this definitely-occurred-later
relation.
Ø Delivery order of messages in computer networks:
Ø Temporal?
Ø Causal?
Ø Consistent?
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
7
Clocks and
Timestamps
Ø A clock is a device that contains a counter and increments this
counter periodically (microticks)
Ø Assumption of an external observer with an atomic clock that
has a granularity that is much smaller than the duration of any
intervals of interest:
Ø Reference clock 𝑧
Ø High precision, e.g., 1 femto second(10−15sec)
Ø The granularity of a clock 𝑐 is the number of microticks of the
reference clock between any two consecutive microticks of 𝑐.
Ø Given a clock and an event, a timestamp of the event is the
state of clock immediately after the event occurrence,
denoted by
Ø 𝑐𝑙𝑜𝑐𝑘 (𝑒𝑣𝑒𝑛𝑡)
Ø We assume that relativistic effects can be neglected.
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
8
Clock Drift
Ø Clock Drift:
" "
𝑧(𝑚𝑖𝑐𝑟𝑜𝑡𝑖𝑐𝑘!#$ ) − 𝑧(𝑚𝑖𝑐𝑟𝑜𝑡𝑖𝑐𝑘! )
𝐷𝑟𝑖𝑓𝑡!" =
𝑛"
Ø where:
Ø 𝑘 the clock we are looking at
Ø 𝑛𝑘 nominal number of ticks of the reference clock within a
granule of clock 𝑘
Ø 𝑧 timestamp of the reference clock
Error in Counter
(state error)
Precision
Ø Offset between two clocks j,k at tick i:
%" %
𝑜𝑓𝑓𝑠𝑒𝑡! = 𝑧(𝑚𝑖𝑐𝑟𝑜𝑡𝑖𝑐𝑘! ) − 𝑧(𝑚𝑖𝑐𝑟𝑜𝑡𝑖𝑐𝑘!" )
Accuracy
Ø The offset of clock 𝑘 w.r.t. the reference
clock 𝑧 at tick 𝑖 is called the accuracy.
Ø Accuracy denotes the maximum offset
of a given clock from the external time
reference.
Ø This process of resynchronization of a
clock with the reference clock is called
external synchronization.
Ø If all clocks are externally synchronized
with an accuracy 𝐴, then the ensemble
is also internally synchronized with a
precision of at most 2 · 𝐴.
Ø The opposite is not true.
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
12
Time Standards
Ø International AtomicTime (TAI):
Ø TAI is a physical time standard that defines the second as the
duration of 9 192 631 770 periods of the radiation of a specified
transition of the cesium atom 133.
Ø TAI is a chronoscopic timescale, i.e., a timescale without any
discontinuities.
Ø Defines the epoch, the origin of time measurement, as January 1,
1958 at 00:00 hours, and continuously increases the counter.
Ø Universal Time Coordinated(UTC):
Ø UTC is an astronomical time standard that is the basis for the time
on the "wall clock".
Ø Duration of the second conforms to TAIstandard.
Ø Number of seconds in an hour is occasionally modified by inserting
leap seconds to maintain synchrony between the wall-clock time and
the astronomical phenomena, like day and night.
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
13
Global Time
Ø If there is a single reference clock available,all time
measurements can be performed by this single clock that
acts as a common “global”time.
Ø In a distributed system we synchronize clocks in order to
generate a common notion of time, a “global time” in the
distributed system.
Ø However, such a global time is an abstract notion thatcan
only be approximated by the clocks in the nodes.
Ø It is possible to select a subset of the microticks of each local
clock k for the generation of the local implementation of a
global notion of time. We call such a selected local microtick
a macrotick (or a tick) of the global time.
Π/Δ Precedence
Ø Given a set of events {𝐸} and two durations 𝜋 and Δ
where 𝜋 ≪ Δ , such that for any two elements 𝑒𝑖
and 𝑒𝑗 of this set the following condition holds:
[ z(e i ) - z(e j ) £ p ] Ú [ z(e i ) - z(e j ) > D ]
Dense Time
Ø A timebase is dense if events can occur at any point of
the timeline.
Ø Consequences of these fundamental limits of time
measurement in distributed systems:
Ø If a single event occurring on a dense timebase is
observed by two nodes of the distributed system (e.g., to
achieve redundancy in the observations), then an explicit
agreement protocol is needed to establish a consistent
view of the temporal point of event occurrence.
Ø If two events occur on a dense timebase, then it is
impossible to always recover the temporal order of the
events if they occur within an interval of 3𝑔.
0 1 2 3 4 5 6 7 8 9
Time
p D p D p
Space/Time Lattice
Past Future
good good
A B
C to A: 9:00 C to B 15:00
C
two faced malicious
Delay Jitter
Ø The difference dmax − dmin is called the delay jitter 𝜀.
Ø Typical protocol execution time in standard OSI
protocols (with time redundant transmissions)
synchronize clocks?
Convergence Function
Ø Examples:
Ø Average Algorithm
Ø Fault-Tolerant Average (FTA)
Ø Fault-Tolerant Midpoint
Ø Interactive Consistency Algorithms
If 𝑘 = 1,then
Fault Tolerant
Midpoint
1. Measured values are ordered according to size.
2. k largest and k smallest values are deleted from this list.
3. Smallest and largest values are selected from the
remaining values.
4. These two values are added and divided by two.
Deviation
Embedded
R. Obermaisser,Embedded
Systems Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
40
Interactive
Consistency Algorithms
Ø To overcome the problem of the Byzantine error factor,
every node sends its view of the ensemble to all other
nodes in order that every node has the global view of
the situation, i.e., it can find out which node has been
cheating.
Ø Every node takes this consistent global view, i.e., the
matrix of time vectors, as the basis of the correction
factor calculation.
Ø Pro: 𝜇(𝑁, 𝑘) = 1
Ø Con: Extra round of communication
1
∆ABC = 𝜀 1 −
𝑁
Critical Parameters
Ø What are the critical parameters that determine the
quality of the global time base?
Ø Drift offset Γ = 2 · 𝑅𝑠𝑦𝑛𝑐 · 𝜌
Ø Delay jitter 𝜀 = d max −𝑑𝑚𝑖𝑛
Ø The occurrence of Byzantine failures is a rare event
Ø The delay jitter is smallest, if the clock synchronization
is performed very close to the physical level – by the
hardware.
Ø Compared to the delay jitter, the algorithmic effects
are small.
Ø How long will it take until the clocks drift so far from each other
that they will leave the slack interval?
𝑔 − Π 𝑔 Granularity
𝑑 ()*+,-./ = P Precision
2𝜌 r Drift rate
Ø (Assume Byzantine error factor 𝜇 = 1)
Embedded Systems [Ref.:H.Kopetz,Real-Time Systems 2011]
45
Summary
and Key Takeaways
Ø Instants, Durations,Events and Clocks
Ø Causal Order and TemporalOrder
Ø Clock Drift
Ø GlobalTime, Precision and Accuracy
Ø Reasonableness Condition
Ø Fundamental Limits to TimeMeasurement
Ø Dense and SparseTime
Ø Central Master and Distributed Clock Synchronization
Ø Fault-Tolerant Algorithms (FTA, FTM, Interactive Consistency)
Ø State and Rate Correction
Ø Blackout Survivability