0% found this document useful (0 votes)
46 views

Prof. D.S.R. Murthy OS-6 CPU Scheduling 1

The document discusses various CPU scheduling algorithms: 1. FCFS, SJF, Priority, and Round Robin scheduling algorithms are described. SJF is optimal for minimizing average waiting time. 2. Multilevel queue scheduling partitions processes into separate queues like foreground and background that each use different scheduling algorithms. 3. Real-time scheduling and scheduling on multiple processors are also addressed briefly. The key goals of scheduling algorithms are maximizing CPU utilization and minimizing waiting time and response time for processes.

Uploaded by

jrahulroy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Prof. D.S.R. Murthy OS-6 CPU Scheduling 1

The document discusses various CPU scheduling algorithms: 1. FCFS, SJF, Priority, and Round Robin scheduling algorithms are described. SJF is optimal for minimizing average waiting time. 2. Multilevel queue scheduling partitions processes into separate queues like foreground and background that each use different scheduling algorithms. 3. Real-time scheduling and scheduling on multiple processors are also addressed briefly. The key goals of scheduling algorithms are maximizing CPU utilization and minimizing waiting time and response time for processes.

Uploaded by

jrahulroy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

CPU Scheduling

Basic Concepts

Scheduling Criteria

Scheduling Algorithms
FCFS
SJF
Nonpreemptive
Preemptive (SRTF)
Priority
RR
Multilevel Queue
Multilevel Feedback Queue

Multiple-Processor Scheduling

Real-Time Scheduling

Prof. D.S.R. Murthy OS-6 CPU Scheduling 1


Basic Concepts
 
Maximum CPU utilization obtained with multiprogramming.

CPU–I/O Burst Cycle


Process execution consists of a cycle of CPU execution and I/O wait.

Alternating Sequence of CPU and I/O Bursts

Prof. D.S.R. Murthy OS-6 CPU Scheduling 2


Basic Concepts
 
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:

1. Switches from running to waiting state Nonpreemptive.

2. Switches from running to ready state Preemptive.

3. Switches from waiting to ready Preemptive.

4. Terminates Nonpreemptive.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 3


Basic Concepts
 
Dispatcher
 
module gives control of the CPU to the process
selected by the short-term scheduler.

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.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 4


Scheduling Criteria
 
CPU utilization
Keep the CPU as busy as possible.
Range 0 – 100%

Throughput
No. of processes completed 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 it takes to start responding, not output
(for time-sharing environment).
Prof. D.S.R. Murthy OS-6 CPU Scheduling 5
Scheduling Criteria
 
Optimization Criteria
 
Maximise
CPU utilization
Throughput

Minimise
Turnaround time
Waiting time
Response time

Prof. D.S.R. Murthy OS-6 CPU Scheduling 6


Scheduling Algorithms
First-Come, First-Served (FCFS) Scheduling
 
Process that requests the CPU first is allocated the CPU first.
Nonpreemptive.
Example:
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1, P2, P3
 

Gantt Chart for the schedule is:


P1 P2 P3

0 24 27 30
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27) / 3 = 17

Prof. D.S.R. Murthy OS-6 CPU Scheduling 7


Scheduling Algorithms
First-Come, First-Served (FCFS) Scheduling
 
Example:
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order P2, P3, P1.
 

Gantt Chart for the schedule is:


P2 P3 P1

0 3 6 30
Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3) / 3 = 3
Much better than previous case.
Convoy effect short process behind long process

Prof. D.S.R. Murthy OS-6 CPU Scheduling 8


Scheduling Algorithms
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.

Schemes:
Nonpreemptive
Once CPU given to the process it cannot be preempted
until completes its CPU burst.
Preemptive
If a new process arrives with CPU burst length less than
remaining time of current executing process, preempt.
Shortest-Remaining-Time-First (SRTF).
 
SJF is optimal
Gives minimum average waiting time for a given set of processes.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 9


Scheduling Algorithms
Shortest-Job-First (SJF) Scheduling

Example of Non-Preemptive SJF


Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
 
Gantt chart for the schedule is:

P1 P3 P2 P4

0 3 7 8 12 16

Average waiting time = (0 + 6 + 3 + 7) / 4 = 4

Prof. D.S.R. Murthy OS-6 CPU Scheduling 10


Scheduling Algorithms
Shortest-Job-First (SJF) Scheduling

Example of Preemptive SJF / SRTF


Process Arrival Time Burst Time
  P1 0 7
P2 2 4
P3 4 1
P4 5 4
 
Gantt chart for the schedule is:
P1 P2 P3 P2 P4 P1

0 2 4 5 7 11 16

Average waiting time = (9 + 1 + 0 +2) / 4 = 3

Prof. D.S.R. Murthy OS-6 CPU Scheduling 11


Scheduling Algorithms
Priority Scheduling
 
Priority no. (integer) is associated with each process.

CPU is allocated to the process with the highest priority


(Smallest integer – Highest priority).
Preemptive
Nonpreemptive

SJF is a priority scheduling


where priority is the predicted next CPU burst time.

Major Problem
Starvation – low priority processes may never execute.

Solution
Aging – as time progresses increase the priority of the process.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 12


Scheduling Algorithms
Priority Scheduling
 
Example of Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2

Gantt chart for the schedule is:


P2 P5 P1 P3 P4

0 1 6 16 18 19

Average waiting time = (6 + 0 + 16 + 18 + 1) / 5 = 8.2

Prof. D.S.R. Murthy OS-6 CPU Scheduling 13


Scheduling Algorithms
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.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 14


Scheduling Algorithms
Round Robin (RR)
 
Example of RR with Time Quantum = 20
  Process Burst Time
P1 53
P2 17
P3 68
P4 24
 
Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162


Average waiting time
= [(77 + 24) + (20) + (37 + 40 + 17) + (57 + 40)] / 4
= [101 + 20 + 94 + 97] / 4
= 312 / 4
= 78
Prof. D.S.R. Murthy OS-6 CPU Scheduling 15
Scheduling Algorithms
Multilevel Queue Scheduling

Prof. D.S.R. Murthy OS-6 CPU Scheduling 16


Scheduling Algorithms
Multilevel Queue Scheduling

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;
i.e., 80% to foreground in RR
20% to background in FCFS

Prof. D.S.R. Murthy OS-6 CPU Scheduling 17


Scheduling Algorithms
Multilevel Feedback Queue Scheduling
 
Allows process to move between various queues.

Aging can be implemented.

Defines the following parameters:


No. of queues
Scheduling algorithms for each queue
Method used to determine when to upgrade a process
Method used to determine when to demote a process
Method used to determine which queue a process will enter
when that process needs service

Prof. D.S.R. Murthy OS-6 CPU Scheduling 18


Scheduling Algorithms
Multilevel Feedback Queue Scheduling
 

Example of Multilevel Feedback Queue


 
 
 
 
 
 
 
Queues:
Q0 – time quantum 8 milliseconds
Q1 – time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 that 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.
At Q1 job is again served FCFS and receives 16 additional milliseconds.
If Prof. D.S.R. Murthy
it still OS-6 CPU Scheduling
does not complete, it is preempted and moved to queue Q 2. 19
Scheduling Algorithms
Multiple-Processor Scheduling

CPU scheduling more complex when multiple CPUs are available.

Homogeneous processors within a multiprocessor.

Load sharing

Asymmetric multiprocessing
Only one processor accesses the system data structures,
alleviating the need for data sharing.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 20


Scheduling Algorithms
Real-Time Scheduling

Hard real-time systems


required completing a critical task within a guaranteed amount of time.

Soft real-time computing


requires that critical processes receive priority over less fortunate ones.

Prof. D.S.R. Murthy OS-6 CPU Scheduling 21


Scheduling Algorithms
Solaris 2 Scheduling

Prof. D.S.R. Murthy OS-6 CPU Scheduling 22


Scheduling Algorithms
Windows 2000 Priorities

Prof. D.S.R. Murthy OS-6 CPU Scheduling 23

You might also like