dr. kalpakis cmsc621 advanced operating systems synchronization
TRANSCRIPT
CMSC 621
2
Clock Synchronization
When each machine has its own clock, an event that occurred after
another event may nevertheless be assigned an earlier time.
CMSC 621
3
Physical Clocks
Implemented via timers
Counter + holding register with value H
Clock tick = the interrupt generated every H oscillations of a quartz
crystal
Clock skew = difference in the time readings of different clocks
CMSC 621
4
Solar Time
Transit of the sun = the event of the sun reaching the highest point in the
horizon every day
Solar day = time duration between two consecutive transits of the sun
Solar second = 1/86400th of the solar day
the period of earth’s rotation is not constant
Solar seconds get longer over time!
CMSC 621
5
Atomic Time
Atomic clocks
1 second = the time it takes for the Cesium 133 atom to make
9,192,631,770 transitions
Bureau International de L’Heure averages the readings fo
several atomic clocks to produce the International Atomic Time
(TAI)
TAI= #seconds since Jan 1, 1958.
Since solar days get longer over time, keeping time more
accurately with atomic clocks leads to problems
Over time, noon will be occurring in the early morning hours!
CMSC 621
6
Atomic Time and leap seconds
TAI seconds are of constant length, unlike solar secondsTAI and Solar time can get out of synch over time Leap seconds are introduced when necessary to keep in phase with the sun.
Introduced whenever the difference between atomic time and solar time reaches 800 msecs
Universal Coordinated Time (UTC) = TAI with leap secondsTotal leap seconds in UTC is about 30
CMSC 621
7
UTC Servers
Could also utilize the frequency of AC in power lines for
keeping track of time
NIST operates the WWV short-wave radio station that
broadcasts a pulse at the beginning of each UTC second
WWV has is accurate within 1 msec
CMSC 621
8
Measuring time with the Global Positioning System
GPS uses 29 satellites with atomic clocks in an orbit of height
about 20,000Km
Each satellite broadcasts its location and its local atomic time
Receivers can estimate their clock skew Ts since
Distance from satellite I = speed of light x (T – Ti)
Delay in getting msg from satellite I = (T-Ti) + Tdrift
Using 4 satellites, receiver can find its location (x,y,z) and Tdrift by solving
a system of 4 eqs. With 4 unknowns
CMSC 621
9
Physical Clock Synchronization
Cp(t) = the local time at p when UTC is t
Clock skew = C’p(t) -1
Clock offset wrt t = Cp(t) – t
clock theof ratedrift maximum theis where dt
dC
seconds 2every edsynchroniz
be toneed clockssuch two than more no of difference ensure to
t after timet 2by apart becan ratedrift max. with closks two
CMSC 621
10
Network Time Protocol
Estimating A’s clock offset relative to B’s clock
A sends request to B and receives response from B
Request and response are timestamped by the local clocks of A and BT1 = time req. is send by A
T2 = time req. is received by B
T3 = time response is send by B
T4 = time response is received by A
Assuming the propagation delays are symmetric (ie (T2-T1 = T4-T3), the
offset of A relative to B is
use the offset corresponding to the least delay among 8 such measurements
between A and B
If A’s clock is fast/slow, A slowdowns/fasten gradually over time
2
)()( isdelay the where
2
)()( 341243123
TTTTTTTTT
CMSC 621
11
Network Time Protocol
Problem: possible that node with morew accurate clock adapts
to a less accurate clock!
Stratify the nodes
Server with reference clock is at stratum 1
A node A adjuststs clock only when it has an offset from a node B with
lower stratum, in which case stratum(A) becomes stratum(B)+1
CMSC 621
12
The Berkeley Algorithm
a) The time daemon asks all the other machines for their clock values
b) The machines answer
c) The time daemon tells everyone how to adjust their clock
CMSC 621
13
Clock synchronization in wireless networks
Reference Broadcasting Synchronization (RBS)
Server queries nodes for their times to compute an offset for them
Server’s clock is left out of the synchronization
Assumes no multihop routing
Sender sends message
Propagation delay is same for all receivers
Nodes estimate their offsets from each other
T(p,m) = time p receives m
Relative offset of node p wrt to node q is
Can also estimate relative offset via a linear regression
M
kqTkpTM
k
1
]),[],[( q]Offset[p,
CMSC 621
14
Lamport Timestamps
a) Three processes, each with its own clock. The clocks run at different rates.b) Lamport's algorithm corrects the clocks.
CMSC 621
15
Example: Totally-Ordered Multicasting
Updating a replicated database and leaving it in an inconsistent state.
CMSC 621
18
Global State (3)
b) Process Q receives a marker for the first time and records its local statec) Q records all incoming messaged) Q receives a marker for its incoming channel and finishes recording the state of the
incoming channel
CMSC 621
19
The Bully Algorithm (1)
The bully election algorithmProcess 4 holds an electionProcess 5 and 6 respond, telling 4 to stopNow 5 and 6 each hold an election
CMSC 621
22
Mutual Exclusion: A Centralized Algorithm
a) Process 1 asks the coordinator for permission to enter a critical region. Permission is grantedb) Process 2 then asks permission to enter the same critical region. The coordinator does not reply.c) When process 1 exits the critical region, it tells the coordinator, when then replies to 2
CMSC 621
23
A Distributed Algorithm
a) Two processes want to enter the same critical region at the same moment.b) Process 0 has the lowest timestamp, so it wins.c) When process 0 is done, it sends an OK also, so 2 can now enter the critical
region.
CMSC 621
24
A Toke Ring Algorithm
a) An unordered group of processes on a network.
b) A logical ring constructed in software.
CMSC 621
25
Comparison
A comparison of three mutual exclusion algorithms.
AlgorithmMessages per
entry/exit
Delay before entry (in
message times)Problems
Centralized 3 2 Coordinator crash
Distributed 2 ( n – 1 ) 2 ( n – 1 ) Crash of any process
Token ring 1 to 0 to n – 1Lost token, process
crash
CMSC 621
27
The Transaction Model (2)
Examples of primitives for transactions.
Primitive Description
BEGIN_TRANSACTION Make the start of a transaction
END_TRANSACTION Terminate the transaction and try to commit
ABORT_TRANSACTION Kill the transaction and restore the old values
READ Read data from a file, a table, or otherwise
WRITE Write data to a file, a table, or otherwise
CMSC 621
28
The Transaction Model (3)
a) Transaction to reserve three flights commitsb) Transaction aborts when third flight is unavailable
BEGIN_TRANSACTION
reserve WP -> JFK;
reserve JFK -> Nairobi;
reserve Nairobi -> Malindi;
END_TRANSACTION
(a)
BEGIN_TRANSACTION
reserve WP -> JFK;
reserve JFK -> Nairobi;
reserve Nairobi -> Malindi full =>
ABORT_TRANSACTION
(b)
CMSC 621
30
Private Workspace
a) The file index and disk blocks for a three-block fileb) The situation after a transaction has modified block 0 and appended block 3c) After committing
CMSC 621
31
Writeahead Log
a) A transactionb) – d) The log before each statement is executed
x = 0;
y = 0;
BEGIN_TRANSACTION;
x = x + 1;
y = y + 2
x = y * y;
END_TRANSACTION;
(a)
Log
[x = 0 / 1]
(b)
Log
[x = 0 / 1]
[y = 0/2]
(c)
Log
[x = 0 / 1]
[y = 0/2]
[x = 1/4]
(d)
CMSC 621
33
Concurrency Control (2)
General organization of
managers for handling
distributed transactions.
CMSC 621
34
Serializability
a) – c) Three transactions T1, T2, and T3
d) Possible schedules
BEGIN_TRANSACTION
x = 0;
x = x + 1;
END_TRANSACTION
(a)
BEGIN_TRANSACTION
x = 0;
x = x + 2;
END_TRANSACTION
(b)
BEGIN_TRANSACTION
x = 0;
x = x + 3;
END_TRANSACTION
(c)
Schedule 1 x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3 Legal
Schedule 2 x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3; Legal
Schedule 3 x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3; Illegal
(d)