19
GENERALIZED TASK SCHEDULER In practical applications we need to be able to schedule a mixture of periodic, aperiodic, and sporadic tasks. Assigning aperiodic and sporadic tasks to frames will affect the overall achievable utilization factor of the system. Slack time in a frame is the time left after the periodic tasks allocated to the frame complete. In a generalized scheduler, initially a schedule only for periodic tasks is developed; the sporadic and aperiodic tasks are scheduled in the slack time available in the frames. An arriving sporadic task is taken for scheduling only if enough slack time is available the task to complete before its deadline => acceptance test upon its arrival The best effort can be made to schedule them in the available slack no guarantee for meeting deadlines. Aperiodic task do not have strict deadline EFFICIENT IMPLEMETATION slack times for all frames are stored in a table and during acceptance test this table is used to check schedulability of the arriving tasks POPULAR ALTERNATIVE all sporadic and aperiodic tasks are accepted and best effort is made to meet their deadlines ENGG4420 ‐‐ CHAPTER 4 ‐‐ LECTURE 4 November1209 2:49 PM CHAPTER 4 By Radu Muresan University of Guelph Page 1

2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

GENERALIZED TASK SCHEDULER

In practical applications we need to be able to schedule a mixture of periodic, aperiodic, and sporadic tasks.

Assigning aperiodic and sporadic tasks to frames will affect the overall achievable utilization factor of the system.

Slack time in a frame is the time left after the periodic tasks allocated to the frame complete.

In a generalized scheduler, initially a schedule only for periodic tasks is developed; the sporadic and aperiodic tasks are scheduled in the slack time available in the frames.

An arriving sporadic task is taken for scheduling only if enough slack time is available the task to complete before its deadline => acceptance test upon its arrival

The best effort can be made to schedule them in the available slack ‐ no guarantee for meeting deadlines.

○Aperiodic task do not have strict deadline •

EFFICIENT IMPLEMETATION ‐ slack times for all frames are stored in a table and during acceptance test this table is used to check schedulability of the arriving tasks

POPULAR ALTERNATIVE ‐ all sporadic and aperiodic tasks are accepted and best effort is made to meet their deadlines

ENGG4420 ‐‐ CHAPTER 4 ‐‐ LECTURE 4November‐12‐092:49 PM

CHAPTER 4 By Radu Muresan University of Guelph Page 1

Page 2: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

PSEUDO‐CODE FOR A GENERALIZED SCHEDULER

The generalized scheduler below schedules periodic, aperiodic, and sporadic tasks; it is assumed that the precomputed schedule for periodic tasks is stored in a schedulable table, and the sporadic tasks have been subjected to an acceptance test and only the tasks that have passed the test are available for scheduling

cyclic-scheduler( ) {current-task T = Schedule-Table [k];k = k + 1; //N is the total number of tasksk = k mod N; //in the schedule table

dispatch-current-Task (T);schedule-sporadic-tasks( ); //current task T //completed early, sporadic task can be takenschedule-aperiodic-tasks ( ); //at the end of the //frame, the running task is preempted, //if not completeidle ( ); //no task to run, idle}

The cyclic scheduler routine cyclic‐scheduler() is activated at the end of every frame by a periodic timer

CHAPTER 4 By Radu Muresan University of Guelph Page 2

Page 3: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

COMPARISON OF CYCLIC AND TABLE‐DRIVEN SCHEDULING

A cyclic scheduler needs to set a periodic timer only once at the application initialization time; this timer continues to give an interrupt exactly at every frame boundary.

In a table‐driven scheduling, a timer has to be set every time a task starts to run; the execution time of a typical real‐time task is usually of the order of a few milliseconds => a call to a timer is made every few milliseconds => degraded system performance.

A CYCLIC SCHEDULER IS MORE EFFICIENT THAN A TABLE‐DRIVEN SCHEDULER

The frame size must be chosen to be greater than the largest execution time of a task => processor time can be wasted when we execute tasks that have their execution times smaller than the frame size.

If the overhead of setting a timer can be ignored A TABLE DRIVEN SCHEDULER IS MORE PROFICIENT than a cyclic scheduler because:

CHAPTER 4 By Radu Muresan University of Guelph Page 3

Page 4: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

HYBRID SCHEDULERS

In hybrid schedulers, the scheduling points are defined both through the clock interrupts and the event occurrences.

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan; Fall 200628

Time-Sliced Round-Robin SchedulingAlso, called processor-sharing algorithm

Round-robin approach is used for scheduling time-shared applications

n n-1 3 2 1

FIFO Queue

Scheduling Algorithmti – time slice (xx ms)

t1 t2 tn

Job Completion

preempted

jobs enteringthe queue

the job at the head of the queueenters execution for at most one time slice

Round period = n*tWhere: n - number of jobsand t - time slice1/n – processor share/job

Time sliced round‐robin schedulers are commonly used in the traditional operating systems.

This type of scheduler treats all task equally, and all tasks are assigned identical time slices irrespective of their priority, criticality, or closeness to their deadline.

A time‐sliced round‐robin scheduler is less proficient than table‐driven or cyclic scheduler

We can extend the round‐robins scheme and assign weights to tasks.

CHAPTER 4 By Radu Muresan University of Guelph Page 4

Page 5: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan29

Weighted Round-Robin Approach

WRR has been used for scheduling real-time traffic in high-speed switched networks

n n-1 3 2 1

FIFO Queue

Scheduling Algorithmt – time slice (xx ms)

w1t w2t wnt

Job Completion

preempted

jobs enteringthe queue

the job at the head of the queueenters execution for wt slices

Round length = ∑(wi*t)

The weighted round‐robin algorithm has been used for scheduling real‐time traffic in high‐speed switched networks. 

Rather than giving all the ready jobs equal shares of the processor, different jobs may be given different weights. Here, the weight of a job refers to the fraction of processor time allocated to the job.

Specifically, a job with weight w gets w*t time slices every round, and the length of a round is equal to the sum of the weights of all the ready jobs. By adjusting the weights of the jobs, we can speed up or retard the progress of each job toward its completion.

CHAPTER 4 By Radu Muresan University of Guelph Page 5

Page 6: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

SHORTCOMINGS OF CYCLIC SCHEDULERSDifficult to determine a suitable frame size as well as a feasible schedule when the number of tasks is large

In almost every frame some processing time is wasted (as the frame size is larger than all task execution times) resulting in sub‐optimal schedules

Reduced proficiency in handling sporadic and aperiodic tasks

EVENT DRIVEN SCHEDULERS  overcome these shortcomings, however they are less efficient as they deploy more complex scheduling algorithms => event‐driven schedulers are less suitable for embedded applications as they required to be of small size, low cost, and consume minimal amount of power.In event‐driven schedulers, the scheduling points are defined by tasks completion and task arrival events

These class of schedulers are normally preemptive, that is, a higher priority task when ready, preempts any lower priority task that may be running

WE DISCUSS 3 important examples of event‐driven schedulers: 1) foreground‐background; 2) EDF; 3) RMA

EVENT‐DRIVEN SCHEDULINGNovember‐13‐096:33 PM

CHAPTER 4 By Radu Muresan University of Guelph Page 6

Page 7: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan31

Priority-Driven Approach (Event-Driven) The term priority-driven algorithms refers to a large class of

scheduling algorithms that never leave any resources idle intentionally

Priority-driven algorithms are event-driven scheduling decisions are made when events such as release and

completions of jobs occur A priority-driven algorithm is greedy because it tries to make

locally optimal decisions A priority-driven algorithm is list scheduling because any priority-

driven algorithm can be implemented by assigning priorities to jobs

ResourceAvailability Data

List of PrioritiesQueues

Releasesand

Completionsof Jobs

Priority Driven Scheduling Algorithms

Events

greedy scheduling list scheduling

A priority driven algorithm is greedy because it tries to make locally optimal decisions. Leaving a processor or resource idle while some job is ready to use them is not locally optimal. However, sometimes it is better to have some jobs wait even when they are ready to execute and the resources they require are available. 

The term list scheduling implies assigning priorities to jobs. Jobs ready for execution are placed in one or more queues ordered by the priorities of the jobs. At any scheduling decision time, the jobs with the highest priorities are scheduled and executed on the available processors. Hence, a priority‐driven scheduling algorithm is defined to a great extent by the list of priorities it assigns to jobs; the priority list and other rules, such as whether preemption is allowed, define scheduling algorithm completely. 

A resource (processor or other type) idles only when no job requiring the resource is ready for execution. Scheduling decisions are made when events such a release and completions of jobs occur. Hence, priority‐driven algorithm are event‐driven. Other commonly used names for this approach are greedy scheduling, list scheduling and work‐conserving scheduling. 

Examples include: FIFO (First‐In‐First‐Out), LIFO (Last‐In‐First‐Out) which assign priorities to jobs according to their release time; SETF (Shortest‐Execution‐Time‐First) and LEFT (Longest‐Execution‐Time‐First), which are algorithm that assign priorities based on the basis of job execution time.

○Most scheduling algorithms used in non‐real‐time systems are priority‐driven. •

CHAPTER 4 By Radu Muresan University of Guelph Page 7

Page 8: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan33

Example of Priority-Driven Approach

Schedule and execute the jobs J1, …, J8 on 2 processors with shared memory

Task graph: Ji, k i job number

k execution time

J5 released at 4; all other jobs at time 0

Priority list Ji > Jk if i < k

(a) jobs are preemptable

(b) jobs are nonpreemptable

Priority list

0 1 2 3 4 5 6 7 8 9 10 11 12

0 1 2 3 4 5 6 7 8 9 10 11 12

0 1 2 3 4 5 6 7 8 9 10 11 12

0 1 2 3 4 5 6 7 8 9 10 11 12

P1

P2

P1

P2

J1

J2

J2

J1

J3

J3

J4 J7 J6

J5J7 J8

J4 J5 J6

J7 J8

(J1, J2,…,J8)

J1,3

J3,2 J4,2J2,1

J6,4J5,2

J7,4 J8,1

(a)

(b)

All edges in the task graph shown represent precedence constraints.  The priority list is given next to the graph: Ji has a higher priority than Jk if i < k. All the jobs are preemptable; scheduling decisions are made whenever some job becomes ready for execution or some job completes. 

At time 1, J2 completes and hence, J3 becomes ready; J3 is placed in the priority queue ahead of J7 and is scheduled on P2 (P2 was freed by J2).

At time 3, both J1 and J3 complete; J5 is still not released; J4 and J7 are scheduled.

At time 4, J5 is released. Now we have 3 jobs ready. J7 has the lowest priority; consequently it is preempted and J4 and J5 have the processors. 

At time 5, J4 completes; J7 resumes on processor P1.○At time 6, J5 completes; because J7 is not yet completed, both J6 and J8 are not ready for execution; consequently, P2 becomes idle.

J7 finally completes at time 8; J6 and J8 can now be scheduled.○

Schedule (a) shows the schedule of jobs on the two processors generated by the priority‐driven algorithm following this priority assignment. At time 0, jobs J1, J2, and J7 are ready for execution. They are the only jobs in the common priority queue at this time. J1 and J2 are scheduled. The following events occur and new scheduling decisions are made:

Schedule (b) shows a non‐preemptive schedule according to the same priority assignment. It turns out that for this system the postponment of J5 at time 4 benefits the set of jobs as a whole. In general, nonpreemptive scheduling is not better than preemptive scheduling.

CHAPTER 4 By Radu Muresan University of Guelph Page 8

Page 9: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

FOREGROUND‐BACKGROUND SCHEDULER

Simplest priority‐driven preemptive schedulerReal‐time tasks are run as foreground tasks;•The sporadic, aperiodic, and non‐real‐time tasks are run as background tasks ‐ the background tasks run at the lowest priority.

Assume that we have n foreground periodic tasks T1, T2, ..., Tn and one background task TB with its execution time eB. In this case the completion time ctB for the background task is given by:

CHAPTER 4 By Radu Muresan University of Guelph Page 9

Page 10: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

EXAMPLE 1

Consider a real‐time system in which tasks are scheduled using foreground‐background scheduling of one foreground task Tf and one background task TB. Compute the completion time for the background task if: 

CHAPTER 4 By Radu Muresan University of Guelph Page 10

Page 11: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

ASSIGNMENTS

PROBLEM 1. In a simple priority‐driven preemptive scheduler, two periodic tasks T1 and T2 and a back‐ground task T3 are scheduled. The periodic task T1 has the highest priority and executes once every 20 ms and requires 10 ms of execution time each time. T2 requires 20 ms of processing every 50 ms. T3, the background task, requires 100 ms to complete. Assuming that all the tasks start at time 0, determine the time at which T3 will complete.

PROBLEM 2. Suppose that in PROBLEM 1, an overload of 1 ms on account of every context switch is to be taken into account. Compute the completion time of T3.

CHAPTER 4 By Radu Muresan University of Guelph Page 11

Page 12: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

In EDF scheduling, at every scheduling point the task having the shortest absolute deadline is taken up for scheduling.A task set is schedulable under EDF, if and only if it satisfies the condition that the total processor utilization due to the task set is less than 1. For a set of periodic real‐time tasks {T1, T2, ..., Tn}, EDF schedulability criterion can be expressed as:

EDF has been proven to be an optimal uniprocessor scheduling algorithm.

If pi > di, then each task needs ei execution time every min(pi, di). Therefore, Eq (2) can be rewritten as:

However, if pi < di, it is possible that a set of tasks is EDF schedulable, even when the task set fails to meet Eq. (3). Therefore, Eq. (3) is conservative in this case and is not a necessary condition, but only a sufficient condition for a given task set to be EDF schedulable.

EARLIEST DEADLINE FIRST (EDF) SCHEDULINGNovember‐13‐096:35 PM

CHAPTER 4 By Radu Muresan University of Guelph Page 12

Page 13: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

EXAMPLE OF EDF SCHEDULE

Consider the following task set

CHAPTER 4 By Radu Muresan University of Guelph Page 13

Page 14: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

MINIMUM LAXITY FIRST (MLF) scheduling is a variant of EDF. In MLF, at every scheduling point, a laxity value is computed for every task in the system, and the task having the minimum laxity is executed first. 

Unlike EDF, MLF takes into consideration the execution time of a task

Laxity of a task measures the amount of time that would remain if the task is taken up for execution next ‐ laxity is a measure of the flexibility available for scheduling a task.

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan96

Minimum Laxity First (MLF) Algorithm

Scheduler checks the slack of all the ready jobs each time a new job is released (Slack = d-t-x) and schedules based: The smaller the slack the higher the priority

Ex. {T1,T2} = {(2, 0.9), (5, 2.3)} => MLF identical with EDF Ex.{T1,T2,T3} = {(2, 0.8), (5, 1.5), (5.1,1.5)} => Φi=0; Di=pi

(p1,e1) (p2,e2) (p3,e3)(Φi,pi,ei,Di)

2 4 5 10

2 4 5 10

Decision

Execution

Decision

Execution

Φ=0J1,1

J2,1

J3,1

J1,2

J2,1

J3,1

CHAPTER 4 By Radu Muresan University of Guelph Page 14

Page 15: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

EDF EXAMPLE

Consider the 3 periodic real‐time tasks to be scheduled using EDF on a uniprocessor: T1:(20, 10); T:(50, 5); T3:(35, 10). 

Determine whether the task set is schedulable.

CHAPTER 4 By Radu Muresan University of Guelph Page 15

Page 16: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

IS EDF REALLY A DYNAMIC PRIORITY SCHEDULING ALGORITHM

If EDF were to be considered a dynamic priority‐scheduling algorithm, we should be able to determine the priority value of each task at any point of time and also be able to show how it changes with time.As described, EDF scheduling does not require any priority value for any task to be computed at any time. 

Tasks are scheduled solely on their proximity to their deadlines

However, the longer the task waits in the ready queue, the higher the chance  (probability) of being taken up for scheduling => a virtual priority value associated with a task keeps increasing with time until the task is taken up for scheduling

CHAPTER 4 By Radu Muresan University of Guelph Page 16

Page 17: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

ENGG4420: Real-Time Systems Design; Developed by Radu Muresan95

EDF Algorithm

0 2 4 6 8 10

EDF algorithm: dynamic-priority algorithm assigns priorities to individual jobs in the tasks according to their

absolute deadlines task-level dynamic-priority (and job-level fixed-priority) algorithm

once a job is placed in the ready queue according to its priority its order with respect to other jobs in the queue remains fixed

Ex: Priority of T1 is > priority of T2 from time 0 until time 4 T2 starts to have higher priority at time 4 When job J2,2 is released, T2 again has a lower priority

(b)

RM-ScheduleAn earliest-deadline-first schedule of (2, 0.9) and (5, 2.3)

0 2 4 6 8 10

CHAPTER 4 By Radu Muresan University of Guelph Page 17

Page 18: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

IMPLEMENTATION OF EDF

Maintain all ready tasks in a queuea.Insert new freshly arriving tasks at the end of queueb.Every node in the queue will contain the Di of tasksc.At every preemption point the entire queue will be scanned from beginning to determine the task with the shortest deadline

d.

Complexity of the scheme: insertion of a task is achieved in O(1) or constant time; task selection (to run next) and its deletion would require O(n) time.

e.

NAIVE IMPLEMENTATION OF EDF: 1.

Maintain all ready tasks in a sorted priority queue that can be efficiently implemented by using a heap data structure ‐ the sort criteria is in accordance to the tasks proximity to their deadline

a.

When a task arrives, a record for it can be inserted into the heap in O(log2n) time

b.

At every scheduling point, the next task to be run can be found at the top of the heap => O(1) time.

c.

EFFICIENT IMPLEMENTATION 1 OF EDF: 2.

Assume that the number of distinct deadlines that tasks in an application can have are restricted

a.

A separate FIFO queue is maintained for each distinct relative deadline

b.

The scheduler inserts a newly arrived task at the end of the corresponding relative deadline queue => tasks in each queue are ordered according to their absolute deadline

c.

Complexity: find the task to run is in O(1) time; time to insert a task is O(1)

d.

EFFICIENT IMPLEMENTATION 2 OF EDF:3.

CHAPTER 4 By Radu Muresan University of Guelph Page 18

Page 19: 2:49 PM GENERALIZED TASK SCHEDULER - uoguelph.ca 4 LECTURE 4...defined both through the clock interrupts and the event occurrences. ENGG4420: Real-Time Systems Design; Developed by

SHORTCOMINGS OF EDF

When EDF is used to schedule a set of periodic real‐time tasks, a task overshooting its completion time can cause other task(s) to miss their deadlines.

a.

We can't predict which task will miss its deadline, and it can happen with the most critical task.

b.

TRANSIENT OVERLOAD PROBLEM: denotes the overload of a system for a very short time. Transient overload occurs when some task takes more time to complete due to reasons such as, entering an infinite loop, entering a rarely used branch due to some abnormal input values, etc.

1.

RESOURCE SHARING PROBLEM: when EDF is used to schedule a set of real‐time tasks, unacceptably high overheads might have to be incurred to support resource sharing among the tasks without making tasks to miss their respective deadlines (later).

2.

EFFICIENT IMPLEMENTATION PROBLEM: the efficient implementation that assumes a restricted number of tasks with distinct deadlines is not always feasible. For a more flexible EDF algorithm, we need to keep the tasks ordered in terms of their deadlines using a priority queue.

3.

CHAPTER 4 By Radu Muresan University of Guelph Page 19