Top Banner
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University
39

Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Jan 01, 2016

Download

Documents

Godfrey Allison
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Real-Time Scheduling

CS4730 Fall 2010Dr. José M. Garrido

Department of Computer Science and Information Systems

Kennesaw State University

Page 2: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

CPU Scheduling

Overview of basic non-real time Scheduling techniques

The most relevant RT scheduling techniques

Page 3: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

General Processor Scheduling

Allocation of tasks to processor for execution, in some order

A set of performance metrics is usually derived

3

Page 4: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

CPU Scheduling

The scheduler selects the next process to execute from among several processes waiting in the ready queue.

The dispatcher allocates the CPU to the selected process at the appropriate time.

Page 5: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Scheduling (General)

Issues in scheduling Basic scheduling algorithms

First-come First-served Round Robin Shortest Process Next Priority based

Real-time scheduling

5

Page 6: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

6

Scheduling Issues

Application Profile: A program alternates between CPU usage and

I/O Relevant question for scheduling: is a program

compute-bound (mostly CPU usage) or I/O-bound (mostly I/O wait)

Multi-level scheduling (e.g., 2-level in Unix) Swapper decides which processes should

reside in memory Scheduler decides which ready process gets

the CPU next

Page 7: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Scheduling Issues

When to context-switch When a process is created When a process terminates When a process issues a blocking call (I/O,

semaphores) On a clock interrupt On I/O interrupt (e.g., disk transfer finished,

mouse click) System calls for IPC (e.g., up on semaphore,

signal, etc.)

7

Page 8: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

8

Scheduling Issues

Is preemption allowed? Nonpreemptive scheduler does not use clock interrupts to stop a

process What performance metrics should be optimized?

CPU utilization: Fraction of time CPU is in use Throughput: Average number of jobs completed per time unit Turnaround Time: Average time between job submission and

completion Waiting Time: Average amount of time a process is ready but waiting Response Time: in interactive systems, time until the system responds

to a command Response Ratio: (Turnaround Time)/(Execution Time) -- long jobs

should wait longer

Page 9: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

9

Scheduling Issues

Different applications require different optimization criteria Batch systems (throughput, turnaround time) Interactive system (response time, fairness, user

expectation) Real-time systems (meeting deadlines)

Overhead of scheduling Context switching is expensive (minimize context switches) Data structures and book-keeping used by scheduler

What’s being scheduled? Processes and Threads

Page 10: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Process Activities

Every process that request CPU service, carries out the following sequence of actions:

1. Join the ready queue and wait for CPU service. 2. Execute (receive CPU service) for the duration of the

current CPU burst or for the duration of the time slice (timeout).

3. Join the I/O queue to wait for I/O service or return to the ready queue to wait for more CPU service.

4. Terminate and exit if service is completed, i.e., there are no more CPU or I/O bursts. If more service is required, return to the ready queue to wait for more CPU service.

Page 11: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Simple Model for CPU Scheduling

Page 12: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Scheduler

Insertion of processes that request CPU service into the ready queue. This function is carried by the enqueuer, a component of the scheduler.

The occurrence of a context switch, carried by the context switcher that saves the context of the current process and de-allocates the CPU from that process.

The selection of the next process from the ready queue and loading its context. This can be carried out by the dispatcher, which then allocates the CPU to the newly selected process.

Page 13: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Dispatcher

Dispatcher module gives control of the CPU to the process selected by the short-term scheduler context switching switching to user mode jumping to the proper location in the user program to

restart (resume) that program Dispatch latency – the time that elapses from

the stopping one process to the starting of the newly selected process

Page 14: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

14

RT SCHEDULING

In real-time systems, the purpose of scheduling is to determine whether or not a set of computations are feasible in time

A set of computations are feasible or schedulable on one or more processors if there exist: sufficient processor cycles, and some execution orderingto execute all the computations

Page 15: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Schedule

A specific time allocation of tasks to the processors is called a schedule

If the scheduling algorithm can allocate the tasks so that all constraints are met, then the resulting schedule is said to be feasible

15

Page 16: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Cyclic Executives

General traditional algorithmic and software methods for organizing real-time processes

Are designed mainly for periodic processes The principal goal is to allocate one or more

processors to a set of processes in such a manner that they meet their deadlines

A feasible execution schedule is constructed by interleaving process executions

Fall 2010 (C) J M Garrido 16

Page 17: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Organizing Proceeses for CE

A periodic process consists of a sequence of computations, each called: slice, action, scheduling block

Each computation has a worst case computing time interval and is scheduled as an atomic unit by the CE

A major schedule is an allocation of these process computations for all processes, such that all deadlines are met

Fall 2010 (C) J M Garrido 17

Page 18: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Foreground/Background Computing

The periodic real-time processes are allocated to the foreground

The non-real-time, soft real-time, and non-critical processes are allocated to the background

The processes in the background can be preempted by those in the foreground

Fall 2010 (C) J M Garrido 18

Page 19: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

A Major Cycle in a Schedule

Fall 2010 (C) J M Garrido 19

Page 20: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

20

Periodic Tasks

Typical real-time application has many tasks that need to be executed periodically Reading sensor data Computation Sending data to actuators Communication

Standard formulation: Given a set of tasks T1, … Tn. Each task Ti has period Pi and computation time Ci

Page 21: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Schedulability Problem

Can all the tasks be scheduled so that every task Ti gets the CPU for Ci units in every interval of length Pi ?

Page 22: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

22

Periodic Tasks Example

Example: Task T1 with period 10 and CPU time 3 Task T2 with period 10 and CPU time 1 Task T3 with period 15 and CPU time 8

Possible schedule: repeats every 30 sec T1 from 0 to 3, 12 to 15, 24 to 27 T2 from 3 to 4, 15 to 16, 27 to 28 T3 from 4 to 12, 16 to 24 If T2 has period 5 (instead of 10) then there is no feasible schedule

Simple test: Task Ti needs to use CPU for Ci/Pi fraction per unit Utilization = Sum of Ci/Pi

Task set is schedulable if and only if utilization is 1 or less.

Page 23: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Issues in RT Scheduling Example1

23

Two processes: P1 (1,2,2) and P2 (2, 5, 5)prio (P1) > prio (P2)No preemption

Schedule can be repeated at time t = 10

Page 24: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

If the priorities are reversed, prio (P2) > prio(p1)

P2 starts at t = 0 P2 will compute for 2 time units, which is the

first cycle of P1 P1, will therefore, miss its deadline

Page 25: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

RR with Preemption

25

Two processes: P1 (1, 2, 2) and P2 (2, 5, 5)

Page 26: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

RR Scheduling Example 2

26

Two processes: P1 (3, 4, 4) and P2 (2, 8, 8) using RR scheduling with one unit time intervals. At time t = 4, P1 has executed only 2 time units

Page 27: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

RR Scheduling Example 2

27

Two processes: P1 (3, 4, 4) and P2 (2, 8, 8) using RR scheduling with one unit time intervals. P1 has higher priority than P2.P2 is preempted by P1 at t = 4

Page 28: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Real-Time Scheduling

Earliest Deadline First (EDF)Rate Monotonic Scheduling (RMS)

28

Page 29: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Rate Monotonic Scheduling

Based on fixed priorities The shorter the period of the task, the higher

the priority assigned Example:

P1 = (3, 4, 4)

P2 = (2, 8, 8)

29

Page 30: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

RM Scheduling

30

P1 = (3, 4, 4)P2 = (2, 8, 8)

Page 31: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

Least Compute Time (LCT)

Also based on fixed priorities The shorter the compute time of the task, the

higher the priority assigned Example:

P1 = (3, 4, 4)

P2 = (2, 8, 8)

P2 will have higher priority. P1 will missed its first deadline

31

Page 32: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

RT Scheduling with Dynamic Priorities

Shortest Completion Time (SCT) Earliest Deadline First (EDF) Least Slack Time (LST)

32

Page 33: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

33

Earliest Deadline First Scheduling: EDF

Based on dynamic priorities. EDF scheme: Choose the task with the earliest

(current) deadline Preemptive: scheduling decision made when a

task finishes as well as when a new task arrives Theorem: If there is a possible schedule, then

EDF will find one Example:

Two processes: P1 (2, 4, 4) and P2 (5, 10, 10)

Page 34: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

EDF Example 1

34

P1 (2, 4, 4) and P2 (5, 10, 10)At times t=4 and t=12, P2 is preempted

Page 35: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

35

Task T1 with period 10 and CPU time 3 Task T2 with period 10 and CPU time 1 Task T3 with period 15 and CPU time 8

0 3 4 10 12 1516 20 2324 28

EDF Example 2

T1 T2 T3 T3 T1 T2 T3 T1 T2 T3

Page 36: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

36

Scheduling Algorithm: RMS

Rate Monotonic Scheduling (Liu and Layland, 1973) Based on static priorities. Preemptive: scheduling decision made when a task finishes

as well as when a new task arrives Scheduling algorithm: Choose the task with smallest period

(among ready tasks) Theorem: If utilization is smaller than 0.7, then RMS is

guaranteed to find one If utilization is between 0.7 to 1, RMS may or may not succeed

Example:

Page 37: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

37

The Priority Inversion Problem

T1

T2

T3

failed attempt to lock R lock(R)

unlock(R)

lock(R)

unlock(R)

Priority order: T1 > T2 > T3

T2 is causing a higher priority task T1 wait !

Page 38: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

38

Priority Inversion

1. T1 has highest priority, T2 next, and T3 lowest2. T3 comes first, starts executing, and acquires some

resource (say, a lock).3. T1 comes next, interrupts T3 as T1 has higher priority4. But T1 needs the resource locked by T3, so T1 gets blocked5. T3 resumes execution6. T2 arrives, and interrupts T3 as T2 has higher priority than

T3, and T2 executes till completion7. In effect, even though T1 has priority than T2, and arrived

earlier than T2, T2 delayed execution of T18. This is “priority inversion” !! Not acceptable.

9. Solution T3 should inherit T1’s priority at step 5

Page 39: Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.

39

Priority Inheritance Protocol

T1

T2

T3

lock R fails

lock(R)

unlock(R)

lock(R)

unlock(R)

T3 blocks T2T3 directly blocks T1

T3 has priority of T1

T2 arrives