Publicado el 15 de Octubre del 2018
624 visualizaciones desde el 15 de Octubre del 2018
226,0 KB
30 paginas
Creado hace 17a (14/11/2007)
ditdit
UPM
Esquemas de tareas de
tiempo real
Juan Antonio de la Puente
DIT/UPM
Objetivos
Reconocer un conjunto de esquemas básicos para
construir sistemas de tiempo real
– Tareas periódicas
– Tareas esporádicas
– Recursos compartidos
– Sincronización
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Veremos esquemas basados en UML
– También algunos esquemas más generales
14/11/07
Esquemas de tareas de tiempo real
1
Realización de un componente
de tiempo real
component
THREAD
OBCS
OPCS
RI
PI
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
OBCS : object control structure → objeto protegido
THREAD → tarea
OPCS : operation control structure → objeto pasivo
Un componente puede tener sólo algunos de estos elementos
14/11/07
Esquemas de tareas de tiempo real
2
Componente cíclico
C
Name
period = …
deadline = …
Name
thread
OPCS
periodic_activity
14/11/07
Esquemas de tareas de tiempo real
3
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente cíclico: realización
with Ada.Real_Time; use Ada.Real_Time;
with System; use System;
package Name is
Start_Time : Time := ... ;
Period : Time_Span := ... ;
Thread_Priority : Priority := ... ;
pragma Elaborate_Body (Name);
end Name;
No hay operaciones visibles
– Elaborate_Body indica que el
paquete tiene cuerpo
Atributos temporales
– Start_Time
– Period
– Thread_Priority
No se detecta si se excede el plazo
de ejecución o el tiempo de cómputo
with Ada.Real_Time; use Ada.Real_Time;
-- other context clauses
package body Name is
task Thread is
pragma Priority (Thread_Priority);
end Thread;
task body Thread is
Next_Time : Time := Start_Time ;
begin
-- thread initialization
loop
delay until Next_Time;
OPCS.Periodic_Activity;
Next_Time := Next_Time + Period;
end loop;
end Thread;
begin
-- package initialization
end Name;
14/11/07
Esquemas de tareas de tiempo real
4
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente esporádico
S
Name
period = …
deadline = …
«start» Start
Name
thread
OBCS
start
OPCS
sporadic_activity
14/11/07
Esquemas de tareas de tiempo real
5
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente esporádico: realización
with System; use System;
package Name is
Thread_Priority : Priority := ... ;
procedure Start;
end Name;
La única operación visible es la
operación de arranque (Start)
El OBCS se realiza con un objeto de
suspensión
No se vigila el cumplimiento de la
separación mínima entre sucesos
No se detecta si se excede el plazo
de ejecución o el tiempo de cómputo
with Ada.Synchronous_Task_Control;
use Ada.Synchronous_Task_Control;
-- other context clauses
package body Name is
task Thread is
pragma Priority (Thread_Priority);
end Thread;
Control : Suspension_Object;
task body Thread is
begin
-- thread initialization
loop
Suspend_Until_True(Control);
OPCS.Sporadic_Activity;
end loop;
end Thread;
procedure Start is
begin
Set_True (Control);
end Start;
begin
-- package initialization
end Name;
14/11/07
Esquemas de tareas de tiempo real
6
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente esporádico:
Sincronización con objeto protegido (1)
with System; use System;
package Name is
Thread_Priority : Priority := ... ;
Control_Priority: Priority := ... ;
procedure Start;
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
private
protected OBCS is
pragma Priority (Control_Priority);
procedure Start;
entry Wait;
private
Started : Boolean := False;
end OBCS;
procedure Start
renames OBCS.Start;
end Name;
El objeto de sincronización se sustituye por un objeto protegido
Funcionalmente es equivalente, aunque menos eficiente
Es fácil de extender para tener en cuenta la separación mínima entre sucesos
Permite poner parámetros en las operaciones
14/11/07
Esquemas de tareas de tiempo real
7
Componente esporádico:
Sincronización con objeto protegido (2)
with System; use System;
package body Name is
task Thread is
pragma Priority (Thread_Priority);
end Thread;
task body Thread is
begin
-- thread initialization
loop
OBCS.Wait;
OPVS.Sporadic_Activity;
end loop;
end Thread;
protected body OBCS is
procedure Start is
begin
Started := True;
end Start;
entry Wait when Started is
begin
Started := False;
end Wait;
end OBCS;
begin
-- package initialization
end Name;
14/11/07
Esquemas de tareas de tiempo real
8
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente esporádico:
Separación mínima (1)
with Ada.Real_Time; use Ada.Real_Time;
with System; use System;
package Name is
Separation : Time_Span := ... ;
Thread_Priority : Priority := ... ;
Control_Priority: Priority := ... ;
procedure Start;
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
private
protected OBCS is
pragma Priority (Control_Priority);
procedure Start;
entry Wait(Start_Time : out Time);
private
Started : Boolean := False;
Event_Time : Time;
end OBCS;
procedure Start
renames OBCS.Start;
end Name;
El objeto OBCS registra el tiempo en que se hace Start
(no es necesariamente el mismo en que se ejecuta la acción esporádica)
14/11/07
Esquemas de tareas de tiempo real
9
Componente esporádico:
Separación mínima (2)
with Ada.Real_Time; use Ada.Real_Time;
with System; use System;
package body Name is
task Thread is
pragma Priority (Thread_Priority);
end Thread;
task body Thread is
Start_Time : Time;
begin
-- thread initialization
loop
OBCS.Wait (Start_Time);
OPCS.Sporadic_Activity;
delay until
Start_Time + Separation;
end loop;
end Thread;
protected body OBCS is
procedure Start is
begin
Started := True;
Event_Time := Ada.Real_Time.Clock;
end Start;
entry Wait
(Start_Time : out Time)
when Started is
begin
Started := False;
end Wait;
end OBCS;
begin
-- package initialization
end Name;
Start_Time := Event_Time;
Inconveniente: dos cambios de contexto
– si se está seguro de la separación mínima es mejor el esquema anterior
14/11/07
Esquemas de tareas de tiempo real
10
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente protegido
Pr
Name
«paer» op1
«pser» op2
…
op1
op2
Name
OBCS
{procedure | function}
{entry}
OPCS
op1_code
op2_code
14/11/07
Esquemas de tareas de tiempo real
11
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente protegido: realización (1)
with System; use System;
package Name is
Ceiling_Priority : Priority
:= ... ;
procedure op1 (…);
procedure op2 (…);
…
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
private
protected OBCS is
pragma Priority(Ceiling_Priority);
procedure op1 (…);
entry op2 (…);
private
…
end OBCS;
procedure op1 renames OBCS.op1;
procedure op2 renames OBCS.op2;
end Name;
i
t
o
n
o
n
A
n
a
u
J
©
Las operaciones visibles son las especificadas en UML
pser : síncronas (entradas)
paser : asíncronas (procedimientos y funciones)
Atributos temporales
– Ceiling_Priority
14/11/07
Esquemas de tareas de tiempo real
12
Componente protegido: realización (2)
Las operaciones síncronas se
implementan como entradas
package body Name is
protected body OBCS is
Las operaciones asíncronas
corresponden a procedimientos
y funciones
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
procedure op1 (…) is
…
begin
OPCS.op1_code;
end op1;
entry op2 when … is
…
begin
OPCS.op2_code;
end op2;
end OBCS;
begin
-- package initialization
end Name;
14/11/07
Esquemas de tareas de tiempo real
13
Componente pasivo
Name
Pa
op1
op2
…
No es un objeto de tiempo real
Se implementa mediante un
paquete de Ada, sin más
14/11/07
Esquemas de tareas de tiempo real
14
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Componente pasivo: realización
package Name is
procedure op1 (…);
procedure op2 (…);
…
-- otros procedimientos o funciones
end Name;
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
package body Name is
procedure op1 (…) is
…
begin
…
end op1;
procedure op2 is
…
begin
…
end op2;
begin
-- package initialization
end Name;
Las operaciones visibles son las especificadas en UML
son todas asíncronas (no bloquean a la tarea que llama)
14/11/07
Esquemas de tareas de tiempo real
15
Ejemplo: control de una bomba de agua
operador
arranca/para
bomba
motor
Sistema
de
control
nivel alto
nivel bajo
arqueta
14/11/07
Esquemas de tareas de tiempo real
16
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Arquitectura lógica
mine control system
check safe
pump controller
environment_monitor
commands
alarms
log ops
operator console
data_logger
14/11/07
Esquemas de tareas de tiempo real
17
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
Pump_controller
check_safe
Pr
Motor
C
Water_flow_sensor
alarms
log_ops
S
HLW_Handler
start
Pr
<<interrupt handler>>
HLW_Controller
hlw_interrupt_handlers
commands
7
0
0
2
-
0
0
0
2
e
t
n
e
u
P
a
l
e
d
i
t
o
n
o
n
A
n
a
u
J
©
14/1
Comentarios de: Esquemas de tareas de tiempo real (0)
No hay comentarios