CSE316 - CPU Scheduling Unit2
CSE316 - CPU Scheduling Unit2
Basic Concept
CPU Scheduling is:
Basis of Multi-programmed OS
Objective of Multi-programming:
To have some processes running all the time to
maximize CPU Utilization.
CPU and I/O Bursts
Sequence of CPU and I/O Bursts
CPU Scheduling Decisions
Non-Preemptive
Preemptive
Non-Preemptive
Once the CPU is allocated to a process, process keeps
the CPU until:
it releases when it completes
by switching to waiting state
E.g : 1. Windows 3.x and Apple Macintosh operating
systems uses non-preemptive scheduling
2. Windows (also 10) uses a round-robin technique with
a multi-level feedback queue for priority scheduling
Process is executed till completion. It cannot be
interrupted.
Eg First In First Out
Preemptive Scheduling
The running process is interrupted for some
time and resumed later on, when the priority
task has finished its execution.
OR
Turnaround time = Burst time + Waiting time
First-Come, First-Served (FCFS)
17
Example: First-Come, First-Served (FCFS)
Consider AT(0,1,2,3)
First Come First Serve
Process AT BT CT TAT WT
P1 0 2
P2 3 1
P3 5 6
First Come First Serve (Convoy Effect
H.W
Process AT BT CT TAT WT
P1 0 4
Calculate avg. P2 1 3
CT, TAT,WT P3 2 1
P4 3 2
P5 4 5
First Come First Serve (Convoy Effect
Process AT BT CT TAT WT
P1 0 4 4
P2 1 3 7
P3 2 1 8
P4 3 2 10
P5 4 5 15
29
H.W. Practice: Shortest Job First (Non
Preemption)
Q1. Consider foll. Processes with A.T and B.T
Process A.T B.T
P1 1 7
P2 2 5
P3 3 1
P4 4 2
P5 5 8
Cal. Completion time, turn around time and avg. waiting time.
H.W. Practice: Shortest Job First
(Preemption)
idle p0 p1 p2 idle
0 2 9 23 44 47
Total time spent = 47
Idle time = 2 + 3 = 5
Percentage of idle time = (5/47)*100 = 10.6 %
Priority Scheduling
Priority is associated with each process.
CPU is allocated to the process with highest
priority.
If 2 processes have same priority FCFS
P1 0 2 10
P2 2 1 5 Consider 0 as
P3 3 0 2 Lowest and 3
P4 5 3 20 as Highest
Priority
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 0 2 10
P2 2 1 5 Consider 3 as
P3 3 0 2 Lowest and 0
P4 5 3 20 as Highest
Priority
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 1 4 4
P2 2 5 2 Consider 4 as
P3 2 7 3 Lowest and 8
P4 3 8 5 as Highest
P5 3 5 1 Priority
P6 4 6 2
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 1 2 4
P2 1 2 2 Consider 2 as
P3 2 10 5 Lowest and 10
P4 3 6 3 as Highest
Priority
Priority Scheduling (Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 0 2 4
P2 1 4 2 Consider 2 as
P3 2 6 3 Lowest and 12
P4 3 10 5 as Highest
P5 4 8 1 Priority
P6 5 12 4
P7 6 9 6
Priority Scheduling (Non-Preemptive)
Process Arrival Priority Burst Completion
Time Time Time
P1 0 4 4
P2 1 5 5 Consider 7 as
P3 2 7 1 Lowest and 1
P4 3 2 2 as Highest
P5 4 1 3 Priority
P6 5 6 6
Round Robin Scheduling
A Time Quantum is associated to all processes
P1 0 5
P2 1 7
P3 2 1
P1 0 3
P2 3 4
P3 4 6
Round Robin
P1 0 4 8
P2 1 5 18
P3 2 2 6
P4 3 1 9
P5 4 6 21
P6 6 3 19
Multilevel Queue
A multilevel queue scheduling algorithm partitions
the ready queue into several separate queues.
1. System processes
2. Interactive processes
3. Interactive editing processes
4. Batch processes
5. Student/ user processes
Multilevel Queue
A process can move between various queues
Multilevel Queue Scheduler defined by the following
parameters:
No. of queues
Scheduling algorithms for each queue
Method used to determine when to upgrade / demote
a process
Method used to determine which queue a process
will enter and when that process needs service.
Multilevel Queue
Multilevel Queue
Multilevel Queue
1. System Processes: These are programs that belong to OS
(System Files)
4. Student/User Processes
Multilevel Queue
Disadvantages:
1. Until high priority queue is not empty, No process from
lower priority queues will be selected.
2. Starvation for lower priority processes
Advantage:
Can apply separate scheduling algorithm for each queue.
Multilevel Feedback Queue
Solution is: Multilevel Feedback Queue
If a process is taking too long to execute.. Pre-empt
it send it to low priority queue.
Don’t allow a low priority process to wait for long.
After some time move a least priority process to
high priority queue Aging
Multilevel Feedback Queue
Allows a process to move between queues.
1. Asymmetric multiprocessing
1. Processor Affinity
(a process has an affinity for the processor on which it is currently
running.)
Consider what happens to cache memory when a process
has been running on a specific processor?
1. Processor Affinity
1. Processor Affinity
2. Hard affinity
Operating system will attempt to keep a process on a single
processor, it is possible for a process to migrate between
processors.
Issues concerning SMP systems
Hard affinity
Example:
2. Load Balancing
2. Load Balancing
Load balancing is necessary only on systems where each
processor has its own private queue of eligible processes to
execute.
2. Load Balancing
Two approaches to load balancing: push migration and pull
migration.
3. Multicore Processors
3. Multicore Processors
Memory Stall
For example
Consider P1, P2 with time period 50,100 resp. and B.T 20,35
resp.
Cal. CPU utilization of each process and total CPU
utilization.
Sol:
CPU utilization=(Burst time/Time period)= (Ti/Pi)
For P1: (20/50)=0.40 i.e 40%
For P2: (35/100)=0.35 i.e 35%
Total CPU utilization is 75%
Earliest Deadline First Scheduling
Earliest-deadline-first (EDF) scheduling dynamically assigns
priorities according to deadline.
The earlier the deadline, the higher the priority the later the
deadline, the lower the priority.