42
technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra Nolte, Gesine Marwedel, 2003 2011/10/21 These slides use Microsoft clip arts. Microsoft copyright restrictions apply.

Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

Embed Size (px)

Citation preview

Page 1: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

technische universität dortmund

fakultät für informatikinformatik 12

Models of computation

Peter MarwedelTU DortmundInformatik 12

Gra

phic

s: ©

Ale

xand

ra N

olte

, Ges

ine

Mar

wed

el, 2

003

2011/10/21These slides use Microsoft clip arts. Microsoft copyright restrictions apply.

Page 2: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 2 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Models of computation

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.

C-1

C-2

Page 3: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 3 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Models of computationconsidered in this course

Communication/local computations

Shared memory

Message passingSynchronous | Asynchronous

Undefined components

Plain text, use cases | (Message) sequence charts

Communicating finite state machines

StateCharts SDL

Data flow (Not useful) Kahn networks, SDF

Petri nets C/E nets, P/T nets, …

Discrete event (DE) model

VHDL, Verilog, SystemC, …

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

Von Neumann model C, C++, Java C, C++, Java with librariesCSP, ADA |

Page 4: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 4 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Why not just use von-Neumann computing (C, Java, …) ?

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

Page 5: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 5 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Why not just use von-Neumann computing (C, Java, …) (2)?

Problems with von-Neumann Computing

Thread-based multiprocessing may access global variables

We know from the theory of operating systems that

• access to global variables might lead to race conditions,

• to avoid these, we need to use mutual exclusion,

• mutual exclusion may lead to deadlocks,

• avoiding deadlocks is possible only if we accept performance penalties.

Page 6: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 6 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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.”

Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides: Design Patterns, Addision-Wesley, 1995

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

Page 7: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 7 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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?

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

Page 8: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 8 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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?

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

Page 9: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 9 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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!

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

x calls addListener

valueChanged

requests

lock

held

by

x

mutex

Page 10: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 10 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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?

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

Page 11: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 11 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

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!

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

Page 12: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 12 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

A stake in the ground …

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

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

Page 13: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 13 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Problems with thread-based concurrency

“… threads as a concurrency model are apoor match for embedded systems. … they work well only … where best-effort scheduling policies are sufficient.”

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

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.

What is needed is nearly a reinvention of computer science.

Page 14: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 14 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Models of computationconsidered in this course

Communication/local computations

Shared memory

Message passingSynchronous | Asynchronous

Undefined components

Plain text, use cases | (Message) sequence charts

Communicating finite state machines

StateCharts SDL

Data flow (Not useful) Kahn networks, SDF

Petri nets C/E nets, P/T nets, …

Discrete event (DE) model

VHDL, Verilog, SystemC, …

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

Von Neumann model C, C++, Java C, C++, Java with librariesCSP, ADA |

No language that meets all language requirements using compromises

Page 15: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

technische universität dortmund

fakultät für informatikinformatik 12

Early design phases

Peter MarwedelTU Dortmund,Informatik 12

Gra

phic

s: ©

Ale

xand

ra N

olte

, Ges

ine

Mar

wed

el, 2

003

2011/05/08

Page 16: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 16 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Capturing the requirements as text

In the very early phases of some design project, only descriptions of the system under design (SUD) in a natural language such as English or Japanese exist.

Expectations for tools:

• Machine-readable

• Version management

• Dependency analysis

• Example: DOORS® [Telelogic/IBM]

Page 17: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 17 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Use cases

Use cases describe possible applications ofthe SUD

Included in UML (Unified Modeling Language) Example: Answering machine

Neither a precisely specified model of the computations nor a precisely specified model of the communication

Page 18: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 18 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

(Message) Sequence charts

Explicitly indicate exchange of information One dimension (usually vertical dimension) reflects time The other reflects distribution in space

Example: Included in UML

Earlier called Message Sequence Charts, now mostly called Sequence Charts

Page 19: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 19 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Example (2)

www.ist-more.org, deliverable 2.1

Page 20: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 20 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Application: In-Car Navigation System

Car radio with navigation systemUser interface needs to be responsiveTraffic messages (TMC) must be processed in a timely waySeveral applications may execute concurrently

© Thiele, ETHZ

Page 21: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 21 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

System Overview

NAV RAD

MMI

DB

Communication

© Thiele, ETHZ

Page 22: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 22 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

NAV RAD

MMI

DB

Communication

Use case 1: Change Audio Volume

< 200 ms

< 50 m

s

© Thiele, ETHZ

Page 23: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 23 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Use case 1: Change Audio Volume

© Thiele, ETHZ

CommunicationResourceDemand

Page 24: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 24 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

NAV RAD

MMI

DB

Communication

< 200 ms

Use case 2: Lookup Destination Address

© Thiele, ETHZ

Page 25: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 25 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Use case 2: Lookup Destination Address

© Thiele, ETHZ

Page 26: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 26 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

NAV RAD

MMI

DB

Communication

Use case 3: Receive TMC Messages

< 1000 ms

© Thiele, ETHZ

Page 27: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 27 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Use case 3: Receive TMC Messages

© Thiele, ETHZ

Page 28: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 28 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

(Message) Sequence Charts (MSC)

No distinction between accidental overlap and synchronizationNo distinction between accidental overlap and synchronization

Page 29: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 29 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Time/distance diagrams as a special case

© w

ww

.ope

ntr

ack

.ch

Levi-TDD

Page 30: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 30 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

UML: Timing diagrams

Can be used to show the change of the state of an object over time.

© Scott Ambler, Agile Modeling,//www.agilemodeling.com, 2003

Page 31: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 31 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Life Sequence Charts* (LSCs)

* W. Damm, D. Harel: LSCs: Breathing Life into Message Sequence Charts, Formal Methods in System Design, 19, 45–80, 2001

Key problems observed with standard MSCs:

During the design process, MSC are initially interpreted as

“what could happen”

(existential interpretation, still allowing other behaviors).

Later, they are frequently assumed to describe

“what must happen”

(referring to what happens in the implementation).

Page 32: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 32 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Extensions for LSCs (1)

Extension 1:

Introduction of pre-charts:Pre-charts describe conditions that must hold for the main chart to apply.

Extension 1:

Introduction of pre-charts:Pre-charts describe conditions that must hold for the main chart to apply.

Pre-chartExample:

Page 33: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 33 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Extensions (2)

Extension 2: Mandatory vs. provisional behavior Extension 2: Mandatory vs. provisional behavior

Level Mandatory (solid lines) Provisional (dashed lines)

Chart All runs of the system satisfy the chart

At least one run of the system satisfies the chart

Location Instance must move beyond location/time

Instance run need not move beyond loc/time

Message If message is sent, it will be received

Receipt of message is not guaranteed

Condition Condition must be met; otherwise abort

If condition is not met, exit subchart

Page 34: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 34 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

PROs: Appropriate for visualizing schedules, Proven method for representing schedules in transportation. Standard defined: ITU-TS Recommendation Z.120:

Message Sequence Chart (MSC), ITU-TS, Geneva, 1996.

Semantics also defined: ITU-TS Recommendation Z.120: Message Sequence Chart (MSC)—Annex B: Algebraic Semantics of Message Sequence Charts, ITU-TS, Geneva.

CONS: describes just one case, no timing tolerances: "What does

an MSC specification mean: does it describe all behaviors of a system, or does it describe a set of sample behaviors of a system?” *

* H. Ben-Abdallah and S. Leue, “Timing constraints in message sequence chart specifications,” in Proc. 10th International Conference on Formal Description Techniques FORTE/PSTV’97, Chapman and Hall, 1997.

(Message) Sequence Charts

Page 35: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

technische universität dortmund

fakultät für informatikinformatik 12

Communicating finite state machines

Peter MarwedelTU DortmundInformatik 12

Gra

phic

s: ©

Ale

xand

ra N

olte

, Ges

ine

Mar

wed

el, 2

003

2011/05/08

Page 36: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 36 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Models of computationconsidered in this course

Communication/local computations

Shared memory

Message passingSynchronous | Asynchronous

Undefined components

Plain text, use cases | (Message) sequence charts

Communicating finite state machines

StateCharts SDL

Data flow (Not useful) Kahn networks, SDF

Petri nets C/E nets, P/T nets, …

Discrete event (DE) model

VHDL, Verilog, SystemC, …

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

Von Neumann model C, C++, Java C, C++, Java with librariesCSP, ADA |

Page 37: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 37 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

StateCharts: recap of classical automata

Classical automata:

• Moore-automata:Y = (Z); Z+ = (X, Z)

• Mealy-automataY = (X, Z); Z+ = (X, Z)

• Moore-automata:Y = (Z); Z+ = (X, Z)

• Mealy-automataY = (X, Z); Z+ = (X, Z)

Internal state Zinput X output Y

Next state Z+ computed by function Output computed by function

Z0 Z1

Z2Z3

e=1

e=1

e=1

e=1

0 1

23

clockMoore- + Mealy automata=finite state machines (FSMs)

Moore- + Mealy automata=finite state machines (FSMs)

Page 38: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 38 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Timed automata

Timed automata = automata + models of time The variables model the logical clocks in the system, that are

initialized with zero when the system is started, and then increase synchronously with the same rate.

Clock constraints i.e. guards on edges are used to restrict the behavior of the automaton.A transition represented by an edge can be taken when the clocks values satisfy the guard labeled on the edge.

Additional invariants make sure, the transition is taken. Clocks may be reset to zero when a transition is taken [Bengtsson and

Yi, 2004].

Page 39: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 39 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Example: Answering machine

May take place, but does not have to

Ensures that transition takes place

Page 40: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 40 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Definitions

Let C: real-valued variables C representing clocks.

Let : finite alphabet of possible inputs.

Definition: A clock constraint is a conjunctive formula of atomic constraints of the formx ◦ n or x−y ◦ n for x, y ∈ C, ◦ {≤,<,=,>,≥} and ∈ n ∈N

Let B(C) be the set of clock constraints.

Definition: A timed automaton A is a tuple (S, s0,E, I) where

S is a finite set of states, s0 is the initial state,

E ⊆ S×B(C)× ×2C ×S is the set of edges, B(C): conjunctive condition, 2C: variables to be reset

I : S→B(C) is the set of invariants for each of the states B(C): invariant that must hold for state S

Page 41: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 41 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Definitions (2)

Let C: real-valued variables C representing clocks.Let : finite alphabet of possible inputs.Definition: A clock constraint is a conjunctive formula of atomic constraints of the form x ◦ n or x−y ◦ n for x, y ∈ C, ◦ {≤,<,=,>,≥} and ∈ n ∈NLet B(C) be the set of clock constraints.Definition: A timed automaton A is a tuple (S, s0,E, I) where S is a finite set of states, s0 is the initial state,E ⊆ S×B(C)× ×2C ×S is the set of edges, B(C): conjunctive condition, 2C: variables to be reset I : S→B(C) is the set of invariants for each of the states, B(C): invariant that must hold for state S

Page 42: Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra

- 42 -technische universitätdortmund

fakultät für informatik

P.Marwedel, Informatik 12, 2011

Summary

Motivation for non-von Neumann models

Support for early design phases

• Text

• Use cases

• (Message) sequence charts

Automata models

• Timed automata