a runtime system for software lock elision
play

A Runtime System for Software Lock Elision Amitabha Roy (U. - PowerPoint PPT Presentation

A Runtime System for Software Lock Elision Amitabha Roy (U. Cambridge) Steven Hand (U. Cambridge) Tim Harris (MSR Cambridge) Motivation Multicores mean application scalability is key to good performance Scaling programs synchronising


  1. A Runtime System for Software Lock Elision Amitabha Roy (U. Cambridge) Steven Hand (U. Cambridge) Tim Harris (MSR Cambridge)

  2. Motivation � Multicores mean application scalability is key to good performance � Scaling programs synchronising with locks � Existing software systems use locks � Locks are very popular with programmers � Start with data race free correctly synchronised lock based program � Use transactional memory opportunistically while retaining the locks

  3. Critical Sections & Speculation Thread 1: Lock(L) Do stuff … Unlock(L) Serialize Thread 2: Lock(L) Do stuff … Unlock(L)

  4. Critical Sections & Speculation Rajwar et al: Speculative Lock Elision … Micro 2001 Thread 1: Thread 2: Lock(L) Lock(L) Do stuff … Do stuff … Unlock(L) Unlock(L) � Relies on Hardware Transactional Memory (TM) support to enable optimistic concurrency control � Exploits disjoint-access parallelism (red-black trees, hash tables, etc)

  5. Critical Sections & Speculation Thread 1: Thread 2: Thread 1: Lock(L) Lock(L) Lock(L) Do stuff … Do stuff … Do stuff … Unlock(L) Unlock(L) Unlock(L) Serialize Thread 2: Lock(L) Do stuff … Unlock(L) � Can coexist (excessive conflicts, I/O, wait conditions, ...) � No need for new semantics – start from lock-based programs � This paper: Software Lock Elision (SLE) ; no special h/w required

  6. Coming Up ... � Speculation in software � Retaining lock semantics & behaviour � Implementation and evaluation � Interfacing to the runtime

  7. Speculation � Speculating threads and memory � Isolate using thread private copies � Write back changes atomically � Well developed ideas in the Software Transactional Memory (STM) field � We use a design similar to TL2 � Dice et al: Transactional Locking II … DISC 2006

  8. Speculation: Shadowing Shared Memory Lock(L) � elided … Y: 10 X = Y + 1 … Unlock(L)

  9. Speculation: Shadowing Metadata table Shared Memory Lock(L) � elided … Hash (Address) Y: 10 X = Y + 1 42 … Unlock(L)

  10. Speculation: Shadowing Metadata table Shared Memory Lock(L) � elided … Hash (Address) Y: 10 X = Y + 1 42 … Unlock(L) Thread Private Log <Y V42 10>

  11. Speculation: Shadowing Metadata table Shared Memory Lock(L) � elided … Y: 10 X = Y + 1 42 … Unlock(L) Hash (Address) X: 99 50 Thread Private Log <Y V42 10> <X V50 11>

  12. Speculation: Commit � Commit (2PL): Lock, Verify, Write, Unlock � Odd version numbers used to Lock(L) � elided … represent locked objects X = Y + 1 … � Manipulate with Compare and Unlock(L) � commit Swap (CAS) for atomicity Dirty: <X V50 11> Clean: <Y V42 10>

  13. Speculation: Commit � Commit (2PL): Lock , Verify, Write, Unlock Lock(L) � elided CAS … 1. Hash(X): 50 51 X = Y + 1 … Unlock(L) � commit Dirty: <X V50 11> Clean: <Y V42 10> Abort speculation and restart on conflict

  14. Speculation: Commit � Commit (2PL): Lock, Verify , Write, Unlock Lock(L) � elided CAS … 1. Hash(X): 50 51 X = Y + 1 … 2. Hash(Y): == 42 ? Unlock(L) � commit Dirty: <X V50 11> Clean: <Y V42 10> Abort speculation and restart on conflict

  15. Speculation: Commit � Commit (2PL): Lock, Verify, Write , Unlock Lock(L) � elided CAS … 1. Hash(X): 50 51 X = Y + 1 … 2. Hash(Y): == 42 ? Unlock(L) � commit Write 3. X: 99 11 Dirty: <X V50 11> Clean: <Y V42 10> Abort speculation and restart on conflict

  16. Speculation: Commit � Commit (2PL): Lock, Verify, Write, Unlock Lock(L) � elided CAS … 1. Hash(X): 50 51 X = Y + 1 … 2. Hash(Y): == 42 ? Unlock(L) � commit Write 3. X: 99 11 CAS Dirty: <X V50 11> 4. Hash(X): 51 52 Clean: <Y V42 10> Abort speculation and restart on conflict

  17. Coming Up ... � Speculation in software � Retaining lock semantics & behaviour � Implementation and evaluation � Interfacing to the run-time

  18. Semantics � Programmers should see the same semantics with SLE as when using locks � This means: � Lock acquisition must be allowed � No constraints on memory recycling � Solve this via insertion of Safe() calls: Safe(O) : while(metadata(O) is locked) wait; � We also want to ensure there’s no unexpected (i.e. additional) blocking on other threads � Safe(O) must not wait for any other thread

  19. Semantics – Application Locks � Acquisition of critical section locks � Need to reconcile with speculating threads Thread 1 Init: X = Y = 0 Thread 2 Lock(L) � Elided Lock(L) � Acquired X = Y + 1 Y = X + 1 Unlock(L) Unlock(L) Can X == Y ?

  20. Semantics – Application Locks � Acquisition of critical section locks � Need to reconcile with speculating threads Thread 1 Init: X = Y = 0 Thread 2 Lock(L) � Elided Lock(L) � acquired X = Y + 1 { Y=0 � X = 1 } Y = X + 1 { X=0 � Y=1 } Unlock(L) Unlock(L) X == Y == 1 !!!

  21. Semantics – Application Locks Roy et al: Brief Announcement: A Transactional Approach to Lock Scalability … SPAA’08 � Basic idea: add a version number to locks � Lock is a shared memory object Lock(L) � Lock(L) ; version(L)++ Unlock(L) � Version(L)++; Unlock(L) Elide (L) � L.version even: Log (L.version) � Check for non speculative access � Use Safe(O) as defined before � Additional complexity to handle reader locks � No information required about other threads

  22. Semantics – Privatisation � Memory no longer protected by a lock Thread 1 Thread 2 Lock(L) � Elided Lock(L) � Elided node = List_head(list) node = List_head(list) List_delete(node) node.value = 42 Unlock(L) Unlock(L) free (node)

  23. Semantics – Privatisation � Memory no longer protected by a lock Thread 1 Thread 2 Lock(L) � Elided node = List_head(list) node.value = 42 Lock(L) � Elided node = List_head(list) List_delete(node) Unlock(L) free (node) Unlock(L) Memory corruption � Unmanaged environment � no Garbage Collector

  24. Semantics – Privatisation � Memory no longer protected by a lock Thread 1 Thread 2 Lock(L) � Elided node = List_head(list) node.value = 42 Lock(L) � Elided node = List_head(list) List_delete(node) Unlock(L) Unlock(L ) Safe(node) free (node) OK! ☺

  25. Semantics – Avoiding Blocking � Locked metadata blocks non-speculative threads � Execution behaviour changes: � Can block on other threads even if not at Lock(L) Example from Apache webserver Thread 1 Thread 2 Lock(L) � not elided Lock(L) � elided do stuff … do stuff … if(error) { Unlock(L) signal(FATAL_EXIT); do cleanup } Blocked on held metadata Unlock(L) Exit on SIG

  26. Semantics – Avoiding Blocking Harris et al: Revocable Locks for Non-Blocking Programming … PPoPP’05 � We use revocable locks : � Allow lock to be revoked, displacing lock holder’s execution to a special cleanup path � Call revoke(O, v) if Safe(O) finds O locked at version v commit{ revoke(O, v) { … CAS(Metadata(O), v, v + 2); Checkpoint: setjmp … signal(previous holder); .. if(Metadata(O) == expected) � At this point we own the metadata make changes (copy new data) } … }

  27. Semantics – Avoiding Blocking revoke(O, v) { commit{ CAS(Metadata(O), v, v + 2); … signal(previous holder); Checkpoint: setjmp … .. � At this point we own metadata if(Metadata(O) == expected) } make changes (copy new data) … } Signal Handler: longjmp

  28. Semantics – Avoiding Blocking revoke(O, v) { commit{ CAS(Metadata(O), v, v + 2); … signal(previous holder); Checkpoint: setjmp … .. � At this point we own the lock if(Metadata(O) == expected) } make changes (copy new data) … } Signal Handler: longjmp How to synchronously signal ? We use a custom signalling service implemented as a kernel module

  29. Semantics – Avoiding Blocking � Problem: we know nothing of target thread state � Can send an inter-processor interrupt (IPI) � Signal delivery on return to userspace

  30. Semantics – Avoiding Blocking � Problem: we know nothing of target thread state � Can send an inter-processor interrupt (IPI) � Signal delivery on return to userspace Source Thread Target Thread Set signal pending in target Cpu = last_running_on(target) Count = IPI_count(Cpu)

  31. Semantics – Avoiding Blocking � Problem: we know nothing of target thread state � Can send an inter-processor interrupt (IPI) � Signal delivery on return to userspace Source Thread Target Thread Set signal pending in target Cpu = last_running_on(target) Count = IPI_count(Cpu) Send_IPI(Cpu) Received Kernel to Userpace transition

  32. Semantics – Avoiding Blocking � Problem: we know nothing of target thread state � Can send an inter-processor interrupt (IPI) � Signal delivery on return to userspace Source Thread Target Thread Set signal pending in target Cpu = last_running_on(target) Count = IPI_count(Cpu) Send_IPI(Cpu) Received Kernel Until IPI_Count(Cpu) != Count to Userpace transition Ok for thread to be swapped out/migrated !

  33. Coming Up ... � Speculation in software � Retaining lock semantics & behaviour � Implementation and evaluation � Interfacing to the run-time

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend