-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
1/44
SHRI SANT GAJANAN MAHARAJ COLLEGE OF ENGINEERINGDepartment of Electronics & Telecommunication Engineering
Real Time Task SchedulingUnit-III::Real Time Systems & RTOS
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
2/44
Scheduling of Tasks
A real time system executes several tasks
concurrently
The sequence in which tasks can run
depends upon scheduling algorithms
Programmer needs to write code for defining
tasks and algorithm
The scheduler within RTOS runs the tasks
as per the algorithm
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
3/44
Task Scheduling Algorithms
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
4/44
RTOS Scheduler
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
5/44
Schedulability Problem
Given: A set of tasks {Ti}
Periodic
Sporadic (with minimum inter arrival time)
Aperiodic Synchronization requirements
Precedence
Mutual exclusion
Wanted:
Test to determine if set schedulable
Scheduling algorithm
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
6/44
Schedulability Test
Task set complexity
Sufficient NecessaryExact
If a sufficient schedulabilitytest is positive, these tasksare definitely schedulable
If a necessary schedulabilitytest is negative, these tasks
are definitely not schedulable
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
7/44
Scheduling Algorithm
Is there an algorithm that will find afeasible schedule in bounded time ?
Is the algorithm optimal, i.e. will it find a
schedule whenever one exists ?
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
8/44
Scheduling Algorithm
Classification
Best effort vs. Guaranteed Static vs. Dynamic
Pre-emptive vs. Non pre-emptive
Centralized vs. Distributed
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
9/44
Scheduling AlgorithmBest Effort vs. Guaranteed
Best effort: Algorithm can fail
No feasible schedule
Not enough time to find one.
Guaranteed: All tasks will meet
deadlines
Task set is schedulable Algorithm will always find feasible schedule
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
10/44
Scheduling AlgorithmStatic vs. Dynamic
Static Scheduling:
All scheduling decisions at compile time.
Temporal task structure fixed.
Precedence and mutual exclusion satisfied by the
schedule (implicit synchronization).
One solution is sufficient.
Any solution is a sufficient schedulability test.
Run time task dispatcher looks up a table.
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
11/44
Scheduling AlgorithmStatic vs. Dynamic
Dynamic Scheduling:
All scheduling decisions at run time.
Based upon set of ready tasks.
Mutual exclusion and synchronization enforced by
explicit synchronization constructs. Benefits:
Flexibility.
Only actually used resources are claimed.
Disadvantages:
Guarantees difficult to support Replica determinism hard to enforce
Computational resources required for scheduling
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
12/44
Scheduling AlgorithmPreemptive vs. Non pre-emptive
Preemptive Scheduling:
Event driven.
Each event causes interruption of running tasks.
Choice of running tasks reconsidered after eachinterruption.
Benefits:
Can minimize response time to events.
Disadvantages:
Requires considerable computational resources for
scheduling
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
13/44
Scheduling AlgorithmPreemptive vs. Non pre-emptive
Non pre-emptive Scheduling:
Tasks remain active till completion
Scheduling decisions only made after task completion.
Benefits:
Reasonable when Less computational resources needed for scheduling
Disadvantages:
Shortest guaranteed response time =
longest task time + shortest task time + switching
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
14/44
Round Robin Scheduling
Each process is assigned a quantum (time interval)it is allowed to run.
Process only runs for quantum or until blocked or
finished Analysis needs to be done to pick a good quantum
since a context switch is a good deal of overhead. Setting quantum can result in too many process
switches and lowers CPU efficiency Setting too long may cause poor response
Assumes all processes are equally important
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
15/44
Rate Monotonic Algorithm
Assumptions
1. No non pre-emptible parts in a task, and
negligible preemption cost2. Resource constraint on CPU time only
3. No precedence constraints among tasks
4.All tasks periodic5. Relative deadline = period
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
16/44
RM Parameters
Let Ti be period of task
Ci = Execution time
Di = Deadline
Utilization ratio Ui = Ci/Ti
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
17/44
RM Algorithm
Order tasks according to their period
Task with shortest period get highest
priority
e.g. Period Priority
10 1 (highest)12 2
15 3
20 4 (lowest)
RM E l
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
18/44
RM Example
Rate monotonic with two tasks
C1=2 , T1=D1=5 C2=4 , T2=D2=7
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
19/44
RM Scheduling Example 1
Property indicating whether a real-time
system (a set of real-time tasks) can meet
their deadlines
(4,1)
(5,2)
(7,2)
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
20/44
Real-Time Scheduling
Determines the order of real-time task
executions
Static-priority scheduling (RM)
(4,1)
(5,2)
(7,2)
5
5
10
10 15
15
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
21/44
RM (Rate Monotonic)
Optimal static-priority scheduling
It assigns priority according to period A task with a shorter period has a higher priority
Executes a job with the shortest period
(4,1)
(5,2)
(7,2)
5
5
10
10 15
15
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
22/44
RM (Rate Monotonic)
Executes a job with the shortest period
(4,1)
(5,2)
(7,2)
5
5
10
10 15
15
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
23/44
RM (Rate Monotonic)
Executes a job with the shortest period
(4,1)
(5,2)
(7,2)
Deadline Miss !
5
5
10
10 15
15
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
24/44
Rate Monotonic Scheduling Example 2
Response time
Duration from released time to finish time
(4,1)
(5,2)
(10,2)
5
5
10
10 15
15
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
25/44
Response Time
Response time Duration from released time to finish time
(4,1)
(5,2)
(10,2)
Response Time
5
5
10
10 15
15
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
26/44
Response Time
Response Time (Ri)
(4,1)
(5,2)
(10,2)
( )k i
ii ki
T HP T k
RR C C
T
5
5
10
10
T1
T2
T3
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
27/44
RM - Schedulability Analysis
Real-time system is schedulable under
RM
if and only ifRi Tifor all task(Ti,Ci)
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
28/44
RM Utilization Bound
Real-time system is schedulable under
RM if
Ui n (21/n-1)
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
29/44
RM Utilization Bound: An Example
Real-time system is schedulable under RM if
Ui n (21/n-1)
Example: T1(4,1), T2(5,1), T3(10,1),
Ui = 1/4 + 1/5 + 1/10
= 0.55
3 (21/3-1) 0.78
Thus, {T1, T2, T3} is schedulable under RM.
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
30/44
RM Utilization Bounds
0.5
0.6
0.7
0.8
0.9
1
1.1
1 4 16 64 256 1024 4096
The Number of Tasks
Utilization
RM Utilization Bound
Real-time system is schedulable under RMif
Ui n (21/n-1)
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
31/44
Rate Monotonic Algorithm Analysis
Amongst a set of tasks, the task that occurs most frequently is assigned
highest priority
Priority of each task is fixed, i.e., Static priority
Preemptive scheduling
Proposed by Liu & Leyland (1973)
RM is considered optimal in the sense that if a set of tasks cannot be
scheduled by this algorithm, it cannot be scheduled by any other
algorithm that assigns static priorities
Despite being optimal, RMS has a limitation: CPU utilization is bounded
and it is not always possible to fully maximize CPU resources.
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
32/44
Properties of Utilization Bound U(n) = n(21/n-1)
n Bound for Utilization
1 100% One task
2 83% Two tasks case
3 78%
4 76%
69.3% = (ln 2) Infinite task case
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
33/44
CPU Utilization and Utilization Bound
In RM, one tasks CPU Utilization Ui = Ci/Ti
n tasks CPU Utilization U = Ci/Ti = Ui + U2+ + Un Utilization Bound for n tasks U(n)= n (21/n-1)
Utilization Bound Theorem:
Consider a set of n independent periodic tasks. They areschedulable under RM ifU U(n)
Ci/Ti n (21/n-1)
Conclusion:01]IfU is less than 0.693, the tasks are definitely schedulable as per RM
02] If 0.693 < U < 1, then RM schedule is still valid but there is no
guarantee of success
03] IfU > 1, the tasks are definitely not schedulable as per RM
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
34/44
Necessary Conditions for RM Schedulability
01] Individual UtilizationFor each task, Ci Ti. This means that for each task, the
execution time should be equal or less than its period.
02] Total Utilization U = [Ci / Ti] 1
This indicates that sum of all utilization ratios cannot
exceed 1. [Ci / Ti] = 1 means that CPU is 100% time
loaded. It cannot do any extra task.
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
35/44
Worst Case Response Time Ri for RM
( )i
iii j
Tj HP T j
RR C CT
Here HP(Ti) is set of higher priority tasks than T
i
In this equation Ri appears both on left as well as right side
of equality sign
This implies that the equation should be solved by multipleIteration Method
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
36/44
Worst Case Response Time for RM
( 1)
( )i
nin i i j
Tj HP T j
RR C C
T
The previous equation has been rewritten
R(n+1)i is the (n+1)th approximation to worst case response
time Rni and is found in the term of nth approximation
Multiple iterations will converge R(n+1)i = Rni
For iteration calculation we can begin with initial value R0i = 0
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
37/44
Numerical on Worst Case Response Time of Tasks
Task C has highest priority, Task Bmedium and Task A has lowest priority
Lowest priority task A has tasks B and C inhp (A) set. This is because tasks B and Chave higher priorities than task A
Step-I Calculation of R
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
38/44
Step-I Calculation of RA
Lowest priority task A
has tasks B and C in hp
(A) set. This is because
tasks B and C havehigher priorities than
task A
In order to start
iteration, we choose R0A= 0
Now subsequent
iterations are calculated
as shown:
( 1)
( )i
nin i i j
Tj HP Tj
RR C C
T
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
39/44
Step-II Calculation of RB
Medium priority task B has only one task i.e. Task C in hp (B) set. This isbecause task C has higher priority than task B
Hence RB = 20
St III C l l ti f R d C l i
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
40/44
Step-III Calculation of RC and Conclusion
There is no task having higher priority than Task C. Soset hp (C) is empty, Hence RC = CC = 10
So far we have calculated RA = 52, RB = 20 and RC = 10
Now the table of tasks is rewritten with worst-caseresponse times added in last column
Conclusion:
In each of the three tasks it is seen that Ri DiHence this task set is schedulable under RM
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
41/44
How to solve RM Numerical
Three tasks T1, T2 and T3 have periods of 50, 100 and 200 and execution
times as 10, 20 and 50 respectively. Assume Period Ti = Deadline Di
(a)What is utilization of each task?(b)What is total CPU Utilization Ui?
(c) Calculate Utilization Bound U(n)
(d) Mention priority of each task
(e) Is the task set schedulable as Utilization Bound Test?
(f) Draw Time Line Diagram of the three tasks(g)Draw Time Line Diagram of RM Scheduling sequence of the three
tasks
(h)Find out worst case response times RT1, RT2 and RT3
(i) With reference to worst case response times, is the task set RM
schedulable?
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
42/44
Step-I Calculate Ui and Ui
Ui = 0.20 + 0.20 + 0.25 = 0.65
U(n) = U(3) = 3(21/3 1) = 0.78
Since U < U(n), the task set is RM schedulable as perUtilization Bound Test
Task with lowest period has highest priority. Hence T1 has
highest priority, T2 medium and T3 lowest priority
Step-II Time Line Diagram of RM Schedule of Three Tasks
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
43/44
Step-II Time Line Diagram of RM Schedule of Three Tasks
-
7/28/2019 ESD UNIT III Lecture 03 Task Scheduling Rate Monotonic.ppt
44/44
Summary of RM TestsUtilization bound test is simple but conservative
Worst Case Response Timetest is more exactbut also more complicated
UB and Worst Case Response Time tests share
the same limitations:
all tasks run on a single processor all tasks periodic and non-interacting
deadlines always at the end of the period
no interrupts
rate monotonic priorities assigned
zero context switch overhead
tasks do not suspend themselves