1 / 23

CS444/CS544 Operating Systems

CS444/CS544 Operating Systems. Scheduling 1/31/2007 Prof. Searleman jets@clarkson.edu. CS444/CS544 Spring 2007. CPU Scheduling Reading assignment: Chapter 5 HW#3: done in lab 2-2-2007 HW#4 posted, due: 2-7-2007 Help for Lab1, 6-7 pm tonight in ITL/COSI. Benefits of Concurrency.

Download Presentation

CS444/CS544 Operating Systems

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. CS444/CS544Operating Systems Scheduling 1/31/2007 Prof. Searleman jets@clarkson.edu

  2. CS444/CS544 Spring 2007 • CPU Scheduling Reading assignment: • Chapter 5 HW#3: done in lab 2-2-2007 HW#4 posted, due: 2-7-2007 Help for Lab1, 6-7 pm tonight in ITL/COSI

  3. Benefits of Concurrency • Hide latency of blocking I/O without additional complexity • Without concurrency • Block whole process • Manage complexity of asynchronous I/O (periodically checking to see if it is done so can finish processing) • Ability to use multiple processors to accomplish the task • Servers often use concurrency to work on multiple requests in parallel • User Interfaces often designed to allow interface to be responsive to user input while servicing long operations

  4. Scheduling • CPU or “short term” scheduler selects process from ready queue (every 10 msec or so) • “dispatcher” does the process switching • “long-term” scheduler controls “degree of multiprogramming” (number of processes in memory); selects a good “job mix” • “job mix” – I/O-bound, CPU-bound, interactive, batch, high priority, background vs. foreground, real-time • “non-preemptive” (cooperative) vs. “preemptive”

  5. Performance Measures • Throughput: #processes/time unit • Turnaround time: time completed – time submitted • Waiting time: sum of times spent in ready queue • Response time: time from submission of a request until the first response is produced • Variation of response time (predictability) • CPU utilization • Disk (or other I/O device) utilization

  6. I/O-bound & CPU-bound Device1 P1 CPU time quantum Device2 P2 CPU

  7. Turnaround time for P1 I/O-bound & CPU-bound P1: CPU-bound Device1 idle Device1 idle Device1 idle CPU idle CPU idle

  8. Turnaround time for P2 I/O-bound & CPU-bound P2: I/O-bound Device2 idle Device2 idle CPU idle CPU idle

  9. I/O-bound & CPU-bound Schedule1: non-preemptive, P1 selected first Turnaround time for P1 Turnaround time for P2 Without P1

  10. I/O-bound & CPU-bound Schedule2: non-preemptive, P2 selected first Turnaround time for P1 Turnaround time for P2

  11. I/O-bound & CPU-bound • How does the OS know whether a process is • I/O-bound or CPU-bound? • can monitor the behavior of a process & save the info in the PCB • example: how much CPU time did the process use in its recent time quanta? (a small fraction => I/O intensive; all of the quantum => CPU intensive) • The nature of a typical process changes from I/O-bound to CPU-bound and back as it works through its Input/Process/Output Cycle

  12. t2 t0 ready: P1, P2 t1 ready: P2 blocked: P1 Preemptive vs. Non-Preemptive

  13. t2 ready: P1 blocked: P2 t3 ready: P2 running: P1 Preemptive vs. Non-Preemptive Non-Preemptive: must continue to run P1 at t3 Preemptive: can choose between P1 & P2 at t3

  14. (4) exit, abort New dispatch admit Terminated (2) interrupt Running Ready (1) block for I/O or wait for event (3) I/O completed or event occurs Waiting • nonpreemptive (cooperative): (1) and (4) only • preemptive: otherwise

  15. First Come First Serve (FCFS) • Also called First In First Out (FIFO) • Jobs scheduled in the order they arrive • When used, tends to be non-preemptive • If you get there first, you get all the resource until you are done • “Done” can mean end of CPU burst or completion of job • Sounds fair • All jobs treated equally • No starvation (except for infinite loops that prevent completion of a job)

  16. P1 P3 P2 0 18 20 24 P1, P2, P3 ready FCFS • average waiting time = (0 + 18 + 20)/3 = 12.6 Gantt chart

  17. Problems with FCFS/FIFO • Can lead to poor overlap of I/O and CPU • If let first in line run till they are done or block for I/O then can get convoy effect • While job with long CPU burst executes, other jobs complete their I/O and the I/O devices sit idle even though they are the “bottleneck” resource and should be kept as busy as possible • Also, small jobs wait behind long running jobs (even grocery stores know that) • Results in high average turn-around time

  18. Shortest Job First (SJF) • So if we don’t want short running jobs waiting behind long running jobs, why don’t we let the job with the shortest CPU burst go next • Can prove that this results in the minimum (optimal) average waiting time • Can be preemptive or non-preemptive • Preemptive version called shortest-remaining-time first (SRTF)

  19. P1 P3 P2 0 24 2 P1, P2, P3 ready SJF • average waiting time = (0 + 2 + 6)/3 = 2.6 Gantt chart 6

  20. P1 P3 P2 P4 7 12 16 2 4 5 8 P1 running P2, P3 , P4 ready P1 ready P1 running P2, P3 ready P1 runningP2ready SJF nonpreemptive • average waiting time = (0 + 6 + 3 + 7)/4 = 4 0

  21. P2 P2 P4 P1 P3 P1 7 11 16 2 4 5 P1, P4 ready P1 ready P2 running P1, P3 ready P1 ready P3 completes P1, P2 , P4 ready P1 runningP2ready SRTF preemptive • average waiting time = (9 + 1 + 0 + 2)/4 = 3 0

  22. P2 P2 P4 P1 P3 P1 11 16 SRTF preemptive 16 – 0 = 16 9 1 7 – 2 = 5 • average waiting time = (9 + 1 + 0 + 2)/4 = 3 • average turnaround time = (16 + 5 + 1 + 6)/4 0 5 – 4 = 1 11 – 5 = 6 2 7 0 2 4 5

  23. Problems with SJF • First, how do you know which job will have the shortest CPU burst or shortest running time? • Can guess based on history but not guaranteed • Bigger problem is that it can lead to starvation for long-running jobs • If you never got to the head of the grocery queue because someone with a few items was always cutting in front of you

More Related