embedded software from concurrent component...

18
ACM SIGPLAN 2001 Workshop on Languages, Compilers, and Tools for Embedded Systems (LCTES'2001) Jun 22-23, 2001, Snowbird, Utah, USA Embedded Software from Concurrent Component Models Edward A. Lee UC Berkeley with Shuvra Bhattacharyya, Johan Eker, Christopher Hylands, Jie Liu, Xiaojun Liu, Steve Neuendorffer, Jeff Tsay, and Yuhong Xiong E. A. Lee, Berkeley, 2 View of SW Architecture: Actors with Ports and Attributes Port Port Actor Actor Link Relation Actor Port connection connection connection Link Link Attributes Attributes Attributes Model of Computation: • Messaging schema • Flow of control • Concurrency Examples: • Time triggered • Process networks • Discrete-event systems • Dataflow systems • Publish & subscribe Key idea: The model of computation is part of the framework within which components are embedded not part of the components themselves.

Upload: others

Post on 03-Jul-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

1

ACM SIGPLAN 2001 Workshop on Languages, Compilers, and Tools forEmbedded Systems (LCTES'2001) Jun 22-23, 2001, Snowbird, Utah, USA

Embedded Software fromConcurrent Component Models

Edward A. LeeUC Berkeley

withShuvra Bhattacharyya, Johan Eker,

Christopher Hylands, Jie Liu, Xiaojun Liu,Steve Neuendorffer, Jeff Tsay, and Yuhong Xiong

E. A. Lee, Berkeley, 2

View of SW Architecture:Actors with Ports and Attributes

PortPort

Actor ActorLink

Relation

ActorPort

connection

connection conn

ectio

n

Link

Link

Attributes Attributes

Attributes

Model of Computation:

• Messaging schema• Flow of control• Concurrency

Examples:

• Time triggered• Process networks• Discrete-event systems• Dataflow systems• Publish & subscribe

Key idea: The model of computation is part of the frameworkwithin which components are embedded not part of thecomponents themselves.

Page 2: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

2

E. A. Lee, Berkeley, 3

Actor View of Producer/ConsumerComponents

Models of Computation:

• continuous-time• dataflow• rendezvous• discrete events• synchronous• time-driven• publish/subscribe•…

Actor

IOPort IORelation

P2P1

E1

E2

send(0,t) receiver.put(t) get(0)

token tR1

Basic Transport:

Receiver(inside port)

E. A. Lee, Berkeley, 4

Examples of Actors+PortsSoftware Architectures

Simulink (The MathWorks)Labview (National Instruments)OCP, open control platform (Boeing)SPW, signal processing worksystem (Cadence)System studio (Synopsys)ROOM, real-time object-oriented modeling (Rational)Port-based objects (U of Maryland)I/O automata (MIT)VHDL, Verilog, SystemC (Various)Polis & Metropolis (UC Berkeley)Ptolemy & Ptolemy II (UC Berkeley)…

Page 3: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

3

E. A. Lee, Berkeley, 5

What a Program Looks Like

Ptolemy II model of an embedded control system and the systembeing controlled. This is a hierarchical, heterogeneous modelthat combines four models of computation.

Model by Johan Eker

E. A. Lee, Berkeley, 6

Contrast with Object OrientationCall/return imperative semantics

band-aids: futures, proxies, monitorsPoorly models the environment

which does not have call/return semanticsConcurrency is via ad-hoc calling conventionsNothing at all to say about time

ComponentEntityCompositeEntity

AtomicActor

CompositeActor

0..10..n

«Interface»Actor

+getDirector() : Director+getExecutiveDirector() : Director+getManager() : Manager+inputPortList() : List+newReceiver() : Receiver+outputPortList() : List

«Interface»Executable

+fire()+initialize()+postfire() : boolean+prefire() : boolean+preinitialize()+stopFire()+terminate()+wrapup()

Director

Object modelingemphasizes inheritanceand procedural interfaces.

Actor modelingemphasizes concurrencyand communicationabstractions.

Page 4: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

4

E. A. Lee, Berkeley, 7

Hierarchy and Heterogeneity 1Modal Models Model by Johan Eker

E. A. Lee, Berkeley, 8

Domains

Each level of the hierarchy may have its own“laws of physics”

communication semanticsflow of control constraints

Domaina region of the universe where a certain set of “laws ofphysics” appliesRealizes a “model of computation”

Page 5: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

5

E. A. Lee, Berkeley, 9

A Problem: Compiling these Models:“Code generation”

E. A. Lee, Berkeley, 10

Outline of our ApproachDomain semantics defines communication, flow of control

Ptolemy II model

scheduler

Schedule: - fire Gaussian0 - fire Ramp1 - fire Sine2 - fire AddSubtract5 - fire SequenceScope10

parser

method call

if

block

method call

block

for (int i = 0; i < plus.getWidth(); i++) {

if (plus.hasToken(i)) {

if (sum == null) {

sum = plus.get(i);

} else {

sum = sum.add(plus.get(i));

}

}

}

All actors aregiven in Java,then translatedto embeddedJava, C, VHDL,etc. target codeabstract syntax tree

Jeff Tsay,Christopher Hylands,Steve Neuendorffer

Page 6: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

6

E. A. Lee, Berkeley, 11

Division of Responsibility

Domain semantics definesflow of control across actorscommunication protocols between actors

Actors define:functionality of components

Hierarchy:Code generation at a level of the hierarchy produces anew actor definition

Multiple domains may be used in the same model

E. A. Lee, Berkeley, 12

Software Basis

Build on:First version on Titanium (UC Berkeley)Second version on Soot (McGill)

Targeting:Simulation accelerationEmbedded software synthesisConfigurable hardware synthesis

Page 7: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

7

E. A. Lee, Berkeley, 13

Our Generator Approach

Actor libraries are built and maintained in Javamore maintainable, easier to writepolymorphic libraries are rich and small

Java + Domain translates to target languageconcurrent and imperative semantics

Efficiency gotten through code transformationsspecialization of polymorphic typescode substitution using domain semanticsremoval of unnecessary code

E. A. Lee, Berkeley, 14

Code transformations (data types)// Original actor source

Token t1 = in.get(0);

Token t2 = in.get(1);

out.send(0, t1.multiply(t2));

specialization of Token declarations

// With specialized types

IntMatrixToken t1 = in.get(0);

IntMatrixToken t2 = in.get(1);

out.send(0, t1.multiply(t2));

The Ptolemy II type systemsupports polymorphic actorswith propagating typeconstraints and static typeresolution. The resolved typescan be used in optimizedgenerated code.

See Jeff Tsay, A Code Generation Framework for Ptolemy II

Page 8: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

8

E. A. Lee, Berkeley, 15

Type System

Output of typegeneral - pureevent with no value

Input of generaltype - anything willdo

Polymorphic output- type depends onthe parametersdouble

general

int

general

double

Polymorphic actoruses late binding inJava to determineimplementation ofaddition.

Opaque port -types propagatedfrom inside

double

Lossless runtimetype conversion

Type system by Yuhong Xiong

E. A. Lee, Berkeley, 16

Type System

Extensible type latticeUnification infrastructure

Finds a least fixed pointComposite types

records, arrays, matricesHigher-order types plannedExperiments with dependent types

encoding domain constraints

Page 9: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

9

E. A. Lee, Berkeley, 17

Code transformations (domains)

transformation using domain semantics

// With specialized types

IntMatrixToken t1 = in.get(0);

IntMatrixToken t2 = in.get(1);

out.send(0, t1.multiply(t2));

Domain-polymorphic code isreplaced with specializedcode.

// Extended Java with specialized communication

int[][] t1 = _inbuf[0][_inOffset = (_inOffset+1)%5];

int[][] t2 = _inbuf[1][_inOffset = (_inOffset+1)%5];

_outbuf[_outOffset = (_outOffset+1)%8] = t1 * t2;

See Jeff Tsay, A Code Generation Framework for Ptolemy II

E. A. Lee, Berkeley, 18

Synchronous Dataflow (SDF) Domain Balance equations (one for each channel):

FAN = FBM Scheduled statically Decidable resource requirements

Available optimizations:eliminate checks for input datastatically allocate communication buffersstatically sequence actor invocations (and inline?)

send(0,t) get(0)

token tN MA

B

Page 10: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

10

E. A. Lee, Berkeley, 19

Synchronous/Reactive DomainA discrete model of time progresses as asequence of “ticks.” At a tick, the signals aredefined by a fixed point equation:

A

CB

x

yz

xyz

ff zf x y

A t

B t

C t

LNMMMOQPPPL

NMMM

O

QPPP

,

,

,

( )( )( , )

1

Available optimizations:• Statically sequence fixed-point iteration• Communication via registers

E. A. Lee, Berkeley, 20

Other Domains with Useful Propertiesfor Code Generation

Strong static analyzabilityGiotto (time triggered)Finite state machinesDiscrete time

Good for hardware descriptionsDiscrete eventsProcess networksContinuous time (analog hardware)

Page 11: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

11

E. A. Lee, Berkeley, 21

Hierarchical Heterogeneity

P6 P3P2 P5P1E1

E2

E4

E0

M: Manager

D1: local director

D2: local director

P4 P7

E3

E5

OpaqueComposite

Actor

TransparentComposite

Actor

Ptolemy II composes domains hierarchically,where components in a model can be refinedinto subcomponents where the componentinteractions follow distinct semantics.

E. A. Lee, Berkeley, 22

Hierarchical Code Generation

atomic actor definition

atomic actor definitionatomic actor definition

atomic actor definition

Page 12: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

12

E. A. Lee, Berkeley, 23

Basic Object Model forExecutable Components

ComponentEntityCompositeEntity

AtomicActor

CompositeActor

0..10..n

«Interface»Actor

+getDirector() : Director+getExecutiveDirector() : Director+getManager() : Manager+inputPortList() : List+newReceiver() : Receiver+outputPortList() : List

«Interface»Executable

+fire()+initialize()+postfire() : boolean+prefire() : boolean+preinitialize()+stopFire()+terminate()+wrapup()

Director

E. A. Lee, Berkeley, 24

Abstract Semantics –How Components Interactflow of control

InitializationExecutionFinalization

communicationStructure of signalsSend/receive protocols

Page 13: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

13

E. A. Lee, Berkeley, 25

Abstract Semantics –How Components Interactflow of control

InitializationExecutionFinalization

communicationStructure of signalsSend/receive protocols

preinitialize()declare static information, liketype constraints, schedulingproperties, temporalproperties, structuralelaboration

initialize()initialize variables

E. A. Lee, Berkeley, 26

Abstract Semantics –How Components Interactflow of control

InitializationExecutionFinalization

communicationStructure of signalsSend/receive protocols

iterate()

Page 14: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

14

E. A. Lee, Berkeley, 27

Abstract Semantics –How Components Interactflow of control

InitializationExecutionFinalization

communicationStructure of signalsSend/receive protocols

iterate()prefire()fire()postfire()

stopFire()

E. A. Lee, Berkeley, 28

The Key Action MethodsPrefire()

obtain required resourcesmay read inputsmay start computationsreturns a boolean indicating readiness

Fire()produces results

Postfire()commits state updates (transactional)

StopFire()request premature termination

All of these are atomic (non-preemptible)

Page 15: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

15

E. A. Lee, Berkeley, 29

BenefitsComposable semantics

arbitrarily deep hierarchiesheterogeneous hierarchies

controller plant

actuatordynamics

sensor

task1

task2

TTA

TTA

Hierarchical, heterogeneous,system-level model

E. A. Lee, Berkeley, 30

This Abstract Semanticshas Worked For

Continuous-time modelsFinite state machinesDataflowDiscrete-event systemsSynchronous/reactive systemsTime-driven models (Giotto)…

We can even make it work for priority-drivenmultitasking (RTOS style)!

Hybrid systems

Page 16: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

16

E. A. Lee, Berkeley, 31

A Twist: Threaded ModelsThe Precise Mode Change Problem

How do you getthe processesto a quiescentstate to take amode change?

thread or process

thread or process

thread or process

Problem posed by Boeing

E. A. Lee, Berkeley, 32

HPM DomainHierarchical Preemptive Multitasking

Objective:support priority-driven preemptive schedulinguse atomic execution, to get composabilitysolve the precise mode change problemmake behavior (more) deterministic

Solution:Atomic execution when possibleFaçade to long-running processes when not

Split phase execution (read phase, write phase)

Domain by Jie Liu

Page 17: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

17

E. A. Lee, Berkeley, 33

Atomic Façade to Long-RunningComputations

Each componentdefines the interactionbetween the atomicfaçade and the long-running process.

There are several usefulpatterns:

allow task to completeenforce declared timing“anytime” computationtransactional

Declared time

OperationDispatcher

Atomic Facade

prefire()

readystart

priority-drivenmultitaskingrun other

atomic andnon-atomicoperations

fire()produceoutputs

Task

join

postfire()commitstatecontinue

produce outputs

read inputs

commit state

E. A. Lee, Berkeley, 34

Inter-domain example:Shared-resource controllers

plant1

plant2

computercontroller1

controller2

Model by Jie Liu

Page 18: Embedded Software from Concurrent Component Modelsptolemy.eecs.berkeley.edu/presentations/01/embedS... · Synchronous/Reactive Domain A discrete model of time progresses as a sequence

18

E. A. Lee, Berkeley, 35

ConclusionSystematic, principled, real-time, heterogeneous,hierarchical composition of:

Processes and/or threadsFinite automata (mode controllers)Other models of computation

Continuous-time modelsDataflow models…

Code generation

The key is the abstract semantics of Ptolemy II, whichdefines hierarchical heterogeneous composition of modelsof computation.

http://ptolemy.eecs.berkeley.edu