Eraser A Dynamic Data Race Detector for Multithreaded

  • Slides: 20
Download presentation
Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al

Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al 5 th Mar 2008 presented by Hong, Shin 2021 -03 -09 Hong, Shin @ PSWLAB Eraser: A Dynamic Data Race Detector for Multithreaded Programs 1 / 20

Introduction 1/3 • Multi-threading has become a common programming technique. • It is easy

Introduction 1/3 • Multi-threading has become a common programming technique. • It is easy to make a mistake in synchronization that produces a data race, yet it can be hard to locate the mistake during debugging. • Eraser is a tool to dynamically detect data races in multi -threaded programs 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 2 / 20

Introduction 2/3 • Definitions – Lock • a synchronization object used for mutual exclusion.

Introduction 2/3 • Definitions – Lock • a synchronization object used for mutual exclusion. • a lock is either available or owned by a thread. • the operations on a lock m are lock(m) and unlock(m) – Data race occurs when • two concurrent threads access a shared variable, and • at least one access is a write, and • the threads use no explicit mechanism to prevent the accesses from being simultaneous. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 3 / 20

Introduction 3/3 • Eraser checks that all shared memory accesses follow a consistent locking

Introduction 3/3 • Eraser checks that all shared memory accesses follow a consistent locking discipline. – a locking discipline is a programming policy that ensures the absence of data races. – E. g. every variable shared between threads is protected by a matual exclusion lock. What is the locking discipline Eraser checks? How the locking discipline checking works in Eraser? 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 4 / 20

Lockset Algorithm 1/4 • The basic lockset algorithm enforce the locking discipline that every

Lockset Algorithm 1/4 • The basic lockset algorithm enforce the locking discipline that every shared variable is protected by some lock, in the sense that the lock is held by any thread whenever it accesses the variable. • Eraser checks whether the program respect this discipline by monitoring all reads and writes as the program executes. • Eraser infers the protection relation from the execution history. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 5 / 20

Lockset Algorithm 2/4 • For each shared variable v, Eraser maintains the set C(v)

Lockset Algorithm 2/4 • For each shared variable v, Eraser maintains the set C(v) of candidate locks for v. This set contains those locks that have protected v for the computation so far. • A lock l is in C(v) if in the computation up to that point, every thread that has accessed v was holding l at the moment of the access. • When a new variable v is initialized, its candidate set C(v) is considered to hold all possible locks. • When the variable is accessed, Eraser updates C(v) with the intersection of C(v) and the set of locks held by the current thread( Lockset refinement). 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 6 / 20

Lockset Algorithm 3/4 • If some lock l consistently protects v, it will remain

Lockset Algorithm 3/4 • If some lock l consistently protects v, it will remain in C(v) as C(v) is refined. If C(v) becomes empty, this indicates that there is no lock that consistently protects v. • In summary, the first lockset algorithm is Let locks_held(t) be the set of locks held by thread t For each v, initialize C(v) to the set of all locks. On each access to v by thread t, set C(v) : = C(v) Å locks_held(t) ; if C(v) = { }, then issue a warning. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 7 / 20

Lockset Algorithm Programs locks_held 4/4 C(v) {} {mu 1, mu 2} lock( mu 1)

Lockset Algorithm Programs locks_held 4/4 C(v) {} {mu 1, mu 2} lock( mu 1) ; {mu 1} lock( mu 2) ; {mu 1, mu 2} v : = v+1 ; {mu 1, mu 2} unlock( mu 2) {mu 1} ; 1 2 3 4 5 6 7 v : = v+2 ; 8 {} unlock( mu 1) 9 {mu 2} ; 10 11 lock( mu 2) ; {} v : = v+1 ; unlock( mu 2) ; 2021 -03 -09 {mu 1} { } issues an alarm Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 8 / 20

Improving the Locking Discipline 1/5 • Improving the locking discipline, there are 3 very

Improving the Locking Discipline 1/5 • Improving the locking discipline, there are 3 very common programming practices that violate the discipline yet are free from any data race. – Initialization Shared variables are frequently initialized without holding a lock. – Read-shared data Some shared variables are written during initialization only and are read-only thereafter. – Read-write lock extends the lockset algorithm to accommodate these 3 cases. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 9 / 20

Improving the Locking Discipline 2/5 • Initialization and read-sharing To avoid false alarms caused

Improving the Locking Discipline 2/5 • Initialization and read-sharing To avoid false alarms caused by unlocked initialization writes, Eraser delays the refinement of a location’s candidate set until after it has been initialized. → No easy way of knowing when initialization is complete. Eraser considers a shared variable to be initialized when it is first accessed by a second thread. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 10 / 20

Improving the Locking Discipline the variable is new and has not yet been referenced

Improving the Locking Discipline the variable is new and has not yet been referenced by any thread. Virgin read or write by first thread the variable has been accessed, but by one thread only. The subsequent reads and writes by the same thread do not update C(v). Exclusive read by new thread Shared write by new thread C(v) is updated, but data races are not reported even if C(v) is empty. Shared. Modified read or write 2021 -03 -09 3/5 C(v) is updated, but data races are reported if C(v) is empty. Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 11 / 20

Improving the Locking Discipline 4/5 • Read-write lock – pthread_rwlock_rdlock(pthread_rwlock_t * rwlock) the calling

Improving the Locking Discipline 4/5 • Read-write lock – pthread_rwlock_rdlock(pthread_rwlock_t * rwlock) the calling thread acquires the read lock if a writer does not hold the lock and no writers are blocked on the lock. – pthread_rwlock_wrlock(pthread_rwlock_t * rwlock) the calling thread acquires the write lock if no other reader thread or writer thread holds the lock. pthread_rwlock_t rwlock ; int data = 0 ; thread 2() { int local ; pthread_rwlock_rdlock(&rwlock) ; local = data ; pthread_rwlock_unlock(&rwlock) ; } thread 1() { pthread_rwlock_rdlock(&rwlock) ; data = data + 1 ; /* data is not protected by rwlock */ pthread_rwlock_unlock(&rwlock) ; } 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 12 / 20

Improving the Locking Discipline 5/5 In Shared-Modified state, Let locks_held(t) be the set of

Improving the Locking Discipline 5/5 In Shared-Modified state, Let locks_held(t) be the set of locks held in any mode by thread Let write_locks_held(t) be the set of locks held in write mode by thread t. On each read of v by thread t, set C(v) : = C(v) Å locks_held(t) ; ( if C(v) = { }, then issue a warning ) On each write of v by thread t, set C(v) : = C(v) Å write_locks_held(t) ; ( if C(v) = { }, then issue a warning ) 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 13 / 20

Implementation 1/4 • Eraser is implemented using ATOM binary modification system. • To maintain

Implementation 1/4 • Eraser is implemented using ATOM binary modification system. • To maintain C(v), Eraser instruments each load and store in the program and also each call to storage allocator for dynamically allocated data • To maintain lock_held(t) for each thread t, Eraser instruments each call to acquire or release a lock as well as the stubs that manage thread initialization and finalization. • In Eraser, shared variables are assumed to be in global location, or in heap. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 14 / 20

Implementation 2/4 • A naïve implementation of locksets would store a list of candidate

Implementation 2/4 • A naïve implementation of locksets would store a list of candidate locks for each memory location. → Potentially consuming many times the allocated memory of the program. • The number of distinct sets of locks observed in practice is quite small. represent each set of locks by a small integer, a lockset index into a table whose entries canonically represent the set of locks as sorted vectors of lock addresses. • For every 32 -bit word in data segment and heap, there is a corresponding shadow word that is used to contain a 30 -bit lockset index and 2 -bit state condition. Eraser: A Dynamic Data Race Detector for Multithreaded 2021 -03 -09 Programs Hong, Shin @ PSWLAB 15 / 20

Implementation 3/4 • Eraser shows that it can produce false alarms. Find effective annotations

Implementation 3/4 • Eraser shows that it can produce false alarms. Find effective annotations to suppress false alarms without accidentally losing useful warnings. • Three broad categories of false alarms – Memory reuse – Private locks – Benign races • For each of these categories, we developed a program annotation to allow user of Eraser to eliminate the false alarms. inform additional information to race detector by annotations. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 16 / 20

Implementation 4/4 • For memory reuse Eraser. Reuse(address, size) • For private locks Eraser.

Implementation 4/4 • For memory reuse Eraser. Reuse(address, size) • For private locks Eraser. Read. Lock(lock) Eraser. Read. Unlock(lock) Eraser. Write. Lock(lock) Eraser. Write. Unlock(lock) • For benign races Eraser. Ignore. On() Eraser. Ignore. Off() 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 17 / 20

Experience 1/1 • Performance Application typically slow down by a factor of 10 to

Experience 1/1 • Performance Application typically slow down by a factor of 10 to 30 while using Eraser. • Alta. Vista – mhttpd – 5, 000 lines of C source code, 100 distinct locks, 9 annotations. – Ni 2 – 20, 000 lines of C source code, 900 distinct locks, 10 annotations. • Vesta Cache Server – 30, 000 lines of C++ source code, 10 threads, 26 distinct locks, 10 annotations. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 18 / 20

Conclusion 1/1 • The advantage of enforcing a simple locking discipline instead of checking

Conclusion 1/1 • The advantage of enforcing a simple locking discipline instead of checking for races in general parallel programs. • Eraser is practical and effective way to avoid data races. 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 19 / 20

Reference [1] Eraser: A Dynamic Data Race Detector for Multithreaded Programs, Stefan Savage et

Reference [1] Eraser: A Dynamic Data Race Detector for Multithreaded Programs, Stefan Savage et al, ACM TOCS 97 [2] Solaris 10 Software Developer Collection http: //docs. sun. com/app/docs/doc/816 -5137/sync-tbl-62? l=ko&a=view 2021 -03 -09 Eraser: A Dynamic Data Race Detector for Multithreaded Programs Hong, Shin @ PSWLAB 20 / 20