1 / 26

CPU Scheduling, Part Deux

CS423UG Operating Systems . CPU Scheduling, Part Deux. Indranil Gupta Lecture 6 Sep 7, 2005. Content: Scheduling Algorithms. Batch systems First come First Serve (FCFS) Shortest job first Interactive systems Round-robin Priority scheduling

bree
Télécharger la présentation

CPU Scheduling, Part Deux

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 Deux Indranil Gupta Lecture 6 Sep 7, 2005

  2. Content: Scheduling Algorithms • Batch systems • First come First Serve (FCFS) • Shortest job first • Interactive systems • Round-robin • Priority scheduling • Multi Queue & Multi-level Feedback • Shortest process time • Guaranteed Scheduling • Lottery Scheduling • Fair Sharing Scheduling CS 423UG - Operating Systems, Indranil Gupta

  3. Review: Scheduling • Short-term: Deciding which process/thread should occupy the resource (CPU, disk, etc) • Preemptive vs. non-preemptive • Scheduling objectives • Scheduling performance metrics • First-come-first-serve (FCFS) • Process that enters ready queue FIRST is allocated the CPU FIRST • Used in batch systems CS 423UG - Operating Systems, Indranil Gupta

  4. I. Shortest Job First (SJF) “Job”=Process • Schedule the job with the shortest running time first • Scheduling in Batch Systems • Non-preemptive only (for now) • Requirement: the running time of the process needs to be known in advance • SJF Achieves Optimal AWTif all jobs are available simultaneously (provable) • “Optimal AWT”=least possible avg. waiting time among all possible scheduling algorithms (includes, FCFS, priority, round robin, etc.)! CS 423UG - Operating Systems, Indranil Gupta

  5. Non-preemptive SJF: Example P4 (3) P1 (6) P3 (7) P2 (8) 3 9 16 24 0 P4 waiting time: 0-0 P1 waiting time: 3-0 P3 waiting time: 9-0 P2 waiting time: 16-0 The total running time is: 24 The average waiting time (AWT): (0+3+9+16)/4 = 7 time units CS 423UG - Operating Systems, Indranil Gupta

  6. Comparing to FCFS (Breaking ties by choosing process with lower ID) P1 (6) P2 (8) P3 (7) P4 (3) 14 21 24 0 6 The total time is the same. The average waiting time (AWT): (0+6+14+21)/4 = 10.25 time units (> SJF’s 7 time units) P1 waiting time: 0 P2 waiting time: 6 P3 waiting time: 14 P4 waiting time: 21 CS 423UG - Operating Systems, Indranil Gupta

  7. Caveat: SJF may not be optimal when… …all the jobs are not available simultaneously P1 (10) P2 (2) 0 2 (p2 arrives) 10 12 The average waiting time (AWT): (0+8)/2 = 4 P1 waiting time: 0 P2 waiting time: 8 CS 423UG - Operating Systems, Indranil Gupta

  8. What if the scheduler waits for 2 time units? (Do it yourself) P2 (2) P1 (10) 0 2 4 14 The average waiting time (AWT): (0+4)/2 = 2 Downside: Wastes 2 time units of CPU. How long to wait? P1 waiting time: 4 P2 waiting time: 0 CS 423UG - Operating Systems, Indranil Gupta

  9. II. Preemptive SJF “Job”=Process • Also called Shortest Remaining Time First • Schedule the job that has the shortest remaining running time • Requirement: the total running time of a process needs to be known in advance CS 423UG - Operating Systems, Indranil Gupta

  10. Preemptive SJF: Same Example P2 (2) P1 (2) P1 (8) 0 2 4 12 The average waiting time (AWT): (0+2)/2 = 1 No CPU time wasted!!! P1 waiting time: 4-2 =2 P2 waiting time: 0 CS 423UG - Operating Systems, Indranil Gupta

  11. So, what’s the catch with SJF? • Starvation • SJF may cause some jobs to wait forever! • Example: SJF • Process A with running time of 1 hour arrives at time 0 • Then, every 2 minutes, a short process with running time of 2 minutes arrives • Process A never gets to run CS 423UG - Operating Systems, Indranil Gupta

  12. Interactive Scheduling Algorithms • Usually preemptive • Time is sliced into quanta (plural of quantum) • Quantum=(fixed) time interval • Scheduling decision is made at start of each quantum • Performance Criteria • Min Response time • Best proportionality • Representative algorithms: • Priority-based • Round-robin • Multi Queue & Multi-level Feedback • Shortest process time • Guaranteed Scheduling • Lottery Scheduling • Fair Sharing Scheduling CS 423UG - Operating Systems, Indranil Gupta

  13. III. Priority Scheduling • Each job is assigned a priority. • Priority could be based on user, urgency, interactivity, etc. • Scheduler • Select highest priority task that is currently ready • Caveats: • May not give the best AWT • Could cause starvation in some cases CS 423UG - Operating Systems, Indranil Gupta

  14. Setting a Process’ Priority • Two approaches • Static (for system with well-known and regular application behaviors) • Dynamic • Priority may be based on: • Cost to user • Importance of user • Aging • Percentage of CPU time used in last X hours. • Ex. priorities: DVD player > sendmail; Senior’s job > Junior’s job CS 423UG - Operating Systems, Indranil Gupta

  15. Priority Scheduling: Example Lower priority #== more important P2 (8) P4 (3) P3 (7) P1 (6) 24 0 8 11 18 P2 waiting time: 0 P4 waiting time: 8 P3 waiting time: 11 P1 waiting time: 18 The average waiting time (AWT): (0+8+11+18)/4 = 9.25 (worse than SJF’s) CS 423UG - Operating Systems, Indranil Gupta

  16. IV. Round-Robin • Simple, popular, one of the oldest scheduling strategies • Idea: • Select process from head of queue • Run it for 1 quantum • Put process back at tail of queue • Repeat • Advantages: • Fair • Avoids starvation • Problems: • Does not consider priority • High Context switch overhead CS 423UG - Operating Systems, Indranil Gupta

  17. Round-robin: Example Suppose time quantum is: 1 unit. P1, P2 & P3 have no I/O P1 P2 P3 P1 P2 P3 P1 P2 P3 P2 0 10 P1 waiting time: 4 P2 waiting time: 6 P3 waiting time: 6 The average waiting time (AWT): (4+6+6)/3 = 5.33 CS 423UG - Operating Systems, Indranil Gupta

  18. Selecting a good Time Quantum • Time slice too large • FIFO behavior • Poor response time • Time slice too small • Too many context switches (high overhead) • Inefficient CPU utilization • Heuristic (rule of thumb): select quantum so that 70%-80% of jobs block within quantum length • Typical time-slice: 10 ms to 100 ms • Time spent in system depends on size of the job and the number of jobs CS 423UG - Operating Systems, Indranil Gupta

  19. V. Multi-Queue Scheduling • Hybrid between Priority and Round-Robin • Multiple and finite number of queues • Each process assigned permanently to one of these queues • Scheduler: first choose a queue, then a job from that queue • Scheduler: Choosing a queue/level • Fixed Priorities • % CPU spent on queue • Scheduler: Choosing a job within a queue • Round Robin • FCFS • Example: one queue/level for each of • System processes • Interactive programs • Student Processes • Background Processes • % CPU + Round Robin addresses the starvation and infinite blocking problems CS 423UG - Operating Systems, Indranil Gupta

  20. Multi-Queue Scheduling: Example 20% 30% 50% CS 423UG - Operating Systems, Indranil Gupta

  21. Real Life Analogy • Tasks (to-do list) for poor Bob • Class 3 priority (lowest): Bob’s tasks • Watch football on TV (20%) • Class 2 priority: tasks given by his boss • “Where is the report?” (30%) • Class 1 priority (highest) : tasks given by his girlfriend • Buy me a … (50%) CS 423UG - Operating Systems, Indranil Gupta

  22. VI. A Variation: Multi-level Feedback Algorithm • Multi-Level Queue with priorities • Processes may move between queues • Each queue represents jobs with similar CPU usage • Each queue is RR with a fixed quantum, but different queues have different quantum values • Rationale: Once an I/O-bound process completes an I/O request, it should have higher CPU priority CS 423UG - Operating Systems, Indranil Gupta

  23. Multi-level Feedback Algorithm: Example CS 423UG - Operating Systems, Indranil Gupta

  24. Multi-level Feedback Algorithm (Details) • Example: Queuei has time-slice t = 2i • If a job in Queuei doesn't block by end of time-slice, it is moved to Queuei +1 • Lowest priority Queue (highest i value) is FIFO • Problem: • Starvation: Aging may move Process to lower priority queue CS 423UG - Operating Systems, Indranil Gupta

  25. Summary We’ve learnt many scheduling algorithms! • Shortest job first (SJF) • SJF-preemptive • Priority • Round-robin • Multi-Queue • Multi-level Feedback CS 423UG - Operating Systems, Indranil Gupta

  26. Announcements • Reading for this lecture was: Section 2.5.3 • Reading for this Friday: Rest of 2.5 • Real-time systems • Multiple processors • Threads • You’ve all the information that you need for MP1! • HW1 due this Friday at start of lecture. CS 423UG - Operating Systems, Indranil Gupta

More Related