chess analysis and t esting of concurrent programs
play

CHESS: Analysis and T esting of Concurrent Programs Sebastian - PowerPoint PPT Presentation

CHESS: Analysis and T esting of Concurrent Programs Sebastian Burckhardt, Madan Musuvathi, Shaz Qadeer Microsoft Research Joint work with T om Ball, Peli de Halleux, and interns Gerard Basler (ETH Zurich), Katie Coons (U. T. Austin), P .


  1. CHESS: Analysis and T esting of Concurrent Programs Sebastian Burckhardt, Madan Musuvathi, Shaz Qadeer Microsoft Research Joint work with T om Ball, Peli de Halleux, and interns Gerard Basler (ETH Zurich), Katie Coons (U. T. Austin), P . Arumuga Nainar (U. Wisc. Madison), Iulian Neamtiu (U. Maryland, U.C. Riverside) Adjusted by Maria Christakis

  2. Concurrent Programming is HARD  Concurrent executions are highly nondeterminisitic  Rare thread interleavings result in Heisenbugs  Diffjcult to fjnd, reproduce, and debug  Observing the bug can “fjx” it  Likelihood of interleavings changes, say, when you add printfs  A huge productivity problem  Developers and testers can spend weeks chasing a single Heisenbug

  3. Main T akeaways  You can fjnd and reproduce Heisenbugs  new automatic tool called CHESS  for Win32 and .NET  CHESS used extensively inside Microsoft  Parallel Computing Platform (PCP)  Singularity  Dryad/Cosmos  Released by DevLabs

  4. CHESS in a nutshell  CHESS is a user-mode scheduler  Controls all scheduling nondeterminism  Guarantees:  Every program run takes a difgerent thread interleaving  Reproduce the interleaving for every run  Provides monitors for analyzing each execution

  5. CHESS Architecture Concurrency Concurrency Unmanaged Unmanaged Analysis Analysis Program Program Monitors Monitors Win32 Wrappers Windows Windows CHESS CHESS Exploration Exploration Engine Engine CHESS CHESS Scheduler Scheduler Managed Managed • Every run takes a different interleaving Program Program • Reproduce the interleaving for every run .NET Wrappers CLR CLR

  6. CHESS Specifjcs  Ability to explore all interleavings  Need to understand complex concurrency APIs (Win32, System.Threading)  Threads, threadpools, locks, semaphores, async I/O, APCs, timers, …  Does not introduce false behaviors  Any interleaving produced by CHESS is possible on the real scheduler

  7. CHESS: Find and Reproduce Heisenbugs Program CHESS runs the scenario in a loop CHESS • Every run takes a different interleaving TestScenario() { While(not done) { While(not done) { … • Every run is repeatable TestScenario() TestScenario() } } } Uses the CHESS scheduler CHESS CHESS • T o control and direct interleavings scheduler scheduler Win32/.NET Detect • Assertion violations Kernel: Kernel: Threads, Scheduler, Threads, Scheduler, • Deadlocks Synchronization Objects Synchronization Objects • Dataraces • Livelocks

  8. The Design Space for CHESS  Scale  Apply to large programs  Precision  Any error found by CHESS is possible in the wild  CHESS should not introduce any new behaviors  Coverage  Any error found in the wild can be found by CHESS  Capture all sources of nondeterminism  Exhaustively explore the nondeterminism

  9. CHESS Scheduler

  10. Concurrent Executions are Nondeterministic x = 1; x = 1; x = 2; x = 2; y = 1; y = 1; y = 2; y = 2; 0,0 0,0 2,0 2,0 1,0 1,0 x = 1; x = 1; 1,1 1,1 2,0 2,0 1,0 1,0 2,2 2,2 y = 1; y = 1; 2,1 2,1 2,1 2,1 1,1 1,1 1,2 1,2 1,2 1,2 2,2 2,2 x = 2; x = 2; y = 2; y = 2; 2,1 2,1 1,2 1,2 1,1 1,1 1,1 1,1 2,2 2,2 2,2 2,2

  11. High level goals of the scheduler  Enable CHESS on real-world applications  IE, Firefox, Office, Apache, …  Capture all sources of nondeterminism  Required for reliably reproducing errors  Ability to explore these nondeterministic choices  Required for finding errors

  12. Sources of Nondeterminism 1. Scheduling Nondeterminism  Interleaving nondeterminism  Threads can race to access shared variables or monitors  OS can preempt threads at arbitrary points  Timing nondeterminism  Timers can fire in different orders  Sleeping threads wake up at an arbitrary time in the future  Asynchronous calls to the file system complete at an arbitrary time in the future

  13. Sources of Nondeterminism 1. Scheduling Nondeterminism  Interleaving nondeterminism  Threads can race to access shared variables or monitors  OS can preempt threads at arbitrary points  Timing nondeterminism  Timers can fire in different orders  Sleeping threads wake up at an arbitrary time in the future  Asynchronous calls to the file system complete at an arbitrary time in the future  CHESS captures and explores this nondeterminism

  14. Sources of Nondeterminism 2. Input nondeterminism  User Inputs  User can provide difgerent inputs  The program can receive network packets with difgerent contents  Nondeterministic system calls  Calls to gettimeofday(), random()  ReadFile can either fjnish synchronously or asynchronously

  15. Sources of Nondeterminism 2. Input nondeterminism  User Inputs  User can provide difgerent inputs  The program can receive network packets with difgerent contents  CHESS relies on the user to provide a scenario  Nondeterministic system calls  Calls to gettimeofday(), random()  ReadFile can either fjnish synchronously or asynchronously  CHESS provides wrappers for such system calls

  16. Sources of Nondeterminism 3. Memory Model Effects  Hardware relaxations  The processor can reorder memory instructions  Can potentially introduce new behavior in a concurrent program  Compiler relaxations  Compiler can reorder memory instructions  Can potentially introduce new behavior in a concurrent program (with data races)

  17. Sources of Nondeterminism 3. Memory Model Effects  Hardware relaxations  The processor can reorder memory instructions  Can potentially introduce new behavior in a concurrent program  CHESS contains a monitor for detecting such relaxations  Compiler relaxations  Compiler can reorder memory instructions  Can potentially introduce new behavior in a concurrent program (with data races)  Future Work

  18. Interleaving Nondeterminism: Example init: init: balance = 100; balance = 100; Deposit Thread Withdraw Thread void Deposit100(){ void Deposit100(){ void Withdraw100(){ void Withdraw100(){ EnterCriticalSection(&cs); EnterCriticalSection(&cs); int t; int t; balance += 100; balance += 100; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); EnterCriticalSection(&cs); EnterCriticalSection(&cs); } } t = balance; t = balance; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance = t - 100; balance = t - 100; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); } } final: final: assert(balance = 100); assert(balance = 100);

  19. Invoke the Scheduler at Preemption Points Deposit Thread Withdraw Thread void Deposit100(){ void Deposit100(){ void Withdraw100(){ void Withdraw100(){ ChessSchedule(); ChessSchedule(); int t; int t; EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance += 100; balance += 100; ChessSchedule(); ChessSchedule(); ChessSchedule(); ChessSchedule(); EnterCriticalSection(&cs); EnterCriticalSection(&cs); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); t = balance; t = balance; } } ChessSchedule(); ChessSchedule(); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); ChessSchedule(); ChessSchedule(); EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance = t - 100; balance = t - 100; ChessSchedule(); ChessSchedule(); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); } }

  20. Introducing Unpredictable Delays Deposit Thread Withdraw Thread void Deposit100(){ void Deposit100(){ void Withdraw100(){ void Withdraw100(){ Sleep( rand () ); Sleep( rand () ); int t; int t; EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance += 100; balance += 100; Sleep( rand() ); Sleep( rand() ); Sleep( rand() ); Sleep( rand() ); EnterCriticalSection(&cs); EnterCriticalSection(&cs); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); t = balance; t = balance; } } Sleep( rand() ); Sleep( rand() ); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); Sleep( rand() ); Sleep( rand() ); EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance = t - 100; balance = t - 100; Sleep( rand() ); Sleep( rand() ); LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); } }

  21. Introduce Predictable Delays with Additional Synchronization Deposit Thread Withdraw Thread void Deposit100(){ void Deposit100(){ void Withdraw100(){ void Withdraw100(){ int t; int t; EnterCriticalSection(&cs); EnterCriticalSection(&cs); t = balance; t = balance; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); SetEvent( e1 ); SetEvent( e1 ); WaitEvent( e1 ); WaitEvent( e1 ); EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance += 100; balance += 100; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); SetEvent( e2 ); SetEvent( e2 ); } } WaitEvent( e2 ); WaitEvent( e2 ); EnterCriticalSection(&cs); EnterCriticalSection(&cs); balance = t - 100; balance = t - 100; LeaveCriticalSection(&cs); LeaveCriticalSection(&cs); } }

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