You are on page 1of 6

9/15/2010

Constraints of real-time tasks


• Timing constraints
• The basic concept of task parameters
• Formal notation of tasks & scheduling
REAL TIME SYSTEM • Precedence constraints
• Resource constraints
Hệ thống thời gian thực

Trần Tuấn Vinh


Computer Engineering Department
School of Information and Communication Technology

15/09/2010 Copyright (C) by VinhTT 1

• Scheduling policy: • All activated tasks enters in “ready queue” at first.


• The criterion to assign the CPU time to concurrent tasks which will be • The scheduler selects one task in the Ready queue according to the tasks’
executed on the CPU priorities allocated based on the scheduling algorithm.
• The selected task is dispatched and becomes in “running” state.
• Scheduling algorithm: • After the selected task is completed, it is removed from the Ready queue.
• The set of rules that determines the order in which tasks are executed
• Selects a task to allocate the CPU for any time Scheduler

• A task can potentially execute on CPU, if it has been selected by


scheduling algorithm or waiting if another task is executing. Start/
• Task can potentially execute, is called active task. dispatched terminate
activate
• Task waiting for CPU, is called active task. task Ready queue running
• Task in execution, is called active task.
preempted
released Wait/blocked
Wait queues

1
9/15/2010

• J = {J1,…,Jn} A set of tasks


• In dynamic OS , the running task can be interrupted at any
• :R+N A schedule
point, so that a more important task that arrives can
• A function mapping from time to task, which represents executed task
immediately gain the processor.
with respect to time
• The running task is interrupted and inserted to the ready queue, • If (t)=i for t[t1,t2), task Ji is executed during time duration [t1,t2).
while CPU is assigned to the most important ready task which • If (t)=0, the CPU is idle.
just arrived.
• Preemption is the solution for dynamic OS.
• Why preemption is needed in real-time systems?
• Exception handling of a task
• Treating with different criticalities of tasks, permits to anticipate the
execution of the most critical activities
• Efficient scheduling to improve system responsiveness

Notation of scheduling(2)
• Preemptive schedule:
• A schedule in which the running task can be arbitrarily
Idle J1 J2 J3 idle suspended at any time, to assign the CPU to another task
• Feasible schedule:
3 • A schedule where if all tasks can be completed according to a
(t) set of specified constraints
2
• Schedulable task set:
1 A time slice • A set of tasks for which there exists at least one scheduling
algorithm that can produce feasible schedule

t1 t2 t3 t4

Context switching are performed at these times

2
9/15/2010

J1
• Timing constraints
t
J2 t
• Precedence constraints
J3 t • Resource constraints

(t)

15/09/2010 Copyright (C) by VinhTT 9

• Timing constraints: Li
• Constraints on execution time, is the time that must be meet in order to Lateness
Ci
achieve the desired behavior.
• Typical constraint: deadline
• Relative deadline: deadline is specified with respect to the arrival time time
• Absolute deadline: deadline is specified with respect to time zero. fi
Di relative deadline
• Classification of real-time tasks Ci Execution
• Hard : if completion after its deadline can cause catastrophic time
consequence on the system
Ready
• Soft : if missing its deadline decrease the performance of the system but Running
does not jeopardize its correct behavior time
ai Si fi di
arrival time start time finishing absolute
time deadline

Xi Laxity

3
9/15/2010

• Other task parameters • Regularity of task activation


• Response time : different between the finishing time and the • Periodic:
request time Ri = fi - ri • Consists of infinite sequence of identical activities, called instances or jobs
• Criticality: Hard or Soft • Aperiodic
• Value vi: relative importance of task with respect to the other tasks • Sporadic:
• An aperiodic job where consecutive jobs are separated by a minimum
• Lateness: the delay of a task completion with respect to its interarrival time
deadline Li = fi –di
• Tardiness or Exceeding time: Ei = max(0,Li) is the time a task
stays active after its deadline.
• Laxity or Slack time Xi = di – ai – Ci is the maximum time a task
can be delayed on its activation to complete within its deadline

Absolute deadline Arrival time • Two tasks can have a precedence constraint:
of 1st job of 2nd job • A task has to be executed after another task is completed

Di Di
Relative deadline Relative deadline • Notation:
• Precedence relations are described by a directed acycric graph
Ti period Ti G.
Ci Ci • : task Ja is a predecessor of task Jb
ready running ready running • : task Ja is an immediate predecessor of Jb

Φi
Phase
1st job 2nd job

4
9/15/2010

An example of precedence relations (Figure


2.6)
To be executed • The application to classify a number objects moving on a
conveyor belt through a stereo vision system
earlier • The stereo vision system mounts two cameras
J1
• Tasks:
• acq1 & acq2: Two tasks for image acquisition to transfer the image
from the camera to the processor memory
J2 J3
• edge1 & edge2: Two tasks for low-level image processing of images
from the camera
• Shape: a task for extracting two-dimensional features from the object
contours
J4 J5 • disp: a task for computing the pixel disparities from the two images
To be executed • H: a task for determining the object height from the result of disp
• rec: a task for final classification
later

An example of
deriving precedence relations
• Resource
acq1 acq2 • Any software structure that can be used by the process to
advance its execution
• Ex:
edge1 edge2 • data structure, a set of variables, main memory area, a file, a
piece of program, a set of registers of a peripheral device

disp shape • Private resource:


• A resource dedicated to a particular process
• Shared resource:
• A resource that can be used by more tasks
H

rec

5
9/15/2010

An example of mutual exclusion

• Shared resource do not allow simultaneous accesses but Higher priority Lower priority
mutual exclusion (called mutually exclusive resource) J1 J2

• Critical section:
• A piece of code under mutual exclusion constraints
• Example:
Let R be a mutually exclusive resource shared by task Ja and Jb. Wait(s)
Wait(s)
If A is the operation performed on R by Ja and B by Jb Shared resource
Critical section
A and B must never be executed at the same time R Critical section
Signal(s)
Signal(s)

scheduling
• Scheduling with preemption

activation Termination
preempts blocked READY RUN

Higher priority
J1 preemption

Signal free Wait on busy


resource resource
Lower priority
J2 WAITING

Locks resource Unlocks resource

normal execution critical section 15/09/2010 Copyright (C) by VinhTT 24

You might also like