1 / 39

Real-Time Scheduling

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. General Processor Scheduling.

tola
Télécharger la présentation

Real-Time Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

  4. CPU Scheduling • The schedulerselects 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

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

  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. 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: • Join the ready queue and wait for CPU service. • Execute (receive CPU service) for the duration of the current CPU burst or for the duration of the time slice (timeout). • Join the I/O queue to wait for I/O service or return to the ready queue to wait for more CPU service. • 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. 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

  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 (C) J M Garrido

  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 (C) J M Garrido

  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 (C) J M Garrido

  19. A Major Cycle in a Schedule (C) J M Garrido

  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

  21. 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 ?

  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.

  23. Issues in RT Scheduling Example1 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 Two processes: P1 (1, 2, 2) and P2 (2, 5, 5)

  26. RR Scheduling Example 2 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 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)

  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)

  30. RM Scheduling 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

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

  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 P1 (2, 4, 4) and P2 (5, 10, 10) At times t=4 and t=12, P2 is preempted

  35. EDF Example 2 • 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 T1 T2 T3 T3 T1 T2 T3 T1 T2 T3

  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. failed attempt to lock R lock(R) unlock(R) lock(R) unlock(R) The Priority Inversion Problem Priority order: T1 > T2 > T3 T1 T2 T3 T2 is causing a higher priority task T1 wait !

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

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

More Related