Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University."— Presentation transcript:

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

2 CPU Scheduling Overview of basic non-real time Scheduling techniques The most relevant RT scheduling techniques

3 General Processor Scheduling Allocation of tasks to processor for execution, in some order A set of performance metrics is usually derived 3

4 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.

5 Scheduling (General) Issues in scheduling Basic scheduling algorithms First-come First-served Round Robin Shortest Process Next Priority based Real-time scheduling 5

6 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

7 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

8 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

9 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

10 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.

11 Simple Model for CPU Scheduling

12 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.

13 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

14 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 ordering to execute all the computations

15 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

16 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 Garrido16

17 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 Garrido17

18 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 Garrido18

19 A Major Cycle in a Schedule Fall 2010(C) J M Garrido19

20 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 T 1, … T n. Each task T i has period P i and computation time C i

21 Schedulability Problem Can all the tasks be scheduled so that every task T i gets the CPU for C i units in every interval of length P i ?

22 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 T i needs to use CPU for C i /P i fraction per unit Utilization = Sum of C i /P i Task set is schedulable if and only if utilization is 1 or less.

23 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

24 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

25 RR with Preemption 25 Two processes: P1 (1, 2, 2) and P2 (2, 5, 5)

26 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

27 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

28 Real-Time Scheduling Earliest Deadline First (EDF) Rate Monotonic Scheduling (RMS) 28

29 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

30 RM Scheduling 30 P1 = (3, 4, 4) P2 = (2, 8, 8)

31 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

32 RT Scheduling with Dynamic Priorities Shortest Completion Time (SCT) Earliest Deadline First (EDF) Least Slack Time (LST) 32

33 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)

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

35 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 T1T2T3 T1T2T3T1T2T3

36 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:

37 37 The Priority Inversion Problem T1T1 T2T2 T3T3 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 !

38 38 Priority Inversion 1. T1 has highest priority, T2 next, and T3 lowest 2. T3 comes first, starts executing, and acquires some resource (say, a lock). 3. T1 comes next, interrupts T3 as T1 has higher priority 4. But T1 needs the resource locked by T3, so T1 gets blocked 5. T3 resumes execution 6. T2 arrives, and interrupts T3 as T2 has higher priority than T3, and T2 executes till completion 7. In effect, even though T1 has priority than T2, and arrived earlier than T2, T2 delayed execution of T1 8. This is “priority inversion” !! Not acceptable. 9. Solution T3 should inherit T1’s priority at step 5

39 39 Priority Inheritance Protocol T1T1 T2T2 T3T3 lock R fails lock( R) unlock( R) lock( R) unlock( R) T3 blocks T2 T3 directly blocks T1 T3 has priority of T1 T2 arrives


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

Similar presentations


Ads by Google