You are on page 1of 49

BITS C 553 Chapter 6 and 7

Swati Keskar

BITS Pilani
Pilani|Dubai|Goa|Hyderabad

BITS Pilani
Pilani|Dubai|Goa|Hyderabad

Real-Time Systems : Scheduling

Plan of The Lecture


Priority-driven scheduling Scheduling aperiodic jobs

Swati Keskar September 21, 2013 1-3


BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Priority-Driven scheduling
Before starting the discussion, we assume that The tasks are independent There are no aperiodic and sporadic jobs Job is ready for execution as soon as it is released Jobs are preemptible and never suspends itself Scheduling decisions are made immediately upon job releases and completion Context switch overhead is negligible

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Priority-Driven scheduling
It is an on-line scheduler, does not precompute the schedule It assigns the priorities to the job after they are released and places the jobs in ready queue Two main classifications Fixed priority: assigns the same priority to all the jobs in each task Dynamic priority: assigns different priorities to the individual jobs in each task

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Fixed Priority Algorithms


Rate-Monotonic Algorithm RMA shorter the period, the higher the priority i.e. higher the rate of occurrence, higher the priority Deadline-Monotonic Algorithm DMA shorter the relative deadline, higher the priority

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Example
Consider a task set T1(7,3) , T2(12,3), T3(20,5)

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Dynamic Priority algorithms


Earliest Deadline First (EDF) assigns the priority to individual jobs in the tasks according to their absolute deadlines Least Slack-Time-first (LST) the scheduler checks the slacks of al the ready jobs each time a new job is released then the smaller the slack, the higher the priority FIFO, LIFO etc

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Schedulable Utilization
A scheduling algorithm can feasibly schedule any set of periodic tasks on a processor if the total utilization of the tasks is equal to or less than the schedulable utilization of the algorithm Higher the schedulable utilization of an algorithm , the better the algorithm A scheduling algorithm whose schedulable utilization is equal to 1 is an optimal algorithm

September 21, 2013

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

EDF Algorithm
A system T of independent, preemptable tasks with relative deadlines equal to their respective periods can be feasibly scheduled on one processor if and only if its total utilization is equal to or less than 1

ek UEDF = ---------------- 1 min(Dk,pk)

September 21, 2013

Swati Keskar

10

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

RMA and DMA


A system of simply periodic, independent, preemptible tasks whose relative deadlines are equal to or larger than their periods is schedulable on one processor according to the RM algorithm if and only if its total utilization is equal to or less than 1

September 21, 2013

Swati Keskar

11

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Schedulability Test
Schedulability test for tasks with short response times ie where the response times of the jobs are smaller than or equal to their respective periods Every job completes before the next job in the same task is released We have to the critical instant

September 21, 2013

Swati Keskar

12

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Critical Instant
A critical instant of a task Ti is a time instant which is such that the job in Ti released at the instant has the maximum response time. This maximum response time is called Worst Case Execution Time and is denoted by Wi Theorem: In a fixed priority system where every job completes before the next job in the same task is released, a critical instant of any task Ti occurs when one of its job Ji,c is released at the same time with a job in every higher priority task

September 21, 2013

Swati Keskar

13

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Time Demand Analysis


To determine whether a task can meet all its deadlines, we have to compute the total demand for processor time by a job released at a critical instant of the task and by all the higher priority tasks at that critical instant We will then check whether this demand can be met before the deadline of the job This test is called Time Demand analysis

Wi(t) = ei + t/pk ek
This Wi(t) t for some t Di
September 21, 2013 Swati Keskar

for 0< t pi

14

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Example
A task set T1(7,3); T2(12,3) and T3(20,5) is Given. It is scheduled by using Rate Monotonic Algorithm. Check its schedulability.

September 21, 2013

Swati Keskar

15

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Busy Interval
Here is a schedulability test for fixed-priority tasks with arbitrary response time When relative deadline are larger than their respective periods, we have to determine the schedulability Approach is find the busy interval and then apply time demand analysis test A level-i busy interval (t0,t ] starts at an instant t0 when All jobs in Ti released before the instant have completed A job in Ti is released The interval ends at the first instant t after to when all jobs in Ti released since t0 are complete
September 21, 2013 Swati Keskar 16

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Sufficient Schedulability condition


Schedulable utilization of RM and DM Algorithms for tasks with Di = Pi gives us a flexible design guidelines for the choices of the periods and execution times of the tasks Theorem : A system of n independent, preemptible periodic tasks with relative deadlines equal to their respective periods can be feasibly scheduled on a processor according to the RMA if its total utilization U is less than or equal to URM(n) = n(21/n -1)
September 21, 2013

and U URM
17

Swati Keskar

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

URM as a Function of Task Parameters


Schedulable utilization as a function task utilization Schedulable utilization of simply periodic tasks Period ratio Values of periods Tasks with arbitrary relative deadlines

September 21, 2013

Swati Keskar

18

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Practical Factors
Assumptions we have made at the starting are not always valid. Considering the practical factors, blocking and priority inversion has to be discussed Nonpreemptivity Self suspension Context switches Limited priority levels Tick Scheduling

September 21, 2013

Swati Keskar

19

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Tick Scheduling
We are assuming that the scheduler is event-driven This assumption is always not valid, sometimes the scheduler is time-driven Scheduling decisions are made at these time instants called clock interrupts This method is also called time-based scheduling and scheduler executes only at clock interrupts

September 21, 2013

Swati Keskar

20

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Example

September 21, 2013

Swati Keskar

21

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

16/08/2010

Swati Keskar BITS Pilani

22

Scheduling Aperiodic and Sporadic Jobs


We assume that the operating system maintains the priority queue. The ready periodic tasks are placed in the periodic task queue according to their priority assigned by any one of the algorithms Each accepted sporadic job is assigned a priority and is placed in priority queue Each newly arrived aperiodic job is placed in the aperiodic job queue

September 21, 2013

Swati Keskar

23

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

September 21, 2013

Swati Keskar

24

Alternative approaches
Background execution Polled execution Interrupt driven execution

September 21, 2013

Swati Keskar

25

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Background Execution
Aperiodic jobs are scheduled and executed only at times when there is no periodic or sporadic job ready for execution Always produces correct schedules Simple to implement Drawback is that the execution of aperiodic jobs is delayed and response time is prolonged

September 21, 2013

Swati Keskar

26

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Interrupt Driven Execution


Whenever an aperiodic job arrives, the execution of periodic tasks are interrupted and the aperiodic job is executed. In this case, aperiodic job may have the shortest possible response time But it has main disadvantage that if aperiodic job always execute as soon as possible ,periodic task may miss some deadlines

September 21, 2013

Swati Keskar

27

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Polling Server
A poller or polling server is a periodic task whose polling period is ps and es is its execution time The poller is ready for execution periodically and is scheduled together with the periodic tasks in the system When it executes, it examines the aperiodic job queue If the queue is nonempty, the poller executes the job at the head of the queue Server suspends its execution when either budget is exhausted or when the queue becomes empty

September 21, 2013

Swati Keskar

28

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Polling Server
The main disadvantage of poling server is that if at the beginning of a polling period the poller finds the aperiodic job queue empty , it suspends immediately It will not be ready for execution and able to examine the queue again until the next polling period

September 21, 2013

Swati Keskar

29

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Periodic Server
The periodic server is nothing but a periodic task created for the purpose of executing aperiodic jobs It has period ps and execution time es which is called as execution budget or simply budget The ratio us = es/ps is the size of the server At the beginning of each period, the budget of the poller is set to es i.e. its budget is replenished

September 21, 2013

Swati Keskar

30

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Periodic Server
The periodic server is backlogged whenever the aperiodic job queue is nonempty and there is at least an aperiodic job to be executed by the server The server is idle when the queue is empty The server is eligible for execution only when it is backlogged and budget When the server is scheduled and executes aperiodic jobs, it consumes its budget at the rate of one per unit time The server budget becomes exhausted when the budget becomes zero

September 21, 2013

Swati Keskar

31

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Bandwidth-preserving Servers
If we can preserve the execution budget of the poller when it finds an empty queue and allow it to execute later in the period if any aperiodic job arrives, we can improve the response time of aperiodic job Algorithms that improve the polling approach in ths manner are called bandwidth preserving server algorithm These are periodic servers, each type of server is defined by a set of consumption and replenishment rules

September 21, 2013

Swati Keskar

32

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Bandwidth-preserving Servers
Types of bandwidth-preserving servers Deferrable servers Sporadic servers Constant utilization/total bandwidth servers and weighted fair-queuing servers

September 21, 2013

Swati Keskar

33

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Deferrable servers
Consumption rule: The execution budget of the server is consumed at the rate of one per unit time whenever the server executes Replenishment rule : The execution budget of the server is set to es at time instants kpk for k = 0,1,2

September 21, 2013

Swati Keskar

34

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

September 21, 2013

Swati Keskar

35

September 21, 2013

Swati Keskar

36

September 21, 2013

Swati Keskar

37

Schedulability with deferrable Server


Time demand analysis can be used to determine whether all the periodic tasks remain schedulable in the presence of a deferrable server (highest priority) The time demand function of the task Ti in presence of deferrable server is given by

September 21, 2013

Swati Keskar

38

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Schedulable Utilization
Schedulability of a fixed-priority system in which a deferrable server is scheduled at an arbitrary priority cannot be assured Only exception is when the deferrable server has shortest period in a system of n tasks and the system is scheduled ratemonotonically

September 21, 2013

Swati Keskar

39

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Theorem for Schedulable Utilization


Consider a system of n independent, preemptible periodic tasks whose periods satisfy the inequalities ps < p1 < p2 < < pn < 2ps and pn > ps + es and whose relative deadlines are equal to their respective periods. This system is schedulable rate-monotonically with a deferrable server (ps, es) if their total utilization is less than or equal to

September 21, 2013

Swati Keskar

40

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Theorem for Schedulable Utilization


When the servers period is arbitrary, we can use URM(n) to determine whether each periodic task Ti is schedulable if the periodic tasks and the server are scheduled ratemonotonically We can treat additional es units of time as additional blocking time of the task Ti. Ti is surely schedulable if

September 21, 2013

Swati Keskar

41

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Schedulability with deadline-driven systems


A periodic task Ti in a system of n independent, preemptive periodic tasks is schedulable with a deferrable server with period ps, execution budget es and utilization us, according to the EDF algorithm if

September 21, 2013

Swati Keskar

42

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Sporadic Servers
Improved version of deferrable servers The consumption and replenishment rules of this server ensure that each sporadic server with period ps and budget es never demands more processor time than the periodic task (ps,es) in any time interval We can treat the sporadic server exactly like the periodic task when we check for the schedulability of the system A system of periodic tasks containing a sporadic server may be schedulable while the same system containing a deferrable server with same parameters is not

September 21, 2013

Swati Keskar

43

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Simple Sporadic Server


Consumption rules : at any time t after tr ie replenishment time, the servers budget is consumed at the rate of 1 unit per time until the budget is exhausted when either one of the following conditions are true C1 : The server is executing C2: The server has executed since tr and END <t where END is the end of the latest busy interval

September 21, 2013

Swati Keskar

44

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Replenishment Rules
Replenishment rules of Simple Fixed-Priority-Sporadic server are R1 : Initially when the system begins execution and each time when the budget is replenished, the execution budget = es and tr = the current time R2: At the time tf (first instant after tr when server begins execution), if END = tf , te = max( tr, BEGIN). If END < tf, te=tf. The next replenishment time is set at te+ps

September 21, 2013

Swati Keskar

45

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Replenishment Rules
R3 : The next replenishment occurs at the next replenishment time, except under the following conditions If the next replenishment time te + ps is earlier than tf, the budget is replenished as soon as it is exhausted If the system T becomes idle before the next replenishment time te + ps , and becomes busy again at tb, the budget is replenished at min( te+ps, tb).

September 21, 2013

Swati Keskar

46

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Scheduling of Sporadic Jobs


The scheduler performs an acceptance test on each sporadic job upon its arrival The acceptance tests are performed on sporadic jobs in the EDF order Once accepted, sporadic jobs are ordered among themselves in the EDF order

September 21, 2013

Swati Keskar

47

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Acceptance Test
For deadline-driven system For first sporadic job S (t,d,e), the scheduler accepts S if its density e/(d-t) < 1-

For new sporadic jobs , the scheduler accepts the job S if e / (d t) + s,k 1- for all k = 1,2

September 21, 2013

Swati Keskar

48

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

Acceptance Test
For fixed-priority systems For first sporadic job, find slack time s,1(t) = (ds,1-t)/ps es es,1 0

For next sporadic jobs, the scheduler computes the slack s,I according to
s,i(t) = (ds,i-t)/ps es es,I (es,k - s,k) 0

September 21, 2013

Swati Keskar

49

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

You might also like