Access Point Event Simulator APES for Legacy Software

  • Slides: 28
Download presentation
Access Point Event Simulator (APES) for Legacy Software Systems (LESS) Stefan Resmerita Joint work

Access Point Event Simulator (APES) for Legacy Software Systems (LESS) Stefan Resmerita Joint work with Patricia Derler and Edward Lee February 17, 2009

Contents 1. 2. 3. 4. 5. Goals and motivation Approach Ptolemy II components Further

Contents 1. 2. 3. 4. 5. Goals and motivation Approach Ptolemy II components Further work Demos February 17, 2009 APES-LESS: Contents 2

Main Goals • Short-term: – Simulate (on a host computer) execution of embedded software

Main Goals • Short-term: – Simulate (on a host computer) execution of embedded software written in C for OSEK-compliant OS and given platform model – Achieve fast Software-in-the-Loop testing • Medium to long term: – Enable modeling of legacy applications – Apply MBD principles to legacy software February 17, 2009 APES-LESS: Goals and Motivation 3

Software in the Loop Testing Plant Model User Input Actuator models Sensor Models Simulation

Software in the Loop Testing Plant Model User Input Actuator models Sensor Models Simulation of original application code Simulation of modified application code February 17, 2009 APES-LESS: Goals and Motivation + Error – 4

Classical Problem Simulation write(angle) read(angle) S-function d. C m. C time Motor. Controller. c

Classical Problem Simulation write(angle) read(angle) S-function d. C m. C time Motor. Controller. c Memory … 0023456 12 0023457 0 0023459 6 0023460 23 0023461 0 0023463 0 … February 17, 2009 void m. C_step() { … read(angle); … } Dynamics. Controller. c Execution on the ECU preemption read(angle) write(angle) d. C m. C void d. C_step() { … write(angle); … } APES-LESS: Goals and Motivation time 5

Simulation Engine Based on Ptolemy II • Fast prototyping – Discrete event simulation –

Simulation Engine Based on Ptolemy II • Fast prototyping – Discrete event simulation – Java threads • • Component-based design Visual modeling Portability Enables execution of legacy code under different models of computation February 17, 2009 APES-LESS: Approach 6

Model Structure • • • Functionality actors OSEK actors Actor execution Actor interaction Java-C

Model Structure • • • Functionality actors OSEK actors Actor execution Actor interaction Java-C bridge February 17, 2009 Request Response APES-LESS: Ptolemy II components 7

Event-Based Approach Access Point Event (APE) • • An access point is a line

Event-Based Approach Access Point Event (APE) • • An access point is a line of source code with an I/O access or a system call In a run of the software, an access point event occurs whenever the code of an access point starts executing void app. Dispatcher(){ while (app. Running){ Wait. Event(app. Dispatcher. Event); Clear. Event(app. Dispatcher. Event); if(sim. Step%5 == 0){ Activate. Task(d. C_Task); } Set. Event(m. C_Task, m. C_Event); sim. Step++; } Terminate. Task(); } void d. C_step() { … angle = t 1*s 1; … } void d. C_step() { … Send. Message(m_a, angle); … } void m. C_step() { … tmp_a = angle; … } void m. C_step() { … Receive. Message(m_a, angle); … } February 17, 2009 APES-LESS: Approach 8

Execution Control at Access Points • Insert a callback to the simulation engine at

Execution Control at Access Points • Insert a callback to the simulation engine at every access point – Determine the execution time since the previous APE – Send the timestamped APE to the task scheduler – Pause the execution of the task • The task scheduler generates an Access Granted Event (AGE) • The execution of the task is resumed upon receiving the AGE T 2 T 1 t 2 activate(T 1) activate(T 2) APET ( 1) 1 February 17, 2009 APET ( 2) 2 t 2 + 2 t 1 + 2 AGET 2 terminate(T 2) APES-LESS: Approach 1 APET( 1’) 9

Example CCode. Library CTask. java Motor. Controller. c Thread c. Code. Thread; 2. start

Example CCode. Library CTask. java Motor. Controller. c Thread c. Code. Thread; 2. start void fire() { notify(); } void a. PCallback(time) { request. Exec. Time(time); sleep(); } ack b l l a 3. c top) (s February 17, 2009 APES-LESS: Approach a. b. change task state, reschedule sys t em cal 4. A l PE GE ger 5. A rig 1. T 6. resume void m. C_step() { … a. PCallback(12); tmp_angle = angle; … … a. PCallback(42); Wait. Event(ev. Mask); … } 10

Functionality Actor: CTask • Executes a C function mapped to an OSEK task in

Functionality Actor: CTask • Executes a C function mapped to an OSEK task in a dedicated thread • Implements two callback methods: – – access. Point. Callback(execution. Time, minimum. Delay); • before every access point where no monitoring is needed access. Point. Callback(execution. Time, minimum. Delay, var. Name, value); • Inserted in the C code after the line where var. Name is updated • Parameters: – The name of a C function mapped to an OSEK task – The priority of the task • Ports: – Multicast output port, used to send APEs – Multicast input port, used to receive AGEs – Regular I/O ports for global variables February 17, 2009 APES-LESS: Ptolemy II components 11

Multithreaded DE Simulation: Problem ev 1 ev 2 APE 1 ev 3 t 1

Multithreaded DE Simulation: Problem ev 1 ev 2 APE 1 ev 3 t 1 t 2 t 1 + 1 t 3 model time CT 2 CT 1 callback( t 1) Generate APE 1 with timestamp t 1 + 1 1 CT 1 Process ev 1 Trigger task 1 Wake up thread of C task 1 (CT 1) February 17, 2009 Process ev 2 Process ev 3 APES-LESS: Ptolemy II components real time 12

Multithreaded DE Simulation: Solution ev 1 ev 2 ev´ 1 APE 1 ev 3

Multithreaded DE Simulation: Solution ev 1 ev 2 ev´ 1 APE 1 ev 3 t 1 t 2 t 1 + 1 t 3 model time CT 2 CT 1 callback( 1, 2) Resume DE thread Suspend C thread 1, 1 CT 1 Process ev 1 Trigger task 1 Wake up thread of C task 1 (CT 1) Ask to be re-fired at t 1 + 1 February 17, 2009 Process ev 2 Process ev´ 1 Suspend execution of DE thread Generate APE 1 Finish ev´ 1 processing APES-LESS: Ptolemy II components Process APE 1 real time 13

OSEK Actor: Task. Scheduler ready er trigg February 17, 2009 APES-LESS: Ptolemy II components

OSEK Actor: Task. Scheduler ready er trigg February 17, 2009 APES-LESS: Ptolemy II components suspended mi ate tas k AGE waiting nt ed k eve or bloc e it f wa sourc re • Receives task status notifications from other OSEK actors • Sends AGEs to functionality actors preemption – Activate. Task, Terminate. Task running ter • Maintains task status information • Implements task system services eve nt/r rec esourc eiv ed e • Fixed priority preemptive scheduling • Receives APEs from CTask actors 14

OSEK Actor: Event. Manager • Implements event OSEK services – Send. Event – Get.

OSEK Actor: Event. Manager • Implements event OSEK services – Send. Event – Get. Event – Clear. Event • Notifies the Task. Scheduler to change task status – If a task needs to wait for an event – If a waiting task receives an event February 17, 2009 APES-LESS: Ptolemy II components 15

Source (sensor) Actor: Formatted. Line. Reader • Reads data from an input file –

Source (sensor) Actor: Formatted. Line. Reader • Reads data from an input file – At each iteration, data from one line is send to the output ports • Assumes input text in tabular format – A column is a sampled signal – A line contains the values of all signals at a sample time • Maps port names and types to named columns • Buffered reading – All the file is processed at initialization, when all tokens are created and stored in memory February 17, 2009 APES-LESS: Ptolemy II components 16

Infrastructure Element: Multi. Cast. IOPort • Provides line-free connectivity between actors • Output port:

Infrastructure Element: Multi. Cast. IOPort • Provides line-free connectivity between actors • Output port: – Destination actors are specified at runtime in each send action – Static filter for eligible destinations given as a parameter • Input: – Static filter for source actors specified as a parameter • Can help in modeling service oriented applications February 17, 2009 APES-LESS: Ptolemy II components 17

Monitoring • Task execution: Visualization of task states in time • Global variables February

Monitoring • Task execution: Visualization of task states in time • Global variables February 17, 2009 APES-LESS: Ptolemy II components 18

Java-C bridge • Java classes – OSEKEntry. Point: Receives all system calls from C

Java-C bridge • Java classes – OSEKEntry. Point: Receives all system calls from C tasks and routes them to the appropriate OSEK actors – Access. Point. Callback. Dispatcher: Routes the callbacks from C to the appropriate functionality actors • C wrapping code – APES layer – OS layer – Application layer February 17, 2009 APES-LESS: Ptolemy II components 19

Next Steps: The Simulator • Methods – Refine source line granularity – Adapt and

Next Steps: The Simulator • Methods – Refine source line granularity – Adapt and use existing methods for estimation of execution time • Automatization tools – Code instrumentation – Generation of the APES model • Visualization tools • Performance evaluation February 17, 2009 APES-LESS: Further work 20

Application Performance Evaluation • Simulation of closed-loop control applications – Bridging different simulation environments

Application Performance Evaluation • Simulation of closed-loop control applications – Bridging different simulation environments – Tool support • Testing with code coverage • Stability analysis/validation with regard to execution times February 17, 2009 APES-LESS: Further work 21

Modeling of Legacy Applications • Task Model • Functional Model • Timing Model •

Modeling of Legacy Applications • Task Model • Functional Model • Timing Model • Modal Model February 17, 2009 APES-LESS: Further work 22

Demos: Active Rear Steering Control • Simulink model: February 17, 2009 APES-LESS: Demos 23

Demos: Active Rear Steering Control • Simulink model: February 17, 2009 APES-LESS: Demos 23

Demo 1: Building a Basic APES model • C code is generated from the

Demo 1: Building a Basic APES model • C code is generated from the Simulink model for each of the three subsystems • Both controllers and the plant model are compiled in the same native library • Input is read in the C part from a file • CTask actors are used only for execution control • No connections necessary at the Ptolemy level February 17, 2009 APES-LESS: Demos 24

The ARS Model for Demo 1 February 17, 2009 APES-LESS: 25

The ARS Model for Demo 1 February 17, 2009 APES-LESS: 25

Demo 2: APES model with plant actor in C • The two controllers are

Demo 2: APES model with plant actor in C • The two controllers are compiled in the same native library • Speed input is provided by a Ptolemy DE actor, and front angle input from a file at the Ptolemy level • The plant is wrapped in an Embedded. CActor • Connections are needed between controllers and their environment February 17, 2009 APES-LESS: Demos 26

The ARS Model for Demo 2 February 17, 2009 APES-LESS: Demos 27

The ARS Model for Demo 2 February 17, 2009 APES-LESS: Demos 27

Thank you for your attention!

Thank you for your attention!