Modeling, Simulation, And Design Of Concurrent Real-Time .

2y ago
40 Views
2 Downloads
7.18 MB
52 Pages
Last View : 1d ago
Last Download : 3m ago
Upload by : Camille Dion
Transcription

Modeling, Simulation, and Design ofConcurrent Real-Time EmbeddedSystems Using PtolemyEdward A. LeeRobert S. Pepper Distinguished ProfessorEECS DepartmentUC BerkeleyPtutorialEECS 249, Sept. 13, 2012The Ptolemy ProjectThe Ptolemy project studies modeling, simulation,and design of concurrent, real-time, embeddedsystems. The focus is on assembly of concurrentcomponents. The key underlying principle in theproject is the use of well-defined models ofcomputation that govern the interaction betweencomponents. A major problem area beingaddressed is the use of heterogeneous mixtures ofmodels of computation. A software system calledPtolemy II is being constructed in Java, and servesas the principal laboratory for experimentation.Lee, Berkeley 2l 1

History:The project wasThe Ptolemy Projectstarted in 1990, thoughDemographics, 2012its mission and focushas evolvedSponsors:considerably. An opensource, extensible Governmentsoftware frameworkl National Science Foundation(Ptolemy II) constitutesl Army Research Labthe principall DARPA (MuSyC: Multiscale Systems Center)experimentall Air Force Research Lablaboratory. IndustryStaffing:l Bosch 1 professorl National Instruments 9 graduate studentsl SRC (MuSyC: Multiscale Systems Center) 3 postdocsl Thales 2 research staffl Toyota several visitorsLee, Berkeley 3Contributors to Ptolemy IIPrincipal Authors Christopher Brooks Dai Bui Chamberlain Fong John Davis, II Patricia Derler Thomas Huining Feng Mudit Goel Rowland Johnson Bilung Lee Edward Lee Ben Lickly Jie Liu Xiaojun Liu Lukito Muliadi Stephen Neuendorffer John Reekie Neil Smyth Jeff Tsay Yuhong Xiong Haiyang Zheng Gang ZhouOther Contributors Jim Armstrong Vincent Arnould Kyungmin Bae Philip Baldwin Chad Berkley Frederic Boulanger Raymond Cardillo Jannette Cardoso Adam Cataldo Christine Cavanessians Chris Chang Albert Chen Chihong Patrick Cheng Elaine Cheong Colin Cochran Brieuc Desoutter Pedro Domecq William Douglas Johan Eker Thomas Huining Feng Tobin Fricke Teale Fristoe Shanna-Shaye Forbes Hauke Fuhrmann Geroncio Galicia Ben Horowitz Heloise HseEfrat JaegerJörn JanneckZoltan KemenczyBart KienhuisChristoph Meyer KirschSanjeev KohliVinay KrishnanRobert KroegerDaniel Lázaro CuadradoDavid LeeMan-kit (Jackie) LeungMichael LeungJohn LiIsaac LiuAndrew MihalEleftherios MatsikoudisAleksandar NecakovMike Kofi OkyereSarah PackmanShankar RaoBert RodiersRakesh ReddyAdriana RicchiutiSonia SachsIsmael M. SarmientoMichael Shilman Sean SimmonsMandeep SinghMiro SpoenemannPeter N. SteinmetzDick StevensMary StewartNed StoffelManda SutijonoStavros TripakisNeil TurnerGuillaume VibertKees VissersBrian K. VogelYuke WangXavier WarzeeScott WeberPaul WhitakerWinthrop WilliamsEd WillinkMichael WirthlinMichael WetterWilliam WuXiaowen XinPaul YangJames YehNick ZamoraCharlie ZhongLee, Berkeley 4l 2

References Ptolemy project home page:http://ptolemy.org Latest release:http://ptolemy.org/ptolemyII/ptIIlatest/ Latest version in the SVN al/Lee, Berkeley 5ForthcomingBookChapters1. Heterogeneous Modeling2. Building Graphical Models3. Dataflow4. Process Networks and Rendezvous5. Synchronous/Reactive Models6. Finite State Machines7. Discrete Event Models8. Modal Models9. Continuous Time Models10. Cyber-Physical SystemsAppendicesA. ExpressionsB. Signal DisplayC. The Type SystemD. Creating Web PagesLee, Berkeley 6l 3

Getting More Information: DocumentationVolume 1:User-OrientedVolume 2:Developer-OrientedVolume 3:Researcher-OrientedTutorial information: http://ptolemy/conferences/07/tutorial.htmLee, Berkeley 7Outline Building modelsModels of computation (MoCs)Creating actorsCreating directorsSoftware architectureMiscellaneous topicsLee, Berkeley 9l 4

Building Models – Hello WorldLee, Berkeley 10Building more interesting modelsDE Director specifies that thiswill be a discrete-event modelLee, Berkeley 11l 5

Building more interesting modelsModel of regularly spacedevents (e.g., a clock signal).Lee, Berkeley 12Building more interesting modelsModel of irregularly spacedevents (e.g., a failure event).Lee, Berkeley 13l 6

Building more interesting modelsModel of a subsystem thatchanges modes at random(event-triggered) timesLee, Berkeley 14Building more interesting modelsModel of an observersubsystemLee, Berkeley 15l 7

Building more interesting modelsEvents on the two inputstreams must be seen intime stamp order.Lee, Berkeley 16Ptolemy uses Superdense TimeDiscrete event signalscan have a sequence ofdistinct events at a timeinstant.Lee, Berkeley 17l 8

This is a Component TechnologyModel of a subsystem givenas an imperative program.Lee, Berkeley 18This is a Component TechnologyModel of a subsystem givenas a state machine.Lee, Berkeley 19l 9

This is a Component TechnologyModel of a subsystem givenas a modal model.More types of components: Modal models Functional expressions. Submodels in DE Submodels in other MoCsLee, Berkeley 20ContinuousTimeExampleHybrid systems are particularlyclean with superdense time. Theabove signal has multiple values atthe times of the transitions.Lee, Berkeley 21l 10

Superdense Time forContinuous-Time SignalsAt each tag, the signal has exactly one value. At each time point, thesignal has an infinite number of values. The red arrows indicate valuechanges between tags, which correspond to discontinuities. Signals arepiecewise continuous, in a well-defined technical sense.22Lee, Berkeley 22Contrast with Simulink/StateflowIn Simulink, a signal can only have one value at a giventime. Hence Simulink introduces solver-dependent behavior.The simulator engine of Simulink introducesa non-zero delay to consecutive transitions.Transient StatesLee, Berkeley 23l 11

Outline Building modelsModels of computation (MoCs)Creating actorsCreating directorsSoftware architectureMiscellaneous topicsLee, Berkeley 24MoC Example 1:Discrete Events (DE)DE Director implementstimed semantics using anevent queueIn DE, actors send timestamped events to oneanother, and events areprocessed in chronologicalorder.Event sourceSignalput() method inserts a tokeninto the event queue.Time lineLee, Berkeley 25l 12

MoC Example 2:Kahn Process Networks (PN)actor threadsignal streamIn PN, everyactor runs ina thread,with blockingreads ofinput portsand nonblockingwrites tooutputs.reads blockwrites don’tKahn, MacQueen, 1977Lee, Berkeley 26MoC Example 3:Synchronous Dataflow (SDF)In SDF, actors “fire,” and in each firing, consume afixed number of tokens from the input streams, andproduce a fixed number of tokens on the outputstreams.SDF is a special case of PNwhere deadlock andboundedness are decidable. It iswell suited to static schedulingand code generation. It can alsobe automatically parallelized.Lee, Berkeley 27l 13

MoC Example 4:Synchronous/Reactive (SR)At each tick of a global “clock,” everysignal has a value or is absent.Like SDF, SR is decidable and suitable forcode generation. It is harder to parallelizethan SDF, however.SR languages: Esterel, SyncCharts, Lustre,SCADE, Signal.Lee, Berkeley 28MoC Example 5:RendezvousIn Rendezvous, everyactor runs in a thread,with blocking reads ofinput ports and blockingwrites to outputs. Everycommunication is a(possibly multi-way)rendezvous.writes blockCSP (Hoare), SCCS (Milner),Reo (Arbab)actor threadreads blockLee, Berkeley 29l 14

MoC Example 6:Continuous Time (CT)In CT, actors operate oncontinuous-time and/ordiscrete-event signals. AnODE solver governs theexecution.Signal is acontinuous-timefunction.Director includes an ODE solver.Lee, Berkeley 30Ptolemy II Hierarchy Supports HeterogeneityConcurrent actors governed by one model ofcomputation (e.g., Discrete Events).Modal behavior given in another MoC.Detailed dynamics givenin a third MoC (e.g.Continuous Time)This requires a composable abstract semantics.Lee, Berkeley 31l 15

Outline Building modelsModels of computation (MoCs)Creating actorsCreating directorsSoftware architectureMiscellaneous topicsLee, Berkeley 34ActorsLee, Berkeley 35l 16

Ptolemy Components are Actors and ObjectsThe established: Object-oriented:class nameWhat flows throughan object issequential controldatamethodscallreturnThings happen to objectsThe alternative: Actor oriented:actor namedata (state)parametersportsInput dataActors make things happenWhat flows throughan object isevolving dataOutput dataLee, Berkeley 36Actors Ptolemy has a library of predefined actorsJava classes that implement the “executable” interfaceLee, Berkeley 37l 17

Actors can be defined in Java, C, Python, Cal,and MATLABCal, developed by Joern Janneck (nowat Lund) is a language for definingactors that are analyzable for keybehavioral properties.Lee, Berkeley 38Most Actors are Written in JavaLee, Berkeley 39l 18

Simple String Manipulation Actor in Javapublic class Ptolemnizer extends TypedAtomicActor {public Ptolemnizer(CompositeEntity container, String name)throws IllegalActionException, NameDuplicationException {super(container, name);input new TypedIOPort(this, t.setInput(true);output new TypedIOPort(this, tput.setOutput(true);}public TypedIOPort input;public TypedIOPort output;public void fire() throws IllegalActionException {if (input.hasToken(0)) {Token token input.get(0);String result ((StringToken)token).stringValue();result result.replaceAll("t", "pt");output.send(0, new StringToken(result));}}}Lee, Berkeley 40Object Model forExecutable r fire() initialize() postfire() : boolean prefire() : boolean preinitialize() stopFire() terminate() wrapup() getDirector() : Director getExecutiveDirector() : Director getManager() : Manager inputPortList() : List newReceiver() : Receiver outputPortList() : ctorDirectorAtomicActorLee, Berkeley 41l 19

Definition of the Register Actor (Sketch)class Register extends TypedAtomicActor {private Object state;boolean prefire() {Can theif (trigger is known) { return true; }actor fire?}void fire() {if (trigger is present) {send state to output;React to}else {triggerdata input portassert output is absent;input.}}void postfire() {Read theif (trigger is present) {data inputstate value read from data input;and update}the state.}triggerinputportLee, Berkeley 42Outline Building modelsModels of computation (MoCs)Creating actorsCreating directorsSoftware architectureMiscellaneous topicsLee, Berkeley 43l 20

DirectorsLee, Berkeley 44Object Model (Simplified) forCommunication oomExceptionthrowsthrowsNoTokenException get() : Token getContainer() : IOPort hasRoom() : boolean hasToken() : boolean put(t : Token) setContainer(port : ceiverPNReceiver1.1FIFOQueueArrayFIFOQueueLee, Berkeley 45l 21

Object-Oriented Approach to AchievingBehavioral Polymorphism«Interface»Receiver get() : Token getContainer() : IOPort hasRoom() : boolean hasToken() : boolean put(t : Token) setContainer(port : IOPort)These polymorphic methodsimplement the communicationsemantics of a domain in PtolemyII. The receiver instance used incommunication is supplied by thedirector, not by the component.DirectorIOPortRecall: Behavioral polymorphismis the idea that components can bedefined to operate with multiplemodels of computation and multiplemiddleware frameworks.consumeractorproduceractorReceiverLee, Berkeley 46Extension ExerciseBuild a director that subclasses PNDirector to allow portsto alter the “blocking read” behavior. In particular, if a porthas a parameter named “tellTheTruth” then the receiversthat your director creates should “tell the truth” whenhasToken() is called. That is, instead of always returningtrue, they should return true only if there is a token in thereceiver.Parameterizing the behavior of a receiver is a simple formof communication refinement, a key principle in, forexample, Metropolis.Lee, Berkeley 47l 22

Implementation of theNondogmaticPNDirectorpackage doc.tutorial;import public class NondogmaticPNDirector extends PNDirector {public NondogmaticPNDirector(CompositeEntity container, String name)throws IllegalActionException, NameDuplicationException {super(container, name);}public Receiver newReceiver() {return new FlexibleReceiver();}public class FlexibleReceiver extends PNQueueReceiver {public boolean hasToken() {IOPort port getContainer();Attribute attribute port.getAttribute("tellTheTruth");if (attribute null) {return super.hasToken();}// Tell the truth.return queue.size() 0;}}}Lee, Berkeley 48With NondogmaticPNDirector:Using ItWith PNDirector:Lee, Berkeley 49l 23

Designing a Sensible MoC is not so easy!Consider Kahn Process Networks (PN) A set of components called actors.Each representing a sequential procedure.Where steps in these procedures receive or send messagesto other actors (or perform local operations).Messages are communicated asynchronously withunbounded buffers.A procedure can always send a message. It does not needto wait for the recipient to be ready to receive.Messages are delivered reliably and in order.When a procedure attempts to receive a message, thatattempt blocks the procedure until a message is available.Lee, Berkeley 50Coarse History Semantics given by Gilles Kahn in 1974. More limited form given by Kahn and MacQueen in 1977. Generalizations to nondeterministic systems Bounded memory execution given by Parks in 1995.l l l l Blocking reads and nonblocking writes.Kosinski [1978], Stark [1980s], Solves an undecidable problem.Debate over validity of this policy, Geilen and Basten 2003.l Fixed points of continuous and monotonic functionsRelationship between denotational and operational semantics.Many related models intertwined.l Actors (Hewitt, Agha), CSP (Hoare), CCS (Milner), Interaction (Wegner),Streams (Broy, ), Dataflow (Dennis, Arvind, ).Lee, Berkeley 51l 24

DataflowDataflow models are similar to PN models exceptthat actor behavior is given in terms of discrete“firings” rather than processes. A firing occurs inresponse to inputs.Lee, Berkeley 54A few variants of dataflow MoCs Computation graphs [Karp and Miller, 1966]Static dataflow [Dennis, 1974]Dynamic dataflow [Arvind, 1981]Structured dataflow [Matwin & Pietrzykowski 1985]K-bounded loops [Culler, 1986]Synchronous dataflow [Lee & Messerschmitt, 1986]Structured dataflow and LabVIEW [Kodosky, 1986]PGM: Processing Graph Method [Kaplan, 1987]Synchronous languages [Lustre, Signal, 1980’s]Well-behaved dataflow [Gao, 1992]Boolean dataflow [Buck and Lee, 1993]Multidimensional SDF [Lee, 1993]Cyclo-static dataflow [Lauwereins, 1994]Integer dataflow [Buck, 1994]Bounded dynamic dataflow [Lee & Parks, 1995]Heterochronous dataflow [Girault, Lee, & Lee, 1997]Scenarios [Geilen & Stuijk, 2010] Lee, Berkeley 55l 25

Some Subtleties Termination, deadlock, and livelock (halting)Bounding the buffers.FairnessParallelismData structures and shared dataDeterminismReal-time constraintsSyntaxLee, Berkeley 56Question 1:Is “Fair” Scheduling a Good Idea?In the following model, what happens if everyactor is given an equal opportunity to run?Lee, Berkeley 57l 26

Question 2:Is “Data-Driven” Execution a Good Idea?In the following model, if actors are allowed torun when they have input data on connectedinputs, what will happen?Lee, Berkeley 58Question 3:When are Outputs Required?Is the execution shown for the following modelthe “right” execution?Lee, Berkeley 59l 27

Question 4: Is “Demand-Driven”Execution a Good Idea?In the following model, if actors are allowed torun when another actor requires their outputs,what will happen?Lee, Berkeley 60Question 5: What is the “Correct”Execution of This Program?Lee, Berkeley 61l 28

Question 6: What is the Correct Behaviorof this Program?Lee, Berkeley 62Naïve Schedulers Fail FairDemand drivenData drivenMost mixtures of demand and data drivenIf people insist on building their own MoCs from scratch,what will keep them from repeating the mistakes thathave been made by top experts in the field?Lee, Berkeley 63l 29

Programmers should not have to figure outhow to solve these problems!Undecidability and Turing Completeness [Buck 93]Given the following four actors and Boolean streams, youcan construct a universal Turing machine:Hence, the following questions are undecidable:l l Will a model deadlock (terminate)?Can a model be executed with bounded buffers?Lee, Berkeley 64Question 7:How to support nondeterminism?Merging of streams is needed for someapplications. Does this require fairness?What does fairness mean?Lee, Berkeley 65l 30

These problems have been solved!Let’s not make programmers re-solvethem for every program.Library ofdirectorsProgram using actor-orientedcomponents and a PN MoCDirectors should bedesigned byexperts inlanguages andconcurrency, not byapplication modelbuilders.Lee, Berkeley 66The PN Director solves the aboveproblems by implementing a “usefulexecution”Define a correct execution to be any executionfor which after any finite time every signal is aprefix of the signal given by the (Kahn) leastfixed-point semantics.Define a useful execution to be a correctexecution that satisfies the following criteria:1.2.For every non-terminating model, after any finitetime, a useful execution will extend at least onestream in finite (additional) time.If a correct execution satisfying criterion (1) existsthat executes with bounded buffers, then a usefulexecution will execute with bounded buffers.Lee, Berkeley 67l 31

Our solution:Parks’ Strategy [Parks 95]This “solves” the undecidable problems:l l l l Start with an arbitrary bound on the capacity of all buffers.Execute as much as possible.If deadlock occurs and at least one actor is blocked on a write,increase the capacity of at least one buffer to unblock at least onewrite.Continue executing, repeatedly checking for deadlock.This delivers a useful execution (possibly taking infinitetime to tell you whether a model deadlocks and howmuch buffer memory it requires).Lee, Berkeley 68There are many more subtleties!We need disciplined concurrent models ofcomputation, not arbitrarily flexible libraries.Some principles: Do not use nondeterministic programming models toaccomplish deterministic ends. Use concurrency models that have analogies in thephysical world (actors, not threads). Provide these in the form of models of computation(MoCs) with well-developed semantics and tools. Use specialized MoCs to exploit semantic properties(avoid excess generality). Leave the choice of shared memory or messagepassing to the compiler.Lee, Berkeley 69l 32

Extension Exercise 2Build a director that subclasses Director and allowsdifferent receiver classes to be used on differentconnections. This is a form of what we call “amorphousheterogeneity.”We will not do this today.See PTII/doc/tutorial/domainsLee, Berkeley 70Extension Exercise 3Build a director that fires actors in left-to-right order, asthey are laid out on the screen.We will not do this today.See PTII/doc/tutorial/domainsLee, Berkeley 73l 33

Outline Building modelsModels of computation (MoCs)Creating actorsCreating directorsSoftware architectureMiscellaneous topicsLee, Berkeley 75Ptolemy II Software ArchitectureBuilt for ExtensibilitySRPtolemy II packageshave carefullyconstructeddependencies elSDFuousnitnoCDataLee, Berkeley 76l 34

Hierarchy - Composite ComponentsRelationdanglingPortEntityopaque PortPorttransparent or opaqueCompositeEntity

Modeling, Simulation, and Design of Concurrent Real-Time Embedded Systems Using Ptolemy Edward A. Lee Robert S. Pepper Distinguished Professor EECS Department UC Berkeley Ptutorial EECS 249, Sept. 13, 2012 Lee, Berkeley 2 The Ptolemy Project The Ptolemy project studies modeling, simulation, and design of concurrent, real-time, embedded systems.

Related Documents:

1 Simulation Modeling 1 2 Generating Randomness in Simulation 17 3 Spreadsheet Simulation 63 4 Introduction to Simulation in Arena 97 5 Basic Process Modeling 163 6 Modeling Randomness in Simulation 233 7 Analyzing Simulation Output 299 8 Modeling Queuing and Inventory Systems 393 9 Entity Movement and Material-Handling Constructs 489

ior and achieving simulation of the behavior in real time. Categories and Subject Descriptors: I.6.5 [Simulation and Modeling]: Model Development— Modeling methodologies General Terms: Simulation, Graphics, Dust Additional Key Words and Phrases: Physically-based Modeling, Real-time Simulation, Vehicle, Particle Systems, Computational Fluid .

Modeling and Arena MANUEL D. ROSSETTI University of Arkansas WILEY John Wiley & Sons, Inc. Table of Contents 1 Simulation Modeling 1.1 Why Simulate? 2 1.2 Types of Computer Simulation 3 1.3 How the Discrete-Event Clock Works 5 1.4 Randomness in Simulation 9 1.5 Simulation Languages 9

CS445: Basic Simulation Modeling!!! Travis Desell!! Averill M. Law, Simulation Modeling & Analysis, Chapter 1. What is Simulation? A simulation uses a computer (or computers) to evaluate a model numerically, and data are gathered in order to estimate the desired true characteristics of the model. 1.

Simulation modeling methodology research and simulation analysis methodology research have evolved into two near-ly separate fields. In this paper, ways are shown how simu-lation might benefit from modeling and analysis becoming more closely integrated. The thesis of this paper is that si-mulation analysis and simulation modeling methodologies,

Modeling and simulation modeling . 5 Formulas that are good for expressing static dependencies between variables, fail to work when it comes to describing the systems with dynamic behavior. This is the time for another modeling technology that is specifically designed for analyzing dynamic systems, namely for . simulation modeling. The .

14 D Unit 5.1 Geometric Relationships - Forms and Shapes 15 C Unit 6.4 Modeling - Mathematical 16 B Unit 6.5 Modeling - Computer 17 A Unit 6.1 Modeling - Conceptual 18 D Unit 6.5 Modeling - Computer 19 C Unit 6.5 Modeling - Computer 20 B Unit 6.1 Modeling - Conceptual 21 D Unit 6.3 Modeling - Physical 22 A Unit 6.5 Modeling - Computer

Simulation is a process of emulating real design behavior in a software environment. Simulation helps verify the functionality of a design by injecting stimulus and observing the design outputs. This chapter provides an overview of the simulation process, and the simulation options in the Vivado Design Suite. The process of simulation includes: