Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs...

50
Towards Production-Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Transcript of Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs...

Page 1: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

TowardsProduction-RunHeisenbugsReproductiononCommercialHardware

1

ShiyouHuangBowenCai andJeffHuang

Page 2: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

2

What’sacoder’sworstnightmare?

https://www.quora.com/What-is-a-coders-worst-nightmare

Page 3: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

3

Thebugonlyoccursinproductionbutcannotbereplicatedlocally.

https://www.quora.com/What-is-a-coders-worst-nightmare

Page 4: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Heisenbug

4

Whenyoutracethem,theydisappear!

Page 5: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Heisenbug

5

Whenyoutracethem,theydisappear!

• Localizationishard

Page 6: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Heisenbug

6

Whenyoutracethem,theydisappear!

• Localizationishard• reproductionishard

Page 7: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Heisenbug

7

Whenyoutracethem,theydisappear!

• Localizationishard• reproductionishard• neverknowifitisfixed…

Page 8: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Amotivatingexample

8

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)

Init:x=1,y=2

http://stackoverflow.com/questions/16159203/

z=1

x=2,y=3

x+1==y

contradiction!

Page 9: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Amotivatingexample

9

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)

Init:x=1,y=2

http://stackoverflow.com/questions/16159203/

z=1

x=2,y=3

x+1==y

contradiction!

PSO

Page 10: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Amotivatingexample

10

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)

Init:x=1,y=2

http://stackoverflow.com/questions/16159203/

z==1

x=2,y=3

x+1==y

contradiction!

$12millionlossofequipment!

Page 11: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Record&Replay(RnR)

11

FailureExecution

RecordReplay

Goal: record thenon-determinismatruntimeandreproduce thefailure

Page 12: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Record&Replay(RnR)

12

FailureExecution

RecordReplay

Goal: record thenon-determinismatruntimeandreproduce thefailure

• runtimeoverhead• theabilitytoreproducefailures

Page 13: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

RelatedWork• Software-basedapproach

• order-based:fullyrecordsharedmemorydependenciesatruntime

• LEAP[FSE’10],Order[USENIXATC’11],Chimera[PLDI’12],Light[PLDI’15]RR[USENIXATC’17]…

• Chimera:>2.4x

• search-based:partiallyrecordthedependenciesatruntimeanduseofflineanalysis(e.g.SMTsolvers)toreasonthedependencies

• ODR[SOSP’09],Leeetal.[MICRO’09],Weeratunge etal.[ASPLOS’10],CLAP[PLDI’13]…

• CLAP:0.9x– 3x

• Hardware-basedapproach• Rerun[ISCA’08],Delorean[ISCA’08],Coreracer[MICRO’11],PBI[ASPLOS’13]…

• relyonspecialhardwarethatarenotdeployed13

Page 14: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

RealityofRnR

14

• highoverheads• failingtoreproducefailures• lackofcommodityhardware

support

Inproduction

Page 15: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Contributions

Goal:recordtheexecutionatruntimewithlowoverheadandfaithfully reproduceitoffline

Ø RnR basedoncontrolflowtracingoncommercialhardware(IntelPT)

Ø core-based constraintsreductiontoreducetheofflinecomputation

Ø H3,evaluatedonpopularbenchmarksandreal-worldapplications,

overhead:1.4%-23.4%

15

Page 16: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

IntelProcessor Trace(PT)

PT:Programcontrolflowtracing,supportedon5th and6thgenerationIntel core• Lowoverhead,aslowas5%1

• Highlycompactedpackets,<1bitperretiredinstruction

• Onebit(1/0)forbranchtakenindication

• Compressedbranchtargetaddress

161:https://sites.google.com/site/intelptmicrotutorial.

Page 17: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

PTTracingOverheadIntel CPU core 0...n

Driver

Packets stream(per logical CPU)

Binary Image files

Intel PT Software Decoder

Reconstructed execution

Configure & Enable Intel PT

Runtime data

Figure 4: Components of Intel Processor Tracing (PT).

gram control flow by code instrumentation is difficult orimpossible. For example, if a failure is caused by a bugin the uninstrumented external code, the constraints gen-erated by CLAP may be incomplete and hence fail toreproduce the bug.

2.2 Hardware Control-Flow TracingTracing control flow at the hardware level opens a door toapply CLAP in production runs by addressing the afore-mentioned limitations in three ways. First, hardware-supported control flow tracing is significantly more ef-ficient than software-level path-recording. Compared tothe 10%-3X overhead by software path-recording, PTachieves as low as 5% runtime overhead [2]. Second,hardware can track the full control flow of the code ex-ecuted on each core. PT can not only trace the applica-tion code, but also the whole operating system kernel [2].Third, tracing the control flow on each core enables asignificant reduction of the complexity of the read-writeconstraints, because reads and writes from the same coreare ordered already.

Next, we first review the basics of PT and then show itsperformance improvement over software path-recordingon PARSEC 3.0 benchmarks [5].

Intel PT. As depicted in Figure 4, PT consists of twomain components: tracing and decoding. For tracing,it only records the instructions that are related to thechange of the program control flow and omits everythingthat can be deduced from the code (e.g., unconditionaldirect jumps). For each conditional branch executed, PTgenerates a single bit (1/0) to indicate whether a condi-tional branch is taken or not taken. As such, PT tracksthe control flow information, such as loops, conditionalbranches and function calls of the program, with minimalperturbation, and outputs a highly compact trace.

For decoding, PT provides a decoding library [1] toreconstruct the control flow from the recorded raw trace.It first synchronizes the packet streams with the synchro-nization packets generated during tracing, and then iter-ates over the instructions from the binary image to iden-tify what instructions have been executed. Only when the

Table 1: Runtime and space overhead of PT on PARSEC.

Program Native PTtime (s) time (s) OH(%) trace

bodytrack 0.557 0.573 2.9% 94Mx264 1.086 1.145 5.4% 88Mvips 1.431 1.642 14.7% 98M

blackscholes 1.51 1.56 9.9% 289Mferret 1.699 1.769 4.1% 145M

swaptions 2.81 2.98 6.0% 897Mraytrace 3.818 4.036 5.7% 102Mfacesim 5.048 5.145 1.9% 110M

fluidanimate 14.8 15.1 1.4% 1240Mfreqmine 15.9 17.1 7.5% 2468M

Avg. 4.866 5.105 4.9% 553M

decoder cannot decide the next instruction (e.g., when itencounters a branch), the raw trace is queried to guidethe decoding process.

PT is configurable via a set of model-specific registersby the kernel driver. It provides a privilege-level filter-ing function for developers to decide what code to trace(i.e. kernel vs. user-space) and a CR3 filtering functionto trace only a single application or process. PT on IntelSkylake processors also supports filtering by the instruc-tion pointer (IP) addresses. This feature allows PT to se-lectively trace code that is only within a certain IP range,which can further reduce the tracing perturbation.

PT Performance. Table 1 reports the runtime andspace overhead of PT on the PARSEC 3.0 benchmarks.We report the execution time of the programs withoutand with PT tracing (and the trace size), marked as nativeand PT respectively. Among the 10 benchmarks, PT in-curs 1.4% to 14.7% runtime overhead (4.9% on average)and 88MB to 2.4GB space overhead (0.5GB on average).

3 H3

In this section, we present the technical details of H3.As we have described in Figure 1, H3 integrates hard-ware control-flow tracing with offline symbolic con-straint analysis to reproduce Heisenbugs. Although theoverall flow is easy to understand, there are three techni-cal challenges in the integration:

1. Absence of the thread information. There isno thread information from the PT traces. It isunknown which instruction is executed by whichthread, and hence difficult to construct the inter-thread synchronization and memory dependencyconstraints.

2. Gap between low-level hardware traces andhigh-level symbolic traces. The decoded execu-

4

17

4.9%overheadonexecutionsofPARSEC3.0onaverage

Page 18: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Challenges

• PTtrace:low-levelrepresentation(assemblyinstruction)

• Absenceofthethreadinformation

• Nodatavaluesofmemoryaccesses

18

Page 19: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Solutions

• PTtrace:low-levelrepresentation&nodatavalues• Idea:extractthepathprofilesfromPTtraceandre-executetheprogrambyKLEEtogeneratesymbolvalues

• Absenceofthethreadinformation• Idea:usethreadcontextswitchinformationbyPerf

19

Page 20: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

H3Overviewcore 0 core 1

core 3core 2

T0 Tn...Binary image

Execution recorded by each core

Packet log Decode

user endSymbolic trace of each thread

1. Constraints formula2. SMT solver A global

schedule

Recording & Decoding Offline Constraints Construction & Solving

- Path constraints- Core-based read-write constraints- Synchronization constraints- Memory order constraints

- Path profiles generation

- Symbolic execution

PT tracing

20

Phase1:Control-flowtracing

Phase2:Offlineanalysis

ReconstructtheexecutiononeachcorebydecodingthepacketsgeneratedbyPTandthreadinformationfromPerf

• Pathprofilesofeachthread• Symbolictraceofeachthread• SMTconstraintsoverthetrace

Page 21: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

21

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

A

CB

D

FE

Packets log+

line 1line 2

...line n

Decoding

Matchingline numbers

Binary image

reconstructed execution program's cotrol flow

Binaryimage

TracePackets

Step1:Collectingpathprofilesofeachthread

libipt

Init:x=1,y=2PT:tracingcontrol-flowoftheprogram’sexecution

perfcontextswitchevents(TID,CPUID,TIME…)

T1

A

CB

D

FE

Packets log+

line 1line 2

...line n

Decoding

Matchingline numbers

Binary image

reconstructed execution program's cotrol flow

T2

Page 22: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

22

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

BB1

T1:bb1

T2:bb1,bb2

BB3

BB1

BB2

Step1:Collectingpathprofilesofeachthread

Matchto*.ll

Init:x=1,y=2PT:tracingcontrol-flowoftheprogram’sexecution

A

CB

D

FE

Packets log+

line 1line 2

...line n

Decoding

Matchingline numbers

Binary image

reconstructed execution program's cotrol flow

A

CB

D

FE

Packets log+

line 1line 2

...line n

Decoding

Matchingline numbers

Binary image

reconstructed execution program's cotrol flow

T2

T1

pathprofile

Page 23: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

23

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2Step2:symbolictracegeneration

KLEE[OSDI’08]:executethethreadalongthepathprofile

𝑊"# = 0𝑅'(,𝑊'( = 𝑅'( + 1𝑅,-,𝑊,- = 𝑅,- + 1𝑊". = 1

𝑇𝑟𝑢𝑒 ≡ 𝑅"4 == 1𝑅'5 + 1 ≠ 𝑅,5

T1

T2

Usingsymbolvaluestorepresentconcretevalues,e.g.,𝑊"# :valuewrittentozatline2𝑅'( :valuereadfromzatline3

Page 24: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

24

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailurescheduleCLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

OrdervariableOrepresentstheorderofastatement,e.g.,O2<O3

means2:z=0 happenbefore3:x++

T1

T2

Global

Page 25: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

25

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2Step3:computingglobalfailureschedule

CLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97

matchareadtoawrite

Page 26: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

26

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailurescheduleCLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97

rf

HB matchareadtoawrite

Page 27: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

27

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailurescheduleCLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97

rfHA

Page 28: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

28

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2Step3:computingglobalfailureschedule

CLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97

executionshouldbeallowedbythememorymodel

reorderingPSO

Page 29: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

29

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailurescheduleCLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97

Truemakethefailurehappen

Page 30: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

30

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailurescheduleCLAP[PLDI’13]:Reasondependenciesofmemoryaccesses

Read-WriteConstraints("#$ = 0 ∧ )$ < )+) ∨

("#$ = .#/ ∧ )/ < )$ ∧ ()+ < )/ ∨ )$ < )+))MemoryOrderConstraints

SC PSO)0 < )+ < )123 < )143 < )523

< )543 < )/ < )6)$ < )78 < )79

)0 < )+)/ < )6)123 < )143)523 < )543

)$ < )78 < )79PathConstraints FailureConstraints

"#$ = 1 "87 + 1! = "97Violationmakethefailurehappen

Page 31: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Example

31

T11:T2.start()2:z=03:x++4:y++5:z=16:T2.join()

T27:if(z==1)8:assert(x+1==y)✗

Init:x=1,y=2 Step3:computingglobalfailureschedule

O1=1,O2=2,O3=3,O5=4,O7=5,O8=6,O4=7

Schedule:1-2-3-5-7-8-4reordering

Page 32: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

32

the potential inter-thread memory dependencies; andFmo the memory model constraints. The formula con-tains two types of variables: (1) V - the symbolic valuevariables denoting the values returned by reads; and (2)O - the order variables the order of each operation in thefinal global schedule.

Path Constraints (Fpath). The path constraints areconstructed by a conjunction of all the path conditionsof each thread, with each path condition corresponds toa branch decision by that path. The path conditions arecollected by recording the decision of each branch viasymbolic execution.Bug Constraints (Fbug). The bug constraints enforcethe conditions for a bug to happen. A bug can be acrash segfault, an assert violation, a buffer overflow, orany program state-based property. To construct the bugconstraints, an expression over the symbol values for sat-isfying the bug conditions is generated. For example, theviolation of an assertion exp can be modeled as !exp.Synchronization Constraints (Fsync). The synchro-nization constraints consist of two parts: partial orderconstraints and locking constraints. The partial orderconstraints model the order between different threadscaused by synchronizations fork/join/signal/wait. Forexample, The begin event of a thread t should happenafter the fork event that starts t. A join event for a threadt should happen after the last event of t. The locking con-straints ensures that events guarded by the same lock aremutually exclusive. It is constructed over the orderingof the lock and unlock events. More specifically, for eachlock, all the lock/unlock pairs of events are extracted, andthe following constraints for each two pairs (l1, u1) and(l2, u2) are constructed: Ou1 < Ol2 _Ou2 < Ol1 .Memory Order Constraints (Fmo). The memory or-der constraints enforce orders specified by the underly-ing memory models. H3 currently supports three mem-ory models: SC, TSO and PSO. For SC, all the eventsby a single thread should happen in the program order.TSO allows a read to complete before an earlier write toa different memory location, but maintains a total orderover writes and operations accessing the same memorylocation. PSO is similar to TSO, except that it allowsre-ordering writes on different memory locations.Read-Write Constraints (Frw). Frw matches readsand writes by encoding constraints to enforce the readto return the value written by the write. Consider a read ron a variable v and r is matched to a write w on the samevariable; we must construct the following constraints:the order variables of all the other writes that r can bematched to are either less than Ow or greater than Or.

As discussed in Section 2.1, Frw can be complicatedbecause there may exist many potential matches betweenreads and writes. The size of Frw is cubic in the trace

Figure 5: Core-based constraint reduction.

size and its complexity is exponential in the trace size.Nevertheless, in next subsection, we show that both thesize and complexity of Frw can be greatly reduced in H3.

3.4 Core-based Constraints ReductionBesides the low runtime overhead, another key innova-tion enabled by PT is that the order of executed eventson each core (either by the same thread or by differentthreads) is determined, which can reduce the complex-ity of Frw from exponential in the number of writes toexponential in the core counts.

The key observation of this reduction is that the exe-cuted memory accesses on each core decoded from PTtrace are already ordered, following the program order.Once the order of a certain write in the global schedule isdetermined, all the writes that happen before or after thiswrite, on the same core, should occur before or after thiswrite in the schedule correspondingly. This eliminatesa large number of otherwise necessary read-write con-straints for capturing the potential inter-thread memorydependencies.

Consider an example in Figure 5, which has four coreswith each executing four different writes. Suppose thereis a read R that can be potentially matched with all ofthese writes, because each of them writes a differentvalue to the same shared variable read by R. Withoutthe partial order information of each core, we must in-clude all writes and their orderings into the constraints.

6

• Allthewriteswriteadifferentvaluetothesamememorylocation

MatchRtothewriteW7

Page 33: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

33

Withoutthepartialorderoneachcore

W7-R

W1 W2 W3 W15 W16…

Page 34: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

34

Withoutthepartialorderoneachcore

W7-R

W1 W2 W3 W15 W16…

Page 35: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

35

Withoutthepartialorderoneachcore

W7-R

W1 W2 W3 W15 W16…

Page 36: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

36

Withoutthepartialorderoneachcore

W7-R

W1 W2 W3 W15 W16…

Page 37: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

37

Withoutthepartialorderoneachcore

W7-R

W1 W2 W3 W15 W16…

28.

Page 38: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

38

Knowingthepartialorderoneachcore

W7-R

W1 W2 W3 W4

W13 W14 W15 W16

Page 39: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

39

Knowingthepartialorderoneachcore

W7-R

W1 W2 W3 W4

W13 W14 W15 W16

Page 40: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Core-basedconstraintsreduction

40

Knowingthepartialorderoneachcore

W7-R

W1 W2 W3 W4

5-

W13 W14 W15 W16

5

5

reducedfrom215

Page 41: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

H3Implementation

• Control-flowtracing• PTdecodinglibrary&LinuxPerftool

• Pathprofilesgeneration• PythonscriptstoextractthepathprofilesfromPTtrace

• Symbolictracecollecting• ModifiedKLEE[OSDI’08]forsymbolicexecutionalongthepathprofiles

• Constraintsconstruction• ModifiedCLAP[PLDI’13]toimplementthecore-basedconstraintsreduction• Z3forsolvingtheconstraints

41

Page 42: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Evaluation

• Environment• 4core3.5GHzInteli76700HQSkylake with16GBRAM• Ubuntu14.04,Linuxkernel4.7

• Threesetsofexperiments• runtimeoverhead• howeffectivetoreproducebugs• howeffectiveisthecore-basedconstraintsreduction

42

Page 43: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Benchmarks Table 2: Benchmarks.

Program LOC #Threads #SV #insns #branches #branches Ratio Symb.(executed) (total) (app) app/total time

racey 192 4 3 1,229,632 78,117 77,994 99.8% 107spfscan 1026 3 13 1,287 237 43 18.1% 2.5s

aget-0.4.1 942 4 30 3,748 313 5 1.6% 117spbzip2-0.9.4 1942 5 18 1,844,445 272,453 5 0.0018% 8.7s

bbuf 371 5 11 1,235 257 3 1.2% 5.5ssbuf 151 2 5 64,993 11,170 290 2.6% 1.6s

httpd-2.2.9 643K 10 22 366,665 63,653 12,916 20.3% 712shttpd-2.0.48 643K 10 22 366,379 63,809 13,074 20.5% 698shttpd-2.0.46 643K 10 22 366,271 63,794 12,874 20.2% 643s

then only need to disjunct the order constraints betweenw and those writes from a different core.

5 Evaluation

Our evaluation of H3 focuses on answering two sets ofquestions:

• How is the runtime performance of H3? How muchruntime improvement is achieved by H3 comparedto CLAP?

• How effective is H3 for reproducing real-worldHeisenbugs? How effective is the core-based con-straint reduction technique?

5.1 Methodology

We evaluated H3 with a variety of multithreaded C/C++programs collected from previous studies [18, 35, 6], in-cluding nine popular real-world applications containingknown Heisenbugs. Table 2 summarizes these bench-marks. pfscan is a parallel file scanner containing aknown bug; aget-0.4.1 is a parallel ftp/http download-ing tool containing a deadlock; pbzip2-0.9.4 is a multi-threaded implementation of bzip with a known order vi-olation; bbuf is shared bounded buffer and sbuf is a C++implementation of the JDK1.4 StringBuffer class; httpd-2.2.9, httpd-2.0.48, httpd-2.0.46 are from the ApacheHTTP Server each containing a known concurrency bug;We also included racey [6], a special benchmark withintensive races that are designed for evaluating RnR sys-tems. We use Apache Bench (ab) to test httpd, whichis set to handle 100 requests with a maximum of 10 re-quests running concurrently.

We compared the runtime performance of H3 andCLAP by measuring the time and space overhead causedby PT tracing and software path-recording. We ran eachbenchmark five times and calculated the average. All

experiments were performed on a 4 core 3.5GHz In-tel i7 6700HQ Skylake CPU with 16 GB RAM runningUbuntu 14.04.

We evaluated the effectiveness of H3 for reproducingbugs by checking if H3 can generate a failure reproduc-ing schedule and by measuring the time taken by offlineconstraint solving. We set one hour timeout for Z3 tosolve the constraints.

For most benchmarks, the failures are difficult to man-ifest because the erroneous schedule for triggering theHeisenbugs is rare. Similar to CLAP, we inserted timingdelays (sleep functions) at key places in each benchmarkand executed it repeatedly until the failure is produced.We also added the corresponding assertion to denote thebug manifestation.

Benchmark Characteristics. Table 2 reports the ex-ecution characteristics of the benchmarks. Columns 3and 4 report the number of threads and shared variables,respectively, contained in the execution. We also pro-filed the total number of the executed instructions andbranches in the assembly code, and the branches fromthe LLVM IR code, as reported in Columns 5-7. Col-umn 8 reports the ratio of the number of the branches inthe instrumented application code versus the total num-ber of branches (in both the application code and all theexternal libraries). For most benchmarks (except racey),the ratio is smaller than or around 20%. Column 9 re-ports the time for constructing the symbolic trace for thecorresponding recorded execution of the benchmark.

5.2 Runtime PerformanceTable 3 reports the performance comparison between H3and CLAP. Column 2 reports the native execution timeof the benchmarks. Columns 3-4 report the executiontime with H3 and CLAP and their runtime overhead.Column 5 reports the speedup of H3 over CLAP. Col-umn 6 reports the percentage of branch instructions inthe execution. This number is proportional to the runtime

8

43https://github.com/jieyu/concurrency-bugshttp://pages.cs.wisc.edu/~markhill/ racey.html

Page 44: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Runtimeoverhead

186.60%

11%

12.10%

31.40%

20%

38.50%

34%

32.10%

36.20% 7.50%

23.40%

9.40%

9.80%

13.80%

18.50%

7.50%

13.30%

12.90%

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

racey pfscan aget pbzip2 bbuf sbuf httpd1 httpd2 httpd3

Runtim

eoverhe

ad

ComparisonbetweenH3andCLAP

CLAP H3

44

Page 45: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Runtimeoverhead

186.60%

11%

12.10%

31.40%

20%

38.50%

34%

32.10%

36.20%

7.50%

23.40%

9.40%

9.80%

13.80%

18.50%

7.50%

13.30%

12.90%

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

racey pfscan aget pbzip2 bbuf sbuf httpd1 httpd2 httpd3

Runtim

eoverhe

ad

ComparisonbetweenH3andCLAP

CLAP H3

45

CLAP:64.3%vsH3:12.9%reduction:31.3%

Page 46: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Constraintsreduction

46

1

10

100

1000

10000

100000

1000000

10000000

100000000

1E+09

bbuf sbuf pfscan pbzip2 racey1 racey2 racey3

#Con

straints

Core-basedconstraintsreductionbyH3toCLAP

CLAP H3

reducedby>30%

reducedby>90%

Page 47: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Bugreproduction

47

1

10

100

1000

10000

100000

1000000

10000000

100000000

1E+09

bbuf sbuf pfscan pbzip2 racey1 racey2 racey3

#Con

straints

Core-basedconstraintsreductionbyH3toCLAP

CLAP H3

Reproducedbyboth

OnlyreproducedbyH3

Page 48: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Conclusion

H3:ReproducingHeisenbugsbasedoncontrolflowtracingoncommercialhardware(IntelPT)• RuntimeOverhead• PARSEC3.0:~4.9%• Realapplication:~12.9%vsCLAP[PLDI’13]~64.3%

• Bugreproduction• reproducesonemorebugthanCLAP

48

Page 49: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Discussion

• Symbolicexecutionisslow• Eliminatesymbolicexecution:usehardwarewatchpoints tocatchvaluesandmemorylocations

• Constraintsforlongtraces• Usecheckpointsandperiodicglobalsynchronization

• Non-deterministicprograminputs(e.g.,syscall results)• IntegratewithMozillaRR[USENIXATC’17]• Keyinsight:useH3tohandleschedules,andRRtohandleinputs

49

Page 50: Towards Production -Run Heisenbugs Reproduction on ... · Towards Production -Run Heisenbugs Reproduction on Commercial Hardware 1 Shiyou Huang Bowen Cai and Jeff Huang

Thankyou

50