From Concurrent Programs to Simulating Sequential Programs: - - PowerPoint PPT Presentation

from concurrent programs to simulating sequential
SMART_READER_LITE
LIVE PREVIEW

From Concurrent Programs to Simulating Sequential Programs: - - PowerPoint PPT Presentation

From Concurrent Programs to Simulating Sequential Programs: Correctness of a Transformation VPT 2017 Allan Blanchard, Fr ed eric Loulergue, Nikolai Kosmatov April 29 th , 2017 From Concurrent Programs to Simulating Sequential Programs


slide-1
SLIDE 1

From Concurrent Programs to Simulating Sequential Programs: Correctness of a Transformation

VPT 2017 Allan Blanchard, Fr´ ed´ eric Loulergue, Nikolai Kosmatov April 29th, 2017

slide-2
SLIDE 2

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Table of Contents 1

From Concurrent Programs to Simulating Sequential Programs

2

Correctness of a Transformation

3

Conclusion and Future Work

April 29th, 2017 — N. Kosmatov — p. 2

slide-3
SLIDE 3

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Table of Contents 1

From Concurrent Programs to Simulating Sequential Programs Concurrent Program Analysis Considered Language Principle of the Transformation

2

Correctness of a Transformation

3

Conclusion and Future Work

April 29th, 2017 — N. Kosmatov — p. 3

slide-4
SLIDE 4

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Dedicated Analysis

Most concurrent program analyzers are dedicated to this task they implement a specific analysis they are often hard to design

April 29th, 2017 — N. Kosmatov — p. 4

slide-5
SLIDE 5

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Sequential Code Analyzers

Sequential code analyzers work well How can we bring them to concurrent code analysis? Especially when we have many of them The Frama-C code analysis platform (frama-c.com) Deductive verification (WP) Abstract Interpretation (Eva) Runtime assertion checking (E-ACSL) ...

April 29th, 2017 — N. Kosmatov — p. 5

slide-6
SLIDE 6

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Simulating Code: Motivation

Idea 1: Intrinsically concurrent analysis tools better integration but hard to develop Idea 2: Simulate concurrent programs by sequential ones sequential analyzers will be able to treat it

April 29th, 2017 — N. Kosmatov — p. 6

slide-7
SLIDE 7

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

A Simple Imperative Language

proc ::= m(x)c m ∈ Name instr ::= x := e local assignment | x[y] := e writing to the heap | x := y[e] reading from the heap | while e do c | if e then c else c | m(e) procedure call | atomic(c) atomic block C ∋ c ::= {} | instr; c memory ::= [(l1, sizel1); . . . ; (lm, sizelm)] progseq ::= proc memory progpar ::= proc memory mains (where mains : T → Name)

April 29th, 2017 — N. Kosmatov — p. 7

slide-8
SLIDE 8

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

A Simple Imperative Language with Concurrency

proc ::= m(x)c m ∈ Name instr ::= x := e local assignment | x[y] := e writing to the heap | x := y[e] reading from the heap | while e do c | if e then c else c | m(e) procedure call | atomic(c) atomic block C ∋ c ::= {} | instr; c memory ::= [(l1, sizel1); . . . ; (lm, sizelm)] progseq ::= proc memory progpar ::= proc memory mains (where mains : T → Name)

April 29th, 2017 — N. Kosmatov — p. 7

slide-9
SLIDE 9

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Overview of the Transformation I

Variables

Original heap is kept Each local variable x is simulated by a heap location &x

Assumption

Static memory allocation

April 29th, 2017 — N. Kosmatov — p. 8

slide-10
SLIDE 10

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Overview of the Transformation II

Statements

Maintain a program counter (pct) for each thread Each statement is simulated by a procedure that

Recieves in parameter the thread (tid) to execute Executes the same action using simulating variables Updates the program counter

April 29th, 2017 — N. Kosmatov — p. 9

slide-11
SLIDE 11

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Overview of the Transformation III

Procedure calls and returns

For each procedure p, we add a heap location from(p). It records the program point to return to from p. Simulating a call of p2 from p1:

Update from(p2) with the next instruction of p1 Place the program counter on the first instruction of p2

Simulating a return from p2 to p1:

Put the program counter on the instruction from(p2)

Assumption

No recursive call

April 29th, 2017 — N. Kosmatov — p. 10

slide-12
SLIDE 12

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Overview of the Transformation IV

Main procedure

Initialize program counters Initialize from() for each main procedure Loop until each thread has executed all its instructions:

Choose a thread that still has instructions to execute Resolve its program counter Execute the corresponding simulating procedure

Assumption

Interleaving semantics

April 29th, 2017 — N. Kosmatov — p. 11

slide-13
SLIDE 13

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Statements

Original code

if(x > 0) then p[0] := x else p[0] := 42

Simulating conditional

sim_1(tid){ ptr := &x ; x := ptr[tid] ; if(x > 0) then { ptr := pct ; ptr[tid] := 2 } else { ptr := pct ; ptr[tid] := 4 } }

April 29th, 2017 — N. Kosmatov — p. 12

slide-14
SLIDE 14

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Statements

Original code

if(x > 0) then p[0] := x else p[0] := 42

Simulating memory write

sim_2(tid){ ptr := &x ; x := ptr[tid] ; ptr := &p ; p := ptr[tid] ; p[0] := x ; ptr := pct ; ptr[tid] := 5 }

April 29th, 2017 — N. Kosmatov — p. 13

slide-15
SLIDE 15

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Table of Contents 1

From Concurrent Programs to Simulating Sequential Programs

2

Correctness of a Transformation Bi-simulation Property Equivalence Relations Basic Ideas of the Proof

3

Conclusion and Future Work

April 29th, 2017 — N. Kosmatov — p. 14

slide-16
SLIDE 16

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property I

Theorem

Let progpar be a safe parallel program, progsim its simulating pro- gram, σinit

par (resp. σinit sim) an initial state of progpar (resp. progsim).

  • 1. From σinit

sim, we can reach, by the initialization sequence,

σ0

sim equivalent to σinit par .

  • 2. For all σpar reachable from σinit

par , there exists an equivalent

σsim reachable from σ0

sim with an equivalent trace (Forward

simulation).

  • 3. For all σsim reachable from σ0

sim, there exists an equivalent

σpar reachable from σinit

par with an equivalent trace

(Backward simulation).

April 29th, 2017 — N. Kosmatov — p. 15

slide-17
SLIDE 17

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property I

Theorem

Let progpar be a safe parallel program, progsim its simulating pro- gram, σinit

par (resp. σinit sim) an initial state of progpar (resp. progsim).

  • 1. From σinit

sim, we can reach, by the initialization sequence,

σ0

sim equivalent to σinit par .

  • 2. For all σpar reachable from σinit

par , there exists an equivalent

σsim reachable from σ0

sim with an equivalent trace (Forward

simulation).

  • 3. For all σsim reachable from σ0

sim, there exists an equivalent

σpar reachable from σinit

par with an equivalent trace

(Backward simulation). Initialization establishes equivalence

April 29th, 2017 — N. Kosmatov — p. 15

slide-18
SLIDE 18

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property I

Theorem

Let progpar be a safe parallel program, progsim its simulating pro- gram, σinit

par (resp. σinit sim) an initial state of progpar (resp. progsim).

  • 1. From σinit

sim, we can reach, by the initialization sequence,

σ0

sim equivalent to σinit par .

  • 2. For all σpar reachable from σinit

par , there exists an equivalent

σsim reachable from σ0

sim with an equivalent trace (Forward

simulation).

  • 3. For all σsim reachable from σ0

sim, there exists an equivalent

σpar reachable from σinit

par with an equivalent trace

(Backward simulation). All existing parallel executions are simulated

April 29th, 2017 — N. Kosmatov — p. 15

slide-19
SLIDE 19

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property I

Theorem

Let progpar be a safe parallel program, progsim its simulating pro- gram, σinit

par (resp. σinit sim) an initial state of progpar (resp. progsim).

  • 1. From σinit

sim, we can reach, by the initialization sequence,

σ0

sim equivalent to σinit par .

  • 2. For all σpar reachable from σinit

par , there exists an equivalent

σsim reachable from σ0

sim with an equivalent trace (Forward

simulation).

  • 3. For all σsim reachable from σ0

sim, there exists an equivalent

σpar reachable from σinit

par with an equivalent trace

(Backward simulation). Only existing parallel executions are simulated

April 29th, 2017 — N. Kosmatov — p. 15

slide-20
SLIDE 20

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program

April 29th, 2017 — N. Kosmatov — p. 16

slide-21
SLIDE 21

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program From σinit

sim ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-22
SLIDE 22

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program From σinit

sim ...

... we can reach σ0

sim ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-23
SLIDE 23

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program From σinit

sim ...

... we can reach σ0

sim ...

... s.t. σ0

sim ∼ σinit par

April 29th, 2017 — N. Kosmatov — p. 16

slide-24
SLIDE 24

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program

April 29th, 2017 — N. Kosmatov — p. 16

slide-25
SLIDE 25

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σsim ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-26
SLIDE 26

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σsim ... ... reachable from σ0

sim ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-27
SLIDE 27

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σsim ... ... reachable from σ0

sim ...

... their exists σpar reachable from σinit

par

s.t. σsim ∼ σpar

April 29th, 2017 — N. Kosmatov — p. 16

slide-28
SLIDE 28

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σpar ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-29
SLIDE 29

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σpar ... ... reachable from σinit

par ...

April 29th, 2017 — N. Kosmatov — p. 16

slide-30
SLIDE 30

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property II

σ′

par

σpar σinit

par

Original Program σ′

sim

σsim σ0

sim

σinit

sim

Simulating Program Forall σpar ... ... reachable from σinit

par ...

... their exists σsim reachable from σ0

sim

s.t. σsim ∼ σpar

April 29th, 2017 — N. Kosmatov — p. 16

slide-31
SLIDE 31

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Equivalence Relations

States

The original heap is a subheap of the simulating one The simulating heap correctly models local variables The simulating heap correctly models stacks

Traces

All actions involving global memory in the original program must happen in the same order in the simulation. We also check pro- cedure calls and return’s.

April 29th, 2017 — N. Kosmatov — p. 17

slide-32
SLIDE 32

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Bi-simulation Property III

σ′

par

σpar σ′

sim

σsim Select a thread Simulate its next statement Check termination

April 29th, 2017 — N. Kosmatov — p. 18

slide-33
SLIDE 33

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Basic Ideas of the Proof

By induction

  • n instructions for the forward simulation
  • n loop iterations for the backward simulation

What we can notice

Sequential actions are deterministic, their translation too Thread selection is not determinist, but we can choose the same thread

April 29th, 2017 — N. Kosmatov — p. 19

slide-34
SLIDE 34

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Table of Contents 1

From Concurrent Programs to Simulating Sequential Programs

2

Correctness of a Transformation

3

Conclusion and Future Work

April 29th, 2017 — N. Kosmatov — p. 20

slide-35
SLIDE 35

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Let’s Sum Up

Concurrent program analysis by sequential code analyzers based on a code transformation method simulation of a concurrent program by a sequential one implemented in the Conq2Seq plugin of Frama-C We prove that the simulation is sound if the considered program is sequentially consistent does not contain recursion does not allocate memory dynamically

April 29th, 2017 — N. Kosmatov — p. 21

slide-36
SLIDE 36

From Concurrent Programs to Simulating Sequential Programs Correctness of a Transformation Conclusion and Future Work

Ongoing & Future Work

Our formalization is more general than our Frama-C plugin add function call simulation to Conc2Seq The proof is currently a pen & paper proof mechanized proof using Coq is ongoing

April 29th, 2017 — N. Kosmatov — p. 22

slide-37
SLIDE 37

Universit´ e d’Orl´ eans Laboratoire d’Informatique Fondamentale d’Orl´ eans — Bˆ atiment IIIA Rue L´ eonard de Vinci F-45067 ORL´ EANS http://www.univ-orleans.fr/lifo/