Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5.

Similar presentations


Presentation on theme: "CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5."— Presentation transcript:

1 CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5

2 cs431-cotter2 Basic Concepts CPU - I/O Burst Cycle CPU Burst Distribution

3 cs431-cotter3 CPU Scheduling Decision points: –Process switch from running to waiting state –Process switch from running to ready state –Process switch from waiting to ready state –Process terminates Scheduling types –non-preemptive –preemptive

4 cs431-cotter4 Task Dispatcher Functions: –Switching context –Switching to user mode –Jumping to PC location The time needed to stop one process and start up another is known as dispatch latency.

5 cs431-cotter5  Batch  Interactive  Real time Categories of Scheduling Algorithms Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

6 cs431-cotter6 Figure 2-39. Some goals of the scheduling algorithm under different circumstances. Scheduling Algorithm Goals Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

7 cs431-cotter7  First-come first-served  Shortest job first  Shortest remaining Time next Scheduling in Batch Systems Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

8 cs431-cotter8 Scheduling Algorithms (First-come, First-served) Determine avg waiting time if: –(P1, P2, P3) or (P3, P2, P1) 010 20 30

9 cs431-cotter9 Scheduling Algorithms (First-come, First-served) Determine avg waiting time if: –(P1, P2, P3) 010 20 30 P1 ……………………………………………..P2…..P3……. Waiting time: P1: 0 P2: 24 P3: 27 avg: 17

10 cs431-cotter10 Scheduling Algorithms (First-come, First-served) Determine avg waiting time if: – (P3, P2, P1) 010 20 30 P3….P2….P1………………………………………………... Waiting time: P1: 6 P2: 3 P3: 0 avg: 3

11 cs431-cotter11 Scheduling Algorithms (Shortest Job First) Schedule jobs based on their length. May be preemptive –If a job is queued that is shorter than the remaining time on the current job, there is a switch. May be non-preemptive. –Once a job has started, it works to its normal switch.

12 cs431-cotter12 Scheduling Algorithms (Shortest Job First) Non-Preemptive / preemptive SJF 010 20 30

13 cs431-cotter13 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1.. P1 |

14 cs431-cotter14 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1..P2.. P1 P2 |

15 cs431-cotter15 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1..P2..P3 P1 P2 P3 | | |

16 cs431-cotter16 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1..P2..P3P2.. P1 P2 P3P4 | |

17 cs431-cotter17 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1..P2..P3P2..P4……. P1 P2 P3P4 | |

18 cs431-cotter18 Scheduling Algorithms (Shortest Job First) Preemptive SJF 010 20 30 P1..P2..P3P2..P4…….P1………. P1 P2 P3P4 | |

19 cs431-cotter19 Scheduling Algorithms (Shortest Job First) Non-preemptive SJF 010 20 30 P1…………..P3P2…….P4……. P1 P2 P3P4 | |

20 cs431-cotter20 Scheduling Algorithms (Shortest Job First) Determining the length of the jobs. Use weighted average burst lengths

21 cs431-cotter21 Scheduling Algorithms (Shortest Job First)

22 cs431-cotter22  Round-robin scheduling  Priority scheduling  Multiple queues  Shortest process next  Guaranteed scheduling  Lottery scheduling  Fair-share scheduling Scheduling in Interactive Systems Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

23 cs431-cotter23 Round Robin Scheduling Developed in response to time-sharing systems. Each job is given control of the CPU for a short period - a time quantum. (In the range of 10-100 milliseconds.) Control then passes to the next job (FIFO?) Average waiting time dependent on job size, quantum size.

24 cs431-cotter24 Figure 2-41. Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable processes after B uses up its quantum. Round-Robin Scheduling Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

25 cs431-cotter25 Round Robin Scheduling 010 20 30 All processes arrive at T=0 Vary Quantum time from 1 to 7. Calculate average turnaround time (to job completion).

26 cs431-cotter26 Round Robin Scheduling 010 20 30 All processes arrive at T=0 QuantumAverage SizeTurnaround 111 P1P2P3P4P1P2P4P1P2P4P1P4P1P4P1P4P4

27 cs431-cotter27 Round Robin Scheduling 010 20 30 All processes arrive at T=0 QuantumAverage SizeTurnaround 111 211.5 P1..P2..P3P4..P1..P2P4..P1..P4..P4

28 cs431-cotter28 Round Robin Scheduling 010 20 30 All processes arrive at T=0 QuantumAverage SizeTurnaround 111 211.5 310.75 P1.. P2.. P3P4.. P1.. P4...P4

29 cs431-cotter29 Round Robin Scheduling 10 11 12 9 8 13 1 2 3 4 5 6 7 Quantum avg. turnaround

30 cs431-cotter30 Priority Scheduling Each process (or class of processes) is given a priority. Jobs are executed in priority order Issue: If there are sufficient high priority jobs, lower priority jobs may never get scheduled. One solution: Aging of processes. After a job has been in queue for a given period of time, raise its priority.

31 cs431-cotter31 Figure 2-42. A scheduling algorithm with four priority classes. Priority Scheduling Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

32 cs431-cotter32 Multi-level queue Scheduling Partition the job space into distinct classes or queues –foreground / background –system / interactive / editing / batch / student –etc. Independently assign queueing service disciplines Assign queue priorities –Highest to lowest (empty one queue before starting next) –Divide time between queues 80 / 20 30 / 20 / 20 / 20 / 10

33 cs431-cotter33 Multilevel Feedback Queue Scheduling Similar to Multilevel queue scheduling, but jobs are allowed to move between queues. Avoids process starvation by allowing neglected jobs to move up to a higher queue. Differentiate queues by (for example) quantum size –queue 1 = 8 ms –queue 2 = 16 ms –queue 3 = FCFS

34 cs431-cotter34 Figure 2-43. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per CPU burst. Thread Scheduling (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

35 cs431-cotter35 Figure 2-43. (b) Possible scheduling of kernel-level threads with the same characteristics as (a). Thread Scheduling (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

36 cs431-cotter36 Multiple Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor are usual (heterogeneous processors found in distributed systems). Load sharing used with SMP. –Single queue, multiple servers. Asymmetric Multiprocessing (AMP) –Assign roles (system control, application processing) –Avoids system data sharing

37 cs431-cotter37 Benefits of Multiprocessors Process Scheduling –Process inter-arrival time variation can be characterized by coefficient of variation =  s / s standard deviation of interarrival time / mean service time ratio of 1 = exponential distribution. (your mileage may vary…) –Differences between scheduling algorithms become much less important in multiprocessor systems Single processor Dual processor RR to FCFS thruput ratio Coefficient of Variation

38 cs431-cotter38 Benefits of Multiprocessors Thread Scheduling Allows true parallel processing within an application However, if there is significant interaction among threads, small differences in thread management & scheduling can have big results. General Approaches used –Load Sharing - (not necessarily load balancing) –Gang Scheduling - Schedule related threads together –Dynamic Scheduling - allow # of threads to vary

39 cs431-cotter39 Real-Time Scheduling System Response Classifications –Hard real-time System - requires response guarantees –Soft real-time System – response not guaranteed Dispatch Latency Interrupt processing conflicts dispatch Real-time process execution Dispatch latency Response interval

40 cs431-cotter40 Summary Primary job of an OS is to schedule processes –Batch –Interactive –Real Time Selection of scheduling algorithm depends on optimization criteria

41 cs431-cotter41 Questions On a system with multilevel queue scheduling, would you expect to see the same scheduling algorithms used on all levels, or would you expect them to be different? Justify your answer. Consider the following set of processes, with the length of the CPU burst time given in milliseconds. The processes are assumed to have arrived in the order P1, P2, P3, P4. Process Job Size P110 P21 P32 P45 Of the scheduling algorithms FCFS, SJF, and RR(qt=2) which algorithm offers the best waiting time? In many multiprocessing systems, although there is a fixed limit to the amount of time that a job can keep control of the CPU, in practice, the jobs are released earlier. Why? The book talked about the multiple queueing system used by CTSS. If a process needed 30 quanta to complete, how many times would it be swapped in to complete? How does Lottery Scheduling work? What is its principle advantage over, say, Guaranteed Scheduling?


Download ppt "CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5."

Similar presentations


Ads by Google