How often is ‘cmpxchg’ used? $ cat vmlinux.asm | grep cmpxchg c01046de: c0105591: c01055d9: c010b895: c010b949: c0129a9f: c0129acf: c012d377: c012d41a: c012d968: c012e568: c012e57a: c012e58a: c012e83f: c012e931: c012ea94: c012ecf4: c012f08e: c012f163: c013cb60: c0148b3c: c0150d0f: c0150d87: c0199c5e: c024b06f: c024b2fe: c024b321: c024b34b: c024b960: f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 15 15 15 11 0b 0b 0b 0e 0e 16 2e 2e 2e 13 0a 11 13 4b 11 0e 29 3b 31 0b 0b 51 51 4b 53 3c 99 30 3c 99 30 3c 99 30 18 18 18 18 18 lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock lock cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg cmpxchg %edx,0xc030993c %edx,0xc030993c %edx,0xc030993c %edx,(%ecx) %ecx,(%ebx) %ecx,(%ebx) %ecx,(%ebx) %ecx,(%esi) %ecx,(%esi) %edx,(%esi) %ebp,(%esi) %ebp,(%esi) %ebp,(%esi) %edx,(%ebx) %ecx,(%edx) %edx,(%ecx) %edx,(%ebx) %ecx,0x18(%ebx) %edx,(%ecx) %ecx,(%esi) %ebp,(%ecx) %edi,(%ebx) %esi,(%ecx) %ecx,(%ebx) %ecx,(%ebx) %edx,0x18(%ecx) %edx,0x18(%ecx) %ecx,0x18(%ebx) %edx,0x18(%ebx) Here’s the occurrence that we studied in the ‘rtc_cmos_read()’ kernel-function… …plus 28 other times!
View full slide show




lost Cheli Pedi Ant1 Ant2 Mnd L L L L Mx 1 Mx 2 Chelicerates Crustacea Ant Leg Leg Leg Leg Leg Leg Ancestor Ant1 Mnd Mx 1 Mx 2 Insects Ant Leg Leg Leg Leg Leg Leg Trilobites The elaboration of the head has taken different courses in the major groups but are still considered to show serial homology A=antenna a=acron C=chelicera Ci= Chilarum L = leg Mnd =Mandible Mx = maxilla P= pedipalp 0 = lost segments
View full slide show




Single Lock thread A thread B thread C Lock.acquire() Read data Lock.release() Lock.acquire() Modify data Lock.release() Lock.acquire() Read data Lock.release() thread D thread E thread F Lock.acquire() Read data Lock.release() Lock.acquire() Read data Lock.release() Lock.acquire() Modify data Lock.release()  Drawbacks of this solution? UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 5
View full slide show




Readers/Writers: Example  thread A thread B thread C Lock.acquire() Read data Lock.release() Lock.acquire() Modify data Lock.release() Lock.acquire() Read data Lock.release() thread D thread E thread F Lock.acquire() Read data Lock.release() Lock.acquire() Read data Lock.release() Lock.acquire() Modify data Lock.release() Maximizes concurrency  Great! But how do we implement this? UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 7
View full slide show




Time t1 t2 t3 t4 K req S lock a S lock a . . Time t1 t2 t3 t4 K req S lock a S lock a . . Time t1 t2 t3 t4 K req X lock a X lock a . . L . . req S lock a S lock a L . . req X lock a wait L . req X lock a . wait Chapters 21-22 46
View full slide show




Lock Conversions  Two-phase locking with lock conversions: – First Phase:  can acquire a lock-S on item  can acquire a lock-X on item  can convert a lock-S to a lock-X (upgrade) – Second Phase:  can release a lock-S  can release a lock-X  can convert a lock-X to a lock-S (downgrade)  This protocol assures serializability. But still relies on the programmer to insert the various locking instructions. Database System Concepts 3rd Edition 16.10 ©Silberschatz, Korth and Sudarshan
View full slide show




Using Lock Variable acquaire_lock(A)      acquaire_lock(B)  set lock=0   set lock=1 critical_section(B) release_lock(B)  set lock=0 Lock variable    set lock=1 critical_section(A) release_lock(A)   A software solution A single, shared variable (lock) Assume two processes PA and PB   Program in PA tests the variable to see if lock=0  if 0, PA enters the critical region and sets lock=1  if lock=1, it knows that the critical region is occupied by program in P B What is the problem? Spring 2016, arz CS555A – Real-Time Embedded Systems Stevens Institute of Technology 39
View full slide show




Possible Deadlock class B implements Runnable; { private Lock one, two; public(Lock one,Lock two) { this.one = one; this.two = two; } public void run() { try { two.lock(); doSomething(); one.lock(); doSomethingElse(); } finally { two.unlock(); one.unlock(); } } } class A implements Runnable; { private Lock one, two; public(Lock one,Lock two) { this.one = one; this.two = two; } public void run() { try { one.lock(); doSomething(); two.lock(); doSomethingElse(); } finally { two.unlock(); one.unlock(); } } } Deadlock possible depending on timing, but sometimes will not occur
View full slide show




Case Study To evaluate the proposed planning model, a real-world case study is presented in this section: Site description Leg 1: Distance to neighboring intersection: 650 feet Leg 3 Leg 2 Leg 2: U-turn Bay length: 380 feet Left-turn Bay length: 390 feet Leg 1 Leg 4 18 20th IFORS, Barcelona, Spain Leg 3: Distance to neighboring intersection: 650 feet Leg 4: U-turn Bay length: 250 feet Left-turn Bay length: 300 feet Traffic Safety and Operation Lab Dept. of Civil and Environmental Engineering University of Maryland, College Park
View full slide show