Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deriving Linearizable Fine-Grained Concurrent Objects Martin Vechev Eran Yahav IBM T. J. Watson Research Center Martin Vechev Eran Yahav IBM T. J. Watson.

Similar presentations


Presentation on theme: "Deriving Linearizable Fine-Grained Concurrent Objects Martin Vechev Eran Yahav IBM T. J. Watson Research Center Martin Vechev Eran Yahav IBM T. J. Watson."— Presentation transcript:

1 Deriving Linearizable Fine-Grained Concurrent Objects Martin Vechev Eran Yahav IBM T. J. Watson Research Center Martin Vechev Eran Yahav IBM T. J. Watson Research Center

2 2 Lets suppose… I want a concurrent set that is: correct efficient portable QUICKLY

3 3 Now what…

4 4 The result… Heller et al. (OPODIS’05) Maged (PODC’02) Harris (DISC’01) Vechev & Yahav (PLDI’08)

5 5 bool add(int key) { Entry *pred,*curr,*entry restart: locate(pred,curr,key) k = (curr->key == key) if (k) return false entry = new Entry() entry->next = curr val=CAS(&pred->next,  curr,0 ,  entry,0  ) if (  val) goto restart return true } bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false = curr->next lval=CAS(&curr->next,  r,m ,  r,1  ) if (  lval) goto restart pval=CAS(&pred->next,  curr,0 ,  r,0  ) if (  pval) goto restart return true } New Concurrent Set Algorithm bool contains(int key) { Entry *pred,*curr locate(pred,curr,key) k = (curr->key == key) if (k) return false return true } The Good New algorithm Fine-grained synchronization (CAS) The Good New algorithm Fine-grained synchronization (CAS) The Bad Can you understand what it does? Can you show it is correct? The Bad Can you understand what it does? Can you show it is correct? The Ugly How did you get it? Anything repeatable? Any other similar algorithms? The Ugly How did you get it? Anything repeatable? Any other similar algorithms?

6 6 bool add(int key){ atomic Entry *pred,*curr,*entry locate(pred,curr,key); k = (curr->key == key) if (k) return false entry = new Entry() entry->next = curr pred->next = entry return true } bool remove(int key){ atomic Entry *pred,*curr,*r locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false r = curr->next pred->next = r return true } Sequential Set Algorithm bool contains(int key) { atomic Entry *pred,*curr locate(pred,curr,key) k = (curr->key == key) if (k) return false return true } Understandable Proving correctness easier Understandable Proving correctness easier

7 7 bool add(int key) { Entry *pred,*curr,*entry restart: locate(pred,curr,key) k = (curr->key == key) if (k) return false entry = new Entry() entry->next = curr val=CAS(&pred- >next,  curr,0 ,  entry,0  ) if (  val) goto restart return true } bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false = curr->next lval=CAS(&curr->next,  r,m ,  r,1  ) if (  lval) goto restart pval=CAS(&pred- >next,  curr,0 ,  r,0  ) if (  pval) goto restart return true } Sequential to Highly Concurrent bool add(int key){ atomic Entry *pred,*curr,*entry locate(pred,curr,key); k = (curr->key == key) if (k) return false entry = new Entry() entry->next = curr pred->next = entry return true } bool remove(int key){ atomic Entry *pred,*curr,*r locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false r = curr->next pred->next = r return true } ???

8 8 Concurrent Objects Constructions Today Performance Manual Effort Sequential Naïve STM Fine-grained STM Expert Design This Work Goal

9 Bridging the Gap: Our Approach Find small repeatable transformations  NO magic insights Some transformations applied manually, others automatically 9

10 Computer Assisted Construction

11 Atomicity Reduction: Transformations Removing redundant atomicity Reordering statements Optimistic concurrency Add synchronization meta-data 11 s1 s2 s3 s4 s1 s2 s3 s4 If (validate) update else restart read s1 s2 s3 s4 s2 s1 s3 s4 s3 s4 read update s1 s2 s1 If (t > 0) s2 s3 s4

12 12 A journey from a sequential algorithm to efficient concurrent algorithms Schema Correct Algorithm DCAS Sequential DCAS CAS with LOCKS Priority Queue Stack CAS/DCAS … … Michael (PODC’02) Heller et al. (OPODIS’05) Trieber Stack Existing Algorithm New Algorithm

13 locate(pred,curr,key) 13 Step 1: Optimistic Concurrency [Kung & Robinson’81] bool remove(int key){ Entry *pred,*curr,*r atomic locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false r = curr->next pred->next = r return true } bool remove(int key){ Entry *pred,*curr,*r restart: Read atomic if ( validate ) { Update } goto restart } k = (curr->key ≠ key) if (k) return false r = curr->next pred->next = r return true Update Read

14 Step 2: Run Paraglide 14 Paraglide No correct completion found Insufficient information to write a validation condition bool remove(int key){ Entry *pred,*curr,*r locate(pred,curr,key) atomic if (validate) { k = (curr->key ≠ key) if (k) return false r = curr->next pred->next = r return true } goto restart } truepred->next == currpred == curr ( (pred | curr) (->next)? == (pred | curr) (->next)? ) | true

15 Step 2: Counterexample 15 head add(4) starts 1 tail pred curr remove(1) executes add(4) ends 1 headtail pred curr 4 1 headtail How to deal with removed nodes? add(4) || remove(1) Addition of key 4 is lost

16 But What Now ? Coordination Meta-data SynchronizationTime

17 17 Step 3: Add Synchronization Metadata keynextkeynext marked REMOVE = { R1: k = (curr->key ≠ key) R2: if (k) return false R3: curr->marked = true R4: mp =  pred->marked R5: mc =  curr->marked R6: val= (pred->next == curr) (  mp)? (  mc)? R7: if (  val) goto restart R8: r = curr->next R9: pred->next = r } OBJECT

18 Step 4: Run Paraglide 18 bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) REMOVE return true } REMOVE = { R1: k = (curr->key ≠ key) R2: if (k) return false R3: curr->marked = true R4: mp =  pred->marked R5: mc =  curr->marked R6: val= (pred->next == curr) ? (  mp) ? (  mc) R7: if (  val) goto restart R8: r = curr->next R9: pred->next = r } bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) REMOVE return true } REMOVE = { k = (curr->key ≠ key) if (k) return false curr->marked = true r = curr->next atomic mp =  pred->marked val=(pred->next==curr)  mp if (  val) goto restart pred->next = r } Paraglide

19 19 Concurrent Objects: Constructions Performance Manual Effort Sequential Naïve STM Fine-grained STM Expert Design We are now here Low-level synchronization (e.g., CAS, locks) ?

20 Step 5: Transform to synchronization primitives 20 bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false curr->marked = true r = curr->next atomic mp =  pred->marked val=(pred->next==curr)  mp if (  val) goto restart pred->next = r return true } Implementations CAS (if bit in pointer supported) LOCKS and TRY-LOCKS DCAS REENTRANT LOCKS and TRY-LOCKS LOCKS

21 Challenge: Checking Lineariziability Linearizability [Herlihy and Wing’91]  The accepted correctness criterion for concurrent objects  Compositional What do we check?  Linearizability without specified linearization points x Bounded sequence of operations (e.g. 2 adds) x No user input required x Important for automation  Linearizability with (fixed and dynamic) points x Unbounded sequences of operations x Important for deeper checking x Requires user input (instrumentation) 21

22 22 bool add(int key) { Entry *pred,*curr,*entry restart: locate(pred,curr,key) k = (curr->key == key) if (k) return false entry = new Entry() entry->next = curr val=CAS(&pred->next,  curr,0 ,  entry,0  ) if (  val) goto restart return true } bool remove(int key) { Entry *pred,*curr,*r restart: locate(pred,curr,key) k = (curr->key ≠ key) if (k) return false = curr->next lval=CAS(&curr->next,  r,m ,  r,1  ) if (  lval) goto restart pval=CAS(&pred->next,  curr,0 ,  r,0  ) if (  pval) goto restart return true } Answers bool contains(int key) { Entry *pred,*curr locate(pred,curr,key) k = (curr->key == key) if (k) return false return true } The Good New algorithm Fine-grained synchronization with CAS The Good New algorithm Fine-grained synchronization with CAS The Bad Can you understand what it does? Can you show it is correct? The Bad Can you understand what it does? Can you show it is correct? The Ugly How did you get it? Anything repeatable? Any other similar algorithms? The Ugly How did you get it? Anything repeatable? Any other similar algorithms?

23 23 Concurrent Set Algorithms – Recap DCAS Sequential DCAS CAS with LOCKS Priority Queue Stack CAS/DCAS … … Michael (PODC’02) Heller et al. (OPODIS’05) Trieber Stack Schema Correct Algorithm Existing Algorithm New Algorithm

24 Summary 24 Automatic Tool New Algorithms Systematic Construction Thanks Maged Michael (IBM Watson) Greta Yorsh (IBM Watson) David Bacon (IBM Watson) Mooly Sagiv (Tel-Aviv University) Hagit Attiya (Technion) Noam Rinetzky (Queen Mary) Gerard Holzmann (NASA) Steven German (IBM Watson) Dragan Bosnacki (Eindhoven U) Ras Bodik (Berkeley) Armando Solar-Lezama (Berkeley) Chris Jones (Berkeley)


Download ppt "Deriving Linearizable Fine-Grained Concurrent Objects Martin Vechev Eran Yahav IBM T. J. Watson Research Center Martin Vechev Eran Yahav IBM T. J. Watson."

Similar presentations


Ads by Google