aditya v. nori, sriram k. rajamani microsoft research india

30
An Empirical Study of Optimizations in Yogi Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Upload: anissa-stafford

Post on 02-Jan-2016

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

An Empirical Study of Optimizations in Yogi

Aditya V. Nori, Sriram K. Rajamani

Microsoft Research India

Page 2: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

What is Yogi? An industrial strength program verifier

Idea: Synergize verification and testing

Synergy [FSE โ€™06], Dash [ISSTA โ€˜08], SMASH [POPL โ€˜10] algorithms to perform scalable analysis

Engineered a number of optimizations for scalability

Integrated with Microsoftโ€™s Static Driver Verifier (SDV) toolkit and used internally

Page 3: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Motivation

Share our experiences in making Yogi robust, scalable and industrial strength

Several of the implemented optimizations are folklore Very difficult to design tools that are bug free evaluating

optimizations is hard! Our empirical evaluation gives tool builders information about

what gains can be realistically expected from optimizations

Vanilla implementation of algorithms: (flpydisk, CancelSpinLock) took 2 hours

Algorithms + engineering + optimizations: (flpydisk, CancelSpinLock) took less than 1 second!

Page 4: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Outline

Overview of Yogi

Overview of optimizations

Evaluation setup

Empirical Results

Summary

Page 5: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Property checking

void foo(){ *p = 4; *q = 5; if (condition) error();}

QuestionIs error() unreachable for all possible inputs?

Verification: can prove the absence of bugs, but can result in false errorsTesting: finds bugs, but canโ€™t prove their absence

Page 6: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

The Yogi algorithm

no

no

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

ฯ„ = error path in abstraction f = frontier of error path

yes

no

yes

Proof! yes

Input:Program P

Property ฯˆ

Page 7: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: Abstraction & Tests

no

no

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

ฯ„ = error path in abstraction f = frontier of error path

yes

no

yes

Proof! yes

Input:Program P

Property ฯˆ

void foo(int y){0: int x, lock = 0;1: do {2: lock = 1;3: x = y;4: if (*) {5: lock = 0;6: y = y+1; }7: } while (x != y);8: if (lock != 1)9: error();10:}

y = 101234

56

789

ร—

ร— ร—

ร— ร—

ร— ร—

ร— ร—

ร—

ร—

ร— ร—

ร—

10ร—

Symbolic execution +

Theorem proving

Page 8: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: Refinement

no

no

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

ฯ„ = error path in abstraction f = frontier of error path

yes

no

yes

Proof! yes

Input:Program P

Property ฯˆ

void foo(int y){0: int x, lock = 0;1: do {2: lock = 1;3: x = y;4: if (*) {5: lock = 0;6: y = y+1; }7: } while (x != y);8: if (lock != 1)9: error();10:}

01234

56

78:ฯ

9

ร—

ร— ร—

ร— ร—

ร— ร—

ร— ร—

ร—

ร—

ร— ร—

ร—

10ร—

8:ยฌฯร—

Page 9: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: Proof!

no

no

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

ฯ„ = error path in abstraction f = frontier of error path

yes

no

yes

Proof! yes

Input:Program P

Property ฯˆ

void foo(int y){0: int x, lock = 0;1: do {2: lock = 1;3: x = y;4: if (*) {5: lock = 0;6: y = y+1; }7: } while (x != y);8: if (lock != 1)9: error();10:}

012

34:ยฌs5:ยฌs6:ยฌr

9

ร—

ร— ร—

ร— ร—ร—ร—

ร—ร—

ร—

ร—

7:ยฌqร—

8:ยฌpร—

4:s5:s6:r7:q8:pร—

10

Page 10: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Optimizations

Initial abstraction from property predicates

Relevance heuristics for predicate abstraction Suitable predicates (SP) Control dependence predicates (CD)

Interprocedural analysis Global modification analysis Summaries for procedures

Thresholds for tests

Fine tuning environment models

Page 11: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Evaluation setup

Benchmarks: 30 WDM drivers and 83 properties (2490 runs) Anecdotal belief: most bugs in the tools are

usually caught with this test suite

Presentation methodology: Group optimizations logically such that related

optimizations are in the same group Total time taken, total number of defects found

for every possible choice of enabling/disabling each optimization in the group

Page 12: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Initial abstraction

state { enum {Locked = 0, Unlocked = 1} state = Unlocked;}

KeAcquireCancelSpinlock.Entry { if (state != Locked) { state = Locked; } else abort;}

KeReleaseCancelSpinlock.Entry { if (state == Locked) { state = Unlocked; } else abort;}

01

(๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’โ‰ ๐ฟ๐‘œ๐‘๐‘˜๐‘’๐‘‘)

01

(๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐ฟ๐‘œ๐‘๐‘˜๐‘’๐‘‘)

01๐‘‡

๐‘‡

Page 13: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsAbstractio

n using SLIC predicates

Total time

(minutes)

#defects #timeouts

yes 2160 241 77no 2580 241 86

16%

Page 14: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Relevance heuristics (SP)

Avoid irrelevant conjuncts

AC

๐‘‡

๐‘‡

B๐‘‡

D ๐›ฟ

AC

๐‘‡

ยฌ๐œŒ

B๐‘‡

D ๐›ฟ

C ๐œŒ

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’(๐œ™)

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’(๐œ™)

Irrelevant?

Page 15: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Relevance heuristics (CD)

Abstract assume statements that are not potentially relevant by skip statements

If Yogi proves that the program satisfies property, we are done.

Otherwise, validate the error trace

and refine the abstraction by putting back assume statements, if the error trace is spurious

Page 16: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: SP heuristic

int x;void foo() { bool protect = true; โ€ฆ if (x > 0) protect = false; โ€ฆ if (protect) KeAcquireCancelSpinLock(); for (i = 0; i < 1000; i++) { a[i] = readByte(i); } if (protect) KeReleaseCancelSpinLock();}

AC

๐‘‡

๐‘‡

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

AC

๐‘‡

ยฌ๐œŒ

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

C ๐œŒ

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’( ๐‘–>1000)

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’( ๐‘–>1000)

๐œŒ=(state=Locked )โˆง( ๐‘–>1000)

Page 17: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: SP heuristic

int x;void foo() { bool protect = true; โ€ฆ if (x > 0) protect = false; โ€ฆ if (protect) KeAcquireCancelSpinLock(); for (i = 0; i < 1000; i++) { a[i] = readByte(i); } if (protect) KeReleaseCancelSpinLock();}

AC

๐‘‡

๐‘‡

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

AC

๐‘‡

ยฌ๐œŒ

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

C ๐œŒ

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’( ๐‘–>1000)

๐‘Ž๐‘ ๐‘ ๐‘ข๐‘š๐‘’( ๐‘–>1000)

๐œŒ=(state=Locked )

Page 18: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example: CD heuristic

int x;void foo() { bool protect = true; โ€ฆ if (x > 0) protect = false; โ€ฆ if (protect) KeAcquireCancelSpinLock(); for (i = 0; i < 1000; i++) { a[i] = readByte(i); } if (protect) KeReleaseCancelSpinLock();}

Page 19: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsSP

heuristic

CD heurist

ic

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2580 239 91no yes 2400 238 87no no 2894 235 174

10%

Page 20: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsSP

heuristic

CD heurist

ic

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2580 239 91no yes 2400 238 87no no 2894 235 174

16%

Page 21: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsSP

heuristic

CD heurist

ic

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2580 239 91no yes 2400 238 87no no 2894 235 174

25%

Page 22: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Interprocedural analysis

Yogi performs a compositional analysis : Is it possible to execute starting from

state and reach state ?

Global modification analysis

May-Must analysis (SMASH, POPL 2010)

Page 23: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Example

AC

๐‘‡

๐‘‡

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

AC

๐‘‡

ยฌ๐œŒ

B๐‘‡

D ๐‘ ๐‘ก๐‘Ž๐‘ก๐‘’=๐‘™๐‘œ๐‘๐‘˜๐‘’๐‘‘

C ๐œŒ

๐‘“๐‘œ๐‘œ(โ€ฆ)

foo(โ€ฆ)

โŸจ๐œ™1 , ๐‘“๐‘œ๐‘œ (โ€ฆ) ,๐œ™2 โŸฉ

Page 24: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsModificat

ion analysis

Summaries

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2760 239 109no yes 3180 237 134no no 3780 236 165

32%

Page 25: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsModificat

ion analysis

Summaries

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2760 239 109no yes 3180 237 134no no 3780 236 165

28%

Page 26: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical resultsModificat

ion analysis

Summaries

Total time

(minutes)

#defects

#timeouts

yes yes 2160 241 77yes no 2760 239 109no yes 3180 237 134no no 3780 236 165

42%

Page 27: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Testing

Yogi relies on tests for โ€œcheapโ€ reachability

Long tests avoiding several potential reachability

queries results in too many states and thus

memory consumption

Test thresholds: time vs. space tradeoff

Page 28: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Empirical evaluation

Test threshol

d

Total time

(minutes)

#defects

#timeouts

250 2600 236 92500 2160 241 771000 2359 240 881500 2400 239 89

Page 29: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Modeling the environment

if (DestinationString) { DestinationString->Buffer = SourceString;

// DestinationString->Length should be set to the // length of SourceString. The line below is missing // from the original stub SDV function DestinationString->Length = strlen(SourceString);}

if (SourceString == NULL){ DestinationString->Length = 0; DestinationString->MaximumLength = 0;}

Issue type #issues

Integers used as pointers

8Uninitialized

variables15

Type inconsistencies 9

Page 30: Aditya V. Nori, Sriram K. Rajamani Microsoft Research India

Summary

Described optimizations implemented in Yogi Evaluated optimizations on the WDM test suite

Empirical data used to decide which optimizations to include in Yogi

We believe that this detailed empirical study of optimizations will enable tool builders to decide which optimizations to include and how to engineer their tools

http://research.microsoft.com/yogi