380 likes | 517 Vues
Modelling DEVS applications. The CD++ tool http://cell-devs.sce.carleton.ca/ http://www.sce.carleton.ca/faculty/wainer/CD++BuilderSetup.exe http://www.sce.carleton.ca/faculty/wainer/setupCDpp.exe. Review of the DEVS formalism.
E N D
Modelling DEVS applications The CD++ tool http://cell-devs.sce.carleton.ca/ http://www.sce.carleton.ca/faculty/wainer/CD++BuilderSetup.exe http://www.sce.carleton.ca/faculty/wainer/setupCDpp.exe
Review of the DEVS formalism • Atomic: lowest level model, contains structural dynamics -- model level modularity • Coupled: composed of one or more atomic and/or coupled models -- hierarchical construction Elements of an atomic model: • input ports • output ports • state variables • state transition functions • output function • time advance function Elements of coupled model: • Components • Couplings • Internal Couplings • External Input Couplings • External Output Couplings
DEVS graphs • Algorithmic languages • State-based languages • DEVS graph • Node : sequential state • Arc : (XY{S}) ta(S) Internal transition External transition out ! y=(s0) Internal Transition (i) ta(s0) (ii) out = (s0) , int(s0)=s1 External Transition ext(s0, t, (x,in))=s2 in ? x,t out ! (s0)
DEVS graphs definition [modelname] atomic or coupled model name I/O ports: in : inport1 inport2 ... out : outport1 outport2 ... Internal transitions: int:source destination [outport!value]* ( { (action;)* } ) (Action: complex function to generate an output). External transitions : ext : source destination EXPRESSION ( { (action;)* } )? value
DEVS graphs definition TL=inf TL=100 s TL=inf • States (bubbles) • Internal transitions (dotted lines) • Output_port!output_value • External transitions (full lines) • Input_port?input_value • I/O ports
DEVS graphs analytical specification [myAtomic] in: Port1 PortY out: PortX state: Start Process Finish int: Process Finish PortX!1 ext: Start Process Value(Port1)?0 ext: Finish Start Value(PortY)?1 Start: 0:0:10:0 Process: 0:0:10:0 Finish: 0:0:10:0
CD++ (1997/98) • Basic tool following DEVS formalism. • Extension to include Cell-DEVS models. • High level specification language.
Autonomous Reconnaissance Vehicle • Radar Controller Atomic model
Autonomous Reconnaissance Vehicle • Movement Controller
CD++ programming services • holdIn(state, time) • passivate() • timelast() • timenext() • sendOutput(time, port, value) • state() • distribution().get()
Adding new atomic models • Atomic model definitions • initFunction • externalFunction • outputFunction • internalFunction • Linking with the abstract simulator • registerNewAtomic
Implementing atomic models Generator model: description • Represents a generator of impulses represented by consecutive natural numbers. • Period between impulses defined by a random function using different distributions (Chi2, Gamma, Normal, etc.). Generator f(t) = ... out 0, 1, 2,...
Generator: conceptual definition Transition functions Atomic model Generator • External transition function: none (model does not include input ports) • Internal transition function: generates numbers according to a specified probability distribution. • Output function: sends following consecutive natural number through the out port. ext int Output Port : out 0, 1, 2,...
Generator model: header files class Generator:public Atomic { public: . . . protected: Model &initFunction() ; Model &externalFunction(const ExternalMessage &); Model &internalFunction(const InternalMessage &); Model &outputFunction(const InternalMessage&); private: int next; int initial; Port &out ; Distribution *distribution ; };
Generator: coding example CD++ - initFunction Model &initFunction(){ this->next = this->initial; this->holdIn(Atomic::active, Time::Zero) ; return *this ; } Programmed to have an Instantaneous internal trans.
Generator (cont.) CD++ - internalFunction Model &internalFunction(const InternalMessage &) { this->next++ ; Time t(fabs(this->distribution().get()) ) ; this->holdIn(active, t) ; return *this ; } Obtains the time value by computing a probabilistic function Reprogrammed for the following internal transition.
Generator (cont.) CD++ - outputFunction Model &outputFunction(const InternalMessage &msg) { this->sendOutput(msg.time(), this->out, this->next); return *this ; } The output value increments sequentially
Generator: stand-alone testing gen out CD++ - Coupling scheme [top] components : gen@Generator out : Myout Link : out@gen Myout [gen] distribution : normal mean : 2 deviation : 1 top Myout
Transducer model Description Jobs • It is in charge of computing the number of jobs finished in a given time unit. • It computes the usage ratio for the server (a CPU in this case). • It transfers the outputs with a given frequency. Transducer
Transducer model : conceptual definition DEVS Inputs arrived solved • The external transition function is in charge of record the jobs received and those finished. • The internal transition function should be activated in the following job burst. • The output function will send the metrics through output ports. Atomic Model Transducer ext int throughput cpuusage Outputs
Transducer: header files CD++ class Transducer: public Atomic { public: . . . protected: Model &initFunction(); Model &externalFunction(const ExternalMessage&); Model &internalFunction(const InternalMessage&); Model &outputFunction(const InternalMessage&); private: const Port &arrived, &solved ; Port &throughput, &cpuUsage ; Time frec, tUnit ; long procCount, cpuLoad ; JobsList unsolved ; };
Transducer: coding example CD++ - initFunction State variables initialization Model &initFunction() { cpuLoad = procCount = 0 ; unsolved.erase() ; this->holdIn( active, this->frequence() ) ; return *this ; } The results are sent with a predefined frequency.
Transducer (cont.) CD++ - externalFunction Model &externalFunction( const ExternalMessage &msg ) { Time dif = ( msg.time() - this->lastChange() ) ; cpuLoad += dif.asMsecs() * unsolved.size() if( msg.port() == arrived ) unsolved[ msg.value() ] = msg.time() ; if( msg.port() == solved ) { procCount ++ ; unsolved.erase( msg.value() ) ; } return *this ; } CPU load Record a non- finished job Update the number of tasks
Transducer (cont.) CD++ - internalFunction Model &internalFunction( const InternalMessage & ) { this->holdIn( active, this->frequence() ) ; return *this ; } Programmed to inform the results with a certain frequency
Transducer (cont.) CD++ - outputFunction Model &outputFunction( const InternalMessage &msg ) { long ms = msg.time().asMsecs() ; float t( ms / this->timeUnit().asMsecs() ) ; Time dif = ( msg.time() - this->lastChange() ) ; cpuLoad += dif.asMsecs() * unsolved.size() ) ; this->sendOutput( msg.time(),throughput,procCount/t ); this->sendOutput( msg.time(),cpuUsage, cpuLoad / ms ); return *this ; }
CPU model Description • A processor running individual tasks in a non preemptive fashion. • Execution time for each tasks defined by a probability distribution chosen by the user. CPU f(t) = ... in out 0, 1, 2,... 0, 1, 2,...
CPU: conceptual definition • External transition function starts the processing a task. Internal transition scheduled for the end of the job, defined at random. If model already processing a task, new one is discarded. • Internal transition function finishes processing the job, leaving the model in a passive state waiting for new jobs. • Output function sends the job id trhough the output port out. Atomic Model CPU ext int in out 0, 1, 2,... 0, 1, 2,...
CPU: header files CD++ class CPU : public Atomic { public: . . . protected: Model &initFunction() ; Model &externalFunction(const ExternalMessage&); Model &internalFunction(const InternalMessage &); Model &outputFunction(const InternalMessage&); private: int pid; Port &in, &out ; Distribution *distribution ; };
CPU: coding example CD++ - initFunction Model &initFunction() { this->passivate() ; return *this ; } Passive state kept while cpu waits for new external events in input ports.
CPU (Cont.) CD++ - externalFunction Model &externalFunction(const ExternalMessage &msg) { if( this->state() == passive ) { this->pid = static_cast<int>(msg.value()) ; Time t( fabs(this->distribution().get()) ) ; this->holdIn(active, t) ; } return *this ; } Process Id stored. Schedule internal transition at random using the chosen distribution.
CPU (Cont.) CD++ - internalFunction Model &internalFunction( const InternalMessage & ) { this->passivate() ; return *this ; } Task processing finished. Passivate waiting for the following request.
CPU (Cont.) CD++ - outputFunction Model &outputFunction( const InternalMessage &msg ) { this->sendOutput(msg.time(), this->out, this->pid); return *this ; } Send Process Id and time associated with end of processing for the present task.
CPU model testing top proc out in in out CD++ - Coupling specification [top] components : proc@CPU in : in out : out Link : in in@proc Link : out@proc out [proc] distribution : normal mean : 2 deviation : 1
Input events to test CD++ - External event file (.EV) Job Id 00:00:10:00 in 0 00:00:30:00 in 1 00:01:00:00 in 2 00:02:20:00 in 3 top proc Input port used in out Hh:mm:ss:ms in out
Log file CD++ - Simulation Mensaje I / 00:00:00:000 / Root(00) para top(01) Mensaje I / 00:00:00:000 / top(01) para proc(02) Mensaje D / 00:00:00:000 / proc(02) / ... para top(01) Mensaje D / 00:00:00:000 / top(01) / ... para Root(00) Mensaje X / 00:00:10:000 / Root(00) / in / 0.000 para top(01) Mensaje X / 00:00:10:000 / top(01) / in / 0.000 para proc(02) Mensaje D / 00:00:10:000 / proc(02) / 00:00:01:348 para top(01) Mensaje D / 00:00:10:000 / top(01) / 00:00:01:348 para Root(00) Mensaje * / 00:00:11:348 / Root(00) para top(01) Mensaje * / 00:00:11:348 / top(01) para proc(02) Mensaje Y / 00:00:11:348 / proc(02) / out / 0.000 para top(01) Mensaje D / 00:00:11:348 / proc(02) / ... para top(01) Mensaje Y / 00:00:11:348 / top(01) / out / 0.000 para Root(00) Mensaje D / 00:00:11:348 / top(01) / ... para Root(00) Mensaje X / 00:00:30:000 / Root(00) / in / 1.000 para top(01) Mensaje X / 00:00:30:000 / top(01) / in / 1.000 para proc(02) Mensaje D / 00:00:30:000 / proc(02) / 00:00:03:485 para top(01)
Output file CD++ - Output file Job Id 00:00:11:348 out 0 00:00:33:485 out 1 00:01:00:328 out 2 00:02:21:094 out 3 Output Port Hh:mm:ss:ms