Local Nontermination Detection for Parallel C++ Programs Vladimr - - PowerPoint PPT Presentation

local nontermination detection for parallel c programs
SMART_READER_LITE
LIVE PREVIEW

Local Nontermination Detection for Parallel C++ Programs Vladimr - - PowerPoint PPT Presentation

Local Nontermination Detection for Parallel C++ Programs Vladimr till Ji Barnat Masaryk University Brno, Czech Republic 20th Septempler 2019 Motivation Would you trust a program which was verified, but not tested? 1 / 14


slide-1
SLIDE 1

Local Nontermination Detection for Parallel C++ Programs

Vladimír Štill Jiří Barnat

Masaryk University Brno, Czech Republic

20th Septempler 2019

slide-2
SLIDE 2

Motivation

“Would you trust a program which was verified, but not tested?”

1 / 14

slide-3
SLIDE 3

Motivation

“Would you trust a program which was verified, but not tested?” DEMO: DIVINE

1 / 14

slide-4
SLIDE 4

Motivation

“Would you trust a program which was verified, but not tested?” DEMO: DIVINE . . . at the very least, we should not blindly trust safety checking

1 / 14

slide-5
SLIDE 5

Safety Checking Parallel Programs

targeting assertion violations, memory corruption, data races primarily caused by thread interleaving

  • r by relaxed memory

2 / 14

slide-6
SLIDE 6

Safety Checking Parallel Programs

targeting assertion violations, memory corruption, data races primarily caused by thread interleaving

  • r by relaxed memory

if the program might not terminate. . .

the tool might not terminate

  • r it might report there are no safety violations

2 / 14

slide-7
SLIDE 7

Safety Checking Parallel Programs

targeting assertion violations, memory corruption, data races primarily caused by thread interleaving

  • r by relaxed memory

if the program might not terminate. . .

the tool might not terminate

  • r it might report there are no safety violations (correctly)

2 / 14

slide-8
SLIDE 8

Safety Checking Parallel Programs

targeting assertion violations, memory corruption, data races primarily caused by thread interleaving

  • r by relaxed memory

if the program might not terminate. . .

the tool might not terminate

  • r it might report there are no safety violations (correctly)

not enough for parallel programs

2 / 14

slide-9
SLIDE 9

(Non)Termination Checking

check that the whole program terminates

3 / 14

slide-10
SLIDE 10

(Non)Termination Checking

check that the whole program terminates

  • r checks that certain parts of it terminate

critical sections waiting for condition variables, threads. . . user-defined parts

3 / 14

slide-11
SLIDE 11

Local Nontermination Detection for Parallel Programs

we aim at nontermination caused by unintended parallel interactions

4 / 14

slide-12
SLIDE 12

Local Nontermination Detection for Parallel Programs

we aim at nontermination caused by unintended parallel interactions not at complex control flow & loops

4 / 14

slide-13
SLIDE 13

Local Nontermination Detection for Parallel Programs

we aim at nontermination caused by unintended parallel interactions not at complex control flow & loops should be easy to specify should not report nontermination spuriously should be useful for analysis of services/servers

4 / 14

slide-14
SLIDE 14

Local Nontermination Detection for Parallel Programs

we aim at nontermination caused by unintended parallel interactions not at complex control flow & loops should be easy to specify should not report nontermination spuriously should be useful for analysis of services/servers build on explicit-state model checking → finite-state programs (with possibly infinite behaviour) user can specify what to check bool x = true; while (true) { x = !x; } x ¬x

4 / 14

slide-15
SLIDE 15

What is Nontermination?

mutex mtx; void w() { mutex.lock(); x++; mutex.unlock(); } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate?

5 / 14

slide-16
SLIDE 16

What is Nontermination?

mutex mtx; void w() { mutex.lock(); x++; mutex.unlock(); } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate? . . . yes

5 / 14

slide-17
SLIDE 17

What is Nontermination?

atomic< bool > spin_lock; void w() { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate?

6 / 14

slide-18
SLIDE 18

What is Nontermination?

atomic< bool > spin_lock; void w() { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate? . . . yes

6 / 14

slide-19
SLIDE 19

What is Nontermination?

atomic< bool > spin_lock; void w() { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate? . . . yes But there is an infinite run: [t0: spin_lock.exchange(true) → false] [t1: spin_lock.exchange(true) → true]ω (repeats infinitely)

6 / 14

slide-20
SLIDE 20

What is Nontermination?

atomic< bool > spin_lock; void w() { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } int main() { thread t0(w), t1(w); t0.join(); t1.join(); } Does this program terminate? . . . yes But there is an infinite run: [t0: spin_lock.exchange(true) → false] [t1: spin_lock.exchange(true) → true]ω (repeats infinitely) but only because t0 is not allowed to run

6 / 14

slide-21
SLIDE 21

What is Nontermination?

void w() { while (true) { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } } Does every wait end?

7 / 14

slide-22
SLIDE 22

What is Nontermination?

void w() { while (true) { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } } Does every wait end? yes

7 / 14

slide-23
SLIDE 23

What is Nontermination?

void w() { while (true) { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } } Does every wait end? yes?

7 / 14

slide-24
SLIDE 24

What is Nontermination?

void w() { while (true) { while (spin_lock.exchange(true)) { /* wait */ } x++; spin_lock = false; } } Does every wait end? yes? [t0: spin_lock.exchange(true) → false]

[t1:

spin_lock.exchange(true) → true] [t0: x++] [t0: spin_lock = false] [t0: spin_lock.exchange(true) → false]

ω

both threads can run

7 / 14

slide-25
SLIDE 25

What is Nontermination?

[t0: spin_lock.exchange(true) → false]

[t1:

spin_lock.exchange(true) → true] [t0: x++] [t0: spin_lock = false] [t0: spin_lock.exchange(true) → false]

ω

this run requires a scheduler which allows t1 to run only if t0 is in the critical section

8 / 14

slide-26
SLIDE 26

What is Nontermination?

[t0: spin_lock.exchange(true) → false]

[t1:

spin_lock.exchange(true) → true] [t0: x++] [t0: spin_lock = false] [t0: spin_lock.exchange(true) → false]

ω

this run requires a scheduler which allows t1 to run only if t0 is in the critical section does not happen in reality

8 / 14

slide-27
SLIDE 27

What is Nontermination?

[t0: spin_lock.exchange(true) → false]

[t1:

spin_lock.exchange(true) → true] [t0: x++] [t0: spin_lock = false] [t0: spin_lock.exchange(true) → false]

ω

this run requires a scheduler which allows t1 to run only if t0 is in the critical section does not happen in reality for realistic schedulers an infinite run does not imply nontermination

8 / 14

slide-28
SLIDE 28

What is Nontermination?

Nontermation a program does not terminate if it can reach a point from which it cannot reach its end

9 / 14

slide-29
SLIDE 29

What is Nontermination?

Nontermation a program does not terminate if it can reach a point from which it cannot reach its end Resource Section a block of code with an identifier delimited in the source code

9 / 14

slide-30
SLIDE 30

What is Nontermination?

Nontermation a program does not terminate if it can reach a point from which it cannot reach its end Resource Section a block of code with an identifier delimited in the source code Local Nontermation a resource section does not terminate if the program can reach a point in the resource section from which it cannot reach the corresponding resource section end

9 / 14

slide-31
SLIDE 31

Detecting Nontermination

a program does not terminate if it can reach a point from which it cannot reach its end

10 / 14

slide-32
SLIDE 32

Detecting Nontermination

a program does not terminate if it can reach a point from which it cannot reach its end detect nontrivial terminal strongly connected components ⊥

  • nontriv. terminal SCC

10 / 14

slide-33
SLIDE 33

Going Local: Active Resource Section Instances

lock(m1) do_work_1 lock(m2) do_work_2 unlock(m2) unlock(m1) end

11 / 14

slide-34
SLIDE 34

Going Local: Active Resource Section Instances

lock(m1) do_work_1 lock(m2) do_work_2 unlock(m2) unlock(m1) end

11 / 14

slide-35
SLIDE 35

Going Local: Active Resource Section Instances

ARSI ARSI lock(m1) lock(m1) do_work_1 lock(m2) do_work_2 unlock(m2) unlock(m1) do_work_1 lock(m2) do_work_2 unlock(m2) unlock(m1) end lock(m2) do_work_2 unlock(m2)

11 / 14

slide-36
SLIDE 36

Detecting Local Nontermination

a resource section does not terminate if the program can reach a point in the section from which it cannot reach the corresponding resource section end

12 / 14

slide-37
SLIDE 37

Detecting Local Nontermination

a resource section does not terminate if the program can reach a point in the section from which it cannot reach the corresponding resource section end mark edges in ARSIs as accepting detect fully accepting terminal strongly connected components (FATSCC)

  • nontriv. terminal SCC

FATSCC

12 / 14

slide-38
SLIDE 38

Detection Algorithm

modified Tarjan’s algorithm for SCC decomposition: O(|G|) global nontermination has no overhead for local nontermination the graph can get bigger

13 / 14

slide-39
SLIDE 39

Detection Algorithm

modified Tarjan’s algorithm for SCC decomposition: O(|G|) global nontermination has no overhead for local nontermination the graph can get bigger 100 101 102 103 104 100 101 102 103 104 safety [s] local nonterm. [s] Wall Time (in seconds)

13 / 14

slide-40
SLIDE 40

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

14 / 14

slide-41
SLIDE 41

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

Conclusion we have presented a novel technique which allows detecting bugs not captured by safety (or LTL/CTL*) analysis

14 / 14

slide-42
SLIDE 42

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

Conclusion we have presented a novel technique which allows detecting bugs not captured by safety (or LTL/CTL*) analysis built on explicit-state model checking → finite state space required

14 / 14

slide-43
SLIDE 43

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

Conclusion we have presented a novel technique which allows detecting bugs not captured by safety (or LTL/CTL*) analysis built on explicit-state model checking → finite state space required works also on programs which do not terminate

14 / 14

slide-44
SLIDE 44

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

Conclusion we have presented a novel technique which allows detecting bugs not captured by safety (or LTL/CTL*) analysis built on explicit-state model checking → finite state space required works also on programs which do not terminate

  • pen-source implementation

14 / 14

slide-45
SLIDE 45

Resource Sections & Conclusions

Source of resourcre sections either built-in (mutexes, condition variables, thread joining, . . . )

  • r user-provided (in source code; block of code, function end, . . . )

Conclusion we have presented a novel technique which allows detecting bugs not captured by safety (or LTL/CTL*) analysis built on explicit-state model checking → finite state space required works also on programs which do not terminate

  • pen-source implementation

performance is underwhelming, but it can detect new class of bugs https://divine.fi.muni.cz/2019/lnterm/

14 / 14