21
EE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 1 EE382N: Embedded System Design and Modeling Andreas Gerstlauer Electrical and Computer Engineering University of Texas at Austin [email protected] Lecture 3 – Execution & Simulation Semantics EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 2 Lecture 3: Outline Language semantics Models of concurrency & time Discrete event model Synchronous reactive model SpecC semantics Simulation semantics Formal semantics

EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 1

EE382N:Embedded System Design and Modeling

Andreas GerstlauerElectrical and Computer Engineering

University of Texas at [email protected]

Lecture 3 – Execution & Simulation Semantics

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 2

Lecture 3: Outline

• Language semantics• Models of concurrency & time• Discrete event model• Synchronous reactive model

• SpecC semantics• Simulation semantics• Formal semantics

Page 2: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 2

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 3

System-Level Language Semantics

• Language concepts (syntax)

• Behavioral and structural hierarchy

• Concurrency and time

• Synchronization and communication

• Exception handling

• State transitions

• Language semantics needed to define the meaning

• Semantics of execution for modeling, simulation, synthesis

• Model of concurrency, time, synchronization, communication– Determinism vs. non-determinism

– Atomicity

– …

Source: R. Doemer, UC Irvine

Models of Time (Order)

• Physical

• Continuous time, total order– Physical components naturally interleaved in (very fine) time

• Logical

• Discrete time, partial order– Discrete instants of time (time tags t0 < t1 < ... tk < ... ), nothing in between

– Unspecified interleaving of events with same time tag

Freedom of implementation

• Untimed

• Partial order based on causality only– No ordering in time, explicit dependencies only

Free of implementation (purely behavioral)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 4

Simulation & execution, Design languages

Specification & programming, Models of computation (Lecture 4 & 5)

Differential equations, Hybrid models

Page 3: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 3

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 5

(Logical) Concurrency• Events/actions happening “at the same time”

• Undefined, unspecified or unknown order• Implementation/simulation determines actual interleaving• Communication/synchronization establishes causal order

Non-determinism• Outputs in relation to other outputs and inputs (behavior of system?) Explicit dependencies to define required order

Order in the presence of causality loops?

f()

f()

f()

to ?

to ?

to ?

ti

ti

ti

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 6

Language Semantics

• Motivating example 1

• Given:

• What is the value of x after the execution of B?

• Answer: x = 6

behavior B{

int x;B1 b1(x);B2 b2(x);

void main(void){

b1; b2;}

};

behavior B1(int x){

void main(void){

x = 5;}

};

behavior B2(int x){

void main(void){

x = 6;}

};

B1

B2

Source: R. Doemer, UC Irvine

Page 4: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 4

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 7

Language Semantics

• Motivating example 2

• Given:

• What is the value of x after the execution of B?

• Answer: The program is non-deterministic!(x may be 5, or 6, or any other value!)

behavior B{

int x;B1 b1(x);B2 b2(x);

void main(void){

par{b1; b2;}}

};

behavior B1(int x){

void main(void){

x = 5;}

};

behavior B2(int x){

void main(void){

x = 6;}

};

B1 B2

Source: R. Doemer, UC Irvine

t t

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 8

Language Semantics

• Motivating example 3

• Given:

• What is the value of x after the execution of B?

• Answer: x = 5

behavior B{

int x;B1 b1(x);B2 b2(x);

void main(void){

par{b1; b2;}}

};

behavior B1(int x){

void main(void){

waitfor 10;x = 5;

}};

behavior B2(int x){

void main(void){

x = 6;}

};

Source: R. Doemer, UC Irvine

B1 B2t+10 t

Page 5: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 5

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 9

Language Semantics

• Motivating example 4

• Given:

• What is the value of x after the execution of B?

• Answer: The program is non-deterministic!(x may be 5, or 6, or any other value!)

behavior B{

int x;B1 b1(x);B2 b2(x);

void main(void){

par{b1; b2;}}

};

behavior B1(int x){

void main(void){

waitfor 10;x = 5;

}};

behavior B2(int x){

void main(void){

waitfor 10;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t+10 t+10

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 10

Language Semantics

• Motivating example 5

• Given:

• What is the value of x after the execution of B?

• Answer: x = 6

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

x = 5;notify e;

}};

behavior B2(int x, event e)

{void main(void){

wait e;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t

Page 6: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 6

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 11

Simultaneous Events

• Depending on simulator

• Process C might be invoked once, observing both inputs in one invocation

• Process C might be invoked twice, processing events one at a time

Non-deterministic order of event processing

A B Ct

t

A B Ct

t

Suppose B is invoked first

behavior C(event a, event b)

{void main(void) {while(true) {// a or bwait(a, b);

}}

};

Source: M. Jacome, UT Austin.

behavior B(event a, event b)

{void main(void){while (true) {wait(a);notify(b);

}}

};

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 12

Delta (Superdense) Time

• Two-level model of time

• Break each time instant into multiple delta steps

• Each “zero” delay event results in a delta step

• Delta time has zero delay but imposes semantic order

delta steps

time value

delta timeoffset time steps

Source: M. Jacome, UT Austin.

A B Ct+2

t+

t+ Answer: C is invoked twice

Page 7: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 7

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 13

Delta Semantics

• Motivating example 5

• Given:

• What is the value of x after the execution of B?

• Answer: x = 6

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

x = 5;notify e;

}};

behavior B2(int x, event e)

{void main(void){

wait e;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t +

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 14

Delta Semantics

• Motivating example 6

• Given:

• What is the value of x after the execution of B?

• Answer: x = 6

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

notify e;x = 5;

}};

behavior B2(int x, event e)

{void main(void){

wait e;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t +

Page 8: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 8

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 15

Delta Semantics

• Motivating example 7

• Given:

• What is the value of x after the execution of B?

• Answer: B2 never terminates (x = 6)

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

notify e;x = 4;notify e;x = 5;

}};

behavior B2(int x, event e)

{void main(void){

wait e;x = 6;wait e;x = 7;

}};

Source: R. Doemer, UC Irvine

B1 B2t +

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 16

Delta Semantics

• Motivating example 8

• Given:

• What is the value of x after the execution of B?

• Answer: x = 6

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

waitfor 10;x = 5;notify e;

}};

behavior B2(int x, event e)

{void main(void){

wait e;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t +10+

Page 9: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 9

• Motivating example 9

• Given:

• What is the value of x after the execution of B?

• Answer: B2 never terminates!(the event is lost)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 17

Delta Semantics

behavior B{

int x;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x, event e)

{void main(void){

x = 5;notify e;

}};

behavior B2(int x, event e)

{void main(void){

waitfor 10;wait e;x = 6;

}};

Source: R. Doemer, UC Irvine

B1 B2t +

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 18

Delta Semantics

• Resolve some non-determinism

• As long as each output has “unique” delta delay

• Often not the case, e.g. in SpecC Example 2, Example 4

Ambiguity still exists

• Shared resource accesses in same delta cycle

• Undefined order, non-deterministic

Other approaches based on precedence analysis

• Graph is executed in topologically sorted order [Ptolemy] With B->C dependency, B invoked first

• Still ambiguous If there is no dependency: B or C first?

A B Ct+

t+

Source: M. Jacome, UT Austin.

Page 10: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 10

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 19

• Given

• What is the value of (y,z) at the end of execution?

• Answer: z = 5, y is non-deterministic (0 or 5)

Deterministic Communication

behavior B{

int x = 0;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(out int x, event e)

{void main(void){

x = 5;notify e;

}};

behavior B2(in int x, event e)

{int y, z;

void main(void) { y = x;wait e;z = x;

}};

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 20

Delta-semantics for variables [VDHL, Verilog, SpecC] Signals combine event with current/new value updates

What is the value of (y,z) at the end of execution? Answer: z = 5, y = 0

Resolves concurrent read-write Concurrent writes still a problem

Non-deterministic [SpecC], resolution functions [VHDL, Verilog]

Deterministic Communication

behavior B{

int x = 0;event e;B1 b1(x,e);B2 b2(x,e);

void main(void){

par{b1; b2;}}

};

behavior B1(out int x, event e)

{void main(void){

x = 5;notify e;

}};

behavior B2(in int x, event e)

{int y, z;

void main(void) {y = x;wait e;

z = x;}

};

signal int x = 0;

B1 b1(x);B2 b2(x);

out signal int x in signal int x

notify x; // implicit

wait x;

Page 11: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 11

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 21

• Avoid event loss by combining event with flag

• What is the value of x at the end of execution?

• Answer: actually, can end up being x = 5, why? Race conditions, interleaving of B1 and B2 if D1 == D2

Encapsulate in channel (see c_handshake)

Code in SpecC channel methods is atomic!

Deterministic Communication

behavior B{

int x;bool f = false;event e;B1 b1(x,f,e);B2 b2(x,f,e);

void main(void){

par{b1; b2;}}

};

behavior B1(int x,bool flag, event e)

{void main(void) {

…waitfor(D1);… flag = true;x = 5;notify e;…

}};

behavior B2(int x,bool flag, event e)

{void main(void) {

…waitfor(D2);…if (!flag) wait e;flag = false;x = 6;…

}};

Zero-Delay Feedback Loops

• Causality loop

• Where to start & stop?

• Progress?

Reject zero-delay cycles

Forbid all zero delay (every t must be strictly > 0) [DEVS]

Detect (compile error on zero cycle)

Delta cycle semantics

Oscillate with no time progress [Zeno machine/model]

Approaches based on topological sorting

Annotate feedback arcs to “break” for ordering purposes Insert explicit delay block [Ptolemy]

Same oscillation without progress

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 22

A B C

Source: M. Jacome, UT Austin.

Page 12: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 12

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 23

Discrete Event (DE) Model

General, universal model for system simulation

Hardware [VHDL, Verilog], system [SpecC, SystemC], network [OMNet]

• Formal, generic discrete time model

• Signals = globally ordered streams of events– Event ei = (value, tag), discrete time tags

• Asynchronous event processing– Execute block on input event

– Process input and generate output events with tag+∆t

Flexible Multi-scale, arbitrary dynamic delays

Efficient Event-driven, only evaluate when necessary

• Synthesis challenges

• Semantics: simultaneous events (non-determinism), zero-delay cycles

• Implementation: global order (maintain global notion of time) [PTIDES]

∆t = ta

∆t = tb

∆t = tc

i1, i2, i3, …

o1, o2, o3, …

x1, x2, x3, …

y1, y2, y3, …

z1, z2, z3, …

v1, v2, v3, …

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 24

Synchronous Reactive (SR) Model

• Synchronous hypothesis

• Sequence of discrete lock steps (ticks of logical clock)

• Reactions are instantaneous (zero time)

• Events are simultaneous (broadcast)

Deterministic, static verifiable (independent of actual delays) Precedence analysis, topological sort

No arbitrary shared variables

• Synthesis challenges:

• Semantics: causality loops, conflicts?

• Implementation: broadcast events, global clock

Synchronous languages

Imperative (control) [Esterel] or declarative (data) [Lustre] style

Reject cycles [Lustre] or require unique fixed-point [Esterel]

Hardware (FSMs) or software (safety critical) compilers

∆t = 0

∆t = 0

∆t = 0

∆t = 0

∆t = 0

∆t = 0

∆t = 0

Page 13: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 13

The Esterel Language• Synchronous, imperative language [Berry’83]

• Structural hierarchy– module <name> <b> end module– input <ports>, output <ports>

• Behavior– Sequential: <p> ; <q>– Concurrent: <p> || <q>

• Multiform time– Sequence of logical instants (cycles)– Statements take zero time (same instant) or delay for a number of cycles– Delay for one cycle: pause

• Broadcast signals (valued or unvalued)– Present or absent in each instant (default to absent in each new cycle)– emit <s>(<v>): Make signal <s> present in current instant (optional value)– await <s>: Wait for the next cycle in which <s> is present

• Control (branch, loop, exceptions)– present <s> then <p> else <q> end (in current instant)– loop <b> end, restart when <s> is present: loop <b> each <s>– abort/suspend <b> when <s>, trap <s> in <b> with exit <s> in <b>

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 25

module ABROinput A, B, R;output O;

loop[ await A || await B ];emit O

each R

end module

Esterel Semantics

• Instantaneous communication

• Signal emitted in a cycle is visible immediately

• Bi-directional communication

• Can communicate back and forth in same cycle

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 26

[pause; emit A; pause; emit A

||pause; present A then emit B end

]

AB

A

[pause; emit A; present B then emit C end;pause; emit A

||pause; present A then emit B end

]

ABC

A

Source: S. Edwards, Columbia

Page 14: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 14

Esterel Semantics

• Signal coherence• Signals can not be both absent and present• Writers run before readers do

• Causality• No contradictory or non-deterministic programs (cycles)

• Instantaneous loops• Loops must have at least one statement with delay

Erroneous programs, rejected by compiler Statically verified, guaranteed deterministic

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 27

present A else emit A;

present S1 else emit S2 end;present S2 else emit S1 end;

Source: S. Edwards, Columbia

loop emit A end

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 28

Lecture 3: Outline

Language semanticsModels of concurrency & timeDiscrete event modelSynchronous reactive model

• SpecC semantics• Simulation semantics• Formal semantics

Page 15: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 15

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 29

Specifying Language Semantics

• Language semantics are needed for• System designer (understanding)• Tools

– Validation (compilation, simulation)– Formal verification (equivalence, property checking)– Synthesis

• Documentation and standardization• Objective:

• Clearly define the execution semantics of the language• Requirements and goals:

• completeness• precision (no ambiguities)• abstraction (no implementation details)• formality (enable formal reasoning)• simplicity (easy understanding)

Source: R. Doemer, UC Irvine

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 30

SpecC Language Semantics

• Documentation• Language Reference Manual (LRM) set of rules written in English (not formal)• Abstract simulation algorithm set of valid implementations (not general)

• Reference implementation• SpecC Reference Compiler and Simulator one instance of a valid implementation (not general)• Compliance test bench set of specific test cases (incomplete)

• Formal execution semantics• Time-interval formalism rule-based formalism (incomplete)• Abstract State Machines fully formal approach (not easy to understand)

Source: R. Doemer, UC Irvine

Page 16: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 16

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 31

Formal Semantics

• Two examples of semantics definition:1) Time-interval formalism

• Definition of execution semantics of SpecC V2.0 [SpecC LRM‘02]• Formal definition of timed execution semantics• Sequentiality, concurrency, synchronization• Allows reasoning over execution order, dependencies

2) Abstract State Machines• Formalism of Evolving Algebras [Gurevich’87]• Complete execution semantics of SpecC V1.0 [Mueller‘02]

– wait, notify, notifyone, par, pipe, traps, interrupts– operational semantics (no data types!)

• Influence on the definition of SpecC V2.0• Straightforward extension for SpecC V2.0• Comparable to ASM specifications of SystemC and VHDL 93

Source: R. Doemer, UC Irvine

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 32

Simulation Semantics

• Abstract simulation algorithm for SpecC

• available in LRM (appendix), good for understanding

set of valid implementations

not general (possibly incomplete)

• Definitions:• At any time, each thread t is in one of the following sets:

– READY: set of threads ready to execute (initially root thread)– WAIT: set of threads suspended by wait (initially Ø)– WAITFOR: set of threads suspended by waitfor (initially Ø)

• Notified events are stored in a set N– notify e1 adds event e1 to N

– wait e1 will wakeup when e1 is in N

– Consumption of event e means event e is taken out of N

– Expiration of notified events means N is set to Ø

Source: R. Doemer, UC Irvine

Page 17: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 17

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 33

Simulation Semantics• Abstract simulation algorithm for SpecC

Select thread tREADY, execute t

Add notified events to Nnotify

Move tREADY to WAIT

Move tREADY to WAITFOR

wait

waitfor

READY=Ø

Set N=Ø

READY=Ø

Update simulation time, move earliest tWAITFOR to READY

READY=Ø

Stop

Start

NO

YES

NO

YES

NO

YES

YES

YES

YES

Move all tWAIT waiting for events eN to READY

NO

Source: R. Doemer, UC Irvine

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 34

Simulation Semantics

• Abstract simulation algorithm for SpecC

• Discrete-event model– utilizes delta-cycle mechanism

– matches execution semantics of other languages» SystemC

» VHDL

» Verilog

• Features– clearly specifies the simulation semantics

– easily understandable

– can easily be implemented

• Generality– is one valid implementation of the semantics

– other valid implementations may exist as well

Source: R. Doemer, UC Irvine

Page 18: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 18

Discrete Event Simulation (DES)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 35

10:0

10:1

0:0T:∆th4th2 th3th1• Traditional DES

• Concurrent threads of execution

• Managed by a central scheduler

• Driven by events and time advances– Delta-cycle

– Time-cycle

Partial temporal order with barriers

• Reference simulators• Both SystemC and SpecC

use cooperative multi-threading

A single thread is active at any time!

Cannot exploit multiple parallel cores

• Example: SystemC

Source: R. Doemer, UC Irvine

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 36

Discrete Event Simulation (DES)

• Traditional DE simulation algorithm• Threads managed

in READY queue

• Scheduler picks a single thread and executes it

• Time advances– In delta-cycle

– In timed-cycle

Source: R. Doemer, UC Irvine

Page 19: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 19

Parallel Discrete Event Simulation (PDES)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 37

10:010:1

10:2

20:120:0

20:2

30:0

0:0T:∆th4th2 th3th1• SLDL semantics

• SystemC prescribesCooperative Multi-Threading

– SystemC LRM defines:“process instances execute without interruption”

Preemptive interleaving forbidden

Parallelizing not possible

• SpecC specifiesPreemptive Multi-Threading

– SpecC LRM defines:”preemptive execution”,”No atomicity is guaranteed”

Preemptive interleaving assumed

Can be parallelized

Need critical regions withmutually exclusive access: Channels! Locks inserted by compiler in parallel mode

Source: R. Doemer, UC Irvine

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 38

Parallel Discrete Event Simulation (PDES)

• Parallel DE simulation algorithm• Threads managed

in READY queue

• Parallel delta cycle– Scheduler

picks N threadsand executesthem in parallel

– N = numberof availableCPU cores

• Time advances– In delta-cycle

– In timed-cycle

Source: R. Doemer, UC Irvine

Page 20: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 20

Parallel Discrete Event Simulation (PDES)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 39

10:010:1

10:2

20:120:0

20:2

30:0

0:0T:∆th4th2 th3th1• Parallel DES

• Threads execute in parallel iff– in the same delta cycle, and

– in the same time cycle

Significant speed up!

But: Amdahl’s Law still applies!– Cycle bounds are absolute barriers

Aggressive PDES Optimistic

Let threads run ahead in time

Rollback if conflict detected (event in the past)

Conservative Only run ahead if guaranteed no conflicts

E.g. static code/dependency analysis

Source: R. Doemer, UC Irvine

Out-of-Order Parallel DES (OoO PDES)

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 40

10:010:1

10:2

20:120:0

20:2

30:0

0:0T:∆th4th2 th3th1• Out-of-Order PDES

• Threads execute in parallel iff– in the same delta cycle, and

– in the same time cycle,

– OR if there are no conflicts!

• Can utilize advanced compiler forstatic data conflict analysis

Allows as many threads in parallelas possible

Significantly higher speedup!– Results at [Chen’12], [Chen’14]

Fully preserves…DES execution semantics

Accuracy in results and timing

Source: R. Doemer, UC Irvine

Page 21: EE382N: Embedded System Design and Modelingusers.ece.utexas.edu/~gerstl/ee382n_f15/notes/lecture3.pdfEE382N: Embedded Sys Dsgn/Modeling Lecture 3 © 2015 A. Gerstlauer 6 EE382N: Embedded

EE382N: Embedded Sys Dsgn/Modeling Lecture 3

© 2015 A. Gerstlauer 21

EE382N: Embedded Sys Dsgn/Modeling, Lecture 3 © 2015 A. Gerstlauer 41

Lecture 3: Summary

• Discrete event (DE) model of computation

• Universal model for simulation of concurrent systems

• Challenging to synthesize or implement concurrently– Delta cycles, global order

• SpecC language semantics

• Formal semantics

• Simulation semantics– Simulation algorithm

– Parallel discrete event simulation

Hierarchy of models

• Models of computation (MoCs) for specification

• Discrete event (DE) model for simulation

Capture & simulate other MoCs in a DE language [SpecC]