Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Announcement • Midterm Exam is on Monday June 8th. • Office hours on Friday 2-3 pm. • Exam Material will be posted on Piazza. Operating Systems: Internals and Design Principles Chapter 9 Uniprocessor Scheduling Seventh Edition By William Stallings Modified by Rana Forsati for CSE 410 Learning Objective • Identify different goals of process scheduling algorithms • Identify different types of scheduling and their role • Given a set of processes, evaluate them to identify the next process to run • Identify effect of different scheduling algorithms on CPU bound/I/O bound processes Scheduling and Process State Transitions Types of Scheduling ■ Broken down into three separate functions: long term scheduling medium term scheduling short term scheduling Long-Term Scheduling ■ Determines when to create a new process and which programs are admitted next to the system for processing ■ Once admitted a user program becomes a process and is added to the queue for short term scheduler ■ Controls the degree of multiprogramming ■ The more processes that are created, the smaller the percentage of time that each process can be executed Medium-Term Scheduling ■ Part of the swapping function ■ Swapping-in decisions are based on the need to manage the degree of multiprogramming ■ Considers the memory requirements of the swapped-out processes Short-Term Scheduling ■ Known as the dispatcher ■ The main objective of short-term scheduling is to allocate CPU time to processes ■ Executes most frequently [minimum overhead?] ■ Invoked when an event occurs that may lead to the blocking of the current process or that may provide an opportunity to preempt a currently running process in favor of another - Clock interrupts – I/O interrupts – Operating system calls Short-term success criteria? Short Term Scheduling Algorithms 9 Aim of Short-term-Scheduling ■ Assign processes to be executed by the processor in a way that meets system (performance) objectives: ■ Response time: amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) ■ ■ Throughput: # of processes that complete their execution per time unit ■ ■ Minimize response time Maximize throughput Processor efficiency: keep the CPU as busy as possible ■ Maximize CPU utilization Short-Term Scheduling Dispatcher OR short-term scheduler ■ Short-Term Scheduling: Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them Scheduling Objectives The scheduling function should: – Share time fairly among processes – Prevent starvation of processes – Have low overhead – Prioritize processes when necessary [flexible] Scheduling Policies • First-Come-First-Served (FCFS) • Round-Robin (RR) • Shortest-Process-Next (SPN) • Shortest-Remaining Time (SRT) • Highest Response Ratio Next (HRRN) Selection Function ■ Determines which process, among ready processes, is selected next for execution ■ This function may be based on priority, resource requirements, or the execution characteristics of the process: ▪ time spent in system so far, waiting ▪ time spent in execution so far ▪ total service time required by the process [generally, this quantity must be estimated or supplied by the user] Decision Mode ▪ Two categories: ▪Nonpreemptive ✴Once a process is in the running state, it will continue to execute until • it terminates OR • it blocks itself for I/O or some OS service ▪Preemptive ✴ Currently running process may be interrupted and moved to the Ready state by the operating system. • a new process arrives • interrupt occurs • periodically based on a clock interrupt Process Scheduling Example Whatʼs the execution order? First-Come-First-Served (FCFS) • Each process joins the Ready queue • When the current process ceases to execute, the oldest process in the Ready queue is selected A B C D E What are the potential consequences of this algorithm? First-Come-First-Served (FCFS) • Favors long processes: performs much better for long processes than short ones • A short process may have to wait a very long time before it can execute • Favors CPU-bound processes (mostly uses the processor) • I/O processes have to wait until CPU-bound process completes First-Come-First-Served (FCFS) First-Come-First-Served (FCFS) Process Service Time (ms) P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 P1 P2 P3 0 24 27 • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17 ms 30 First-Come-First-Served (FCFS) Suppose that the processes arrive in the order P2 , P3 , P1 P2 0 P3 3 P1 6 • Waiting time for P1 = 6; P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 ms • Much better than previous case • Convoy effect: short process behind long process 30 Round Robin • Clock interrupt is generated at periodic intervals • When an interrupt occurs, the currently running process is placed in the ready queue • Next ready job is selected • This technique is also known as time slicing ,because each process is given a slice of time before being preempted. • Principal design issue is the length of the time quantum, or slice, to be used [too large —> ?, too short —> ?] Round Robin • Each process gets a small unit of CPU time known as time slicing (time quantum). • After this time has elapsed, the process is preempted and added to the end of the Ready queue. Process P1 P2 P3 P1 0 P2 4 Service Time 24 3 3 P3 7 P1 10 P1 14 P1 18 22 P1 26 P1 30 • An amount of time is determined that allows each process to use the processor for that length of time q=4 Round Robin q=4 A B C D E Whatʼs the execution order? Round Robin, q = 4 Round Robin, q =1 Round Robin Example Finish time of each process? a) Round Robin q=30 b) Round Robin q=10 Example Solution A B C D E Shortest Process Next (SPN) • Another approach to reducing the bias in favor of long processes inherent in FCFS • Associate with each process the length of its next CPU service. Use these lengths to schedule the process with the shortest time ■ Process with the shortest expected processing time is selected next ■ A short process jumps ahead of longer processes ■ Nonpreemptive policy Shortest Process Next (SPN)- Issues ■ The difficulty is knowing or estimating the length of the required processing time of each process. ■ A risk with SPN is the possibility of starvation for longer processes, as long as there is a steady supply of shorter processes. ■ It still is not desirable for a time-sharing or transaction processing environment because of the lack of preemption. Shortest Process Next (SPN) Process Arrival Time P1 0.0 Service Time 6 P2 0.0 8 P3 0.0 7 P4 0.0 3 • SPN: P4 0 P3 P1 3 9 P2 16 • Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 ms 24 Shortest Process Next (SPN) A B C D E Whatʼs the execution order? Shortest Process Next (SPN) Shortest Process Next (SPN) Shortest Process Next (SPN)- Service Estimation ■ One difficulty is the need to know, or at least estimate, the required processing time of each process (Predictability of longer processes is reduced) ■ Possibility of starvation for longer processes ■ If estimated time for process not correct, the operating system may abort it • Can be done by using the length of previous CPU services, using exponential averaging Shortest Remaining Time (SRT) ■ Preemptive version of SPN ■ Scheduler always chooses the process that has the shortest expected remaining processing time • While a process A is running, if a new process B comes whose length is shorter than the remaining time of process A, then B preempts A and B is started to run. ■ Must estimate processing time A B C D E Whatʼs the execution order? Shortest Remaining Time (SRT) ■ Should give superior turnaround time performance to SPN because a short job is given immediate preference to a running longer job ■ Risk of starvation of longer processes Shortest Remaining Time (SRT) • Process P1 Arrival Time 0.0 Burst Time 8 P2 1.0 4 P3 2.0 9 P4 3.0 5 SRT: P1 0 • P2 1 P4 5 P1 10 P3 17 Average waiting time = (9 + 0 + 2 + 15) / 4 = 6.5 ms 26 Highest Response Ratio Next (HRRN) ■ Chooses next process with the greatest value of response ratio ■ Attractive because it accounts for the age of the process ■ While shorter jobs are favored, aging without service increases the ratio so that a longer process will eventually get past competing shorter jobs Highest Response Ratio Next (HRRN) The algorithms with CPU-I/O cycle • The previous examples included processes with just a single CPU service. Each process execution is a CPU-I/O cycle – First, it executes on CPU – Then, it waits for I/O – After completion of I/O, executes on CPU again and so on. – It ends with execution on CPU. • Example – <3, 2, 1, 4, 5> • CPU for 3 time units then I/O for 2, … • We will make the following assumptions while considering these algorithms with I/O services as well. • In this class, we will assume that all I/O is concurrent. The algorithms with CPU-I/O cycle FCFS: – A process that finishes its I/O enters at the end of the ready queue. No other change required. Round Robin: – Same as above – We will assume the process enters the ready queue as soon as its I/O is finished. – If a process finishes its CPU service, another process can start executing immediately. – No history is maintained • E.g., if the time quantum is 10 and the process CPU service is 4 then the process will release the CPU after time 4. – After this process releases the CPU, another process can start right away and will get time quantum of 10 – When the first process comes back again, it will get the entire time quantum of 10. The algorithms with CPU-I/O cycle • SPN and SRT – When a process is being considered, we will focus on the next CPU service to decide who runs first • HRRN – We will consider total service time and total waiting time in deciding the process to be chosen First-Come-First-Served (FCFS) Consider a system where there are 3 processes, A, B, and C. Their details are as follows A: Arrival time = 0, CPU-I/O cycle = <4,3,2,6,6> B: Arrival time = 2, CPU-I/O cycle = <2,5,4,5,4> C: Arrival time = 4, CPU I/O cycle = <5,2,3,3,5> Show the execution with FCFS: Feedback Scheduling • Penalize jobs that have been running longer • Donʼt know remaining time process needs to • execute • Preemptive with time quantum • Demoted to the next lower-priority queue • With each queue (except the lowest priority queue), FCFS • Lowest-priority queue: RR Traditional UNIX Scheduling • Multilevel feedback using round robin within each of the priority queues • Priorities are recomputed once per second • Base priority divides all processes into fixed bands of priority levels • Adjustment factor used to keep process in its assigned band (decreasing order of priority): – Swapper – Block I/O device control – File manipulation – Character I/O device control – User processes Summary ■ The operating system must make three types of scheduling decisions with respect to the execution of processes: ■ Long-term – determines when new processes are admitted to the system ■ Medium-term – part of the swapping function and determines when a program is brought into main memory so that it may be executed ■ Short-term – determines which ready process will be executed next by the processor ■ From a user’s point of view, response time is generally the most important characteristic of a system; from a system point of view, throughput or processor utilization is important ■ Algorithms: ■ FCFS, Round Robin, SPN, SRT, HRRN, Feedback