85
fakultät für informatik informatik 12 technische universität dortmund Specifications - sessions 2-3 - Peter Marwedel TU Dortmund Informatik 12 Germany Slides use Microsoft cliparts. All Microsoft restrictions apply.

fakultät für informatik informatik 12 technische universität dortmund Specifications - sessions 2-3 - Peter Marwedel TU Dortmund Informatik 12 Germany

Embed Size (px)

Citation preview

fakultät für informatikinformatik 12

technische universität dortmund

Specifications- sessions 2-3 -

Peter MarwedelTU Dortmund Informatik 12

Germany

Slides use Microsoft cliparts. All Microsoft restrictions apply.

- 2 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Schedule of the course

Time Monday Tuesday Wednesday Thursday Friday

09:30-11:00

1: Orientation, introduction

2: Models of computation + specs

5: Models of computation + specs

9: Mapping of applications to platforms

13: Memory aware compilation

17: Memory aware compilation

11:00  Brief break  Brief break Brief break   Brief break

11:15-12:30

6: Lab*: Ptolemy

10: Lab*: Scheduling

14: Lab*: Mem. opt.

18: Lab*: Mem. opt.

12:30 Lunch Lunch Lunch Lunch Lunch

14:00-15:20

3: Models of computation + specs

7: Mapping of applications to platforms

11: High-level optimizations*

15: Memory aware compilation

19: WCET & compilers*

15:20 Break  Break Break Break Break

15:40-17:00

4: Lab*: Kahn process networks

8: Mapping of applications to platforms

12: High-level optimizations*

16: Memory aware compilation

20: Wrap-up

* Dr. Heiko Falk

- 3 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Motivation for considering specs

Why considering specs?

If something is wrong with the specs, then it will be difficult to get the design right, potentially wasting a lot of time.

Why not just use standard languages like Java, C++ etc?

Example demonstrating weakness

time

- 4 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Consider a Simple Example

“The Observer pattern defines a one-to-many dependency between a subject object andany number of observer objectsso that when the subject object changes state,all its observer objects are notified and updated automatically.”

Eric Gamman Richard Helm, Ralph Johnson, John Vlissides: Design Patterns, Addision-Wesley, 1995

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 5 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example: Observer Pattern in Java

public void addListener(listener) {…}

public void setValue(newvalue) {

myvalue=newvalue;

for (int i=0; i<mylisteners.length; i++) {

myListeners[i].valueChanged(newvalue) }}

Thanks to Mark S. Miller for the details of this example.

Will this work in a multithreaded context?

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 6 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example: Observer Patternwith Mutual Exclusion (mutexes)

public synchronized void addListener(listener) {…}

public synchronized void setValue(newvalue) {

myvalue=newvalue;

for (int i=0; i<mylisteners.length; i++) {

myListeners[i].valueChanged(newvalue) }} Javasoft recommends against this.

What’s wrong with it?

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 7 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Mutexes using monitors are minefields

public synchronized void addListener(listener) {…}

public synchronized void setValue(newvalue) {

myvalue=newvalue;

for (int i=0; i<mylisteners.length; i++) {

myListeners[i].valueChanged(newvalue) }}

valueChanged() may attempt to acquire a lock on some other object and stall. If the holder of that lock calls addListener(): deadlock!

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

x calls addListener

valueChanged

requests

lock

held

by

x

mutex

- 8 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Simple Observer PatternBecomes not so simple

public synchronized void addListener(listener) {…}

public void setValue(newValue) {

synchronized (this) {

myValue=newValue;

listeners=myListeners.clone();

}

for (int i=0; i<listeners.length; i++) {

listeners[i].valueChanged(newValue) }}

while holding lock, make a copy of listeners to avoid race conditions

notify each listener outside of the synchronized block to avoid deadlock

This still isn’t right.What’s wrong with it?

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 9 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Simple Observer Pattern:How to Make it Right?

public synchronized void addListener(listener) {…}

public void setValue(newValue) {

synchronized (this) {

myValue=newValue;

listeners=myListeners.clone();

}

for (int i=0; i<listeners.length; i++) {

listeners[i].valueChanged(newValue) }}

Suppose two threads call setValue(). One of them will set the value last, leaving that value in the object, but listeners may be notified in the opposite order. The listeners may be alerted to the value-changes in the wrong order!

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 10 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

A stake in the ground …

Nontrivial software written with threads, semaphores, and mutexes is incomprehensible to humans.

© Ed Lee, Berkeley, Artemis Conference, Graz, 2007

- 11 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Problems with thread-based concurrency

“The lack of timing in the core abstraction is a flaw, from the perspective of embedded software, and threads as a concurrency model are a poor match for embedded systems. … they work well only … where best-effort scheduling policies are sufficient.What is needed is nearly a reinvention of computer science.”

Ed Lee: Absolutely Positively on Time, IEEE Computer, July, 2005

Search for non-thread-based, non-von-Neumann MoCs; which are the requirements for appropriate specification techniques?

- 12 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Problems with classical CS theoryand von Neumann computing

Even the core … notion of “computable” is at odds with the requirements of embedded software.

In this notion, useful computation terminates, but termination is undecidable.

In embedded software, termination is failure, and yet to get predictable timing, subcomputations must decidably terminate.

Ed Lee: Absolutely Positively on Time, IEEE Computer, July, 2005

References integrated into slides for modularity & context

- 13 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Specification of embedded systems: Requirements for specification techniques (1)

HierarchyHumans not capable to understand systemscontaining more than ~5 objects.Most actual systems require more objects Hierarchy

• Behavioral hierarchyExamples: states, processes, procedures.

• Structural hierarchyExamples: processors, racks,printed circuit boards

proc proc proc

- 14 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Specification of embedded systems: Requirements for specification techniques (2)

Compositional behaviorMust be “easy” to derive behavior from behavior of subsystems

Timing behavior.

State-oriented behaviorRequired for reactive systems;classical automata insufficient.

Event-handling(external or internal events)

No obstacles for efficient implementation

- 15 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Requirements for specification techniques (3)

Support for the design of dependable systemsUnambiguous semantics, ...

Exception-oriented behaviorNot acceptable to describe exceptions for every state.

We will see, how all the arrows labeled k can be replaced by a single one.

- 16 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Requirements for specification techniques (4)

Concurrency Synchronization and communication Presence of programming elements Executability (no algebraic specification) Support for the design of large systems ( OO) Domain-specific support Readability Portability and flexibility Termination Support for non-standard I/O devices Non-functional properties Adequate model of computation

- 17 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Models of computation- Definition -

What does it mean, “to compute”?

Models of computation define:

Components and an execution model for computations for each component

Communication model for exchange of information between components.

• Shared memory

• Message passing

• …

C-1

C-2

- 18 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Communication

Shared memory

memoryComp-1 Comp-2

Variables accessible to several tasks.

Model is useful only for local systems.

- 19 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Shared memory

Potential race conditions (inconsistent results possible) Critical sections = sections at which exclusive access to resource r (e.g. shared memory) must be guaranteed.

process a { .. P(S) //obtain lock .. // critical section V(S) //release lock}

process b { .. P(S) //obtain lock .. // critical section V(S) //release lock}

Race-free access to shared memory protected by S possible

This model may be supported by:mutual exclusion for critical sectionscache coherency protocols

- 20 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Non-blocking/asynchronous message passing

Sender does not have to wait until message has arrived; potential problem: buffer overflow

…send ()…

…receive ()…

- 21 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Blocking/synchronous message passingrendez-vous

Sender will wait until receiver has received message

…send ()…

…receive ()…

- 22 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Extended rendez-vous

…send ()…

…receive ()…ack…

Explicit acknowledge from receiver required. Receiver can do checking before sending acknowledgement.

- 23 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Components (1)

Discrete event model

abc

timeactiona:=5 b:=7 c:=8 a:=6 a:=9

queue

5 10 13 15 1957

8

6

Von Neumann model

Sequential execution, program memory etc.

- 24 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Components (2)

Finite state machines

Differential equations

bt

x

2

2

- 25 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Combined models- languages presented later in this chapter -

SDL FSM+asynchronous message passing

StateChartsFSM+shared memory

CSP, ADAvon Neumann execution+synchronous message passing

….

See also Work by Ed Lee, UCB Axel Jantsch: Modeling Embedded Systems and Soc's: Concurrency and

Time in Models of Computation, Morgan-Kaufman, 2004

- 26 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Models considered in this course

Communication/local computations

Shared memory

Message passingSynchronous | Asynchronous

Communicating finite state machines

StateCharts SDL

Data flow model Not useful Kahn process networks

Von Neumann model

C, C++, Java

C, C++, Java with librariesCSP, ADA |

Discrete event (DE) model

VHDL, Verilog, SystemC

Only experimental systems, e.g. distributed DE in Ptolemy

- 27 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

StateCharts

Used here as a (prominent) example of a model of computation based on shared memory communication.

appropriate only for local (non-distributed) systems

Deterministic model feasible

Classical automata not useful for complex systems

(complex graphs cannot be understood by humans).

Introduction of hierarchy StateCharts [Harel, 1987]

StateChart = the only unused combination of

„flow“ or „state“ with „diagram“ or „chart“

- 28 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Introducing hierarchy

FSM will be in exactly one of the substates of S if S is active(either in A or in B or ..)

FSM will be in exactly one of the substates of S if S is active(either in A or in B or ..)

- 29 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Definitions

Current states of FSMs are also called active states. States which are not composed of other states are called

basic states. States containing other states are called super-states. For each basic state s, the super-states containing s are

called ancestor states. Super-states S are called OR-super-states, if exactly one

of the sub-states of S is active whenever S is active.

ancestor state of E

superstate

substates

- 30 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Default state mechanism

Try to hide internal structure from outside world!

Default state

Filled circleindicates sub-state entered whenever super-state is entered.

Not a state by itself!

- 31 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

History mechanism

For input m, S enters the state it was in before S was left(can be A, B, C, D, or E).

If S is entered for the first time, the default mechanism applies.

History and default mechanisms can be used hierarchically.

(behavior different from last slide)

km

- 32 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Concurrency

Convenient ways of describing concurrency are required.AND-super-states: FSM is in all (immediate) sub-states of a super-state; Example:

- 33 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Timers

Since time needs to be modeled in embedded systems,timers need to be modeled.In StateCharts, special edges can be used for timeouts.

If event a does not happen while the system is in the left state for 20 ms, a timeout will take place.

If event a does not happen while the system is in the left state for 20 ms, a timeout will take place.

- 34 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Using timers in an answering machine

.

- 35 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

The StateCharts simulation phases (StateMate Semantics)

How are edge labels evaluated?

Three phases:

1. Effect of external changes on events and conditions is

evaluated,

2. The set of transitions to be made in the current step and

right hand sides of assignments are computed,

3. Transitions become effective, variables obtain new

values.

Separation into phases 2 and 3 enables deterministic

and reproducible behavior.

- 36 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Steps

Execution of a StateMate model consists of a sequence of (status, step) pairs

Status= values of all variables + set of events + current time

Step = execution of the three phases (StateMate semantics)

Status= values of all variables + set of events + current time

Step = execution of the three phases (StateMate semantics)

Statusphase 2

phase 3

phase 1 Other implementations of StateCharts do not have

these 3 phases (and hence are nondeterministic)!

- 37 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example

In phase 2, variables a and b are assigned to temporary variables. In phase 3, these are assigned to a and b.

As a result, variables a and b are swapped.

In a single phase environment, executing the left state first would assign the old value of b (=0) to a and b.

Executing the right state first would assign the old value of a (=1) to a and b. The execution would be non-deterministic.

- 38 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Reflects model of clocked hardware

In an actual clocked (synchronous) hardware system, both registers would be swapped as well.

Same separation into phases found in other languages as well, especially those that are intended to model hardware.

Same separation into phases found in other languages as well, especially those that are intended to model hardware.

- 39 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

StateCharts deterministic or not?

Deterministic (in this context) means:

Must all simulators return the same result for a given input?

Separation into 2 phases a required condition

Semantics StateMate semantics may be non-deterministic

Potential other sources of non-deterministic behavior:

Choice between conflicting transitions resolved arbitrarily

Deterministic behavior for StateMate semantics if transition conflicts are resolved deterministicallyand no other sources of non-determinism exist

A A Tools typically issue a warning if such non-determinism could exist

- 40 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Broadcast mechanism

Values of variables are visible to all parts of the StateChart modelNew values become effective in phase 3 of the current step and are obtained by all parts of the model in the following step.

StateCharts implicitly assumes a broadcast mechanism for variables( implicit shared memory communication –other implementations would be very inefficient -).

StateCharts is appropriate for local control systems (), but not for distributed applications for which updating variables might take some time ().

StateCharts implicitly assumes a broadcast mechanism for variables( implicit shared memory communication –other implementations would be very inefficient -).

StateCharts is appropriate for local control systems (), but not for distributed applications for which updating variables might take some time ().

- 41 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Other semantics

Several other specification languages for hierarchical state machines (UML, …) do not include the three simulation phases.

These correspond more to a SW point of view with no synchronous clocks.

LabView (National Instruments) seems to allow turning the multi-phased simulation on and off.

- 42 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Evaluation of StateCharts (1)

Pros:

For StateMate: Deterministic behavior

Hierarchy allows arbitrary nesting of AND- and OR-super states.

(StateMate-) Semantics defined in a follow-up paper to original paper.

Large number of commercial simulation tools available(StateMate, StateFlow, BetterState, ...)

Available “back-ends“ translate StateCharts into C or VHDL, thus enabling SW or HW implementations.

- 43 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Evaluation of StateCharts (2)

Cons:

Generated C programs frequently inefficient,

Not useful for distributed applications,

No program constructs,

No description of non-functional behavior,

No object-orientation,

No description of structural hierarchy.

Extensions: Module charts for description of structural hierarchy.

Extensions: Module charts for description of structural hierarchy.

- 44 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Summary

Non-deterministic thread-based concurrency results in problems

Search for other models of computation =

• models of components- finite state machines (FSMs)

StateCharts (deterministic for StateMate implementation)

- data flow, ….

• + models for communication- Shared memory

- Message passing

- 45 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Lunch break (if on schedule)

Q&A?

- 46 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Schedule of the course

Time Monday Tuesday Wednesday Thursday Friday

09:30-11:00

1: Orientation, introduction

2: Models of computation + specs

5: Models of computation + specs

9: Mapping of applications to platforms

13: Memory aware compilation

17: Memory aware compilation

11:00  Brief break  Brief break Brief break   Brief break

11:15-12:30

6: Lab*: Ptolemy

10: Lab*: Scheduling

14: Lab*: Mem. opt.

18: Lab*: Mem. opt.

12:30 Lunch Lunch Lunch Lunch Lunch

14:00-15:20

3: Models of computation + specs

7: Mapping of applications to platforms

11: High-level optimizations*

15: Memory aware compilation

19: WCET & compilers*

15:20 Break  Break Break Break Break

15:40-17:00

4: Lab*: Kahn process networks

8: Mapping of applications to platforms

12: High-level optimizations*

16: Memory aware compilation

20: Wrap-up

* Dr. Heiko Falk

- 47 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Synchronous vs. asynchronous languages (1)

Description of several processes in many languages non-deterministic:The order in which executable tasks are executed is not specified (may affect result).

Synchronous languages: based on automata models.

“Synchronous languages aim at providing high level, modular constructs, to make the design of such an automaton easier [Halbwachs].

Synchronous languages describe concurrently operating automata. “.. when automata are composed in parallel, a transition of the product is made of the "simultaneous" transitions of all of them“.

- 48 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Synchronous languages implicitly assume the presence of a (global) clock. Each clock tick, all inputs are considered, new outputs and states are calculated and then the transitions are made.

Requires a broadcast mechanism for all parts of the model.

Idealistic view of concurrency.

Has the advantage of guaranteeing deterministic behavior.

StateCharts using StateMate semantics is a synchronous language.

Synchronous vs. asynchronous languages (2)

- 49 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

SDL

Used here as a (prominent) example of a model of computation based on asynchronous message passing.

appropriate also for distributed systems

Communication/Computation Shared

memory

Message passing

blocking Non-blocking

FSM StateCharts SDL

- 50 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

SDL

Language designed for specification of distributed systems.

Dates back to early 70s,

Formal semantics defined in the late 80s,

Defined by ITU (International Telecommunication Union): Z.100 recommendation in 1980Updates in 1984, 1988, 1992, 1996 and 1999

Provides textual and graphical formats to please all users,

Just like StateCharts, it is based on the CFSM model of computation; each FSM is called a process,

However, it uses message passing instead of shared memory for communications,

SDL supports operations on data.

- 51 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

SDL-representation of FSMs/processes

output

input

state

- 52 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Communication among SDL-FSMs

Communication between FSMs (or “processes“) is based on message-passing, assuming a potentially indefinitely large FIFO-queue.

Each process fetches next entry from FIFO,

checks if input enables transition,

if yes: transition takes place,

if no: input is ignored (exception: SAVE-mechanism).

- 53 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Deterministic?

Let tokens be arriving at FIFO at the same time:Order in which they are stored, is unknown:

All orders are legal: simulators can show different behaviors for the same input, all of which are correct.

- 54 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Hierarchy in SDL

Process interaction diagrams can be included in blocks. The root block is called system.

Processes cannot contain other processes, unlike in StateCharts.

- 55 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Application: description of network protocols

- 56 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Evaluation

Excellent for distributed applications (used for ISDN), Commercial tools available from SINTEF, Telelogic,

Cinderella (//www.cinderella.dk). Not necessarily deterministic

(order, in which FSMs are reading input is unknown) no synchronous language,

Implementation requires bound for the maximum length of FIFOs; may be very difficult to compute,

Timer concept adequate just for soft deadlines, Limited way of using hierarchies, Limited programming language support, No description of non-functional properties, Becoming less popular

- 57 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Models of computation considered in this course

Communication/local computations

Shared memory

Message passingSynchronous | Asynchronous

Communicating finite state machines

StateCharts SDL

Data flow model Not useful (Simulink, LabView)

Kahn process networks, SDF

Von Neumann model

C, C++, Java

C, C++, Java with librariesCSP, ADA |

Discrete event (DE) model

VHDL, Verilog, SystemC

Only experimental systems, e.g. distributed DE in Ptolemy

- 58 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Data flow as a “natural” model of applications

http://www.agilemodeling.com/artifacts/dataFlowDiagram.htm

ExamplesRegistering for courses

www.ece.ubc.ca/~irenek/techpaps/vod/vod.html

Video on demand system

- 59 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Data flow modeling

Def.: The process of identifying, modeling and documenting how data moves around an information system.

Data flow modeling examines processes (activities that transform data from one form

to another), data stores (the holding areas for data), external entities (what sends data into a system or

receives data from a system, and data flows (routes by which data can flow).

http://www.webopedia.com/TERM/D/data_flow_modeling.html

See also S. Edwards: http://www.cs.columbia.edu/~sedwards/classes/2001/w4995-02/presentations/dataflow.ppt

- 60 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Reference model for data flow:Kahn process networks

Special case: Kahn process networks:executable task graphs;Communication via infinitely large FIFOs

Special case: Kahn process networks:executable task graphs;Communication via infinitely large FIFOs

For asynchronous message passing:communication between tasks is bufferedFor asynchronous message passing:communication between tasks is buffered

- 61 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Properties of Kahn process networks (1)

Each node corresponds to one program/task;

Communication is only via channels;

Channels include FIFOs as large as needed;

Channels transmit information within an unpredictable but finite amount of time;

Mapping from 1 input seq. to 1 output sequence;

In general, execution times are unknown;

Send operations are non-blocking, reads are blocking.

One producer and one consumer;i.e. there is only one sender per channel;

- 62 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Properties of Kahn process networks (2)

There is only one sender per channel. A process cannot check whether data is available

before attempting a read. A process cannot wait for data for more than one port

at a time. Therefore, the order of reads depends only on data,

not on the arrival time. Therefore, Kahn process networks are deterministic (!);

for a given input, the result will always the same, regardless of the speed of the nodes.SDL-like conflicts at FIFOs do not exist. This is the

key beauty of KPNs!

- 63 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example

© R. Gupta (UCSD), W. Wolf (Princeton), 2003

Model of parallel computations used in practice(e.g. at Philips/NXP).

It is a challenge to schedule KPNs without accumulating tokens

http://en.wikipedia.org/wiki/Kahn_process_networkshttp://ls12-www.cs.tu-dortmund.de/edu/ES/leviKPN.zip: Animation

levi animation

Process f(in int u, in int v, out int w){ int i; bool b = true; for (;;) { i= b ? wait(u) : wait(v); //wait return next token in FIFO, blocks if empty printf (“%i\n”,i); send (i,w); //writes a token into a FIFO w/o blocking b = !b; }

- 64 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Asynchronous message passing:Synchronous data flow (SDF)

Asynchronous message passing=tasks do not have to wait until output is accepted.

Synchronous data flow =all tokens are consumed at the same time.

SDF model allows static scheduling of token production and consumption.In the general case, buffers may be needed at edges.

SDF model allows static scheduling of token production and consumption.In the general case, buffers may be needed at edges.

- 65 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Synchronous Dataflow (SDF)- Fixed Production/Consumption Rates -

Balance equations (one for each channel):

Schedulable statically Decidable:

buffer memory requirements deadlock

fire B { … consume M …}

fire A { … produce N …}

channel

N M

MfNf BA number of tokens consumed

number of firings per “iteration”

number of tokens produced

Source: ptolemy.eecs.berkeley.edu/ presentations/03/streamingEAL.ppt

- 66 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Parallel Scheduling of SDF Models

A

C

D

B

Sequential Parallel

SDF is suitable for automated mapping onto parallel processors and synthesis of parallel circuits.

Many scheduling optimization problems can be formulated. Some can be solved, too!

Source: ptolemy.eecs.berkeley.edu/ presentations/03/streamingEAL.ppt

- 67 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Similar MoC: Simulink- example -

From www.mathworks.co.uk/ access/ helpdesk/help/toolbox/fuzzy/fuzzyt25.shtml

Simulink uses an idealized timing model for block execution and communication. Both happen infinitely fast at exact points in simulated time. Thereafter, simulated time is advanced by exact time steps. All values on edges are constant in between time steps. [Nicolae Marian, Yue Ma]

- 68 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Starting point for “model-based design”

Code automatically generated

© MathWorks, http://www.mathworks.de/ cmsimages/rt_forloop_code_wl_7430.gif

- 69 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Actor languages

© E. Lee, Berkeley

- 70 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Generalization of data flow: Computational graphs Example: Petri nets

Introduced in 1962 by Carl Adam Petri in his PhD thesis.Focus on modeling causal dependencies;no global synchronization assumed (message passing only).Key elements: Conditions

Either met or no met. Events

May take place if certain conditions are met. Flow relation

Relates conditions and events.Conditions, events and the flow relation forma bipartite graph (graph with two kinds of nodes).

- 71 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example: Synchronization at single track rail segment

„Preconditions“

- 72 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Playing the “token game“

use normal view mode!

- 73 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

More complex example (1)

Thalys trains between Cologne, Amsterdam, Brussels and Paris.

Thalys trains between Cologne, Amsterdam, Brussels and Paris.

[http://www.thalys.com/be/en]

- 74 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

s

More complex example (2)

Slightly simplified: Synchronization at Brussels and Paris,using stations “Gare du Nord” and “Gare de Lyon” at Paris

Slightly simplified: Synchronization at Brussels and Paris,using stations “Gare du Nord” and “Gare de Lyon” at Paris

use normal view mode!

- 75 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Condition/event nets

Def.: N=(C,E,F) is called a net, iff the following holds

1. C and E are disjoint sets

2. F (C E) (E C); is binary relation, (“flow relation“)

Def.: Let N be a net and let x (C E). x := {y | y F x} is called the set of preconditions. x := {y | x F y} is called the set of postconditions.

Example:xx x

- 76 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Condition/Event Nets (2)

Def.: A net is called simple if no two transitions t1 and t2 have the same sets of input and output places.

Example (not a simple net):

Def.: Simple nets with no isolated elements meeting some additional restrictions are called condition/event nets(C/E nets).

Def.: Simple nets with no isolated elements meeting some additional restrictions are called condition/event nets(C/E nets).

- 77 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Place/transition nets

Def.: (P, T, F, K, W, M0) is called a place/transition net iff1. N=(P,T,F) is a net with places p P and transitions t T2. K: P (ℕ0 {}) \{0} denotes the capacity of places

( symbolizes infinite capacity)3. W: F (ℕ0 \{0}) denotes the weight of graph edges4. M0: P ℕ0 {} represents the initial marking of places

W

M0

(Segment of some net)

defaults:K = W = 1

defaults:K = W = 1

- 78 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Predicate/transition nets

Goal: compact representation of complex systems.

Key changes:

Tokens are becoming individuals;

Transitions enabled if functions at incoming edges true;

Individuals generated by firing transitions defined through functions

Changes can be explained by folding and unfolding C/E nets,

semantics can be defined by C/E nets.

- 79 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Example: Dining philosophers problem

n>1 philosophers sitting at a round table;n forks,n plates with spaghetti;philosophers either thinkingor eating spaghetti(using left and right fork).

How to model conflict for forks?

How to guarantee avoiding starvation?

How to model conflict for forks?

How to guarantee avoiding starvation?

2 forks needed!

- 80 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Condition/event net modelof the dining philosophers problem

Let x {1..3}tx: x is thinkingex: x is eatingfx: fork x is available

Model quite clumsy.

Difficult to extend to more philosophers.

Model quite clumsy.

Difficult to extend to more philosophers.

Normal view mode!

- 81 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Predicate/transition modelof the dining philosophers problem (1)

Let x be one of the philosophers,let ℓ(x) be the ℓeft spoon of x,let r(x) be the right spoon of x.

Tokens: individuals.

Semantics can be defined by replacing net by equivalent condition/event net.

p1

p3p2

f1f2

f3ℓ(x) ℓ(x)

r(x)r(x)v

xx

u

xx

t

e

f

- 82 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Predicate/transition modelof the dining philosophers problem (2)

p1

p3p2

f1f2

f3

Model can be extended to arbitrary numbers of people.

Model can be extended to arbitrary numbers of people.

use normal view mode!

ℓ(x) ℓ(x)r(x)r(x)

v

xx

u

xx

t

e

f

- 83 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Evaluation

Pros: Appropriate for distributed applications, Well-known theory for formally proving properties, Initially a quite bizarre topic, but now accepted due to

increasing number of distributed applications.

Cons (for the nets presented) : problems with modeling timing, no programming elements, no hierarchy.

Extensions: Enormous amounts of efforts on removing limitations.

back to full screen mode

- 84 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Summary

FSM based models• SDL

Computational graphs• Data flow

- Kahn process networks

• Synchronous data flow• Visual programming languages

Model based design

• Petri nets- Condition/event nets- Place/transition nets- Predicate/event nets

- 85 -technische universitätdortmund

fakultät für informatik

p. marwedel, informatik 12, 2008

Coffee/tea break (if on schedule)

Q&A?