multicore acceleration of priority-based schedulers for ...santosh.nagarakatte/...needlepoint –...

30
Multicore Acceleration of Priority-Based Schedulers for Concurrency Bug Detection Santosh Nagarakatte, Sebastian Burckhardt, Milo Martin, Madan Musuvathi University of Pennsylvania Microsoft Research

Upload: others

Post on 20-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

Multicore Acceleration of Priority-Based Schedulers for Concurrency Bug Detection

Santosh Nagarakatte, Sebastian Burckhardt, Milo Martin, Madan Musuvathi

University of Pennsylvania Microsoft Research

Page 2: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

2 NeedlePoint – Santosh Nagarakatte – PLDI 2012

This work licensed under the Creative Commons Attribution-Share Alike 3.0 United States License

•  You are free: •  to Share — to copy, distribute, display, and perform the work •  to Remix — to make derivative works

•  Under the following conditions: •  Attribution. You must attribute the work in the manner specified by the author or

licensor (but not in any way that suggests that they endorse you or your use of the work).

•  Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.

•  For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to:

http://creativecommons.org/licenses/by-sa/3.0/us/ •  Any of the above conditions can be waived if you get permission from

the copyright holder. •  Apart from the remix rights granted under this license, nothing in this

license impairs or restricts the author's moral rights.

Page 3: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

3

Overview •  Context: Testing multithreaded programs

•  Many policies proposed to explore interleavings •  NeedlePoint: Interleaving Exploration Tool

•  Test and evaluate real world code with policies •  Separate mechanisms from policy, infers blocking

•  Probabilistic Concurrency Testing (PCT) works well •  Detected bugs at least once in 1000 executions •  Unfortunately, it runs one thread at a time

•  Serious bottleneck with real code •  Parallel Probabilistic Concurrency Testing (PPCT)

•  Runs multiple threads •  Effective as PCT in theory and practice

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 4: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

4

Testing Multithreaded Programs • Two aspects of the testing problem

•  Detection of bugs •  Use a test harness •  Use pattern detectors like data race detectors

•  Driving & exploring the interleaving •  Explore all scheduling choices at each point

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Focus of this talk

Page 5: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

5 NeedlePoint – Santosh Nagarakatte – PLDI 2012

Space of Interleavings

(p = 0, bal = 10, q = 0)

(p = 5, bal = 1000, q = 7)

T1: w(y) q = 7 t = bal; bal = t- y

T2:d(x) bal += x p = 5

Page 6: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

6 NeedlePoint – Santosh Nagarakatte – PLDI 2012

Space of Interleavings

(p = 0, bal = 10, q = 0)

(p = 5, bal = 1000, q = 7)

T1: w(y) q = 7 t = bal; bal = t- y

T2:d(x) bal += x p = 5

Page 7: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

7 NeedlePoint – Santosh Nagarakatte – PLDI 2012

Space of Interleavings

(p = 0, bal = 10, q = 0)

(p = 5, bal = 1000, q = 7)

T1: w(y) q = 7 t = bal; bal = t- y

T2:d(x) bal += x p = 5

Page 8: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

8 NeedlePoint – Santosh Nagarakatte – PLDI 2012

Space of Interleavings

(p = 0, bal = 10, q = 0)

Numerous interleavings in the

same program

(p = 5, bal = 1000, q = 7)

T1: w(y) q = 7 t = bal; bal = t- y

T2:d(x) bal += x p = 5

Page 9: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

9

Interleaving Exploration Policies •  Best-effort exploration

•  Random sleep: actively introduce delays •  AtomFuzzer: delays to trigger atomicity violations •  PreemptionAlways: a preemption at every point

•  Exploration with coverage guarantees •  Preemption bounding: introduce bounded number of

preemptions •  PCT: schedule threads according to priorities

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 10: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

10 NeedlePoint – Santosh Nagarakatte – PLDI 2012

Test and understand the interleaving exploration schemes with real world code

Page 11: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

11

NEEDLEPOINT

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 12: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

12

NeedlePoint Framework • Unified framework for controlled scheduling

•  Separation of concerns between mechanisms & policy

• Three mechanisms for controlled scheduling 1.  Introduction of callbacks to the scheduler

•  Real programs use a wide range of synchronization 2.  Support for identifying blocked threads

•  To provide coverage, need to explore the interleaving when the synchronization blocks

3.  Support for starvation freedom •  Spin loops & busy wait synchronization livelocks

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Modeling each synchronization is error-prone & real programs define ad-hoc synchronization

Page 13: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

13

Calls to the NeedlePoint Framework at Schedule Points

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Lock (l); bal += x; Unlock(l);

Lock (l); t = bal;

Unlock(l);

while(true){ schedulingPolicy(); if(state[tid] == Running) break; else yield(); }

Synchronization library calls, atomic operations, shared memory accesses

TID State 1 Running

2 Ready

TID State 1 Running

Page 14: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

14

TID State 1 Running

2 Ready

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Inferring Blocked Threads

… Lock (l); bal += x; Unlock(l);

Lock (l); t = bal;

Unlock(l); ….

while(true){ schedulingPolicy(); if(state[tid] == Running) break; else{ yield(); timeout[tid]++; if(timeout[id] > T) state[rid] = BLOCKED } reset_timeout_counters()

while(true){ schedulingPolicy(); if(state[tid] == Running) break; else{ yield(); timeout[id] ++; if(timeout[id] > T) state[rtid] = BLOCKED } reset_timeout_counters();

Infers whether the thread is blocked How to identify which threads block?

Page 15: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

15

TID State 1 Running

2 Ready

TID State 1 Ready

2 Running

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Inferring Blocked Threads

… Lock (l); bal += x; Unlock(l);

Lock (l); t = bal;

Unlock(l); ….

0

Timeout Clock

while(true){ schedulingPolicy(); if(state[tid] == Running) break; else{ yield(); timeout[tid]++; if(timeout[id] > T) state[rid] = BLOCKED } reset_timeout_counters();

while(true){ schedulingPolicy(); if(state[tid] == Running) break; else{ yield(); timeout[id] ++; if(timeout[id] > T) state[rtid] = BLOCKED } reset_timeout_counters();

1 2

TID State 1 Running

2 Blocked

Allows the lock to execute, acquire operation blocks

Page 16: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

16

Evaluation of Techniques

NeedlePoint – Santosh Nagarakatte – PLDI 2012

1

10

100

1000

10000

100000

Random Sleep Preemption Always Preemption Bounding AtomFuzzer Probabilistic Concurrency Testing

Exe

cutio

ns w

ith

bug

trigg

ered

PCT detects the bug at least once in 1000 executions

Page 17: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

17

Challenges with PCT • PCT was effective in detecting all bugs

• However, one thread at a time is a bottleneck •  Can’t exploit multi-core •  Interacts poorly with NeedlePoint’s blocking inference •  Result: Unable to test highly parallel applications

•  More than 64X slowdown with Chrome browser

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Can we run multiple threads with PCT and maintain its effectiveness in theory &

practice?

Page 18: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

18

PCT BACKGROUND

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 19: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

19

Probabilistic Concurrency Testing (PCT) [ASPLOS 2010]

• Key Idea: Make a few choices to assign priorities •  Schedule the highest priority thread that is not blocked

• Bug depth •  Number of ordering constraints an interleaving need to

exhibit to trigger the bug

•  More constraints means more things have to go “just right” to trigger the bug.

NeedlePoint – Santosh Nagarakatte – PLDI 2012

PCT explores the program to trigger bugs of particular depth

Page 20: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

20

Bug Depth Illustration

NeedlePoint – Santosh Nagarakatte – PLDI 2012

… p = &a;

… p->f ++;

Bug of depth 1: Ordering Violation

Bug of depth 2: Atomicity Violation

Lock(I) t = bal

Unlock(I) Lock(I)

bal += x; Unlock(I) Lock(I)

bal = t – y Unlock(I);

Page 21: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

21

PCT Algorithm for Bug Depth d • At the beginning of the execution

•  Assign unique priorities to the threads •  Reserve d lower priorities •  Choose d-1 priority change points in the execution

• Schedule the threads according to priorities •  Run the highest priority non-blocked thread •  At a change point, lower the priorities to the reserved

priorities

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 22: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

22

PCT for a Bug of Depth 2

NeedlePoint – Santosh Nagarakatte – PLDI 2012 NeedlePoint – Santosh Nagarakatte – PLDI 2012

(p = 0, bal = 10, q = 0)

(p = 5, bal = 1000, q = 7)

Pri = 3 Pri = 2 Change Point: Step#2

Change Point: Priority of deposit

thread changed to 1

✗ 1 T1: w(y) q = 7 t = bal; bal = t- y

T2: d (x) bal += x p = 5

Page 23: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

23 NeedlePoint – Santosh Nagarakatte – PLDI 2012

  Given a program with ◦  n threads (~tens) ◦  k steps (~millions) ◦  a bug of depth d (1,2)

  Each run PCT triggers a bug with a probability (p) of at least

(this is a worst-case guarantee)

Page 24: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

24

PARALLEL PCT

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 25: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

25

Parallel PCT (PPCT) •  Key Idea: Serialize only d threads

•  The d lower priority threads are important to trigger the bug •  Maintain two sets: higher priority set (HS) & lower priority set (LS) •  Insert priority d into LS and others into HS

•  PPCT operates in 2 phases •  PCT mode: run the highest priority non-blocked thread •  Parallel mode: run any unblocked thread with priority > d

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Key difference between PCT and PPCT is the number of choices it provides the adversary

PCT mode

Parallel mode

All threads with

priority > d blocked

Yes

No

PPCT provides same bounds as PCT

Page 26: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

26

PARALLEL PCT EVALUATION

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 27: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

27

Bug Detection with PPCT using NeedlePoint

NeedlePoint – Santosh Nagarakatte – PLDI 2012

1

10

100

1000

10000

100000 PCT PPCT

PPCT detects bug as effectively as PCT in practice

Exe

cutio

ns w

ith

bug

trigg

ered

Page 28: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

28

Slowdown with PCT & PPCT

NeedlePoint – Santosh Nagarakatte – PLDI 2012

0

20

40

60

80

100 PCT PPCT 1 Core PPCT All Cores

• PPCT reduces the overhead from 34X to 6X on a 8-core machine

Slo

wdo

wn

over

na

tive

exec

utio

n (ti

mes

)

• PPCT reduces the overhead even on a single core • Avoids poor interaction with blocking inference

Page 29: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

29

Conclusions

• NeedlePoint framework •  Separation of mechanisms and exploration policy •  Inferring blocked threads

• Proposed Parallel Probabilistic Concurrency Testing

•  For bugs of depth d, runs all but “d” threads •  Provides same coverage guarantees as PCT •  Significant speedups both on single & multiple cores

NeedlePoint – Santosh Nagarakatte – PLDI 2012

Page 30: Multicore Acceleration of Priority-Based Schedulers for ...santosh.nagarakatte/...NeedlePoint – Santosh Nagarakatte – PLDI 2012 2 This work licensed under the Creative Commons

30 NeedlePoint – Santosh Nagarakatte – PLDI 2012

http://www.cis.upenn.edu/~santoshn/needlepoint

Subscribe to

[email protected]