static versioning of global state for race condition
play

Static Versioning of Global State for Race Condition Detection - PowerPoint PPT Presentation

Introduction Static State Versioning Version Computation Conclusion Static Versioning of Global State for Race Condition Detection Steffen Keul Dept. of Programming Languages and Compilers Institute of Software Technology University of


  1. Introduction Static State Versioning Version Computation Conclusion Static Versioning of Global State for Race Condition Detection Steffen Keul Dept. of Programming Languages and Compilers Institute of Software Technology University of Stuttgart 15 th International Conference on Reliable Software Technologies – Ada-Europe 2010 Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 1 / 20

  2. Introduction Static State Versioning Version Computation Conclusion Outline Introduction Motivation Static State Versioning Motivation Algorithm Design Version Computation Algorithm Outline Interference Data Flow Versioning Conclusion Conclusion Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 2 / 20

  3. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Real-World Data Race Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 3 / 20

  4. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Real-World Data Race Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 3 / 20

  5. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Real-World Data Race Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 3 / 20

  6. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Real-World Data Race Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 3 / 20

  7. Introduction Static State Versioning Version Computation Conclusion Motivation Data Races Definition (Data Race) A data race occurs if two threads access a common storage location without ordering constraints, and one of the accesses modifies the storage contents. Presence of data race means: ◮ possibly missing explicit synchronization ◮ for non-atomic accesses, possibility of illegal bit-patterns Absence of data race means: ◮ some serialization of accesses exists ◮ no illegal bit-patterns are created Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 4 / 20

  8. Introduction Static State Versioning Version Computation Conclusion Motivation Race detection ◮ data races can indicate programming errors ◮ confidence in absence of races through static analysis ◮ many analysis algorithms exist for data race detection ◮ some data races can be tolerated if the shared variable is accessed atomically ◮ however, some critical race conditions are not data races ◮ this work aims at detection of all potentially harmful race conditions Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 5 / 20

  9. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Static State Versioning ◮ Shared Variables: sens_1 , sens_2 , sens_3 Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 6 / 20

  10. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Static State Versioning ◮ Shared Variables: sens_1 , sens_2 , sens_3 ◮ Data Race because of read of sens_3 ◮ no synchronization necessary if int s read atomically, Data Race uninteresting Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 6 / 20

  11. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Static State Versioning ◮ Shared Variables: sens_1 , sens_2 , sens_3 ◮ Data Race because of read of sens_3 ◮ no synchronization necessary if int s read atomically, Data Race uninteresting ◮ Versioning of reads Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 6 / 20

  12. Introduction Static State Versioning Version Computation Conclusion Motivation Example: Static State Versioning ◮ Shared Variables: sens_1 , sens_2 , sens_3 ◮ Data Race because of read of sens_3 ◮ no synchronization necessary if int s read atomically, Data Race uninteresting ◮ Versioning of reads ◮ Use of different versions indicates programming error Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 6 / 20

  13. Introduction Static State Versioning Version Computation Conclusion Motivation Violation of Atomicity: uninteresting warnings Example (Conflict accesses on g in thread2 and thread3 , but inconsistent expression only in thread3 ) int g; void *thread1( void *p) { while (1) g = read_sensor_value(); } void *thread2( void *p) { while (1) act_1(5 * g + 17); } void *thread3( void *p) { while (1) act_2(g * g); } Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 7 / 20

  14. Introduction Static State Versioning Version Computation Conclusion Motivation Violation of Atomicity: nonatomic expressions Example (Free of data races, but the mutex_lock -calls around g1+g2 have no effect) void *t1( void *p) void *t2( void *p) { mutex_lock(&m); { mutex_lock(&n); g1 = ...; g2 = ...; mutex_unlock(&m); mutex_unlock(&n); } } int main() { create(t1); create(t2); mutex_lock(&m); mutex_lock(&n); res = g1 + g2; mutex_unlock(&n); mutex_unlock(&m); } Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 8 / 20

  15. Introduction Static State Versioning Version Computation Conclusion Motivation Stale Updates Example (Nonatomic increments) pthread_mutex_lock(&m); int local = global; pthread_mutex_unlock(&m); local += 17; pthread_mutex_lock(&m); global = local; pthread_mutex_unlock(&m); The LHS’s version ( global directly before the assignment) differs from the RHS’s version ( local ). Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 9 / 20

  16. Introduction Static State Versioning Version Computation Conclusion Algorithm Outline State Versioning Algorithm 1. translate source code into intermediate representation, use only atomic read and write operations 2. represent interfering data flow explicitly by insertion of ψ -nodes for ◮ conflict reads ◮ uses of shared variables in protected regions 3. assign versions to reads in every function independent of calling context, in bottom-up traversal of the call graph 4. adjust versions depending on context in top-down traversal of the call graph 5. produce warning list for potentially inconsistent expressions Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 10 / 20

  17. Introduction Static State Versioning Version Computation Conclusion Interference Data Flow Lockset analysis ◮ determine the set of all possible (mutex-) locks: L full ◮ associate each site s in the program with the set of mutex-locks l act ( s ) ⊆ L full that are active ◮ use monotonic analysis framework over ( 2 L full , ⊆ ) ◮ initial value ∅ at function entry, L full for all other basic blocks ◮ at confluence points use intersection as meet operator ◮ distinguish different caller locksets at call sites Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 11 / 20

  18. Introduction Static State Versioning Version Computation Conclusion Interference Data Flow Interference flow for conflict reads ◮ determine shared objects ◮ use locksets to determine conflict reads ◮ place ψ -node in front of every conflict read Example (Insertion of ψ -nodes for conflict reads) s m 1 = 0 ; s = 0; s m 2 = ψ ( s m 1 , s t 1 , . . . , s tn ) ; ⇒ s m 3 = ψ ( s m 1 , s t 1 , . . . , s tn ) ; s = s + s; s m 4 = s m 2 + s m 3 ; So far . . . ◮ Synchronization is ignored Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 12 / 20

  19. Introduction Static State Versioning Version Computation Conclusion Interference Data Flow Interference flow for protected regions ◮ identify protected regions ◮ regions protected by a common lock are mutually exclusive ◮ data flow can only occur from end to beginning of mutually exclusive regions ⇒ Add Link-out and ψ nodes ◮ interference flow for multiple objects is stored into a single ψ -node A = { ( l old , l new ) ∈ 2 L full × 2 L full : l old ∩ L out ( bb ) � = ∅ ∧ l new ∩ L out ( bb ) = ∅ ∧ l old ∩ L act ( bb ) = ∅ ∧ l new ∩ L act ( bb ) = ∅ } Steffen Keul (University of Stuttgart) Static Versioning of Global State for Race Condition Detection AE 2010 13 / 20

Recommend


More recommend