50
A Code Generation Framework for Distributed Real-Time Embedded Systems M. Bambagini and M. Di Natale 17th International Conference on Emerging Technologies & Factory Automation Krakow, Poland, September 17-21, 2012 TeCIP Institute, Scuola Superiore Sant’Anna Area della Ricerca CNR, Via Moruzzi, 1 56127 Pisa, ITALY

A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

A Code Generation Framework for DistributedReal-Time Embedded Systems

M. Bambagini and M. Di Natale

17th International Conference on Emerging Technologies & Factory AutomationKrakow, Poland, September 17-21, 2012

TeCIP Institute, Scuola Superiore Sant’AnnaArea della Ricerca CNR, Via Moruzzi, 1

56127 Pisa, ITALY

Page 2: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Outline

1 Introduction

2 Proposed framework

3 Code generation issues

4 Evaluation example

5 Conclusions

Page 3: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Page 4: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Page 5: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Page 6: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

We propose a modeling framework/methodology that bridges thegap between MBD and MDA approaches while:

I providing separation of concerns between functional modelingand platform modeling

I improves portability and extensibilityI enables the definition of functional components with

re-targetable interfaces

I exploiting the best-in-class software: Matlab/Simulink andEclipse/EMF

I generating a code implementation for distributed systems withonly changes in the platform and mapping models

I enabling back-annotation of time performance and evaluationof response time in the average and worst-case (vs. deadlines)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 4/20

Page 7: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

We propose a modeling framework/methodology that bridges thegap between MBD and MDA approaches while:

I providing separation of concerns between functional modelingand platform modeling

I improves portability and extensibilityI enables the definition of functional components with

re-targetable interfaces

I exploiting the best-in-class software: Matlab/Simulink andEclipse/EMF

I generating a code implementation for distributed systems withonly changes in the platform and mapping models

I enabling back-annotation of time performance and evaluationof response time in the average and worst-case (vs. deadlines)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 4/20

Page 8: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 9: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

1. By model-based tools, algorithms are developed and validatedwithout considering any implementation or hardware detail

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 10: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

2. The Platform Independent Model is parsed and translated intoanother model according to the internal functional meta-model

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 11: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

3. Designers define the deployed HW and SW resources: ECUs,buses, devices, RTOSs, tasks, drivers and communication protocols

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 12: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

4. Designers map functional components onto the computationand communication resources. Timing back-annotations are added

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 13: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

5. The Platform Specific Model is completed

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 14: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

6. The system performance (time, energy...) can be staticallyanalyzed to evaluate if the mapping satisfies the constraints

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 15: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

7. If the performance is not as good as required: the design maybe changed at the platform and functional levels

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 16: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework

8. The binary files are obtained by compiling together thefunctional code, the RTOSs, drivers and the generated code

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Page 17: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework - Implementation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Page 18: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework - Implementation

Functional area: Matlab/Simulink/Embedded Coder

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Page 19: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework - Implementation

Functional/Mapping/Architectural areas: set of Eclipse Plug-ins

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Page 20: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Proposed framework - Implementation

Code generation: Acceleo scripts (Eclipse Plug-in)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Page 21: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Page 22: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()

TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Page 23: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Page 24: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between the blocks

A middleware level provides the actual implementation of thecommunications

TASK( t a s k 1 ) {. . .s u b S y s t e m 1 s t e p ( ) ;w r i t e s u b 1 O u t 2 ( ) ;. . .

}

TASK( t a s k 2 ) {. . .r e a d s u b 2 I n 1 ( ) ;s u b S y s t e m 2 s t e p ( ) ;. . .

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 8/20

Page 25: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between the blocks

A middleware level provides the actual implementation of thecommunications

TASK( t a s k 1 ) {. . .s u b S y s t e m 1 s t e p ( ) ;w r i t e s u b 1 O u t 2 ( ) ;. . .

}

TASK( t a s k 2 ) {. . .r e a d s u b 2 I n 1 ( ) ;s u b S y s t e m 2 s t e p ( ) ;. . .

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 8/20

Page 26: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Intra-Task communication

TASK(singleTask) {

subSystem1_step ();

write_sub1_Out2 ();

...

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

inline void write_sub1_Out2 ()

{

X = subSystem1_Y.Out2;

}

inline void read_sub2_In1 ()

{

subSystem2_U.In1 = X;

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 9/20

Page 27: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Intra-Task communication

TASK(singleTask) {

subSystem1_step ();

write_sub1_Out2 ();

...

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

inline void write_sub1_Out2 ()

{

X = subSystem1_Y.Out2;

}

inline void read_sub2_In1 ()

{

subSystem2_U.In1 = X;

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 9/20

Page 28: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Inter-Task communication

TASK(task_1) {

subSystem1_step ();

write_sub1_Out2 ();

}

TASK(task_2) {

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

Mutex mutex_X;

inline void write_sub1_Out2 () {

GetResource(mutex_X );

X = subSystem1_Y.Out2;

ReleaseResource(mutex_X );

}

inline void read_sub2_In1 () {

GetResource(mutex_X );

subSystem2_U.In1 = X;

ReleaseResource(mutex_X );

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 10/20

Page 29: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Inter-Task communication

TASK(task_1) {

subSystem1_step ();

write_sub1_Out2 ();

}

TASK(task_2) {

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

Mutex mutex_X;

inline void write_sub1_Out2 () {

GetResource(mutex_X );

X = subSystem1_Y.Out2;

ReleaseResource(mutex_X );

}

inline void read_sub2_In1 () {

GetResource(mutex_X );

subSystem2_U.In1 = X;

ReleaseResource(mutex_X );

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 10/20

Page 30: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 11/20

Page 31: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Code generation issues

Communication between blocks: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 11/20

Page 32: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Evaluation example

Evaluation case: Ball&Plate system

I Target: keep the ball as close as possible to the plate center

I Sensing: a touch screen sensor on the top of the plate totrack the ball

I Actuation: two servomotors to control the pitch and rollangles of the plate

M. Bambagini c©2012 Scuola Superiore Sant’Anna 12/20

Page 33: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Evaluation example

Functional model (in Simulink): 5 subsystems and 3 custom blocks

The C functional functions subTouch step(), subController step(),subServoX step() and subServoY step() are generated

M. Bambagini c©2012 Scuola Superiore Sant’Anna 13/20

Page 34: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Evaluation example

Functional model (in Simulink): 5 subsystems and 3 custom blocks

The C functional functions subTouch step(), subController step(),subServoX step() and subServoY step() are generated

M. Bambagini c©2012 Scuola Superiore Sant’Anna 13/20

Page 35: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Page 36: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Page 37: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Page 38: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Page 39: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Page 40: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Page 41: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Page 42: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Page 43: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Page 44: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Page 45: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Page 46: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Page 47: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Future work

Next step: functional model back-annotation with theestimated/measured communication delays

M. Bambagini c©2012 Scuola Superiore Sant’Anna 18/20

Page 48: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Future work

Next step: functional model back-annotation with theestimated/measured communication delays

M. Bambagini c©2012 Scuola Superiore Sant’Anna 18/20

Page 49: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

Conclusions

A framework/methodology for code generation for real-timedistributed systems has been introduced

It aims at combining MBD and MDA approaches for covering allthe steps from the idea devising to the development

In the experiments, three different designs were considered bychanging only the architectural and mapping models, withoutwriting any line of C code

M. Bambagini c©2012 Scuola Superiore Sant’Anna 19/20

Page 50: A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD), Matlab/Simulink/Scade I formally models the execution semantics I lets designers simulate

dummy

thank [email protected]

M. Bambagini c©2012 Scuola Superiore Sant’Anna 20/20