CPU Scheduling
CPU Scheduling
► Selects from among the processes in ready queue, and allocates the CPU to
one of them
► Queue may be ordered in various ways
► CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates
► Scheduling under 1 and 4 is nonpreemptive
► All other scheduling is preemptive
► Consider access to shared data
► Consider preemption while in kernel mode
► Consider interrupts occurring during crucial OS activities
Dispatcher
► Dispatcher module gives control of the CPU to the process selected by the
short-term scheduler; this involves:
► switching context
► switching to user mode
► jumping to the proper location in the user program to restart that program
► Dispatch latency – time it takes for the dispatcher to stop one process and
start another running
Scheduling Criteria
► CPU utilization – keep the CPU as busy as possible
► Waiting time – amount of time a process has been waiting in the ready queue
► 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)
Scheduling Algorithm Optimization Criteria
0 24 27 30
0 3 6 30
► SJF is optimal – gives minimum average waiting time for a given set of
processes
► The difficulty is knowing the length of the next CPU request
► Could ask the user
Example of SJF
P4 5.0 3
► SJF0scheduling chart
3 9 16 24
► Now we add the concepts of varying arrival times and preemption to the analysis
0 1 5 10 17 26
► The CPU is allocated to the process with the highest priority (smallest integer ≡
highest priority)
► Preemptive
► Nonpreemptive
► SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
0 4 7 10 14 18 22 26 30
► Three queues:
► Q0 – RR with time quantum 8 milliseconds
► Q1 – RR time quantum 16 milliseconds
► Q2 – FCFS
► Scheduling
► A new job enters queue Q0 which is served FCFS
► When it gains CPU, job receives 8 milliseconds
► If it does not finish in 8 milliseconds, job is moved to queue Q1
► Deterministic modeling
► Type of analytic evaluation
► Takes a particular predetermined workload and defines the performance of each
algorithm for that workload