Efficient Tracing of Cold Code via Bias-Free Sampling - - PowerPoint PPT Presentation

efficient tracing of cold code via bias free sampling
SMART_READER_LITE
LIVE PREVIEW

Efficient Tracing of Cold Code via Bias-Free Sampling - - PowerPoint PPT Presentation

Efficient Tracing of Cold Code via Bias-Free Sampling Baris Kasikci + , Thomas Ball * , George Candea + , John Erickson * , Madanlal Musuvathi * * MicrosoD


slide-1
SLIDE 1

Efficient ¡Tracing ¡of ¡Cold ¡Code ¡via ¡ Bias-­‑Free ¡Sampling ¡

Baris ¡Kasikci+, ¡Thomas ¡Ball*, ¡ ¡ George ¡Candea+, ¡John ¡Erickson*, ¡ Madanlal ¡Musuvathi* ¡

*MicrosoD ¡ ¡

Research ¡

+

slide-2
SLIDE 2

Why ¡Should ¡We ¡Sample ¡Cold ¡Code? ¡

  • Cold ¡code ¡is ¡not ¡well ¡tested ¡

– Bugs ¡lurk ¡in ¡cold ¡code ¡[Marinescu ¡et ¡al., ¡Cris6an ¡et ¡al.] ¡

  • Cold ¡vs. ¡hot ¡code ¡is ¡not ¡known ¡a ¡priori ¡

– Cold ¡code ¡is ¡rarely ¡executed ¡during ¡program ¡execu6on ¡

We ¡need ¡to ¡be ¡able ¡to ¡efficiently ¡sample ¡cold ¡code ¡

slide-3
SLIDE 3

Current ¡Dynamic ¡Sampling ¡ ¡Approaches ¡ ¡

  • StaNc ¡instrumentaNon ¡(e.g., ¡Gcov, ¡bbcover) ¡

– Incurs ¡lots ¡of ¡overhead ¡(>2x) ¡ – Requires ¡separate ¡builds ¡

  • Dynamic ¡instrumentaNon ¡(e.g., ¡Pin-­‑based) ¡

– Do ¡not ¡handle ¡mul6threaded ¡programs ¡efficiently ¡

  • Temporal ¡sampling ¡(e.g., ¡CBI ¡[Liblit ¡et ¡al.]) ¡

– Less ¡overhead ¡per-­‑execu6on ¡ – Need ¡lots ¡of ¡execu6ons ¡to ¡catch ¡cold ¡code ¡

Current ¡approaches ¡are ¡inefficient ¡and ¡do ¡not ¡scale ¡

slide-4
SLIDE 4

How ¡to ¡Efficiently ¡Sample ¡Cold ¡Code? ¡

Breakpoint ¡ PC ¡

  • Sample ¡instrucNon ¡
  • Mark ¡as ¡“executed” ¡
  • Record ¡the ¡accessed ¡memory ¡

address ¡

  • … ¡
  • Use ¡code ¡breakpoints ¡
  • One ¡breakpoint ¡per ¡basic ¡block ¡
  • Present ¡ ¡in ¡all ¡modern ¡CPUs ¡
  • 0 ¡cost ¡once ¡removed ¡

PC ¡

slide-5
SLIDE 5

Challenges ¡

  • Don’t ¡change ¡behavior ¡of ¡

– Instrumented ¡programs ¡ – Services ¡such ¡as ¡debuggers ¡

  • Number ¡of ¡breakpoints ¡

– In ¡the ¡worst ¡case, ¡a ¡breakpoint ¡for ¡every ¡block ¡ – Exis6ng ¡frameworks ¡cannot ¡handle ¡such ¡volume ¡

  • MulNthreaded ¡code ¡
  • JIT ¡and ¡managed ¡code ¡

– Cannot ¡be ¡handled ¡like ¡normal ¡code ¡due ¡to ¡op6miza6on ¡

slide-6
SLIDE 6

Bias-­‑Free ¡Sampling ¡(BfS) ¡

  • Design ¡
  • ImplementaNon ¡
  • EvaluaNon ¡

NaNve/managed, ¡kernel/user ¡space, ¡x86/ARM ¡ Ran ¡on ¡679 ¡programs, ¡incurs ¡overheads ¡of ¡1-­‑6% ¡

slide-7
SLIDE 7

BfS’s ¡Design ¡Goal ¡ ¡

  • Sample ¡cold ¡instrucNons ¡without ¡ ¡

¡ ¡ ¡ ¡over-­‑sampling ¡hot ¡instrucNons ¡

  • Sample ¡all ¡the ¡other ¡instrucNons ¡

independently ¡of ¡their ¡execuNon ¡frequency ¡

for (i=0; i<1,000,000; ++i) if (…) statement_1 else statement_2 Executes ¡once ¡every ¡

  • ne ¡million ¡iteraNons ¡
slide-8
SLIDE 8

BfS ¡Parameters ¡-­‑ ¡DefiniNons ¡

  • K: ¡Desired ¡sample ¡count ¡per-­‑instrucNon ¡

– Ensures ¡first ¡K ¡execu6ons ¡are ¡sampled ¡ – Bounds ¡the ¡overhead ¡ – 0 ¡cost ¡aSer ¡K ¡breakpoints ¡

  • P: ¡Sampling ¡distribuNon ¡

– Can ¡be ¡uniform ¡or ¡biased ¡

  • R: ¡Sampling ¡rate ¡

– Number ¡of ¡samples ¡generated ¡per ¡second ¡ – Controls ¡the ¡overhead ¡

slide-9
SLIDE 9

Applica'on ¡ Count ¡(K) ¡ Distribu'on ¡(P) ¡ Rate ¡(R) ¡ Coverage ¡ 1 ¡ First ¡instrucNon ¡in ¡the ¡ block ¡ 0 ¡ Full ¡tracing ¡

∞ ¡

¡

First ¡instrucNon ¡in ¡the ¡ block ¡

∞ ¡

¡ Memory ¡leak ¡detector ¡ 1 ¡to ¡∞ ¡

Only ¡memory ¡operaNons ¡ 0 ¡to ¡∞ ¡

Data ¡race ¡detector ¡

1 ¡to ¡∞ ¡

¡

Only ¡memory ¡accesses ¡ that ¡cannot ¡be ¡proven ¡ as ¡data ¡race ¡free ¡ 0 ¡to ¡∞ ¡

BfS ¡Parameters ¡-­‑ ¡Examples ¡

slide-10
SLIDE 10

Bias-­‑Free ¡Sampling ¡

  • Design ¡
  • ImplementaNon ¡
  • EvaluaNon ¡
slide-11
SLIDE 11

Breakpoints ¡Primer ¡

  • Hardware ¡support ¡

– int 3 on ¡x86 ¡traps ¡into ¡the ¡OS ¡

  • Breakpoint ¡instrucNons ¡are ¡not ¡larger ¡than ¡

any ¡instrucNon ¡in ¡the ¡ISA ¡

– Allows ¡overwri6ng ¡only ¡a ¡single ¡instruc6on ¡ – Atomic ¡add/removal ¡ – Helps ¡lower ¡the ¡overhead ¡

slide-12
SLIDE 12

Debugger ¡Interplay ¡

BfS ¡Framework ¡ Program ¡ Debugger ¡

BfS ¡framework ¡is ¡invisible ¡to ¡the ¡debugger, ¡ allowing ¡transparent ¡breakpoint ¡processing ¡

BfS ¡breakpoint ¡ Regular ¡breakpoint ¡

slide-13
SLIDE 13

MulN-­‑Shot ¡Breakpoints ¡

  • Debuggers ¡processing ¡a ¡breakpoint ¡ ¡

– Restore ¡original ¡instruc6on ¡ – Single ¡step ¡ – Restore ¡the ¡breakpoint ¡

  • BfS ¡framework ¡

Inst ¡2 ¡ Inst ¡1 ¡

Sampled ¡instrucNon ¡ ¡ with ¡breakpoint ¡

Jmp ¡to ¡ Inst ¡2 ¡ Inst ¡1 ¡

Resumed ¡instrucNon ¡copy ¡ In ¡thread-­‑local ¡buffer ¡

Set ¡PC ¡ ¡ to ¡copy ¡ Jmp ¡to ¡return ¡to ¡ ¡ the ¡instruc'on ¡a=er ¡ ¡ the ¡sampled ¡one ¡

slide-14
SLIDE 14

Managed ¡Code ¡Support ¡

  • BfS ¡uses ¡CLR ¡debugging ¡APIs ¡

– Bypassing ¡the ¡APIs ¡does ¡not ¡work ¡ – CLI ¡(interpreter) ¡performs ¡introspec6on ¡ – Cannot ¡modify ¡the ¡binary ¡without ¡the ¡CLR’s ¡knowledge ¡

  • May ¡need ¡to ¡disable ¡JIT ¡opNmizaNons ¡for ¡

some ¡tasks ¡

– E.g., ¡to ¡have ¡exact ¡coverage ¡results ¡

slide-15
SLIDE 15

Bias-­‑Free ¡Sampling ¡

  • Design ¡
  • ImplementaNon ¡
  • EvaluaNon ¡

679 ¡programs: ¡ ¡ ¡ ¡All ¡Windows ¡system ¡binaries, ¡Z3 ¡constraint ¡solver, ¡ ¡ ¡ ¡SPECint ¡benchmark ¡suite, ¡and ¡C# ¡benchmarks ¡

slide-16
SLIDE 16

Use ¡Case ¡1 ¡– ¡Z3 ¡Coverage ¡

BfS’s ¡coverage ¡

  • verhead ¡(1%) ¡is ¡

independent ¡of ¡ ¡ program ¡behavior, ¡ ¡ it ¡is ¡a ¡funcNon ¡of ¡ program ¡size ¡ ¡

0 ¡ 50 ¡ 100 ¡ 150 ¡ 200 ¡ 250 ¡ 300 ¡ 0 ¡ 50 ¡ 100 ¡ 150 ¡ 200 ¡

bbcover ¡ BfS ¡

Coverage ¡Measurement ¡ ¡ RunNme ¡[sec] ¡ RunNme ¡with ¡no ¡coverage ¡ ¡ measurement ¡[sec] ¡

No ¡

  • verhead ¡
slide-17
SLIDE 17

Use ¡Case ¡2 ¡– ¡Coverage ¡in ¡TesNng ¡ Windows ¡8 ¡Binaries ¡

  • Coverage ¡with ¡BfS ¡and ¡bbcover ¡

– 665 ¡system ¡binaries: ¡32 ¡and ¡64 ¡bit, ¡x86 ¡and ¡ARM ¡ – 70 ¡to ¡1,000,000 ¡basic ¡blocks ¡ – A ¡total ¡of ¡4 ¡hours ¡on ¡17 ¡machines ¡ ¡

  • bbcover ¡failed ¡for ¡45 ¡binaries ¡due ¡to ¡Nmeout ¡
  • For ¡all ¡but ¡40 ¡tests, ¡BfS ¡reports ¡more ¡

coverage ¡

– Less ¡coverage ¡cases ¡are ¡due ¡to ¡non-­‑determinism ¡

Coverage ¡overhead ¡is ¡always ¡less ¡than ¡6% ¡

slide-18
SLIDE 18

Use ¡Case ¡3 ¡– ¡Z3 ¡Cold ¡Code ¡Tracing ¡

0 ¡ 200 ¡ 400 ¡ 600 ¡ 800 ¡ 1000 ¡ 1200 ¡ 1400 ¡ 1600 ¡ 1800 ¡ 0 ¡ 500 ¡ 1000 ¡ 1500 ¡ 2000 ¡ 2500 ¡ 3000 ¡ 3500 ¡ 4000 ¡ 4500 ¡

  • 1. ¡init/parse ¡
  • 3. ¡rewriter/simplifier ¡
  • 5. ¡sat ¡solver ¡
  • 6. ¡output, ¡ ¡

freeing ¡

  • 2. ¡init ¡

tacNcs ¡

  • 4. ¡bit ¡blasNng ¡

Cold-­‑code ¡tracing ¡idenNfies ¡sets ¡of ¡related ¡funcNons ¡

Index ¡in ¡event ¡log ¡ FuncNon ¡id ¡

slide-19
SLIDE 19

Bias-­‑Free ¡Sampling ¡

  • Low ¡overhead ¡technique ¡to ¡idenNfy ¡cold ¡code ¡
  • Leverages ¡breakpoint ¡support ¡

– Ideal ¡for ¡mul6threaded ¡code ¡ – No ¡need ¡for ¡a ¡separate ¡build ¡

  • ImplementaNon ¡on ¡various ¡platorms ¡

– 32 ¡and ¡64 ¡bit, ¡x86 ¡and ¡ARM, ¡kernel ¡and ¡user ¡space, ¡na6ve ¡ and ¡managed ¡

  • Comprehensive ¡evaluaNon ¡

– 1-­‑6% ¡overhead ¡for ¡coverage ¡and ¡cold ¡block ¡tracing ¡