CPU Scheduling-- Scheduling Algorithms
Scheduling Algorithms
CPU
scheduling deals with the problem of deciding which of the processes in the
ready queue is to be allocated the CPU. In this section, we describe several of the many CPU-scheduling algorithms that exist.
First-Come, First-Served Scheduling
This non-preemptive scheduling algorithm follows the first-in,
first-out (FIFO) policy. As each process becomes ready, it joins the
ready queue. When the current running process finishes execution, the oldest process
in the ready queue is selected to run next.
By far the simplest CPU-scheduling
algorithm is the first-come, first-served (FCFS) scheduling algorithm. With this scheme, the process that
requests the CPU first is allocated the CPU first. The implementation of the FCFS policy is easily managed with a FIFO queue. When a process enters the
ready queue, its PCB is linked onto the tail of the queue. When the CPU is
free, it is allocated to the process at the head of the queue. The running
process is then removed from the queue. The code for FCFS scheduling is simple
to write and understand. The average waiting time under the FCFS policy,
however, is often quite long.
Shortest-Job-First Scheduling
This scheduling algorithm favors
processes with the shortest expected execution time. As each process becomes
ready, it joins the ready queue.
When the current running process finishes execution, the process in the ready queue with the shortest expected execution time is selected to
run next.
A different approach to CPU
scheduling is the shortest-job-first (SJF) scheduling algorithm. This algorithm associates with each process the length of the latter's next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst. If two
processes have the same length next CPU burst, FCFS scheduling is used to break
the tie (to choose one). Note that a more appropriate term would be the shortest next CPU burst,
because the scheduling is
done by examining the length of the next CPU burst of a process, rather than
its total length. We use the term SJF because most people and textbooks refer
to this type of scheduling discipline as SJF.
Priority Scheduling
The SJF
algorithm is a special case of the general priority-scheduling algorithm. A
priority is associated with each process, and the CPU is allocated to the process
with the highest priority. Equal-priority processes are scheduled in FCFS order
An SJF algorithm is simply a priority
algorithm where the priority (p) is the inverse
of the (predicted) next CPU burst. The larger the CPU burst, the lower the
priority, and vice versa.
Note that we discuss scheduling in
terms of high priority
and low
priority.
Priorities are generally some fixed
range of numbers, such as 0 to 7, or 0 to 4,095.
However, there is no general
agreement on whether 0 is the highest or lowest priority. Some systems use low
numbers to represent low priority; others use low numbers for high priority.
This difference can lead to confusion. In this text, we use low numbers to
represent high priority.
Robin Scheduling
The round-robin (RR) scheduling algorithm is designed
especially for timesharing systems. It is similar to FCFS scheduling, but preemption is
added to switch between processes.
A small unit of time, called a
time quantum (or time slice), is defined. A time quantum is generally from 10
to 100 milliseconds. The ready queue is treated as a circular queue. The CPU
scheduler goes around the ready queue, allocating the CPU to each process for a
time interval of up to 1 time quantum
To implement RR scheduling, we keep the ready queue as a FIFO queue of
processes. New processes are added to the tail of the ready queue. The CPU scheduler
picks the first process from the ready queue, sets a timer to interrupt after 1
time quantum, and dispatches the process.
Comments
Post a Comment