Sie sind auf Seite 1von 44

SHRI SANT GAJANAN MAHARAJ COLLEGE OF ENGINEERING

Department of Electronics & Telecommunication Engineering



Real Time Task Scheduling
Unit-III: : Real Time Systems & RTOS
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
Task Scheduling Algorithms
RTOS Scheduler
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
Schedulability Test
Task set complexity
Sufficient Necessary Exact
If a sufficient schedulability
test is positive, these tasks
are definitely schedulable
If a necessary schedulability
test is negative, these tasks
are definitely not schedulable
Scheduling Algorithm
Is there an algorithm that will find a
feasible schedule in bounded time ?

Is the algorithm optimal, i.e. will it find a
schedule whenever one exists ?

Scheduling Algorithm
Classification
Best effort vs. Guaranteed
Static vs. Dynamic
Pre-emptive vs. Non pre-emptive
Centralized vs. Distributed
Scheduling Algorithm
Best 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
Scheduling Algorithm
Static 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.
Scheduling Algorithm
Static 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
Scheduling Algorithm
Preemptive vs. Non pre-emptive
Preemptive Scheduling:
Event driven.
Each event causes interruption of running tasks.
Choice of running tasks reconsidered after each
interruption.
Benefits:
Can minimize response time to events.
Disadvantages:
Requires considerable computational resources for
scheduling
Scheduling Algorithm
Preemptive 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
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
Rate Monotonic Algorithm
Assumptions
1. No non pre-emptible parts in a task, and
negligible preemption cost
2. Resource constraint on CPU time only
3. No precedence constraints among tasks
4. All tasks periodic
5. Relative deadline = period
RM Parameters
Let Ti be period of task
Ci = Execution time
Di = Deadline
Utilization ratio Ui = Ci/Ti
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 Example
Rate monotonic with two tasks
C
1
=2 , T
1
=D
1
=5
C
2
=4 , T
2
=D
2
=7

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)
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
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
T
1
T
2
T
3
RM (Rate Monotonic)
Executes a job with the shortest period
(4,1)
(5,2)
(7,2)
5
5
10
10 15
15
T
1
T
2
T
3
RM (Rate Monotonic)
Executes a job with the shortest period
(4,1)
(5,2)
(7,2)
Deadline Miss !
5
5
10
10 15
15
T
1
T
2
T
3
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
T
1
T
2
T
3
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
T
1
T
2
T
3
Response Time
Response Time (Ri)








(4,1)
(5,2)
(10,2)
( ) k i
i
i k
i
T HP T
k
R
R C C
T
e
(
= +
(
(

5
5
10
10
T
1
T
2
T
3
RM - Schedulability Analysis
Real-time system is schedulable under
RM
if and only if R
i
T
i
for all task (T
i
,C
i
)




RM Utilization Bound
Real-time system is schedulable under
RM if
U
i
n (2
1/n
-1)



RM Utilization Bound: An Example
Real-time system is schedulable under RM if
U
i
n (2
1/n
-1)

Example: T
1
(4,1), T
2
(5,1), T
3
(10,1),

U
i
= 1/4 + 1/5 + 1/10

= 0.55
3 (2
1/3
-1) 0.78

Thus, {T
1
, T
2
, T
3
} is schedulable under RM.


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
U
t
i
l
i
z
a
t
i
o
n
RM Utilization Bound
Real-time system is schedulable under RM
if
U
i
n (2
1/n
-1)



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.



Properties of Utilization Bound U(n) = n(2
1/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
CPU Utilization and Utilization Bound
In RM, one tasks CPU Utilization U
i
= C
i
/T
i
n tasks CPU Utilization U = C
i
/T
i
= U
i
+ U
2
+ + U
n
Utilization Bound for n tasks U(n) = n (2
1/n
-1)
Utilization Bound Theorem:
Consider a set of n independent periodic tasks. They are
schedulable under RM if U U(n)
C
i
/T
i
n (2
1/n
-1)
Conclusion:
01] If U 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] If U > 1, the tasks are definitely not schedulable as per RM






Necessary Conditions for RM Schedulability
01] Individual Utilization
For each task, C
i
T
i.
This means that for each task, the
execution time should be equal or less than its period.

02] Total Utilization U = [C
i
/ T
i
] 1
This indicates that sum of all utilization ratios cannot
exceed 1. [C
i
/ T
i
] = 1 means that CPU is 100% time
loaded. It cannot do any extra task.



Worst Case Response Time R
i
for RM
( ) i
i
i
i j
Tj HP T
j
R
R C C
T
e
(
= +
(
(
(

Here HP(T
i
) is set of higher priority tasks than T
i

In this equation R
i
appears both on left as well as right side
of equality sign

This implies that the equation should be solved by multiple
Iteration Method
Worst Case Response Time for RM
( 1)
( ) i
ni
n i i j
Tj HP T
j
R
R C C
T
+
e
(
= +
(
(
(

The previous equation has been rewritten



R
(n+1)i
is the (n+1)th approximation to worst case response
time R
ni
and is found in the term of nth approximation

Multiple iterations will converge R
(n+1)i
= R
ni

For iteration calculation we can begin with initial value R
0i
= 0



Numerical on Worst Case Response Time of Tasks
Task C has highest priority, Task B
medium and Task A has lowest priority
Lowest priority task A has tasks B and C in
hp (A) set. This is because tasks B and C
have higher priorities than task A
Step-I Calculation of R
A
Lowest priority task A
has tasks B and C in hp
(A) set. This is because
tasks B and C have
higher priorities than
task A
In order to start
iteration, we choose R
0
A

= 0
Now subsequent
iterations are calculated
as shown:

( 1)
( ) i
ni
n i i j
Tj HP T
j
R
R C C
T
+
e
(
= +
(
(
(

Step-II Calculation of R
B
Medium priority task B has only one task i.e. Task C in hp (B) set. This is
because task C has higher priority than task B

Hence R
B
= 20
Step-III Calculation of R
C
and Conclusion

There is no task having higher priority than Task C. So
set hp (C) is empty, Hence R
C
= C
C
= 10
So far we have calculated R
A
= 52, R
B
= 20 and R
C
= 10
Now the table of tasks is rewritten with worst-case
response times added in last column
Conclusion:
In each of the three tasks it is seen that R
i
D
i
Hence this task set is schedulable under RM
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 T
i
= Deadline D
i

(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 R
T1
, R
T2
and R
T3

(i) With reference to worst case response times, is the task set RM
schedulable?

Step-I Calculate U
i
and U
i
Ui = 0.20 + 0.20 + 0.25 = 0.65

U(n) = U(3) = 3(2
1/3
1) = 0.78

Since U < U(n), the task set is RM schedulable as per
Utilization 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
Summary of RM Tests
Utilization bound test is simple but conservative
Worst Case Response Time test is more exact
but 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

Das könnte Ihnen auch gefallen