CPU–I/O Burst Cycle:
Process execution consists of a cycle of CPU execution & I/O wait
CPU Scheduler
· Selects
from among the processes in memory that are ready to
execute, and allocates the CPU to one of them
· CPU
scheduling decisions may take place when a process:
o
Switches from running
to waiting state
o
Switches from running
to ready state
o
Switches from waiting
to ready
o
Terminates
Dispatcher
· Dispatcher
module gives control of the CPU to the process selected by the scheduler;
· 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
· Throughput –
# of processes that complete their execution per time unit
· Turnaround
time – amount of time to execute a particular process
· Waiting
time – amount of time a process has been waiting in the ready queue
· Response
time – amount of time from when a request was submitted until the first response is produced.
Scheduling Algorithm Optimization Criteria
· Maximize
CPU utilization
· Maximize
throughput
· Minimize
turnaround time
· Minimize
waiting time
· Minimize
response time
« First-Come, First-Served (FCFS) Scheduling
Process Burst Time
P1 24
P2 3
P3 3
The Gantt Chart for the schedule is:
·
Waiting time for P1 = 0; P2 = 24; P3 = 27
·
Average waiting time: (0 + 24 +
27)/3 = 17
«
Shortest-Job-First (SJF) Scheduling
· Associate with each process the length
of its next CPU burst.
· Use these lengths to schedule the
process with the shortest time
· 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
Example
of SJF
Process Burst Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling Gantt chart
Average
waiting time = (3 + 16 + 9 + 0) /
4 = 7
Determining Length of Next CPU Burst
To estimate
the length of next CPU burst
using the length of previous CPU bursts
Prediction of the Length of the Next CPU
Burst (α = 0.5)
«
Priority Scheduling
· A priority
number (integer) is associated with each process
· The
CPU is allocated to the process with the highest priority
§ Preemptive
§ Non-preemptive
· SJF
is a priority scheduling where priority is the predicted next CPU burst time
· Problem
º Starvation – low
priority processes may never execute
· Solution
º Aging –
as time progresses increase the priority of the process
«
Round Robin (RR)
· Each
process gets a small unit of CPU time (time quantum), usually 10-100
milliseconds.
· After
this time has elapsed, the process is preempted and
added to the end of the ready queue.
· If
there are n
processes in the ready queue and the time quantum is q,
then each
process gets 1/n of
the CPU time in chunks of at most q time
units at once.
No process waits more than (n-1)q time
units.
· Performance
§ q
large Þ FIFO
§ q small
Þ q
must be large with respect to context
switch, otherwise overhead is too high
Typically, higher average turnaround than SJF, but better response
«
Multilevel Queue
· Ready
queue is partitioned into separate queues:
§ foreground (interactive)
§ background (batch)
· Each
queue has its own scheduling algorithm
§ foreground
– RR
§ background
– FCFS
· Scheduling
must be done between the queues
· Fixed
priority scheduling; (i.e., serve all from foreground then from
background).
Possibility
of starvation.
· Time
slice – each queue gets a certain amount of CPU time which it can schedule
amongst its processes;
E.g., 80% to
foreground in RR and 20% to background
in FCFS
Multilevel
Queue Scheduling
Example of
Multilevel Feedback Queue
«
Multiple-Processor
Scheduling
· CPU
scheduling more complex when multiple CPUs are available
· Symmetric
multiprocessing (SMP) –
each processor is self-scheduling,
all
processes in common ready queue, or
each has its own private queue of ready processes