Vous êtes sur la page 1sur 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)

Table of Contents

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 )

Typically, 106 seconds/second

After 4 months, clock may have an error of 10.37 seconds

Although relative error is bounded, absolute error may grow


with time

Table of Contents

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

Table of Contents

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

External Synchronization

Clocks of processes are synchronized with an external clock

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

Table of Contents

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

Interpretation: Clocks agree within the bound D

Internally synchronized clocks may show inaccurate time

Externally synchronized clocks are also internally synchronized

Table of Contents

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

Table of Contents

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

Cristians Algorithm (Contd.)

Clients hardware may have a non-zero drift

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

Table of Contents

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

The Berkeley Algorithm

Performs internal synchronization

Master-slave approach:

One of the machines is chosen as master


Other machines become slaves

Algorithm is polling based:

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)

The Berkeley Algorithm (Contd.)


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


requires adjustment

Table of Contents

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

Network Time Protocol

Used for distributing time information over the Internet

Service is provided by a network of servers arranged in a


hierarchical manner

Servers at highest-level (root) are primary servers

Directly connected to a time source (e.g., radio clock receiving


UTC)

Servers at lowest-level (leaf) are users workstations


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

Clock accuracy decreases as level decreases

Network Time Protocol (Contd.)


B

Network Time Protocol (Contd.)

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

= 1 + 2 = T1r T1s + T2r T2s

Set oe as

T1r T1s + T2s T2r


2

Network Time Protocol (Contd.)

Subtracting 1 from 2 , we obtain:


2 1
o = oe +
2

This implies that:


|o oe |

|2 1 |
2

|2 + 1 |
2

Interpretation: oe is an estimate of oe with error bounded by

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

Selects offset estimate with the least error for clock adjustment

Vous aimerez peut-être aussi