Download - G53SRP: Introduction to Real Time Scheduling
1
G53SRP: Introduction to Real Time Scheduling
Chris GreenhalghChris Greenhalgh
School of Computer ScienceSchool of Computer Science
2
Contents• Specifying timing constraintsSpecifying timing constraints• Specifying the systemSpecifying the system• Current system exampleCurrent system example
– Tasks, values, time linesTasks, values, time lines
• General strategyGeneral strategy– Fixed Priority Scheduling & DMPOFixed Priority Scheduling & DMPO
• Further issuesFurther issues– Modes, fault tolerance, resource contentionModes, fault tolerance, resource contention
• Book: Wellings 7.5-7.7; Burns & Wellings 13.1-Book: Wellings 7.5-7.7; Burns & Wellings 13.1-13.313.3
3
Real time…• A real-time system is any information A real-time system is any information
processing system which has to respond to processing system which has to respond to externally generated input stimuli within a externally generated input stimuli within a finite and specified periodfinite and specified period
– the correctness depends not only on the the correctness depends not only on the logical result but also the time it was logical result but also the time it was delivereddelivered
4
Specifying timing constraints: temporal scopes
• For a section of code (“process”, “task”, For a section of code (“process”, “task”, “scope”, Java Runnable), specify:“scope”, Java Runnable), specify:– When it should (nominally) startWhen it should (nominally) start– When it must be completed byWhen it must be completed byclass Foo implements Runnable {class Foo implements Runnable { public void run() public void run() {{ … … }}}}
5
Release
Time
a
b
c
Units of executioni.e. actually on CPU
Minimum delayMaximum delay
Maximum execution time = a + b +c
Maximum elapsed time
Deadline
Blocking (sleeping,waiting, I/O), other task(s) running
6
Specifying the system• Decompose into a fixed set of tasksDecompose into a fixed set of tasks• For each task:For each task:
– Specify when it should be startedSpecify when it should be started• E.g. periodic (repeated, on a timer) or triggered by some E.g. periodic (repeated, on a timer) or triggered by some
other/external event (such as an interrupt)other/external event (such as an interrupt)
– Specify then deadline within which it should finishSpecify then deadline within which it should finish• Timing requirements derived from specification, Timing requirements derived from specification,
e.g. system stability requirementse.g. system stability requirements
• Arrange for the system to run those tasks at the Arrange for the system to run those tasks at the right times and in the right order right times and in the right order
7
T
S
P
Concurrency Example (review)
• Overall objective is to keep the temperature and pressure of Overall objective is to keep the temperature and pressure of some chemical process within well-defined limitssome chemical process within well-defined limits
Switch
ADC
ADC
DACScreen
Heater
Thermocouples Pressure Transducer
Pump/Valve
8
Example system processes (or “tasks”, …)
• P1 - temperature control taskP1 - temperature control task– (say) Run once every 100ms(say) Run once every 100ms– Complete within 50msComplete within 50ms
• P2 – pressure control taskP2 – pressure control task– Run once every 150msRun once every 150ms– Complete within 100msComplete within 100ms
9
Example system abstract time-line
0 50 100 150 200 250
Time (ms)
Process
P1
P2
Process Release Time
Process Completion TimeDeadline
Possible taskexecution
10
More questions…• How long will each task actually take How long will each task actually take
execute?execute?
• In what order should the tasks be executed? In what order should the tasks be executed?
• How many processors does the system How many processors does the system have?have?– If more than one, on which processor should If more than one, on which processor should
each task be run?each task be run?
• Will the deadlines be met?Will the deadlines be met?
11
More questions…example system
• How long will each task actually take execute?How long will each task actually take execute?– (say) P1 40ms, P2 60ms(say) P1 40ms, P2 60ms
• In what order should the tasks be executed?In what order should the tasks be executed?– (say) P1 before P2(say) P1 before P2
• How many processors does the system have? How many processors does the system have? – (say) 1 (say) 1
• Will the deadlines be met?Will the deadlines be met?– See next slide…See next slide…
12
60
Example system concrete time-line
0 50 100 150 200 250
Time (ms)
Process
P1
P2
Process Release Time
Process Completion TimeDeadline missed
Actual task execution
Process Completion TimeDeadline met
Task waiting/pre-empted
50 10
All deadlines met
13
Example system Gantt Chart
P1 P2 P1 P2 P1
0 50 100 150 200 250
Time (ms)
P2CPU-1
14
More questions…example system (v.2)
• How long will each task actually take execute?How long will each task actually take execute?– (say) P1 40ms, P2 (say) P1 40ms, P2 70ms70ms
• In what order should the tasks be executed?In what order should the tasks be executed?– (say) P1 before P2(say) P1 before P2
• How many processors does the system have? How many processors does the system have? – (say) 1 (say) 1
• Will the deadlines be met?Will the deadlines be met?– See next slide…See next slide…
15
60
Example system (v.2) concrete time-line
0 50 100 150 200 250
Time (ms)
Process
P1
P2
Process Release Time
Process Completion TimeDeadline missed
Actual task execution
Process Completion TimeDeadline met
Task waiting/pre-empted
50 20
P2 deadlines missed
10
16
More questions…example system (v.3)
• How long will each task actually take execute?How long will each task actually take execute?– (say) P1 40ms, P2 60ms(say) P1 40ms, P2 60ms
• In what order should the tasks be executed?In what order should the tasks be executed?– (say) (say) P2P2 before before P1P1
• How many processors does the system have? How many processors does the system have? – (say) 1 (say) 1
• Will the deadlines be met?Will the deadlines be met?– See next slide…See next slide…
17
60
Example system (v.3) concrete time-line
0 50 100 150 200 250
Time (ms)
Process
P1
P2
Process Release Time
Process Completion TimeDeadline missed
Actual task execution
Process Completion TimeDeadline met
Task waiting/pre-empted
60
First P1 deadline missed
18
General answers… (1)• How long will each task actually take How long will each task actually take
execute?execute?– i.e. worst-case execution timei.e. worst-case execution time– Determine from static code analysis and/or Determine from static code analysis and/or
controlled testingcontrolled testing
19
General answers… (2)• In what order should the tasks be executed? In what order should the tasks be executed?
1.1. Decide a general strategy, (e.g.) Decide a general strategy, (e.g.) fixed priority schedulingfixed priority scheduling– Assign a priority to each process in advance Assign a priority to each process in advance
and always run the highest-priority runnable and always run the highest-priority runnable processprocess
– (Want a strategy that is flexible but (Want a strategy that is flexible but deterministic and analysable – and supported)deterministic and analysable – and supported)
20
2.2. Assign priorities to each process, (e.g.) Assign priorities to each process, (e.g.) Shortest Deadline FirstShortest Deadline First– Also known as Deadline Monotonic Priority Also known as Deadline Monotonic Priority
Ordering (DPMO)Ordering (DPMO)– Can be shown to be optimal, i.e. if any strategy Can be shown to be optimal, i.e. if any strategy
works then this willworks then this will• Example system: P1 deadline 40 < P2 deadline 60 Example system: P1 deadline 40 < P2 deadline 60
21
General answers… (3)• How many processors does the system How many processors does the system
have? If more than one, on which processor have? If more than one, on which processor should each task be run?should each task be run?– Depends on system designDepends on system design– Typically fix tasks to processors for Typically fix tasks to processors for
predictabilitypredictability
22
General answers… (4)• Will the deadlines be met?Will the deadlines be met?
– Can be tackled through static analysis of whole Can be tackled through static analysis of whole systemsystem
– E.g. response time analysis - see later notesE.g. response time analysis - see later notes• Note: equivalent to example time-line with all Note: equivalent to example time-line with all
processes released at time zeroprocesses released at time zero
– N.B. this is what we were after: N.B. this is what we were after: predictable timing behaviourpredictable timing behaviour
23
Further issues: modes• Many systems have different “modes” of Many systems have different “modes” of
operation operation – e.g. start-up, active, shut-downe.g. start-up, active, shut-down– Each may have its own Each may have its own
• Specified process setSpecified process set
• Timing parametersTiming parameters
• PrioritiesPriorities
• Scheduling analysisScheduling analysis
– Plus changes between modes must be checkedPlus changes between modes must be checked
24
Further issues: fault tolerance• What if the running system does…What if the running system does…
– Miss a deadline?Miss a deadline?– Use more processor time than it should?Use more processor time than it should?
• System maySystem may– Detect missed deadlines or cost overrunDetect missed deadlines or cost overrun– Interrupt or suspect that processInterrupt or suspect that process– Call an error handler, to take contingency Call an error handler, to take contingency
actionsactions
25
Further issues: resource contention
• If processes If processes – share resources (e.g. common data or devices) share resources (e.g. common data or devices) – and require exclusive access (i.e. locks)and require exclusive access (i.e. locks)
then this must be taken into account whenthen this must be taken into account when– setting process prioritiessetting process priorities
• perhaps dynamically – see later notesperhaps dynamically – see later notes
– analysing the system’s schedulabilityanalysing the system’s schedulability• may introduce additional process blocking may introduce additional process blocking
26
Summary• A real-time system is comprised of tasks or A real-time system is comprised of tasks or
processes with specified timing constraintsprocesses with specified timing constraints– When/how often it should happenWhen/how often it should happen– When it should finish by (deadline)When it should finish by (deadline)– How long it would take in isolation (cost)How long it would take in isolation (cost)
• The real-time system schedules these tasks The real-time system schedules these tasks – e.g. using fixed priority scheduling and e.g. using fixed priority scheduling and
deadline-monotonic priority orderingdeadline-monotonic priority ordering
27
Summary (2)• On- or off-line analysis of the system can On- or off-line analysis of the system can
then determine whether deadlines should be then determine whether deadlines should be met or notmet or not
• Missed deadlines or cost over-runs may be Missed deadlines or cost over-runs may be detected, allowing the system to respond to detected, allowing the system to respond to failures (fault tolerance)failures (fault tolerance)
• Scheduling and analysis may be Scheduling and analysis may be complicated by (e.g.) system modes or complicated by (e.g.) system modes or contention for shared resourcescontention for shared resources