You are on page 1of 22

# Synchronizing Physical Clocks

Neeraj Mittal
The University of Texas at Dallas

August 9, 2012

Motivation

## Types of Clock Synchronization

External Synchronization
Internal Synchronization

## Algorithms for Clock Synchronization

Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Motivation

## Applications such as real time object tracking need physical

clocks to work properly

## Most hardware clocks have a non-zero drift rate

A clock with maximum drift rate of satisfies the following
property:

## C (t): value of clock C at real time t

t1 and t2 : two instants of real time with t1 t2
Then
(1 )(t2 t1 ) C (t2 ) C (t1 ) (1 + )(t2 t1 )

## Although relative error is bounded, absolute error may grow

with time

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

External Synchronization

## External clock is assumed to be accurate (e.g., Coordinated

Universal Time source)
Formal definition:

## S: clock of the server

Ci : clock of process Pi , for i = 1, 2, . . . , N
D: constant
Clocks are said to be externally synchronized if:
For all processes Pi , and for all real times t: |Ci (t) S(t)| D

## Interpretation: Clocks are accurate to within the bound D

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Internal Synchronization

## Clocks of processes are synchronized with each other

Formal definition:

## Ci : clock of process Pi , for i = 1, 2, . . . , N

D: constant
Clocks are said to be internally synchronized if:
For all pairs of processes Pi and Pj , and for all real times t:
|Ci (t) Cj (t)| D

## Externally synchronized clocks are also internally synchronized

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

Cristians Algorithm
Server

Client
Server

Client
Server

Client
Server

## Drift introduces error in the estimation of the round trip time

A typical hardware clock has maximum drift rate of only 106
seconds/second
Any error in the estimate will be negligible if the round trip
time is small and can be ignored

## Estimate of the current clock value of the server assumes

request and reply messages incurred the same delay

## Actual clock value of the server (when reply message is

received by the client) can vary from s to s + Tround depending
on the actual delay incurred by request and reply messages
Skew in clients clock value just after synchronization lies in
Tround
the range
2

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

## Performs internal synchronization

Master-slave approach:

## One of the machines is chosen as master

Other machines become slaves

## Master periodically requests all slaves to send their clock values

It then estimates the current clock value of each slave by
observing the round-trip time (similar to Cristians algorithm)

Master

Slave S
t1
Master

Slave S
t1

t2

Master

c
Slave S
t1
Master

t2

t3

## The Berkeley Algorithm (Contd.)

Master
compute the average

Slaves

## Master computes the average of all (estimated) clock values

including its own once it has received clock values from all
slaves

## To each slave, it sends the amount by which the slaves clock

Motivation
Types of Clock Synchronization
External Synchronization
Internal Synchronization
Algorithms for Clock Synchronization
Cristians Algorithm
The Berkeley Algorithm
Network Time Protocol (NTP)

## Service is provided by a network of servers arranged in a

hierarchical manner

UTC)

## Servers at lowest-level (leaf) are users workstations

Servers at each level are synchronized with servers at a higher
level (to prevent cycles)

B

Notation:

## o: actual offset of Bs clock relative to that of As clock

1 : transmission time for the first message
2 : transmission time for the second message
: total transmission time for the two messages
oe : estimate of o

1 = T1r (T1s + o)

2 = (T2r + o) T2s

Set oe as

2

2 1
o = oe +
2

|o oe |

|2 1 |
2

|2 + 1 |
2

## Client A computes many (oe , /2) pairs:

Selects offset estimate with the least error for clock adjustment