KEMBAR78
OS-operating systems- ch05 (CPU Scheduling) ... | PPT
Chapter 5: CPU Scheduling
• CPU scheduling is the central in multi-programming
system.
2
• Maximum CPU utilization obtained with
multiprogramming (prevent CPU from being idle).
•Processes residing in the main memory is selected by
the Scheduler that is:
 Concerned with deciding a policy about which process is
to be selected.
Process selection based on a scheduling algorithm.
Basic Concepts
Basic Concepts
3
Basic Concepts
4
• Process execution consists of a cycle of
CPU execution and I/O wait.
• Processes alternate between these two
states. Process execution begins with a
CPU burst. That is followed by an I/O
burst, which is followed by another
CPU burst, then another I/O burst, and
so on.
• CPU bursts vary greatly from process to
process and from computer to computer.
Basic Concepts
5
Schedulers
•Long-term scheduler chooses some of them to go to
memory (ready queue).
•Then, short-term scheduler (or CPU scheduler) chooses
from ready queue a job to run on CPU.
•Medium-term scheduler may move (swap) some
partially-executed jobs from memory to disk (to enhance
performance).
6
Basic Concepts
CPU Scheduler
•Whenever the CPU becomes idle, the operating system
must select one of the processes in the ready queue to be
executed. The selection process is carried out by the short-
term scheduler, or CPU scheduler.
7
Basic Concepts
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
8
Basic Concepts
Scheduling can be
•Non-preemptive
 Once a process is allocated the
CPU, it does not leave until terminate.
•Preemptive
 OS can force (preempt) a process
from CPU at anytime.
 Say, to allocate CPU to another higher-priority process.
9
Basic Concepts
Non-preemptive and Preemptive
•Preemptive is harder: Need to maintain consistency of
data shared between processes, and more importantly,
kernel data structures (e.g., I/O queues).
10
Basic Concepts
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.
11
Basic Concepts
• CPU utilization – keep the CPU as busy as possible.
• Throughput – number of processes that complete their
execution per time unit.
• Turnaround time – amount of time to execute a particular
process. (time from submission to termination)
• 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.
12
Scheduling Criteria
SchedulingAlgorithm Optimization Criteria
• Max CPU utilization.
• Max throughput.
• Min turnaround time.
• Min waiting time.
• Min response time.
13
Scheduling Criteria
• There are many different CPU-scheduling algorithms:
1. First Come, First Served (FCFS).
2. Shortest Job First (SJF).
 Preemptive SJF.
 Non-Preemptive SJF.
3. Priority.
4. Round Robin.
5. Multilevel queues.
14
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Scheduling Algorithms
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
Note: A process may have many CPU bursts, but in the following
examples we show only one for simplicity.
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
P1 24
P2 3
P3 3
 Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1 P2 P3
24 27 30
0
Waiting Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
0 24 27
Average waiting time:
(0 + 24 + 27)/3 = 17
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
24 27 30
Average turnaround time:
(24 + 27 + 30)/3 = 27
Response Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
0 24 27
Average response time:
(0 + 24 + 27)/3 = 17
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
P2 , P3 , P1
 The Gantt chart for the schedule is:
P1
P3
P2
6
3 30
0
Waiting Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
6 0 3
Average waiting time:
(6 + 0 + 3)/3 = 3
Turnaround Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
30 3 6
Average turnaround time:
(30 + 3 + 6)/3 = 13
Response Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
6 0 3
Average response time:
(6 + 0 + 3)/3 = 3
• Much better than previous case
• Convoy effect short process behind long process
Shortest-Job-First (SJR) Scheduling
 Associate with each process the length of its next CPU
burst. Use these lengths to schedule the process with the
shortest time
 Two 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. This scheme is know as the
Shortest-Remaining-Time-First (SRTF)
 SJF is optimal – gives minimum average waiting time for a
given set of processes
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (non-preemptive)
 Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Example of Non-Preemptive SJF
P1 P3 P2
7
3 16
0
P4
8 12
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (preemptive)
 Average waiting time = (9 + 1 + 0 +2)/4 = 3
P1 P3
P2
4
2 11
0
P4
5 7
P2 P1
16
Priority Scheduling
 A priority number (integer) is associated with each process
 The 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
 Problem  Starvation – low priority processes may never execute
 Solution  Aging – as time progresses increase the priority of the
process
3. Priority Scheduling
(2/25)
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
22
3. Priority Scheduling
(2/25)
Process Burst Time Priority
P1 10 3
P2 1 1 Highest priority
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
23
3
. Priority Scheduling
Scheduling Algorithms
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
24
3. Priority Scheduling
(3/25)
25
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
3. Priority Scheduling
(3/25)
26
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
3. Priority Scheduling
(3/25)
27
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
3. Priority Scheduling
Scheduling Algorithms
28
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
Waiting Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑 𝑷
𝟒 𝑷
𝟓
6 0 16 18 1
Average Waiting time =
[6+0+16+18+1]/5 = 8.2 msec
Turnaround Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑 𝑷
𝟒 𝑷
𝟓
16 1 18 19 6
Average Turnaround time =
[16+1+18+19+6]/5 = 12 msec
Response Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑 𝑷
𝟒 𝑷
𝟓
6 0 16 18 1
Average Response time =
[6+0+16+18+1]/5 = 8.2 msec
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
Example of RR with Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
 The Gantt chart is:
 Typically, higher average turnaround than SJF, but better response
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Time Quantum and Context Switch Time
4. Round Robin (RR) Scheduling
Scheduling Algorithms
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
dnuoR .
:mutnauq fo gniludehcs )RR( niboR
4 ms
32
4. Round Robin (RR) Scheduling
Scheduling Algorithms
33
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1
0 4 7 10 14 18 22 26 30
P2 P3 P1 P1 P1 P1 P1
4. Round Robin (RR) Scheduling
Scheduling Algorithms
34
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1
0 4 7 10 14 18 22 26
30
P2
P3 P1 P1 P1 P1 P1
4. Round Robin (RR) Scheduling
Scheduling Algorithms
35
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
4. Round Robin (RR) Scheduling
Scheduling Algorithms
36
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1 P2 P3 P1
0 14 18 22 26 30
P1 P1 P1 P1
4 7 10
4. Round Robin (RR) Scheduling
Scheduling Algorithms
37
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1 P2 P3 P1 P1
0 18 22 26 30
P1 P1 P1
14
4 7 10
4. Round Robin (RR) Scheduling
Scheduling Algorithms
38
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1 P1
0 18 26 30
14
4 7 10 22
P1 P2 P3 P1 P1 P1
4. Round Robin (RR) Scheduling
Scheduling Algorithms
39
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1 P2 P3 P1 P1 P1 P1 P1
0 18 30
26
14
4 7 10 22
4. Round Robin (RR) Scheduling
Scheduling Algorithms
40
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
.
:mutnauq fo gniludehcs )RR( niboR dnuoR
4 ms
P1 P2 P3 P1 P1 P1 P1 P1
0 18 30
26
14
4 7 10 22
4. Round Robin (RR) Scheduling
Scheduling Algorithms
41
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0
niboR dnuoR .
:mutnauq fo gniludehcs )RR(
4 ms
4 7 10
# of context switches = 7
P1 P2 P3 P1 P1 P1 P1 P1
0 18 30
26
14 22
4. Round Robin (RR) Scheduling
Scheduling Algorithms
(11/25)
Process Burst Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4 ms
P1 P2 P3 P1 P1 P1 P1 P1
42
0 18 30
26
14
4 7 10 22
Waiting Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
0
( +
10
−
4
) 4 7
Average waiting time:
(6 + 4 + 7)/3 = 5.667 ms
Turnaround
Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
30 7 10
Average Turnaround time:
(30 + 7 + 10)/3 = 15.667 ms
Response Time
𝑷
𝟏 𝑷
𝟐 𝑷
𝟑
0 4 7
Average Response time:
(0 + 4 + 7)/3 = 3.667 ms
CHAPTER 5 - PART 2
Scheduling Algorithms
(16/25)
5. Multilevel Queue Scheduling
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.
Scheduling Algorithms
(17/25)
5. Multilevel Queue Scheduling
Scheduling Algorithms
(18/25)
5. Multilevel Queue Scheduling
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling Algorithms
(19/32)
5. Multilevel Queue Scheduling
Scheduling
Anew job enters queue 𝑄
0 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 𝑄
1
.
At 𝑄
1 job is again served FCFS and receives 16 additional milliseconds
 If it still does not complete, it is preempted and moved to queue 𝑄
2
.
Scheduling Algorithms
(20/32)
5. Multilevel Queue Scheduling
Now we add the concepts of varying arrival times and preemption to the
analysis
Process Arrival Time Burst Time
P1 0 7
P2 1 60
P3 2 20
P4 3 40
Multilevel Queue Fixed priority
non-preemptive
Using multi-processors
or multi-core processor
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2 P
3
P4
Arrival Time Burst Time
0 7
1 60
2 20
3 40
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
3
𝑃1
Process Arrival Time Burst Time
P1 0 7
P2 1 60
P 2 20
P4 3 40
7ms
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
7ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
3
Process Arrival Time Burst Time
P1 0 7
P2 1 60
P 2 20
P4 3 40
7ms
7ms 8ms
𝑃1 𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2 P
Arrival Time Burst Time
0 7
1
2
3
60 52
20
40
𝑃1 𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
3
P4
15ms
7ms 8ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2 P
Arrival Time Burst Time
0 7
1
2
3
60 52
20
40
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
3
P4
15ms
7ms 8ms 8ms
Scheduling Algorithms
(21/32)
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 44
P3 2 20 12
P4 3 40
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
𝑄0
𝑄1
𝑄2
23ms
7ms 8ms 8ms
Scheduling Algorithms
(21/32)
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
𝑄0
𝑄1
𝑄2
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 44
P3 2 20 12
P4 3 40
23ms
7ms 8ms 8ms 8ms
𝑃1 𝑃2 𝑃3 𝑃4
𝑃2
Scheduling Algorithms
(21/32)
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 44 36
P3 2 20 12
P4 3 40 32
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
𝑄0
𝑄1
𝑄2
31ms
𝑃4
7ms 8ms 8ms 8ms
16ms
Scheduling Algorithms
(21/32)
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 44 36
P3 2 20 12
P4 3 40 32
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
𝑄0
𝑄1
𝑄2
31ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms 12ms
36ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24
20 12
40 32
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
43ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms 12ms
36ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24
20 12
40 32
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
43ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms
𝑃4
12ms 16ms
36ms
Scheduling Algorithms
(21/32)
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 44 36 24 8
P3 2 20 12
P4 3 40 32 16
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
5. Multilevel Queue Scheduling
𝑄0
𝑄1
𝑄2
59ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms
𝑃4
12ms 16ms
36ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24 8
20 12
40 32 16
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
67ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms
𝑃4
12ms 16ms
36ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24 8
20 12
40 32 16
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
67ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24 8
20 12
40 32 16
𝑃1 𝑃2
𝑃2
𝑃3
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃4
7ms 8ms 8ms
𝑃2
𝑃3
8ms
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(21/32)
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 44 36 24 8
20 12
40 32 16
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(22/32)
Process Arrival Time
P1
P2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
5. Multilevel Queue Scheduling
Scheduling Algorithms
(22/32)
Process Arrival Time
P1
P2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0
= 𝟎
5. Multilevel Queue Scheduling
(22/32)
Process Arrival Time
P1
P2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 7 − 1
= 𝟎 = 𝟔
5. Multilevel Queue Scheduling
Scheduling Algorithms
(22/32)
Process Arrival Time
P1
P2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 7 − 1 15 + 8 − 2
= 𝟎 = 𝟔 = 𝟐𝟏
5. Multilevel Queue Scheduling
Scheduling Algorithms
(22/32)
Process Arrival Time
P1
P2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 7 − 1 15 + 8 − 2 23 + 12 + 8 − 3
= 𝟎 = 𝟔 = 𝟐𝟏 = 𝟒𝟎
5. Multilevel Queue Scheduling
Scheduling Algorithms
(23/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
5. Multilevel Queue Scheduling
Scheduling Algorithms
(23/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
7 − 0
= 𝟕
5. Multilevel Queue Scheduling
Scheduling Algorithms
(23/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
7 − 0 67 − 1
= 𝟕 = 𝟔𝟔
5. Multilevel Queue Scheduling
Scheduling Algorithms
(23/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
7 − 0 67 − 1 43 − 2
= 𝟕 = 𝟔𝟔 = 𝟒𝟏
5. Multilevel Queue Scheduling
Scheduling Algorithms
(23/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
7 − 0 67 − 1 43 − 2 83 − 3
= 𝟕 = 𝟔𝟔 = 𝟒𝟏 = 𝟖𝟎
5. Multilevel Queue Scheduling
Scheduling Algorithms
(24/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
5. Multilevel Queue Scheduling
Scheduling Algorithms
(24/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 − 0
= 𝟎
5. Multilevel Queue Scheduling
Scheduling Algorithms
(24/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 − 0 7 − 1
= 𝟎 = 𝟔
5. Multilevel Queue Scheduling
Scheduling Algorithms
(24/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 − 0 7 − 1 15 − 2
= 𝟎 = 𝟔 = 𝟏𝟑
5. Multilevel Queue Scheduling
Scheduling Algorithms
(24/32)
Process
P1 P
Arrival Time
2
P3
P4
0
1
2
3
𝑃1 𝑃2
𝑃2
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
83ms
𝑃3 𝑃4
7ms 8ms
𝑃2
𝑃3
16ms
𝑃4
12ms 16ms
36ms
𝑃4
16ms
59ms67ms
43ms
7ms 15ms 23ms 31ms
8ms 8ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 − 0 7 − 1 15 − 2 23 − 3
= 𝟎 = 𝟔 = 𝟏𝟑 = 𝟐𝟎
Scheduling Algorithms
(25/32)
5. Multilevel Queue Scheduling
Now we add the concepts of varying arrival times and preemption to the
analysis
Process Arrival Time Burst Time
P1 0 7
P2 1 60
P3 2 20
P4 3 40
Multilevel Queue Fixed priority
non-preemptive
Using single-core
processor
5. Multilevel Queue Scheduling
Scheduling Algorithms
(26/32)
𝑄0
𝑄1
𝑄2
𝑄0
𝑄1
𝑄2
1
Process Arrival Time Burst Time
P 0 7
P2 1 60
P3 2 20
P4 3 40
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
𝑃1
𝑄0
𝑄1
𝑄2
7ms
1
Process Arrival Time Burst Time
P 0 7
P2 1 60
P3 2 20
P4 3 40
7ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
𝑃1
𝑄0
𝑄1
𝑄2
7ms
1
Process Arrival Time Burst Time
P 0 7
P2 1 60
P3 2 20
P4 3 40
7ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52
P3 2 20
P4 3 40
𝑃1 𝑃2
7ms 8ms
15ms
7ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52
P3 2 20 12
P4 3 40
7ms 8ms
𝑃1 𝑃2 𝑃3
15ms
7ms 23ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52
20 12
40 32
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 23ms
7ms 8ms 8ms 8ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4
Arrival Time Burst Time
0 7
1
2
3
60 52 36
20 12
40 32
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
5. Multilevel Queue Scheduling
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32 16
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
𝑃4
16ms
75ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32 16
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32 16
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32 16
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
5. Multilevel Queue Scheduling
Scheduling Algorithms
(27/32)
𝑄0
𝑄1
𝑄2
Process
P1 P2
P3 P4 60 52 36
20 12
40 32 16
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
15ms 31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
Arrival Time Burst Time
0 7
1
2
3
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
5. Multilevel Queue Scheduling
(28/32)
Process Arrival Time Burst Time
P1 0 7
P2 1 60 52 36
P3 2 20 12
P4 3 40 32 16
15ms
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
5. Multilevel Queue Scheduling
(29/32)
Process Arrival Time
P1 0
P2 1
P3 2
P4 3
15ms
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 6 + 16
+ 28
13 + 24 20 + 28
+ 36
= 𝟎 = 𝟓𝟎 = 𝟑𝟕 = 𝟖𝟒
5. Multilevel Queue Scheduling
Scheduling Algorithms
(30/32)
Process Arrival Time
P1 0
P2 1
P3 2
P4 3
15ms
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
7 − 0 111 − 1 59 − 2 127 − 3
= 𝟕 = 𝟏𝟏𝟎 = 𝟓𝟕 = 𝟏𝟐𝟒
5. Multilevel Queue Scheduling
Scheduling Algorithms
(31/32)
Process Arrival Time
P1 0
P2 1
P3 2
P4 3
15ms
7ms 23ms
𝑃1 𝑃2 𝑃3 𝑃4
31ms
7ms 8ms 8ms 8ms
𝑃2
16ms
47ms
𝑃3
12ms
59ms
𝑃4
16ms
75ms
𝑃2
36ms
111ms127ms
𝑃4
16ms
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0 − 0 7 − 1 15 − 2 23 − 3
= 𝟎 = 𝟔 = 𝟏𝟑 = 𝟐𝟎
Scheduling Algorithms
(32/32)
Student Example:
Using a Multilevel Queue Scheduling algorithm in Fig.1. Consider the
following processes with the relative CPU bursts.
Process Arrival Time Burst Time
P1 0 20
P2 1 60
P3 2 5
P4 2 40
Multilevel Queue Fixed priority
non-preemptive
Fig.1

OS-operating systems- ch05 (CPU Scheduling) ...

  • 1.
    Chapter 5: CPUScheduling
  • 2.
    • CPU schedulingis the central in multi-programming system. 2 • Maximum CPU utilization obtained with multiprogramming (prevent CPU from being idle). •Processes residing in the main memory is selected by the Scheduler that is:  Concerned with deciding a policy about which process is to be selected. Process selection based on a scheduling algorithm. Basic Concepts
  • 3.
  • 4.
  • 5.
    • Process executionconsists of a cycle of CPU execution and I/O wait. • Processes alternate between these two states. Process execution begins with a CPU burst. That is followed by an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on. • CPU bursts vary greatly from process to process and from computer to computer. Basic Concepts 5
  • 6.
    Schedulers •Long-term scheduler choosessome of them to go to memory (ready queue). •Then, short-term scheduler (or CPU scheduler) chooses from ready queue a job to run on CPU. •Medium-term scheduler may move (swap) some partially-executed jobs from memory to disk (to enhance performance). 6 Basic Concepts
  • 7.
    CPU Scheduler •Whenever theCPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The selection process is carried out by the short- term scheduler, or CPU scheduler. 7 Basic Concepts
  • 8.
    CPU scheduling decisionsmay 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 8 Basic Concepts
  • 9.
    Scheduling can be •Non-preemptive Once a process is allocated the CPU, it does not leave until terminate. •Preemptive  OS can force (preempt) a process from CPU at anytime.  Say, to allocate CPU to another higher-priority process. 9 Basic Concepts
  • 10.
    Non-preemptive and Preemptive •Preemptiveis harder: Need to maintain consistency of data shared between processes, and more importantly, kernel data structures (e.g., I/O queues). 10 Basic Concepts
  • 11.
    Dispatcher •Dispatcher module givescontrol 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. 11 Basic Concepts
  • 12.
    • CPU utilization– keep the CPU as busy as possible. • Throughput – number of processes that complete their execution per time unit. • Turnaround time – amount of time to execute a particular process. (time from submission to termination) • 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. 12 Scheduling Criteria
  • 13.
    SchedulingAlgorithm Optimization Criteria •Max CPU utilization. • Max throughput. • Min turnaround time. • Min waiting time. • Min response time. 13 Scheduling Criteria
  • 14.
    • There aremany different CPU-scheduling algorithms: 1. First Come, First Served (FCFS). 2. Shortest Job First (SJF).  Preemptive SJF.  Non-Preemptive SJF. 3. Priority. 4. Round Robin. 5. Multilevel queues. 14 Scheduling Algorithms
  • 15.
    1. First-Come, First-Served(FCFS) Scheduling Scheduling Algorithms Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: Note: A process may have many CPU bursts, but in the following examples we show only one for simplicity.
  • 16.
    First-Come, First-Served (FCFS)Scheduling Process Burst Time P1 24 P2 3 P3 3  Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: P1 P2 P3 24 27 30 0 Waiting Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 0 24 27 Average waiting time: (0 + 24 + 27)/3 = 17 Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 24 27 30 Average turnaround time: (24 + 27 + 30)/3 = 27 Response Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 0 24 27 Average response time: (0 + 24 + 27)/3 = 17
  • 17.
    FCFS Scheduling (Cont.) Supposethat the processes arrive in the order P2 , P3 , P1  The Gantt chart for the schedule is: P1 P3 P2 6 3 30 0 Waiting Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 6 0 3 Average waiting time: (6 + 0 + 3)/3 = 3 Turnaround Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 30 3 6 Average turnaround time: (30 + 3 + 6)/3 = 13 Response Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 6 0 3 Average response time: (6 + 0 + 3)/3 = 3 • Much better than previous case • Convoy effect short process behind long process
  • 18.
    Shortest-Job-First (SJR) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time  Two 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. This scheme is know as the Shortest-Remaining-Time-First (SRTF)  SJF is optimal – gives minimum average waiting time for a given set of processes
  • 19.
    Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (non-preemptive)  Average waiting time = (0 + 6 + 3 + 7)/4 = 4 Example of Non-Preemptive SJF P1 P3 P2 7 3 16 0 P4 8 12
  • 20.
    Example of PreemptiveSJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (preemptive)  Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P3 P2 4 2 11 0 P4 5 7 P2 P1 16
  • 21.
    Priority Scheduling  Apriority number (integer) is associated with each process  The 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  Problem  Starvation – low priority processes may never execute  Solution  Aging – as time progresses increase the priority of the process
  • 22.
    3. Priority Scheduling (2/25) ProcessBurst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart 22
  • 23.
    3. Priority Scheduling (2/25) ProcessBurst Time Priority P1 10 3 P2 1 1 Highest priority P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart 23
  • 24.
    3 . Priority Scheduling SchedulingAlgorithms Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart 24
  • 25.
    3. Priority Scheduling (3/25) 25 ProcessBurst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart
  • 26.
    3. Priority Scheduling (3/25) 26 ProcessBurst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart
  • 27.
    3. Priority Scheduling (3/25) 27 ProcessBurst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart
  • 28.
    3. Priority Scheduling SchedulingAlgorithms 28 Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart Waiting Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 𝑷 𝟒 𝑷 𝟓 6 0 16 18 1 Average Waiting time = [6+0+16+18+1]/5 = 8.2 msec Turnaround Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 𝑷 𝟒 𝑷 𝟓 16 1 18 19 6 Average Turnaround time = [16+1+18+19+6]/5 = 12 msec Response Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 𝑷 𝟒 𝑷 𝟓 6 0 16 18 1 Average Response time = [6+0+16+18+1]/5 = 8.2 msec
  • 29.
    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
  • 30.
    Example of RRwith Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24  The Gantt chart is:  Typically, higher average turnaround than SJF, but better response P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162
  • 31.
    Time Quantum andContext Switch Time
  • 32.
    4. Round Robin(RR) Scheduling Scheduling Algorithms Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 dnuoR . :mutnauq fo gniludehcs )RR( niboR 4 ms 32
  • 33.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 33 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 0 4 7 10 14 18 22 26 30 P2 P3 P1 P1 P1 P1 P1
  • 34.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 34 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 0 4 7 10 14 18 22 26 30 P2 P3 P1 P1 P1 P1 P1
  • 35.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 35 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms 0 4 7 10 14 18 22 26 30 P1 P2 P3 P1 P1 P1 P1 P1
  • 36.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 36 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 P2 P3 P1 0 14 18 22 26 30 P1 P1 P1 P1 4 7 10
  • 37.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 37 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 P2 P3 P1 P1 0 18 22 26 30 P1 P1 P1 14 4 7 10
  • 38.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 38 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 P1 0 18 26 30 14 4 7 10 22 P1 P2 P3 P1 P1 P1
  • 39.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 39 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 P2 P3 P1 P1 P1 P1 P1 0 18 30 26 14 4 7 10 22
  • 40.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 40 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 . :mutnauq fo gniludehcs )RR( niboR dnuoR 4 ms P1 P2 P3 P1 P1 P1 P1 P1 0 18 30 26 14 4 7 10 22
  • 41.
    4. Round Robin(RR) Scheduling Scheduling Algorithms 41 Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0 niboR dnuoR . :mutnauq fo gniludehcs )RR( 4 ms 4 7 10 # of context switches = 7 P1 P2 P3 P1 P1 P1 P1 P1 0 18 30 26 14 22
  • 42.
    4. Round Robin(RR) Scheduling Scheduling Algorithms (11/25) Process Burst Time P1 24 P2 3 P3 3 All the processes arrive at the same time 0. Round Robin (RR) scheduling of quantum: 4 ms P1 P2 P3 P1 P1 P1 P1 P1 42 0 18 30 26 14 4 7 10 22 Waiting Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 0 ( + 10 − 4 ) 4 7 Average waiting time: (6 + 4 + 7)/3 = 5.667 ms Turnaround Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 30 7 10 Average Turnaround time: (30 + 7 + 10)/3 = 15.667 ms Response Time 𝑷 𝟏 𝑷 𝟐 𝑷 𝟑 0 4 7 Average Response time: (0 + 4 + 7)/3 = 3.667 ms
  • 43.
  • 44.
    Scheduling Algorithms (16/25) 5. MultilevelQueue Scheduling 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.
  • 45.
  • 46.
    Scheduling Algorithms (18/25) 5. MultilevelQueue Scheduling Three queues: Q0 – RR with time quantum 8 milliseconds Q1 – RR time quantum 16 milliseconds Q2 – FCFS
  • 47.
    Scheduling Algorithms (19/32) 5. MultilevelQueue Scheduling Scheduling Anew job enters queue 𝑄 0 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 𝑄 1 . At 𝑄 1 job is again served FCFS and receives 16 additional milliseconds  If it still does not complete, it is preempted and moved to queue 𝑄 2 .
  • 48.
    Scheduling Algorithms (20/32) 5. MultilevelQueue Scheduling Now we add the concepts of varying arrival times and preemption to the analysis Process Arrival Time Burst Time P1 0 7 P2 1 60 P3 2 20 P4 3 40 Multilevel Queue Fixed priority non-preemptive Using multi-processors or multi-core processor
  • 49.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P 3 P4 Arrival Time Burst Time 0 7 1 60 2 20 3 40 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2
  • 50.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) 3 𝑃1 Process Arrival Time Burst Time P1 0 7 P2 1 60 P 2 20 P4 3 40 7ms 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 7ms
  • 51.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) 3 Process Arrival Time Burst Time P1 0 7 P2 1 60 P 2 20 P4 3 40 7ms 7ms 8ms 𝑃1 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2
  • 52.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P Arrival Time Burst Time 0 7 1 2 3 60 52 20 40 𝑃1 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 3 P4 15ms 7ms 8ms
  • 53.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P Arrival Time Burst Time 0 7 1 2 3 60 52 20 40 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 3 P4 15ms 7ms 8ms 8ms
  • 54.
    Scheduling Algorithms (21/32) Process ArrivalTime Burst Time P1 0 7 P2 1 60 52 44 P3 2 20 12 P4 3 40 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 5. Multilevel Queue Scheduling 𝑄0 𝑄1 𝑄2 23ms 7ms 8ms 8ms
  • 55.
    Scheduling Algorithms (21/32) 𝑄0 𝑄1 𝑄2 5. MultilevelQueue Scheduling 𝑄0 𝑄1 𝑄2 Process Arrival Time Burst Time P1 0 7 P2 1 60 52 44 P3 2 20 12 P4 3 40 23ms 7ms 8ms 8ms 8ms 𝑃1 𝑃2 𝑃3 𝑃4 𝑃2
  • 56.
    Scheduling Algorithms (21/32) Process ArrivalTime Burst Time P1 0 7 P2 1 60 52 44 36 P3 2 20 12 P4 3 40 32 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 5. Multilevel Queue Scheduling 𝑄0 𝑄1 𝑄2 31ms 𝑃4 7ms 8ms 8ms 8ms 16ms
  • 57.
    Scheduling Algorithms (21/32) Process ArrivalTime Burst Time P1 0 7 P2 1 60 52 44 36 P3 2 20 12 P4 3 40 32 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 5. Multilevel Queue Scheduling 𝑄0 𝑄1 𝑄2 31ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 12ms 36ms
  • 58.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 20 12 40 32 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 43ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 12ms 36ms
  • 59.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 20 12 40 32 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 43ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 𝑃4 12ms 16ms 36ms
  • 60.
    Scheduling Algorithms (21/32) Process ArrivalTime Burst Time P1 0 7 P2 1 60 52 44 36 24 8 P3 2 20 12 P4 3 40 32 16 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 5. Multilevel Queue Scheduling 𝑄0 𝑄1 𝑄2 59ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 𝑃4 12ms 16ms 36ms
  • 61.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 8 20 12 40 32 16 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 67ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 𝑃4 12ms 16ms 36ms
  • 62.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 8 20 12 40 32 16 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 67ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms
  • 63.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 8 20 12 40 32 16 𝑃1 𝑃2 𝑃2 𝑃3 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃4 7ms 8ms 8ms 𝑃2 𝑃3 8ms 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms
  • 64.
    5. Multilevel QueueScheduling Scheduling Algorithms (21/32) Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 44 36 24 8 20 12 40 32 16 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms
  • 65.
    5. Multilevel QueueScheduling Scheduling Algorithms (22/32) Process Arrival Time P1 P2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
  • 66.
    5. Multilevel QueueScheduling Scheduling Algorithms (22/32) Process Arrival Time P1 P2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 = 𝟎
  • 67.
    5. Multilevel QueueScheduling (22/32) Process Arrival Time P1 P2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 7 − 1 = 𝟎 = 𝟔
  • 68.
    5. Multilevel QueueScheduling Scheduling Algorithms (22/32) Process Arrival Time P1 P2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 7 − 1 15 + 8 − 2 = 𝟎 = 𝟔 = 𝟐𝟏
  • 69.
    5. Multilevel QueueScheduling Scheduling Algorithms (22/32) Process Arrival Time P1 P2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 7 − 1 15 + 8 − 2 23 + 12 + 8 − 3 = 𝟎 = 𝟔 = 𝟐𝟏 = 𝟒𝟎
  • 70.
    5. Multilevel QueueScheduling Scheduling Algorithms (23/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
  • 71.
    5. Multilevel QueueScheduling Scheduling Algorithms (23/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 7 − 0 = 𝟕
  • 72.
    5. Multilevel QueueScheduling Scheduling Algorithms (23/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 7 − 0 67 − 1 = 𝟕 = 𝟔𝟔
  • 73.
    5. Multilevel QueueScheduling Scheduling Algorithms (23/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 7 − 0 67 − 1 43 − 2 = 𝟕 = 𝟔𝟔 = 𝟒𝟏
  • 74.
    5. Multilevel QueueScheduling Scheduling Algorithms (23/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 7 − 0 67 − 1 43 − 2 83 − 3 = 𝟕 = 𝟔𝟔 = 𝟒𝟏 = 𝟖𝟎
  • 75.
    5. Multilevel QueueScheduling Scheduling Algorithms (24/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
  • 76.
    5. Multilevel QueueScheduling Scheduling Algorithms (24/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 − 0 = 𝟎
  • 77.
    5. Multilevel QueueScheduling Scheduling Algorithms (24/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 − 0 7 − 1 = 𝟎 = 𝟔
  • 78.
    5. Multilevel QueueScheduling Scheduling Algorithms (24/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 − 0 7 − 1 15 − 2 = 𝟎 = 𝟔 = 𝟏𝟑
  • 79.
    5. Multilevel QueueScheduling Scheduling Algorithms (24/32) Process P1 P Arrival Time 2 P3 P4 0 1 2 3 𝑃1 𝑃2 𝑃2 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 83ms 𝑃3 𝑃4 7ms 8ms 𝑃2 𝑃3 16ms 𝑃4 12ms 16ms 36ms 𝑃4 16ms 59ms67ms 43ms 7ms 15ms 23ms 31ms 8ms 8ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 − 0 7 − 1 15 − 2 23 − 3 = 𝟎 = 𝟔 = 𝟏𝟑 = 𝟐𝟎
  • 80.
    Scheduling Algorithms (25/32) 5. MultilevelQueue Scheduling Now we add the concepts of varying arrival times and preemption to the analysis Process Arrival Time Burst Time P1 0 7 P2 1 60 P3 2 20 P4 3 40 Multilevel Queue Fixed priority non-preemptive Using single-core processor
  • 81.
    5. Multilevel QueueScheduling Scheduling Algorithms (26/32) 𝑄0 𝑄1 𝑄2 𝑄0 𝑄1 𝑄2 1 Process Arrival Time Burst Time P 0 7 P2 1 60 P3 2 20 P4 3 40
  • 82.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 𝑃1 𝑄0 𝑄1 𝑄2 7ms 1 Process Arrival Time Burst Time P 0 7 P2 1 60 P3 2 20 P4 3 40 7ms
  • 83.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 𝑃1 𝑄0 𝑄1 𝑄2 7ms 1 Process Arrival Time Burst Time P 0 7 P2 1 60 P3 2 20 P4 3 40 7ms
  • 84.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process Arrival Time Burst Time P1 0 7 P2 1 60 52 P3 2 20 P4 3 40 𝑃1 𝑃2 7ms 8ms 15ms 7ms
  • 85.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process Arrival Time Burst Time P1 0 7 P2 1 60 52 P3 2 20 12 P4 3 40 7ms 8ms 𝑃1 𝑃2 𝑃3 15ms 7ms 23ms
  • 86.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 20 12 40 32 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 23ms 7ms 8ms 8ms 8ms
  • 87.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 Arrival Time Burst Time 0 7 1 2 3 60 52 36 20 12 40 32 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms
  • 88.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms
  • 89.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms
  • 90.
    5. Multilevel QueueScheduling (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 16 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms 𝑃4 16ms 75ms
  • 91.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 16 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms
  • 92.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 16 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms
  • 93.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 16 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms
  • 94.
    5. Multilevel QueueScheduling Scheduling Algorithms (27/32) 𝑄0 𝑄1 𝑄2 Process P1 P2 P3 P4 60 52 36 20 12 40 32 16 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 15ms 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms Arrival Time Burst Time 0 7 1 2 3 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms
  • 95.
    5. Multilevel QueueScheduling (28/32) Process Arrival Time Burst Time P1 0 7 P2 1 60 52 36 P3 2 20 12 P4 3 40 32 16 15ms 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms
  • 96.
    5. Multilevel QueueScheduling (29/32) Process Arrival Time P1 0 P2 1 P3 2 P4 3 15ms 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms Waiting Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 6 + 16 + 28 13 + 24 20 + 28 + 36 = 𝟎 = 𝟓𝟎 = 𝟑𝟕 = 𝟖𝟒
  • 97.
    5. Multilevel QueueScheduling Scheduling Algorithms (30/32) Process Arrival Time P1 0 P2 1 P3 2 P4 3 15ms 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms Turnaround Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 7 − 0 111 − 1 59 − 2 127 − 3 = 𝟕 = 𝟏𝟏𝟎 = 𝟓𝟕 = 𝟏𝟐𝟒
  • 98.
    5. Multilevel QueueScheduling Scheduling Algorithms (31/32) Process Arrival Time P1 0 P2 1 P3 2 P4 3 15ms 7ms 23ms 𝑃1 𝑃2 𝑃3 𝑃4 31ms 7ms 8ms 8ms 8ms 𝑃2 16ms 47ms 𝑃3 12ms 59ms 𝑃4 16ms 75ms 𝑃2 36ms 111ms127ms 𝑃4 16ms Response Time 𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 0 − 0 7 − 1 15 − 2 23 − 3 = 𝟎 = 𝟔 = 𝟏𝟑 = 𝟐𝟎
  • 99.
    Scheduling Algorithms (32/32) Student Example: Usinga Multilevel Queue Scheduling algorithm in Fig.1. Consider the following processes with the relative CPU bursts. Process Arrival Time Burst Time P1 0 20 P2 1 60 P3 2 5 P4 2 40 Multilevel Queue Fixed priority non-preemptive Fig.1

Editor's Notes

  • #17 Turnaround Time 𝑷𝟏,𝑷𝟐,𝑷𝟑 24,27,30 Average turnaround time: (24 + 27 + 30)/3 = 27 Response Time 𝑷𝟏,𝑷𝟐,𝑷𝟑 0,24,27 Average response time: (0 + 24 + 27)/3 = 17
  • #18 Turnaround Time 𝑷𝟏--𝑷𝟐--𝑷𝟑 30--3--6 Average turnaround time: (30 + 3 + 6)/3 = 13 Response Time 𝑷𝟏--𝑷𝟐--𝑷𝟑 6—0—3