1 / 20

CPU Scheduling, Part 3/3

CS423UG Operating Systems. CPU Scheduling, Part 3/3. Indranil Gupta Lecture 7 Sep 9, 2005. Agenda. More Scheduling algorithms Shortest process time Guaranteed Scheduling Lottery Scheduling Fair Sharing Scheduling Scheduling for Multiple processors Threads Real-time systems.

lottie
Download Presentation

CPU Scheduling, Part 3/3

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. CS423UG Operating Systems CPU Scheduling, Part 3/3 Indranil Gupta Lecture 7 Sep 9, 2005

  2. Agenda • More Scheduling algorithms • Shortest process time • Guaranteed Scheduling • Lottery Scheduling • Fair Sharing Scheduling • Scheduling for • Multiple processors • Threads • Real-time systems CS 423UG - Operating Systems, Indranil Gupta

  3. I. Shortest Process Time • Based on SJF, but for interactive processes: wait for command-get command-execute command-repeat • Idea: Guess next command execute time based on past command times • Average previous command response times from a process : T0, T1, T2, T3 • Tiapprox := αTimeasured + (1-α)Ti-1approx • For ½ the average time for the next run will be predicted to be T0 /8 + T1 /8 + T2 /4 + T3 /2 “Aging”/Exponential Averaging CS 423UG - Operating Systems, Indranil Gupta

  4. Aging - Pros and Cons • For a process that has all bursts of equal length, exponential averaging/aging is exact • For predictable burst lengths (even variable), the aging process is quite accurate • For highly variable burst lengths, the aging process is not accurate • How close SJF/shortest remaining time first comes to the optimal AWT depends on how accurate the aging is for that process set CS 423UG - Operating Systems, Indranil Gupta

  5. II. Guaranteed Scheduling (QoS) QoS=Quality of service • Make realistic promises to the users about performance and then live up to them • Example: • with n processes running, the scheduler makes sure that each one gets 1/n of the CPU cycles, at least once every n seconds. • Caveat: different processes may require different CPU % times • Scheduling: compute the ratio of actual CPU time consumed to CPU time entitled. Select the one with the lowest ratio • Could this lead to starvation? CS 423UG - Operating Systems, Indranil Gupta

  6. III. Lottery Scheduling • More commonly used • Probability-based: • Give processes lottery tickets. At scheduling time, a lottery ticket is chosen at random, and the process holding that ticket gets that resource. • Give more tickets to higher priority processes • Advantages: • Simple • Highly responsive • Can support cooperation between processes • Easy to support priority and proportion requirement • Disadvantages? Possible Starvation (although a given process will be picked “eventually”). CS 423UG - Operating Systems, Indranil Gupta

  7. IV. Fair-Share Scheduling • Is Round-robin fair? • Yes, it is (from process point of view) • No, it may be not (from user point view) • User-based fair share scheduling • Each user gets fair share • Example: • Alice has 4 processes: A1, A2, A3, A4 • Bob has 1 process: B1 • Then A1, A2, A3, A4 are entitled only to 50% CPU, while B1 alone is entitled to 50% CS 423UG - Operating Systems, Indranil Gupta

  8. V. Multi-Processor Scheduling: Load Sharing • Decides • Which process to run? • How long does it run • Where to run it? (CPU (horsepower)) I want to ride it … Process 2 Process n Process 1 CS 423UG - Operating Systems, Indranil Gupta

  9. Multi-Processor Scheduling Choices • Self-Scheduled • Each CPU dispatches a job from the ready queue • Master-Slave • One “leader” CPU schedules the other CPUs • Asymmetric • One CPU runs the kernel (only) and the others run user applications. • The first CPU handles the network and the others handle applications CS 423UG - Operating Systems, Indranil Gupta

  10. VI. Gang Scheduling for Multi-Processors • A collection of processes belonging to one job set, e.g., parallelized matrix multiplication • All the processes are running at the same time • If one process is preempted, all the processes of the gang should be preempted. • Helps to eliminate the time a process spends waiting for other processes in its parallel computation. CS 423UG - Operating Systems, Indranil Gupta

  11. Why Gang Scheduling? Process 1 Process 2 Switched off Process 2 will not receive anyway… Send Data Receive Data CS 423UG - Operating Systems, Indranil Gupta

  12. VII. Scheduling in Real-Time Systems • Examples: space shuttle systems, multimedia streaming • Concept of Deadlines Di : need to complete process within Di seconds after its arrival • Hard real-time systems: if not, result could be catastrophic, e.g., space shuttle • Soft-real time systems, e.g., multimedia streaming • Hard Real Time: Need to know the worst case execution time Ci of task i a priori (beforehand) • Need to have scheduler decide whether task is schedulable right when task arrives • “Task is schedulable” = its deadline can be satisfied even if the task takes up to its worst case execution time CS 423UG - Operating Systems, Indranil Gupta

  13. Scheduling in Real-Time Systems • Hard-Real Time Systems: Periodic vs. Aperiodic systems. Periodic: • New instance of task i arrives every Pi time units • Di =Pi • Need to set up schedule a priori (before run-time) • Schedulable periodic real-time system. Given • m periodic tasks • task i occurs with period Pi and requires Ci worst-case seconds • Then all deadlines can be satisfied only if CS 423UG - Operating Systems, Indranil Gupta

  14. Priority Inversion and Inheritance Priority Inversion was the problem with the Mars Pathfinder! • Priority inversion • When a higher priority process needs to read or modify kernel data that is currently being accessed by a lower priority process. • The higher priority process must wait! • But the lower priority cannot proceed quickly due to scheduling. • Solution: priority inheritance • When a lower-priority process accesses a resource, it inherits high-priority until it is done with the resource in question. And then its priority reverses to its natural value. CS 423UG - Operating Systems, Indranil Gupta

  15. Policy versus Mechanism • Policy: what the user/process ideally wants • Mechanism: the low-level OS implementation that seeks to satisfy this policy • “It is the policy of this course that you do your HW’s solely by yourself.” • “The mechanism we seek to enforce this policy is to penalize you if you’re caught.” • Mechanism may not always satisfy policy. • Scheduling: one mechanism is to schedule by priorities. Process has control over policy by being able to set childrens’ priorities through system calls. CS 423UG - Operating Systems, Indranil Gupta

  16. User-level Thread Scheduling Possible Scheduling • 50 ms process quantum • Threads run 5 ms/CPU burst CS 423UG - Operating Systems, Indranil Gupta

  17. Kernel-level Thread Scheduling Possible scheduling • 50 ms process quantum • Threads run 5 ms/CPU burst CS 423UG - Operating Systems, Indranil Gupta

  18. Thread Scheduling Example • Solaris 2 • Priority-based process scheduling with four scheduling classes: real-time, system, time sharing, interactive. • Each process starts with one LWP and generates new LWPs as needed. • A set of priorities exists within each class. • The scheduler converts the class-specific priorities into global priorities and selects to run the thread with the highest global priority. The thread runs until (1) it blocks, (2) it uses its time slice, or (3) it is preempted by a higher priority thread (whichever earlier). CS 423UG - Operating Systems, Indranil Gupta

  19. Thread Scheduling Example - 2 • JVM • Schedules threads using a preemptive, priority-based scheduling algorithm. • Schedules the ``runnable'' thread with the highest priority. If two threads have the same priority, JVM applies FIFO. • Schedules a thread to run if (1) other thread exits the ``runnable state'' due to block(), exit(), suspend() or stop() methods; (2) a thread with higher priority enters the ``runnable''state (whichever earlier). CS 423UG - Operating Systems, Indranil Gupta

  20. Announcements • MP1(thread scheduling) • Reading for today’s lecture was: section 2.5 • Next lecture: Synchronization (sections 2.3 & 2.4) • HW2 out today. Due Sep 23, 2005. • Have a good weekend! CS 423UG - Operating Systems, Indranil Gupta

More Related