Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

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

description

Access Point Event Simulator (APES) for Legacy Software Systems (LESS). Stefan Resmerita Joint work with Patricia Derler and Edward Lee February 17, 2009. Contents. Goals and motivation Approach Ptolemy II components Further work Demos. Contents. Main Goals. Short-term: - PowerPoint PPT Presentation

Transcript of Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

Page 1: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

Stefan Resmerita

Joint work with Patricia Derler and Edward LeeFebruary 17, 2009

Page 2: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 2APES-LESS:

Contents

1. Goals and motivation

2. Approach

3. Ptolemy II components

4. Further work

5. Demos

Contents

Page 3: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 3APES-LESS:

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

Goals and Motivation

Page 4: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 4APES-LESS:

Software in the Loop Testing

Plant Model

Actuator modelsSensor Models

Simulation of original application code

Simulation of modified application code

+

User Input

Error

Goals and Motivation

Page 5: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 5APES-LESS:

Classical Problem

DynamicsController.cvoid dC_step() {

…write(angle);…

}

0023456 12

0023457 0

0023459 6

0023460 23

0023461 0

0023463 0

MemoryMotorController.cvoid mC_step() {

…read(angle);…

}

write(angle) read(angle)

dCmC

time

Simulation

dCmC

time

Execution on the ECU

write(angle)read(angle)

preemption

S-function

Goals and Motivation

Page 6: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 6APES-LESS:

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

Approach

Page 7: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 7APES-LESS:

Request

Response

Model Structure

• Functionality actors• OSEK actors• Actor execution• Actor interaction• Java-C bridge

Ptolemy II components

Page 8: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 8APES-LESS:

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

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 dC_step() {…angle = t1*s1;…

}

void mC_step() {…tmp_a = angle;…

}

void dC_step() {…SendMessage(m_a, angle);…

}

void mC_step() {…ReceiveMessage(m_a,angle);…

}

void appDispatcher(){while (appRunning){WaitEvent(appDispatcherEvent);ClearEvent(appDispatcherEvent);if(simStep%5 == 0){ActivateTask(dC_Task);

}SetEvent(mC_Task, mC_Event);simStep++;

}TerminateTask();

}

Approach

Page 9: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 9APES-LESS:

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

Approach

activate(T1) activate(T2) AGET2

AGET1

APET1(1) APET

2(2) terminate(T2)

APET(1’)

T1

T2

t1 t2 t2 + 2 t1 + 1 + 2

Page 10: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 10APES-LESS:

Example

MotorController.c

void mC_step() {…aPCallback(12);tmp_angle = angle;……aPCallback(42);WaitEvent(evMask);…

}

Thread cCodeThread;

void fire() {notify();

}

void aPCallback(time) {requestExecTime(time);sleep();

}

CTask.java

2. start

6. resume

3. callback

(stop)

b. change task state, reschedule

1. T

rigg

er

4. A

PE

a. s

yste

m c

all

CCodeLibrary

5. A

GE

Approach

Page 11: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 11APES-LESS:

Functionality Actor: CTask

• Executes a C function mapped to an OSEK task in a dedicated thread

• Implements two callback methods:– accessPointCallback(executionTime, minimumDelay);

• before every access point where no monitoring is needed– accessPointCallback(executionTime, minimumDelay, varName, value);

• Inserted in the C code after the line where varName 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

Ptolemy II components

Page 12: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 12APES-LESS:

Multithreaded DE Simulation: Problem

Ptolemy II components

t1t2 t3 model time

real timeProcess ev1

Trigger task 1Wake up threadof C task 1 (CT1)

Process ev2Process ev3

CT1 callback(t1)Generate APE1 withtimestamp t1 + 1

ev1 ev2

t1 + 1

APE1 ev3

CT2

CT1 1

Page 13: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 13APES-LESS:

Multithreaded DE Simulation: Solution

Ptolemy II components

t1t2 t3 model time

real timeProcess ev1

Trigger task 1Wake up threadof C task 1 (CT1)Ask to be re-fired at t1 + 1

Process ev2ProcessAPE1

CT1 callback(1, 2)Resume DE threadSuspend C thread

ev1 ev2

t1 + 1

APE1 ev3

CT2

CT1 1, 1

t1 + 1

ev´1

Process ev´1

Suspend executionof DE thread

Generate APE1

Finish ev´1

processing

Page 14: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 14APES-LESS:

OSEK Actor: TaskScheduler

• Maintains task status information

• Implements task system services– ActivateTask, TerminateTask

• Receives task status notifications from other OSEK actors

• Sends AGEs to functionality actors

• Fixed priority preemptive scheduling

• Receives APEs from CTask actors

ready

running

waiting suspended

trigger

AG

E

pre

em

ptio

n

even

t/re

sour

cere

ceiv

ed

wait for event

resource blocked

term

iate

tas

k

Ptolemy II components

Page 15: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 15APES-LESS:

OSEK Actor: EventManager

• Implements event OSEK services – SendEvent

– GetEvent

– ClearEvent

• Notifies the TaskScheduler to change task status– If a task needs to wait for an event

– If a waiting task receives an event

Ptolemy II components

Page 16: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 16APES-LESS:

Source (sensor) Actor: FormattedLineReader

• 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

Ptolemy II components

Page 17: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 17APES-LESS:

Infrastructure Element: MultiCastIOPort

• 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

Ptolemy II components

Page 18: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 18APES-LESS:

Monitoring

• Task execution: Visualization of task states in time

• Global variables

Ptolemy II components

Page 19: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 19APES-LESS:

Java-C bridge

• Java classes– OSEKEntryPoint: Receives all system calls from C

tasks and routes them to the appropriate OSEK actors

– AccessPointCallbackDispatcher: Routes the callbacks from C to the appropriate functionality actors

• C wrapping code– APES layer

– OS layer

– Application layer

Ptolemy II components

Page 20: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 20APES-LESS:

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

Further work

Page 21: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 21APES-LESS:

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

Further work

Page 22: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 22APES-LESS:

Modeling of Legacy Applications

• Task Model

• Functional Model

• Timing Model

• Modal Model

Further work

Page 23: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 23APES-LESS:

Demos: Active Rear Steering Control

• Simulink model:

Demos

Page 24: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 24APES-LESS:

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

Demos

Page 25: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 25APES-LESS:

The ARS Model for Demo 1

Page 26: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 26APES-LESS:

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 EmbeddedCActor• Connections are needed between controllers and

their environment

Demos

Page 27: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

February 17, 2009 27APES-LESS:

The ARS Model for Demo 2

Demos

Page 28: Access Point Event Simulator (APES) for Legacy Software Systems (LESS)

Thank you for your attention!