The Transport Layerjohanl/educ/2IN20/clocksynchro.pdf · June 2004 Peter van der [email protected]...

20
June 2004 Peter van der [email protected] TU/e Computer Science, System Architecture and Networking 1 Real-Time Course Clock synchronization

Transcript of The Transport Layerjohanl/educ/2IN20/clocksynchro.pdf · June 2004 Peter van der [email protected]...

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

1

Real-Time CourseClock synchronization

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

2

Clocks

Clock has drift rateFor t1 and t2, with t2 > t1(1-ρ)(t2-t1) <= Cp(t2)-Cp(t1) <= (1+ρ)(t2-t1)

Processor p has monotonically increasing clock functionCp(t)

Suppose Cp(t) = Cq(t) = C, and ρ = 2 µs/s = 2.10-6

Worst case:Cp(t+1s) = C+1 + 2.10-6

Cq(t+1s) = C+1 - 2.10-6

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

3

Synchronous Systems

• Bounded communication times• Kind of global clock

• | Cp(t) – Cq(t) | < ε

• p and q identify processors

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

4

Clock Drifts

Given t2 , t1, with t2 = t1 + ∆

Maximum drift between p and q at t2, when:Cp(t2) = Cp(t1) + (1+ρ).(t2-t1)

Cq(t2) = Cq(t1) + (1-ρ).(t2-t1)

At t2, difference between p and q clock valuesCp(t2) - Cq(t2) = 2.ρ. ∆

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

5

Synchronization interval

Clocks not synchronized when:Cp(t2) - Cq(t2) = 2.ρ. ∆ > ε

Before ∆ time units expired, clocks must be synchronizedThus: 2.ρ.∆ < εGiven that ε = 50 µs, ρ given by manufacturer,∆ can be calculated

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

6

Clock Synchronization

Three types of clock implementations:

1. Central clock: special purpose connection2. Centrally controlled clock: local clocks

with central reference clock3. Distributed clocks: local clocks agree

In all cases, synchronization is never perfect

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

7

Central clock broadcast

Fixed transmission delay: δSet Cq(t2) equal to Cp(t1) + δ

What is Cp(t2) – Cq(t2) ?

Time

Cp(t1)

Cq(t2)

δt1 t2

q

P

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

8

Central clock broadcast (2)

What is Cp(t2) – Cq(t2) ?

Use: δ.(1- ρ) < Cp(t2) – Cp(t1) < δ.(1+ ρ)

Cp(t2) – Cq(t2) =Cp(t2) – Cp(t1) + Cp(t1) - Cq(t2) =Cp(t2) – Cp(t1) + Cp(t1) – (Cp(t1) + δ) =Cp(t2) – Cp(t1) - δ

δ.(1- ρ) - δ < Cp(t2) – Cp(t1) - δ < δ.(1+ ρ) - δ- δ.ρ < Cp(t2) – Cq(t2) < δ.ρ

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

9

Central clock broadcast (3)

p

q1 q2 q2

- δ.ρ < Cp(t) – Cqx(t) < δ.ρ-2.δ.ρ < Cq1(t) – Cq2(t) < 2.δ.ρ

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

10

Central clock request

p

q

time t1 t2 t t3 t4

a b

d d

Cq(t)

Cp(t1) Cp(t2) Cp(t3) Cp(t4)

t2-t1 = t4-t3 = d is minimum transmission time

Cq(t4)

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

11

Central clock request (2)

Given in p is: Cp(t1), Cp(t4) and Cq(t)What is Cp(t4) - Cq(t4)

First calculate Cq(t4) based on Cq(t) (t4-t)(1- ρ) < Cq(t4) – Cq(t) < (t4-t)(1+ ρ) { t4 – t = d + b}(d+b)(1- ρ) < Cq(t4) – Cq(t) < (d+b)(1+ ρ) { 0 <= b <= t4-t1-2d }d.(1- ρ) < Cq(t4) – Cq(t) < (t4-t1-d)(1+ ρ) {(t4-t1)(1- ρ) < Cp(t4) – Cp(t1) }{(t4-t1)< (Cp(t4) – Cp(t1))/(1- ρ) }

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

12

Central clock request (3)

d.(1- ρ) < Cq(t4) – Cq(t) < (t4-t1-d)(1+ ρ) {(t4-t1)< (Cp(t4) – Cp(t1))/(1- ρ) }

d.(1- ρ) < Cq(t4) – Cq(t) < (Cp(t4) – Cp(t1)).(1+ ρ)/(1- ρ) -d.(1+ ρ){substitute: 2K = (Cp(t4) – Cp(t1)).(1+ ρ)/(1- ρ) }

d.(1- ρ) < Cq(t4) – Cq(t) < 2K - d.(1+ ρ)

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

13

Central clock request (4)

Take Cp(t4) = Cq(t) + K – ρd

Cq(t4) - Cp(t4) = Cq(t4) - Cq(t) + Cq(t) - Cp(t4) == -K + ρ d + Cq(t4) - Cq(t) {d.(1- ρ) < Cq(t4) – Cq(t) < 2K - d.(1+ ρ)}

-K - d < Cq(t4) - Cp(t4) < K + d

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

14

Probabilistic clock synchronization

Transmission time has a given distribution

Send several requests to server.Use value obtained with shortest communication time to synchronize clocks

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

15

Distributed clock synchronization

Failure of central clock results in failure of clock synchronization

High reliability requirement and a well defined clock failure probability leads to distributed clock synchronization protocol

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

16

Distributed clock synchronization (2)

Synchronized clock cp(t) is given by:cp(t) = Cp(t) + FIXp

Where:Cp(t) is clock functionFIXp is repetitively calculated constant

FIXp calculation is based on convergence function CF(cp(t), c1(t) c2(t) ….. cN(t) )

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

17

Distributed clock synchronization (3)

Clock synchronization algorithm

FIXp := 0WHILE TRUE DO

await next synchronizationcollect c1(t) c2(t) ….. cN(t) FIXp := CF(cp(t), c1(t),c2(t) ….. cN(t)) - Cp(t)

OD

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

18

Distributed clock synchronization (3)

Assume that m out of N processors can fail

Egocentric AverageCFEA(tp, t1, t2 ….. tN) = 1/N Σi=1.N xiWhere:ti is value obtained from processor i by

processor pxi = ti if |tp – ti| < εxi = tp otherwise

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

19

Distributed clock synchronization (4)

Calculate largest difference after synchronization between correct processors p and q- Faulty processor, f, can send different clock

values to p and q.- Assume tq > tp

Worst behavior

On processor p: tf = tp – εOn processor p: tf = tq + ε

June 2004 Peter van der [email protected]/e Computer Science, System Architecture and Networking

20

Distributed clock synchronization (5)

Calculate Tp and Tq, values after synchronization

Tp = 1/N( Σf tf + Σi ti )On processor p: Σf tf = m(tp – ε)On processor q: Σf tf = m(tq + ε)Assume Σi ti is same on both p and q

Tq – Tp =1/N( m(tq + ε) - m(tp – ε))=m/N(tq - tp + 2ε)

{ tq - tp < ε}Tq – Tp < 3mε/N required: m < N/3