31
© 2008 Multifacet Project University of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael M. Swift Multifacet Project (www.cs.wisc.edu/multifacet ) Computer Sciences Department University of Wisconsin—Madison

© 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

Embed Size (px)

Citation preview

Page 1: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

© 2008 Multifacet Project University of Wisconsin-Madison

Pathological Interaction of Lockswith

Transactional Memory

Haris Volos, Neelam Goyal, Michael M. Swift

Multifacet Project (www.cs.wisc.edu/multifacet)

Computer Sciences DepartmentUniversity of Wisconsin—Madison

Page 2: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

2

Brain teaser

• What causes the following to deadlock in LogTM?

...atomic { ... memcmp(s1, s2, n); ...}

Dynamic Linker lock

Page 3: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

3

Brain teaser

• What causes the following to deadlock in LogTM?Thread 1

Thread 2...

atomic { ... memcmp(); elf_bndr() enter() rt_mutex_lock(&rtldlock)

...free(); elf_bndr() enter() rt_mutex_lock(&rtldlock) ... ... rt_mutex_unlock(&rtldlock)NACK

Not unique to LogTM

Page 4: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

4

Executive Summary

• Problem– Interaction of locks with transactional memory– Legacy code uses locks

• Interaction Pathologies– Identified five pathologies– Affect a spectrum of TM systems

• Transaction-safe Lock (TxLock)– Execute lock-based critical sections inside transactions– Modified OpenSolaris libC

Page 5: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

5

Outline

• Interaction Pathologies• Transaction-Safe Lock (TxLock)• Conclusion

Page 6: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

6

Interaction Pathologies

• Pathological interaction – Correct code making proper use of locks breaks under

transactions

• Identified five Interaction Pathologies– Blocking

– Deadlock

– Livelock

– Early Release

– Invisible Locking

Affect a spectrum of TM systems

STM HTM

Page 7: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

7

Transactional Memory Design

• Version Management– Eager, in-place update– Lazy, deferred update

• Conflict Detection– Eager, early – Lazy, late

• Conflict Resolution– Requester wins– Requester loses

• Atomicity– Strong– Weak

Page 8: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

8

Deadlock

• Impacted Systems– Strong atomicity– Requester stalls– e.g LogTM, OneTM

• Cause– Two-level locking– No knowledge of lock dependency

• Effect– TM system stalls locks' logical owner

T1 T2

Lock(L)

Lock(L)

Spinning

Stalling

Non-TX

TX

Unlock(L)NACKNACKNACK

time

Page 9: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

9

Livelock

• Impacted Systems– Strong atomicity– Requester wins– e.g Bulk, LTM

• Cause– Two-level locking– No knowledge of lock dependency

• Effect– TM system aborts locks' logical

owner

T1 T2

Lock(L)Lock(L)

SpinningNon-TX

TX

Unlock(L)

Abort

Unlock(L)

Abort

Page 10: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

10

Early Release

• Impacted Systems– Weak atomicity– Eager version management– e.g McRT-STM

• Cause– Restore values without lock held

• Effect– Lose lock-based mutual exclusion

T1 T2

Lock(L)

Lock(L)

SpinningNon-TX

TX

Unlock(L)

Abort

Restore

Page 11: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

11

Summary

Pathology Atomicity Version Conflict SystemsManagement Detection

Blocking Strong Any AnyDeadlock Strong Eager Eager

Strong Any Any Bulk, LTMEarly Release Weak Eager AnyInvisible Locking Weak Lazy Any TL2

LogTM, BulkLogTM, OneTM

LivelockMcRT-STM

Page 12: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

12

Outline

• Pathologies• Transaction-Safe Lock (TxLock)• Conclusion

Page 13: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

13

TxLock Design

• Goals– Execute lock-based critical section code safely– Low overhead in non-transactional path

• Design elements– Non-transactional lock operations– Deferred Unlock– Lock-aware Conflict Resolution

Page 14: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

14

Testing & Acquiring a lock

• Escape when Testing & Acquiring– Prevents transactional conflicts– Allows to observe most recent lock value

• After Acquiring– Compensate action to explicitly restore lock value on abort

Page 15: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

15

When waiting on a lock?

• When waiting– Inform Contention Manager about dependency

Page 16: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

16

When releasing a lock?

• Coordinate release– TM system: Releases transactional locks at commit– TxLocks: Commit action to release logical-lock at commit

Page 17: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

17

Implementation

• LogTM-SE– Wisconsin GEMS

• OpenSolaris C Library– POSIX adaptive mutex locks– 80 lines

• Contention Manager and Policy– 990 lines

Page 18: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

18

Preliminary Results

• Experience– Able to resolve deadlocks in libc malloc()

• Quantitative– Development of workloads in progress– No rigorous performance evaluation – Overhead

Low overheadHigher overhead

Page 19: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

19

Summary

• Problem– Legacy code uses locks– Interaction of locks with transactional memory

• Interaction Pathologies– Identified five pathologies– Affect a spectrum of TM systems

• Transaction-safe Lock (TxLock)– Execute lock-based critical sections inside transactions– Modified OpenSolaris libC

Page 20: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

20

Questions

?

Page 21: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

21

Backup Slides

• TxLocks vs SpinLocks• Rest of Pathologies

– Blocking– Invisible Locking

• Implementation Details – lock• Implementation Details – unlock• Design Elements

Page 22: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

22

Blocking

• Cause– No support to abort while sleeping

• Effect– Cannot abort blocked transaction

safely

T1 T2

Lock(L)

Lock(L)

Abort

Non-TX

TX

Blocking

Page 23: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

23

Blocking

• Cause– No support to abort while sleeping

• Effect– Cannot abort blocked transaction

safely– Blocking degenerates into spinning

• Example Systems– LogTM– Bulk

T1 T2

Lock(L)Abort

Lock(L)

Abort

Lock(L)

Lock(L)Abort

Sp

inn

ing

Non-TX

TX

Page 24: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

24

Invisible Locking

• Cause– Weak atomicity– Lazy Version Management

• Effect– Lose lock-based mutual exclusion

• Example System– TL2

T1 T2

Lock(L)Lock(L)

Non-TX

TX

No Mutual Exclusion

Page 25: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

25

TxLocks vs cxspinlocks

• Programming interface– cxspinlocks: program using locks– TxLocks: program using transactions

• Optimistic concurrency– cxspinlocks: execute critical sections with optimistic concurrency– TxLocks: execute critical sections w/o optimistic concurrency

• Overhead– cxspinlocks: lock always introduces extra coherence traffic– TxLocks: pay extra cost when you acquire locks

• Hardware support– cxspinlocks: require special hardware: xcas and xtest– TxLocks: no special hardware; applicable to both HTM & STM

Page 26: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

26

Implementation Details - lock

1. void lock(txlock_t* mp) {2.➊BEGIN_ESCAPE;3. if (set_lock_byte(&mp->txlock_lockw) == 0) {4. mp->mutex_owner = (uintptr_t)self;5. goto lock_acquired;6. }7. if (mp->mutex_owner == self) {8. mp->rcount++;9. goto lock_acquired_noTS;10. }11. if (txlock_trylock_adaptive(mp) != 0) {12. if (txlock_lock_queue(self, mp) == ABORT) {13.➊ END_ESCAPE;14. ABORT_TRANSACTION15. }16. }17. lock_acquired:18. mp->timestamp = xact_timestamp();19. lock_acquired_noTS:20. if (in_xact()) {21.➊ register_compensating_action(22.➊ txlock_unlock_impl, mp); 23. } 24.➊ END_ESCAPE;25. }

Page 27: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

27

Implementation Details - unlock

26. void unlock(txlock_t* mp) {27. BEGIN_ESCAPE;28. if (mp->mutex_owner == self) {29. mp->rcount++;30. END_ESCAPE;31. return;32. }33. if (in_xact()) {34. register_commit_action(35. txlock_unlock_impl, mp);36. } else {37. txlock_unlock_impl(mp);38. }39. END_ESCAPE;40. }

Page 28: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

28

1. Non-transactional Lock Operations

• Prevents– Invisible Locking– Livelock– Some Deadlock cases

• Method– Escape transactional control of lock code– Restore lock value through compensating action

Page 29: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

29

2. Deferred Unlock

• Prevents– Early Release

• Method– Do not release lock in place but at commit– Recursive locking to avoid deadlock with itself

Page 30: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

30

3. Lock-aware Conflict Resolution

• Prevents– Deadlock– Livelock

• Contention Manager– Is provided with transactional and lock dependencies – Builds full dependence graph– Finds correct victim transaction

Page 31: © 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael

31

4. Block/Wake-up Protocols

• Prevents– Blocking

• Protocols– Locks and contention manager cooperate to wake-up a

blocked transaction– Use Abort/Block protocol when CANNOT suspend a TX– Use Block/Abort protocol when CAN suspend a TX