Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.

Similar presentations


Presentation on theme: "1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in."— Presentation transcript:

1 1 Lecture 10: Uniprocessor Scheduling

2 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in the system n The goal is to achieve u High processor utilization u High throughput F number of processes completed per unit time u Low response time F time elapse from the submission of a request to the beginning of the response

3 3 Classification of Scheduling Activity n Long-term: which process to admit n Medium-term: which process to swap in or out n Short-term: which ready process to execute next

4 4 Queuing Diagram for Scheduling

5 5 Long-Term Scheduling n Determines which programs are admitted to the system for processing n Controls the degree of multiprogramming n If more processes are admitted u less likely that all processes will be blocked u better CPU usage u each process has less fraction of the CPU n The long term scheduler will attempt to keep a mix of processor-bound and I/O- bound processes

6 6 Medium-Term Scheduling n Swapping decisions based on the need to manage multiprogramming n Done by memory management software (discussed in the previous lecture) u see resident set allocation and load control

7 7 Short-Term Scheduling n Determines which process will execute next (also called CPU scheduling) n The short term scheduler is known as the dispatcher n Is invoked on a event that may lead to choose another process for execution: u clock interrupts u I/O interrupts u operating system calls and traps u signals

8 8 Short-Tem Scheduling Criteria n User-oriented u Response Time: Elapsed time from the submission of a request to the beginning of response u Turnaround Time: Elapsed time from the submission of a process to its completion n System-oriented u processor utilization u fairness u throughput: number of process completed per unit time

9 9 Priorities n Implemented by having multiple ready queues to represent each level of priority n Scheduler will always choose a process of higher priority over one of lower priority n Lower-priority may suffer starvation n To fix this, allow a process to change its priority based on its age or execution history n Our first scheduling algorithms will not make use of priorities n We will then present other algorithms that use dynamic priority mechanisms

10 10 Characterization of Scheduling Policies n The selection function: determines which process in the ready queue is selected next for execution n The decision mode: specifies the instants in time at which the selection function is exercised u Nonpreemptive F Once a process is in the running state, it will continue until it terminates or blocks itself for I/O u Preemptive F Currently running process may be interrupted and moved to the Ready state by the OS F Allows for better service since any one process cannot monopolize the processor for very long

11 11 The CPU-I/O Cycle n Processes require alternate use of processor and I/O in a repetitive fashion n Each cycle consist of a CPU burst (typically of 5 ms) followed by a (usually longer) I/O burst n A process terminates on a CPU burst n CPU-bound processes have longer CPU bursts than I/O-bound processes

12 12 Running example to discuss various scheduling policies Process Arrival Time Service Time 1 2 3 4 5 0 2 4 6 8 3 6 4 5 2 Service time = total processor time needed in one (CPU-I/O) cycle Jobs with long service time are CPU-bound jobs and are referred to as “long jobs”

13 13 First Come First Served (FCFS) n Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS) n Decision mode: nonpreemptive u a process run until it blocks itself

14 14 FCFS Drawbacks n A process that does not perform any I/O will monopolize the processor n Favors CPU-bound processes u I/O-bound processes have to wait until CPU-bound process completes u They may have to wait even when their I/O are completed (poor device utilization) u we could have kept the I/O devices busy by giving more priority to I/O bound processes

15 15 n Selection function: same as FCFS n Decision mode: preemptive u a process is allowed to run until the time slice period (quantum, typically from 10 to 100 ms) has expired u then a clock interrupt occurs and the running process is put on the ready queue Round-Robin

16 16 Time Quantum for Round Robin n must be substantially larger than the time required to handle the clock interrupt and dispatching n should be larger then the typical interaction (but not much more to avoid penalizing I/O bound processes)

17 17 Round Robin: Critique n Still favors CPU-bound processes u A I/O bound process uses the CPU for a time less than the time quantum, then is blocked waiting for I/O u A CPU-bound process runs for all its time slice and is put back into the ready queue (thus, getting in front of blocked processes) n A solution: virtual round robin u When a I/O has completed, the blocked process is moved to an auxiliary queue, which gets preference over the main ready queue u A process dispatched from the auxiliary queue runs no longer than the basic time quantum minus the time spent running, since it was selected from the ready queue

18 18 Queuing for Virtual Round Robin

19 19 Shortest Process Next (SPN) n Selection function: the process with the shortest expected CPU burst time n Decision mode: nonpreemptive n I/O bound processes will be picked first n We need to estimate the required processing time (CPU burst time) for each process

20 20 Shortest Process Next: Critique n Possibility of starvation for longer processes as long as there is a steady supply of shorter processes n Lack of preemption is not suited in a time sharing environment u CPU bound process gets lower priority (as it should) but a process doing no I/O could still monopolize the CPU if it is the first one to enter the system n SPN implicitly incorporates priorities: shortest jobs are given preferences n The next (preemptive) algorithm penalizes directly longer jobs

21 21 Multilevel Feedback Scheduling n Preemptive scheduling with dynamic priorities n Several ready to execute queues with decreasing priorities: u P(RQ0) > P(RQ1) >... > P(RQn) n New processes are placed in RQ0 n When they reach the time quantum, they are placed in RQ1. If they reach it again, they are place in RQ2... until they reach RQn n I/O-bound processes will stay in higher priority queues. CPU-bound jobs will drift downward. n Dispatcher chooses a process for execution in RQi only if RQi-1 to RQ0 are empty n Hence long jobs may starve

22 22 Multiple Feedback Queues n FCFS is used in each queue except for lowest priority queue where Round Robin is used

23 23 Time Quantum for feedback Scheduling n With a fixed quantum time, the turnaround time of longer processes can stretch out alarmingly n To compensate, we can increase the time quantum according to the depth of the queue u Ex: time quantum of RQi = 2^{i-1} n Longer processes may still suffer starvation. Possible fix: promote a process to higher priority after some time

24 24 Algorithm Comparison n Which one is the best? n The answer depends on: u the system workload (extremely variable) u hardware support for the dispatcher u relative weighting of performance criteria (response time, CPU utilization, throughput...) u The evaluation method used (each has its limitations...) n Hence the answer depends on too many factors to give any...


Download ppt "1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in."

Similar presentations


Ads by Google