Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 9 Uniprocessor Scheduling Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall
Aim of Scheduling Assign processes to be executed by the processor(s) Response time Throughput Processor efficiency
Types of Scheduling
Scheduling and Process State Transitions
Levels of Scheduling
Long-Term Scheduling Determines which programs are admitted to the system for processing Controls the degree of multiprogramming More processes, smaller percentage of time each process is executed
Medium-Term Scheduling Part of the swapping function Based on the need to manage the degree of multiprogramming
Short-Term Scheduling Known as the dispatcher Executes most frequently Invoked when an event occurs Clock interrupts I/O interrupts Operating system calls Signals (eg semaphores)
Short-Term Scheduling Criteria User-oriented Response Time Elapsed time between the submission of a request until there is output. System-oriented Effective and efficient utilization of the processor
Short-Term Scheduling Criteria Performance-related Quantitative Measurable such as response time and throughput
Scheduling Criteria
Scheduling Criteria
Queuing Diagram
Priorities Scheduler will always choose a process of higher priority over one of lower priority Have multiple ready queues to represent each level of priority Lower-priority may suffer starvation Allow a process to change its priority based on its age or execution history
Priority Queuing
Decision Mode Nonpreemptive Once a process is in the running state, it will continue until it terminates or blocks itself for I/O
Decision Mode Preemptive Currently running process may be interrupted and moved to the Ready state by the operating system Allows for better service since any one process cannot monopolize the processor for very long
Process Scheduling Example
First-Come-First-Served Each process joins the Ready queue When the current process ceases to execute, the process in the Ready queue the longest time is selected
First-Come-First-Served A short process may have to wait a very long time before it can execute Favors CPU-bound processes I/O processes have to wait until CPU-bound process completes, while they only need the CPU for a short amount of time after which they will be blocked (can lead to inefficient use of the CPU)
Round Robin Uses preemption based on a clock
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 Known as time slicing
Effect of Size of Preemption Time Quantum
Effect of Size of Preemption Time Quantum
Round-Robin (2) Processor-bound processes tend to receive an unfair amount of processor time, this results in poor performance for I/O processes, inefficient use of I/O devices, and increase in variance of response time. Solution, Auxiliary queue that has preference over Ready for processes just released from the Blocked Queues.
Queuing Diagram
Shortest Process Next Nonpreemptive policy Process with shortest expected processing time is selected next Short process jumps ahead of longer processes
Shortest Process Next Predictability of longer processes is reduced If estimated time for process not correct, the operating system may abort it Possibility of starvation for longer processes
Shortest Process Next One difficulty is the need to know or at least estimate the required processing time. In a batch job can ask the programmer for an estimate; in a production environment, statistics can be gathered. SS nn+1 = 1 nn nn ii=1 TT ii To avoid recalculating the entire summation each time: SS nn+1 = 1 TT nn nn + nn 1 nn SS nn (equal weight to each instance)
Shortest Process Next Exponential Averaging is used to give more weight to more recent values. SS nn+1 = TT nn + 1 SS nn Which expands to: SS nn = TT nn + 1 TT nn 1 + + 1 ii TT nn ii + + 1 nn SS 1 Depending on the coefficients are shown next:
Exponential Smoothing Coefficients
Use Of Exponential Averaging
Use Of Exponential Averaging
Shortest Remaining Time Preemptive version of shortest process next policy Must estimate processing time
Highest Response Ratio Next Choose next process with the greatest ratio This approach is attractive because it accounts for the age of the process. While shorter jobs are favored, aging will help a longer process eventually get past competing shorter jobs.
Feedback Penalize jobs that have been running longer by making them move to a lower priority queue at each preemption. The simple method will cause the time for longer processes to grow alarmingly A solution is to increase the time quantum at each priority level. One time unit at RQ0, two at RQ1, 2^i at RQi Don t know remaining time process needs to execute
Feedback Scheduling
Scheduling Policies w e s Time spent in system so far Time spent in execution so far Total service time required by the process
Scheduling Policies
Comparison of Scheduling Policies
Formulas
Normalized Response Time
Normalized Response Time
Normalized Response Time
Normalized Turnaround Time
Simulation Result for Waiting Time
Fair-Share Scheduling User s application runs as a collection of processes (threads) User is concerned about the performance of the application Need to make scheduling decisions based on process sets
Fair-Share Scheduler
Traditional UNIX Scheduling Multilevel feedback using round robin within each of the priority queues If a running process does not block or complete within 1 second, it is preempted Priorities are recomputed once per second Base priority divides all processes into fixed bands of priority levels
Bands Decreasing order of priority Swapper Block I/O device control File manipulation Character I/O device control User processes
Example of Traditional UNIX Process Scheduling