• No se han encontrado resultados

UPM Diseño de sistemas de tiempo real

N/A
N/A
Protected

Academic year: 2021

Share "UPM Diseño de sistemas de tiempo real"

Copied!
49
0
0

Texto completo

(1)

UPM

Diseño de sistemas

de tiempo real

Juan Antonio de la Puente

DIT/UPM

(2)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Objetivos

 

Repasaremos algunos conceptos de ingeniería de

software y su aplicación a sistemas de tiempo real

 

Nos centraremos en conceptos relacionados con el diseño

de sistemas de tiempo real mediante objetos

(3)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Aspectos de un sistema

 

Funcionalidad

– 

relación entre entradas y salidas

– 

no se considera concurrencia, sincronización, tiempo real

– 

tampoco fiabilidad ni seguridad

 

Arquitectura

– 

componentes definidos por sus interfaces

» 

interfaz que proporciona (provided interface)

» 

interfaz que necesita (required interface)

 

Concurrencia y tiempo real

– 

hebras, sincronización

– 

planificación y análisis temporal

(4)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Ejemplo de modelo funcional

PID

r

y u

e(t) =r(t) − y(t)

u(t) =K

P

e(t) + K

I

e(s)ds + K

D

de(t)

dt

0 t

⎛

⎝

⎜

⎞

⎠

⎟

e = r − y

u = K

P

e +

K

I

h

2

(e + x) +

K

P

h

(e − x)

⎛

⎝

⎜

⎞

⎠

⎟

x = e

Modelo continuo

Modelo discreto

•  ejecutar cada h

(período)

(5)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Diseño arquitectónico

 

En una primera etapa se modela un sistema como un

conjunto de componentes

 

Cada componente se define por sus interfaces

– 

una interfaz se define como un conjunto de operaciones o

métodos

– 

Provided interface (PI): operaciones que otros componentes

pueden efectuar con el componente

– 

Required interface (RI): operaciones de otros componentes que el

componente necesita invocar

(6)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes e interfaces

 

Una interfaz es una lista de operaciones parametrizadas

 

Un componente puede tener varias interfaces PI o RI

A

PI RI RI

B

PI

C

PI

(7)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes y funcionalidad

Temperature_controller

control

PID

set_reference get_variable

(8)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Concurrencia y tiempo real

Temperature_controller

control

periodic T = 0.100 D = 0.040

(9)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes de bajo nivel

 

Representan objetos que se pueden implementar

directamente en términos de la plataforma de ejecución

– 

hebras periódicas y esporádicas, objetos de datos, etc.

 

Estructura básica:

THREAD OPCS RI component C OBCS Archetype

(10)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Arquetipos

 

Abstracciones comunes en sistemas de tiempo real

 

Tareas periódicas y esporádicas

– 

componentes

cíclicos

y

esporádicos

 

Datos compartidos por varias tareas

– 

componentes

protegidos

 

Abstracción de datos

(11)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes cíclicos

 

Ejecutan una actividad a intervalos regulares

– 

atributos: período, plazo

 

No tienen OBCS

– 

excepto con ATC

 

No tienen interfaz PI

– 

excepto operaciones de ATC

» 

transferencia asíncrona de control

– 

pero pueden tener RI

Temperature_Sensor

C

(12)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes esporádicos

 

Ejecutan una actividad cuando ocurre un suceso externo o

interno

» 

suceso detectado por programa o por interrupción

» 

atributos: separación mínima, plazo

– 

Su interfaz consiste en una única operación (<<start>>)

» 

invocada por el objeto que detecta el suceso de activación

– 

La sincronización se realiza en el OBCS

– 

También pueden ofrecer operaciones de ATC

Level_Sensor

S

report_state

<<start>>

(13)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes protegidos

 

No tienen flujo de ejecución propio (THREAD), pero

pueden controlar cuándo se ejecutan sus operaciones

– 

abstracción de datos compartidos

– 

operaciones en exclusión mutua (OBCS)

– 

restricciones de sincronización adicionales

State

Pr

(14)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Componentes pasivos

 

No tienen flujo de ejecución propio (THREAD) ni control

sobre cuándo se ejecutan sus operaciones (OBCS)

– 

abstracción de datos y operaciones

– 

las operaciones se ejecutan cuando se invocan

 

Sólo se puede invocar sus operaciones desde un único

objeto activo o protegido

– 

para evitar el acceso concurrente a los datos

Display

Pa

(15)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Proceso de desarrollo en “V”

análisis de requisitos diseño arquitectónico diseño detallado realización pruebas de unidades pruebas de integración pruebas de sistema tiempo ab str ac ci ó n

(16)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Inconvenientes

 

Muy rígido

– 

difícil modificar el sistema si es necesario

 

Las pruebas se hacen al final

– 

es costoso corregir los fallos

 

Mejor un proceso iterativo

– 

comprobaciones en todos los modelos

(17)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Model-driven engineering

 

Specify systems in a

platform-independent

manner (PIM)

 

Specify execution

platforms

 

Transform PIM into

platform-specific model

(PSM)

 

The transformation must

realize PIM functionalities

within the bounds of the

platform specification

PIM

PSM

Transformation

(18)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Process vision

FUNCTIONAL

VIEW

A B C + move() : int GNC POS

INTERFACE VIEW

PIVOT

RCM

GNC POS GNC POS

(19)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Basic patterns

 

Cyclic component

 

Sporadic component

 

Protected data component

 

Passive component

(20)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic component

 

Clock-activated activity with fixed rate

 

Attributes

– 

Period

– 

Deadline

– 

Worst-case execution time

 

The most basic cyclic code pattern does not need

the synchronization agent

– 

The system clock delivers the activation event

(21)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic component (basic)

operations (OPCS) thread

cyclic component

RI cyclic operation

(22)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic thread (spec)

task type Cyclic_Thread

(Thread_Priority : Priority; Period : Positive) is pragma Priority(Thread_Priority); end Cyclic_Thread; cannot be Time_Span! ms

(23)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic thread (body)

task body Cyclic_Thread is

Next_Time : Time := <Start_Time>; -- taken at elaboration time --+ higher in the system

--+ hierarchy begin

loop

delay until Next_Time; -- so that all tasks start at T0

OPCS.Cyclic_Operation; -- fixed and parameterless

Next_Time := Next_Time + Milliseconds(Period);

end loop;

(24)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic component

 

Activated by a software-mediated event

– 

Signaled by software or hardware interrupts

 

Attributes

– 

Minimum inter-arrival time

– 

Deadline

– 

Worst-case execution time

 

The synchronization agent of the target

component is used to signal the activation event

(25)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic component

control agent (OBCS) operations (OPCS) thread

sporadic component

signal RI wait sporadic operation PI

(26)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic component (spec)

protected type OBCS(Ceiling : Priority) is pragma Priority(Ceiling);

procedure Signal;

entry Wait; private

Occurred : Boolean := False;

end OBCS;

task type Sporadic_Thread(Thread_Priority : Priority) is pragma Priority(Thread_Priority);

end Sporadic_Thread;

A sporadic thread is activated by calling the Signal operation

(27)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic thread (body)

task body Sporadic_Thread is

Next_Time : Time := <Start_Time>; begin

delay until Next_Time; -- so that all tasks start at T0

loop

OBCS.Wait;

OPCS.Sporadic_Operation;

-- may take parameters if they were delivered by Signal --+ and retrieved by Wait

end loop;

(28)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic control agent (body)

protected body OBCS is procedure Signal is begin

Occurred := True; end Signal;

entry Wait when Occurred is begin

Occurred := False; end Wait;

(29)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Other basic patterns

 

Protected component

– 

No thread, only synchronization and operations

– 

Straightforward direct implementation with protected

object

 

Passive component

– 

Purely functional behavior, neither thread nor

synchronization

– 

Straightforward direct implementation with functional

package

(30)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Temporal properties

 

Basic patterns only guarantee

periodic

or

sporadic

activation

 

They can be augmented to guarantee additional temporal

properties at run time

– 

Minimum inter-arrival time

for sporadic events

– 

Deadline

for all types of thread

(31)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Minimum inter-arrival time

 

Violations of the specified separation interval may cause

increased interference on lower priority tasks

 

Approach: prevent sporadic thread from being activated

earlier than stipulated

– 

Compute earliest (absolute) allowable activation time

(32)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic thread with minimum

separation (spec)

task type Sporadic_Thread

(Thread_Priority : Priority;

Separation : Positive) is

pragma Priority(Thread_Priority); end Sporadic_Thread;

Minimum inter-arrival time ms

(33)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic thread (body)

task body Sporadic_Thread is Release_Time : Time;

Next_Release : Time := <Start_Time>; begin

loop

delay until Next_Release;

OBCS.Wait;

Release_Time := Clock;

OPCS.Sporadic_Operation;

Next_Release := Release_Time + Milliseconds(Separation);

end loop;

(34)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Comments

 

May incur some temporal drift as the clock is read

after task release

– 

Hence preemption may hit just after the release but

before reading the clock

– 

The net effect is a larger

separation than required

 

It is better to read the clock at the place and time

the task is released

– 

Within the synchronization agent

» 

Which is protected and thus less exposed to general

interference

(35)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Minimum inter-arrival time

– alternate pattern

task body Sporadic_Thread is Release_Time : Time;

Next_Release : Time := <Start_Time>; begin

loop

delay until Next_Release;

OBCS.Wait(Release_Time); OPCS.Sporadic_Operation;

Next_Release := Release_Time + Milliseconds(Separation);

(36)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Recording release time (1)

protected type OBCS(Ceiling : Priority) is pragma Priority(Ceiling);

procedure Signal;

entry Wait(Release_Time : out Time); private

Occurred : Boolean := False; end OBCS;

(37)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Recording release time (2)

protected body OBCS is procedure Signal is begin

Occurred := True; end Signal;

entry Wait(Release_Time : out Time) when Occurred is begin

Release_Time := Clock;

Occurred := False; end Wait;

(38)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Deadline overruns

 

Deadline overruns in a task may occur as a result of

– 

Higher priority tasks executing more often than expected

» 

Prevented with inter-arrival time enforcement

– 

Execution time of the same or higher priority tasks longer than

stipulated

» 

Programming errors

 

Bounding assertions violated by functional code

(39)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Detection of deadline overruns

 

Deadline overruns can be detected at run time

with the help of timing events

– 

A mechanism for requiring some application-level

action to be executed at a given time

– 

Timing events can only exist at library level under the

Ravenscar Profile

» 

Statically allocated

 

A minor optimization may be possible for periodic

tasks

(40)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic thread with deadline

overrun detection (spec)

task type Cyclic_Thread

(Thread_Priority : Priority; Period : Positive;

Deadline : Positive) is

pragma Priority(Thread_Priority); end Cyclic_Thread;

(41)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Thread body

Deadline_Overrun : Timing_Event; -- static, local per component

task body Cyclic_Thread is

Next_Time : Time := <Start_Time>; Canceled : Boolean := False;

begin loop

delay until Next_Time;

Set_Handler(Deadline_Overrun,

Next_Time + Milliseconds(Deadline),

Deadline_Overrun_Handler); -- application-specific

OPCS.Cyclic_Operation;

Cancel_Handler(Deadline_Overrun, Canceled);

Next_Time := Next_Time + Milliseconds(Period); end loop;

(42)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Thread body (streamlined)

Deadline_Overrun : Timing_Event; -- static, local per component

task body Cyclic_Thread is

Next_Time : Time := <Start_Time>; Canceled : Boolean := False;

begin loop

-- setting again cancels any previous event

Set_Handler(Deadline_Overrun,

Next_Time + Milliseconds(Deadline),

Deadline_Overrun_Handler); -- application-specific

delay until Next_Time; OPCS.Cyclic_Operation;

Next_Time := Next_Time + Milliseconds(Period); end loop;

(43)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Sporadic thread with deadline

overrun detection (spec)

task type Sporadic_Thread

(Thread_Priority : Priority; Separation : Positive;

Deadline : Positive) is

pragma Priority(Thread_Priority); end Sporadic_Thread;

(44)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Thread body

Deadline_Overrun : Timing_Event; -- static, local per component

task body Sporadic_Thread is Release_Time : Time;

Next_Release : Time := <Start_Time>; Canceled : Boolean := False;

begin loop

delay until Next_Release; OBCS.Wait(Release_Time); Set_Handler(Deadline_Overrun, Release_Time + Milliseconds(Deadline), Deadline_Overrun_Handler); -- application-specific OPCS.Sporadic_Operation; Cancel_Handler(Deadline_Overrun, Canceled);

Next_Release := Release_Time + Milliseconds(Separation); Can’t streamline as the

deadline cannot be computed until returning

(45)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Execution-time overruns

 

Tasks may execute for longer than stipulated,

owing to programming errors

– 

Bounding assertions violated by functional code

 

WCET values used in temporal analysis may be

inaccurate

– 

Optimistic vs. pessimistic

 

WCET overruns can be detected at run time with

the help of execution-time timers

– 

Not included in Ravenscar

(46)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Cyclic thread with WCET overrun

detection (spec)

task type Cyclic_Thread

(Thread_Priority : Priority; Period : Positive;

WCET_Budget : Positive) is

pragma Priority(Thread_Priority); end Cyclic_Thread;

(47)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Thread body

task body Cyclic_Thread is

Next_Time : Time := <Start_Time>;

Id : aliased constant Task_ID := Current_Task;

WCET_Timer : Timer(Id'access);

begin loop

delay until Next_Time;

Set_Handler(WCET_Timer,

Milliseconds(WCET_Budget),

WCET_Overrun_Handler); -- application-specific

OPCS.Cyclic_Operation;

Next_Time := Next_Time + Milliseconds(Period); end loop;

(48)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Observations

 

WCET overruns in sporadic tasks can be detected

similarly

– 

The timer should be set after the activation

(49)

© J ua n An to ni o d e l a P ue nte 2 00 5-20 08

Summary

 

New Ada 2005 mechanisms enable timing behaviour to be

enforced at run-time

 

We have seen Ada patterns for monitoring

– 

Deadline

– 

Minimal inter-arrival time

– 

WCET budget

 

The patterns can be used in a component-oriented

Referencias

Documento similar

4. Un particular contrata un préstamo con las siguientes condiciones: capital prestado 15.000 euros, a devolver mediante cuatro términos amortizativos semestrales con

El Secretario General de la ONU consideraba que una presencia de los cascos azules en la República de Croacia continuaba siendo necesaria para apoyar la paz y la seguridad regional,

retiro o adición En el período de revisión Tamaño físico del inventario “Menor” que el modelo P “Mayor” que el modelo Q Costo de mantenimiento “Alto”, se

Cosas que importa saber sobre el microcontrolador para empezar un proyecto de sistemas embebidos:.. ● Tipo procesador, tamaño palabra,

Las Instituciones deberán entregar Billetes Aptos para Circular en todas las operaciones que realicen en efectivo, tanto en Sucursales Bancarias como en cajeros

a) Familiarizarse con las tareas de producción que suceden en el sector del alojamiento, intermediación turística, restauración y empresas de ocio. b) Ser capaces de

Los sujetos obligados deberán realizar sus registros contables en tiempo real, entendiéndose por tiempo real, el registro contable de las operaciones de ingresos y egresos desde

Además, se están excluyendo a los miembros de las Juntas Directivas Locales dado que no los alcanza el numeral (a) del artículo 117 de la Ley Orgánica del Sistema Bancario