access point event simulator (apes) for legacy software ... · 6. resume b. change task state,...
TRANSCRIPT
Access Point Event Simulator (APES) for Legacy Software Systems (LESS)
Patricia Derler and Stefan Resmerita University of Salzburg, Austria
Derler 2 November 4, 2009
Contents
Goals and Motivation
Approach
Examples of APES Models
Future Work
Conclusions
Derler 3 November 4, 2009
APES-LESS: Goals and Motivation
Derler 4 November 4, 2009
Main Goals
Short-term: Simulate (on a host computer) execution of embedded
software written in C for a given operating system and a given hardware platform model
Achieve fast Software-in-the-Loop testing
Plant Model
Actuator models Sensor Models
Application code
User Input e.g. model of an engine
e.g. engine control software
Derler 5 November 4, 2009
Main Goals
Medium to long term: Enable modeling of legacy applications Apply Model Based Design principles to legacy software
Plant Model
Actuator models Sensor Models
Simulation of original application code
Simulation of modified application code
+
–
User Input
Error
Derler 6 November 4, 2009
The Need to Simulate the Effects of Execution Times and Preemption
write(angle)
dC mC
time
Simulation in Simulink read(angle)
dC_step mC_step
time
Execution on the ECU
preemption
MotorController.c void mC_step() { … read(angle); …
} //high priority
DynamicsController.c void dC_step() { … write(angle); …
} //low priority
…
0023456 12
0023457 0
0023459 6
0023460 23
0023461 0
0023463 0
…
Memory
read(angle) write(angle)
Derler 7 November 4, 2009
APES-LESS: Approach
Derler 8 November 4, 2009
Ptolemy II
Simulation environment for heterogeneous systems Developed at UC Berkeley Actor-oriented design Explicit support for models of computation, e.g.
discrete event, continuous time, synchronous dataflow, process network, …
local director
port
external port
actor
Derler 9 November 4, 2009
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
Derler 10 November 4, 2009
APES Model Structure for OSEK OS
Request
Response
1 Thread for simulation engine
Each application functionality actor runs in a separate thread
Java threads are used for simulating task context switches
execution control of legacy code
implementation of operating system services
Input/Output actors
Executes actors by processing events on a common timeline
event-based communication
protocol
DE Director
Derler 11 November 4, 2009
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 dC_step() { … angle = t1*s1; …
}
void appDispatcher(){ while (appRunning){ WaitEvent(aDispEvent); ... } }
Derler 12 November 4, 2009
Execution Control at Access Points
void dC_step() { … aPCallback(t1); angle = t1*s1; … aPCallback(t2); v = speed; …
}
t2
Send the timestamped APE to the task scheduler and pause the execution The task scheduler generates an Access Granted Event (AGE) The execution of the task is resumed upon receiving the AGE
t1
Insert a callback to the simulation engine at every access point Determine the execution time since
the previous APE
Derler 13 November 4, 2009
Example: Simulating Preemption
activate(T1) activate(T2) AGET2 AGET
1
APET1(Δ1) APET
2(Δ2) terminate(T2) APET(Δ1’)
T2
τ1 τ2 τ 2+Δ2 τ1+Δ1+Δ2
Two tasks: T1 and T2 T2 has higher priority T1 is triggered at time τ1 T2 is triggered at time τ2 Δ2 is the execution time
of T2 Δ1 is the execution time of T1 from the beginning until
its first access point is reached Assume τ2 < τ1 + Δ1
T1
Derler 14 November 4, 2009
Example: Execution Control in APES
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
b. change task state, reschedule
•CCodeLibrary
Derler 15 November 4, 2009
Example: Execution Control in APES
Sends APEs and receives AGEs Implements callback methods
Fixed priority preemptive scheduling
Maintains task status information Implements task system services Communicates with CTask actors Receives task status notifications
from other OSEK actors
ready
running
waiting suspended AG
E
preemption
Task states
Derler 16 November 4, 2009
APES Monitoring
Task execution: Visualization of task states in time
Global variables
Derler 17 November 4, 2009
APES-LESS: Examples of APES Models
Derler 18 November 4, 2009
Active Rear Steering Control (ARS): A Simulink Model
Derler 19 November 4, 2009
Example 1: A Basic APES Model for ARS
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
Derler 20 November 4, 2009
The Basic APES Model for the ARS Code
Derler 21 November 4, 2009
Example 2: Another APES Model for the ARS Legacy Code
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 code of the plant model is wrapped in an EmbeddedCActor
Connections are needed between controllers and their environment
Derler 22 November 4, 2009
The Second APES Model for the ARS Code
Derler 23 November 4, 2009
APES-LESS: Future Work
Derler 24 November 4, 2009
Work in Progress: 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
Derler 25 November 4, 2009
Next Steps I: 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
Derler 26 November 4, 2009
Next Steps II: High Level Models of Legacy Applications
Task Model
Functional Model
Timing Model
Modal Model
Derler 27 November 4, 2009
Further Applications
Comparing methods for execution time estimation
Experimenting with Control systems with timing compensation schemes Dynamic scheduling
Derler 28 November 4, 2009
APES-LESS: Conclusions
Derler 29 November 4, 2009
Summary I
In APES, legacy code is executed in a manner closer to an actual implementation on a given platform
APES provides an experimental platform for a variety of development activities for legacy code, such as: Software-in-the-Loop testing of control systems Time-related application performance evaluation
APES can be used as testing tool in the design of: Execution-aware controllers Control-aware scheduling
Derler 30 November 4, 2009
Summary II
APES offers a bottom-up approach for modeling legacy code applications
The basic elements of APES for OSEK have been developed
There is still significant work to do, especially related to leveraging existing methods for estimation of execution times