Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Kalpakis CMSC621 Advanced Operating Systems Synchronization.

Similar presentations

Presentation on theme: "Dr. Kalpakis CMSC621 Advanced Operating Systems Synchronization."— Presentation transcript:

1 Dr. Kalpakis CMSC621 Advanced Operating Systems Synchronization

2 CMSC Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

3 CMSC 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

4 CMSC 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/86400 th of the solar day the period of earths rotation is not constant Solar seconds get longer over time!

5 CMSC 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 LHeure averages the readings fo several atomic clocks to produce the International Atomic Time (TAI) TAI= #seconds since Jan 1, 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!

6 CMSC Atomic Time and leap seconds TAI seconds are of constant length, unlike solar seconds TAI 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 seconds Total leap seconds in UTC is about 30

7 CMSC 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

8 CMSC 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

9 CMSC Physical Clock Synchronization Cp(t) = the local time at p when UTC is t Clock skew = Cp(t) -1 Clock offset wrt t = Cp(t) – t

10 CMSC Network Time Protocol Estimating As clock offset relative to Bs clock A sends request to B and receives response from B Request and response are timestamped by the local clocks of A and B T1 = 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 As clock is fast/slow, A slowdowns/fasten gradually over time

11 CMSC 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

12 CMSC 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

13 CMSC Clock synchronization in wireless networks Reference Broadcasting Synchronization (RBS) Server queries nodes for their times to compute an offset for them Servers 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

14 CMSC Lamport Timestamps a) Three processes, each with its own clock. The clocks run at different rates. b) Lamport's algorithm corrects the clocks.

15 CMSC Example: Totally-Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state.

16 CMSC Global State (1) a) A consistent cut b) An inconsistent cut

17 CMSC Global State (2) a) Organization of a process and channels for a distributed snapshot

18 CMSC Global State (3) b) Process Q receives a marker for the first time and records its local state c) Q records all incoming message d) Q receives a marker for its incoming channel and finishes recording the state of the incoming channel

19 CMSC The Bully Algorithm (1) The bully election algorithm Process 4 holds an election Process 5 and 6 respond, telling 4 to stop Now 5 and 6 each hold an election

20 CMSC Global State (3) d) Process 6 tells 5 to stop e) Process 6 wins and tells everyone

21 CMSC A Ring Algorithm Election algorithm using a ring.

22 CMSC Mutual Exclusion: A Centralized Algorithm a) Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b) 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

23 CMSC 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.

24 CMSC A Toke Ring Algorithm a) An unordered group of processes on a network. b) A logical ring constructed in software.

25 CMSC Comparison A comparison of three mutual exclusion algorithms. Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized32Coordinator crash Distributed2 ( n – 1 ) Crash of any process Token ring1 to 0 to n – 1 Lost token, process crash

26 CMSC The Transaction Model (1) Updating a master tape is fault tolerant.

27 CMSC The Transaction Model (2) Examples of primitives for transactions. PrimitiveDescription BEGIN_TRANSACTIONMake the start of a transaction END_TRANSACTIONTerminate the transaction and try to commit ABORT_TRANSACTIONKill the transaction and restore the old values READRead data from a file, a table, or otherwise WRITEWrite data to a file, a table, or otherwise

28 CMSC The Transaction Model (3) a) Transaction to reserve three flights commits b) 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)

29 CMSC Distributed Transactions a) A nested transaction b) A distributed transaction

30 CMSC Private Workspace a) The file index and disk blocks for a three-block file b) The situation after a transaction has modified block 0 and appended block 3 c) After committing

31 CMSC Writeahead Log a) A transaction b) – 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)

32 CMSC Concurrency Control (1) General organization of managers for handling transactions.

33 CMSC Concurrency Control (2) General organization of managers for handling distributed transactions.

34 CMSC Serializability a) – c) Three transactions T 1, T 2, and T 3 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 1x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3Legal Schedule 2x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3;Legal Schedule 3x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3;Illegal (d)

35 CMSC Two-Phase Locking (1) Two-phase locking.

36 CMSC Two-Phase Locking (2) Strict two-phase locking.

37 CMSC Pessimistic Timestamp Ordering Concurrency control using timestamps.

Download ppt "Dr. Kalpakis CMSC621 Advanced Operating Systems Synchronization."

Similar presentations

Ads by Google