Lecture 02
Lecture 02
Lecture Outline
Why a reference model? Jobs and tasks Processors and resources Time and timing constraints
Hard real-time Soft real-time
Periodic, aperiodic and sporadic tasks Precedence constraints and dependencies Scheduling
Copyright 2006 University of Glasgow All rights reserved.
Each processor has a speed attribute which determines the rate of progress a job makes toward completion
May represent instructions-per-second for a CPU, bandwidth of a network, etc.
Two processors are of the same type if they are functionally identical and can be used interchangeably
E.g. memory, sequence numbers, mutexes, database locks, etc. Resources have different types and sizes, but do not have a speed attribute Resources are usually reusable, and are not consumed by use
Use of Resources
If the system contains (rho) types of resource, this means:
There are different types of serially reusable resources There are one or more units of each type of resource, only one job can use each unit at once (mutually exclusive access) A job must obtain a unit of a needed resource, use it, then release it
A resource is plentiful if no job is ever prevented from executing by the unavailability of units of the resource
Jobs never block when attempting to obtain a unit of a plentiful resource We typically omit such resources from our discussion, since they dont impact performance or correctness
Copyright 2006 University of Glasgow All rights reserved.
Execution Time
A job Ji will execute for time ei
This is the amount of time required to complete the execution of Ji when it executes alone and has all the resources it needs Value of ei depends upon complexity of the job and speed of the processor on which it is scheduled; may change for a variety of reasons:
Conditional branches Cache memories and/or pipelines Compression (e.g. MPEG video frames)
Execution times fall into an interval [ei-, ei+]; assume that we know this interval for every hard real-time job, but not necessarily the actual ei
Terminology: (x, y] is an interval starting immediately after x, continuing up to and including y
Copyright 2006 University of Glasgow All rights reserved.
Often, we can validate a system using ei+ for each job; we assume ei = ei+ and ignore the interval lower bound
Inefficient, but safe bound on execution time
Response time the length of time from the release time of the job to the time instant when it completes
Not the same as execution time, since may not execute continually
Response time
Copyright 2006 University of Glasgow All rights reserved.
ri-
ri+
Job, Ji
Time
Release time, ri
ri-
ri+
Time
Release time, ri
Absolute deadline, di
Example
A system to monitor and control a heating furnace The system takes 20ms to initialize when turned on After initialization, every 100 ms, the system:
Samples and reads the temperature sensor Computes the control-law for the furnace to process temperature readings, determine the correct flow rates of fuel, air and coolant Adjusts flow rates to match computed values
The periodic computations can be stated in terms of release times of the jobs computing the control-law: J0, J1, , Jk,
The release time of Jk is 20 + (k 100) ms
Copyright 2006 University of Glasgow All rights reserved.
Time (ms)
0 20 120 220 320 420
J0
J1
J2
J3
Release Time
Example
Suppose each job must complete before the release of the next job:
Jks relative deadline is 100 ms Jks absolute deadline is 20 + ((k + 1) 100) ms
Alternatively, each control-law computation may be required to finish sooner i.e. the relative deadline is smaller than the time between jobs, allowing some slack time for other jobs
Relative deadline = 100ms Absolute deadline for J1 = 220ms Slack time
Time (ms)
0 20 120 220 320 420
J0
J1
J2
J3
Release Time
If some deadlines can be missed occasionally, with acceptably low probability, then the system is described as soft real-time
This is a statistical constraint
Probabilistic
e.g. the probability of the response time exceeding 50 ms is less than 0.2
Copyright 2006 University of Glasgow All rights reserved.
Soft real-time:
Stock trading system DVD player Mobile phone Etc.
Types of Task
There are various types of task
Periodic Aperiodic Sporadic
Different execution time patterns for the jobs in the task Must be modelled differently
Differing scheduling algorithms Differing impact on system performance Differing constraints on scheduling
Copyright 2006 University of Glasgow All rights reserved.
Example:
T1 : p1 = 3, e1 = 1 T2 : p2 = 5, e2 = 2
H = lcm(3, 5) = 15
J1,1
Copyright 2006 University of Glasgow All rights reserved.
J1,2
J1,3
J1,4
J1,5
J2,1
J2,2
J2,2
10
J2,3
Time
15 20 25 30
The total utilization of a system is the sum of the utilizations of all tasks in a system: U = ui We will usually assume the relative deadline for the jobs in a task is equal to the period of the task
It can sometimes be shorter than the period, to allow slack time
Many useful, real-world, systems fit this model; and it is easy to reason about such periodic tasks
The release time for sporadic or aperiodic jobs can be modelled as a random variable with some probability distribution, A(x)
A(x) gives the probability that the release time of the job is not later than x
Alternatively, if discussing a stream of similar sporadic/aperiodic jobs, A(x) can be viewed as the probability distribution of their inter-release times
Copyright 2006 University of Glasgow All rights reserved.
[Note: sometimes the terms arrival time (or inter-arrival time) are used instead of release time, due to their common use in queuing theory]
The inter-arrival times between consecutive jobs in such a task may vary widely according to probability distribution A(x) and can be arbitrarily small Similarly, the execution times of jobs are identically distributed random variables with some probability distribution B(x)
Sporadic and aperiodic tasks occur in some real-time systems, and greatly complicate modelling and reasoning
Ji is an immediate predecessor of Jk if Ji < Jk and there is no other job Jj such that Ji < Jj < Jk Ji and Jk are independent when neither Ji < Jk nor Jk < Ji
A job with a precedence constraint becomes ready for execution once when its release time has passed and when all predecessors have completed
Task Graphs
Can represent the precedence constraints among jobs in a set J using a directed graph G = (J, <); each node represents a job represented; a directed edge goes from Ji to Jk if Ji is an immediate predecessor of Jk
(0,7] Feasible intervals (2,9] (4,11] (6,13] Independent Periodic jobs (8,15] p=2, D=7
(2,5]
(5,8]
(8,11]
(11,14]
(14,17]
(0,5]
(4,8]
(5,20]
branch
(0,6]
Copyright 2006 University of Glasgow All rights reserved.
AND
(2,10] 2/3 OR
1/2 Producer-Consumer
An OR constraint indicates that a job may begin after its release time if only some of the immediate predecessors have completed
Unfilled squares in the task graph
Represent conditional branches and joins by filled in circles Represent a pair of producer/consumer jobs with a dotted edge
Functional Parameters
Jobs may have priority, and in some cases may be interrupted by a higher priority job
A job is preemptable if its execution can be interrupted in this manner A job is non-preemptable if it must run to completion once started
Many preemptable jobs have periods during which they cannot be preempted; for example when accessing certain resources
The ability to preempt a job (or not) impacts the scheduling algorithm The context switch time is the time taken to switch between jobs
Forms an overhead that must be accounted for when scheduling jobs
Some jobs have optional parts, that can be omitted to save time (at the expense of a poorer quality result) Usefulness of late results varies; some applications tolerate some delay, others do not
Scheduling
Jobs scheduled and allocated resources according to a chosen set of scheduling algorithms and resource access-control protocols
Scheduler implements these algorithms
A scheduler specifically assigns jobs to processors A schedule is an assignment of all jobs in the system on the available processors. A valid schedule satisfies the following conditions:
Copyright 2006 University of Glasgow All rights reserved.
Every processor is assigned to at most one job at any time Every job is assigned at most one processor at any time No job is scheduled before its release time The total amount of processor time assigned to every job is equal to its maximum or actual execution time All the precedence and resource usage constraints are satisfied
Scheduling
A valid schedule is also a feasible schedule if every job meets its timing constraints.
Miss rate is the percentage of jobs that are executed but completed too late Loss rate is the percentage of jobs that are not executed at all
A hard real time scheduling algorithm is optimal if the algorithm always produces a feasible schedule if the given set of jobs has feasible schedules
Many scheduling algorithms exist: main focus of this module is understanding real-time scheduling
Summary
Outline of terminology and a reference model:
Jobs and tasks Processors and resources Time and timing constraints
Hard real-time Soft real-time
Periodic, aperiodic and sporadic tasks Precedence constraints and dependencies Scheduling