KEMBAR78
05 lcd slides 1 - CPU SCHEDULING (Powerpoint) | PPSX
CPU Scheduling
๏ฑ Classification of CPU Scheduling
๏ฑ Performance Criteria of Good Scheduler
๏ฑ CPU Scheduling Algorithms
*Property of STI J0024
CPU scheduling may be classified as:
๏‚ง Non-preemptive scheduling
CPU scheduling is non-preemptive if once the CPU has been assigned to a
process and the process starts executing, the CPU cannot be taken away from
that process.
๏‚ง Preemptive scheduling
In preemptive CPU scheduling, even though the CPU has been assigned to a
process and the process is already executing, the CPU scheduler may decide to
assign the CPU to another process in the ready queue.
*Property of STI J0024
A good scheduler should optimize the following performance criteria:
๏‚ง CPU utilization
๏‚ง Throughput
๏‚ง Turnaround time
๏‚ง Response time
๏‚ง Waiting time
*Property of STI J0024
The different CPU scheduling algorithms are:
๏‚ง First-Come, First-Served Algorithm
๏‚ง Shortest Process First Algorithm
๏‚ง Shortest Remaining Time First Algorithm
๏‚ง Round Robin Algorithm
๏‚ง Priority Scheduling
๏‚ง Multilevel Feedback Queues
*Property of STI J0024
First-Come, First-Served Algorithm (FCFS)
- the one that enters the Ready queue first gets to execute at the CPU first
a.
b.
c.
A
0 8
A
0
B
8 12
A
0
B C
8 12 17
*Property of STI J0024
First-Come, First-Served Algorithm (FCFS)
d.
e.
WTA = 0 โ€“ 0 = 0 ms
WTB = 8 โ€“ 3 = 5 ms
WTC = 12 โ€“ 4 = 8 ms
WTD = 17 โ€“ 6 = 11 ms
WTE = 20 โ€“ 10 = 10 ms
The average waiting time is
(0 + 5 + 8 + 11 + 10)/5 = 34/5 = 6.8 ms
A
0
B C D
8 12 17 20
A
0
B C D
8 12 17 20
E
22
*Property of STI J0024
First-Come, First-Served Algorithm (FCFS)
TAA = 8 - 0= 8 ms
TAB = 12 - 3 = 9 ms
TAC = 17 - 4 = 13 ms
TAD = 20 - 6 = 14 ms
TAE = 22 - 10 = 12 ms
The average turnaround time is
(8 + 9 + 13 + 14 + 12)/5 = 56/5 = 11.2 ms
*Property of STI J0024
Shortest Process First Algorithm (SPF)
- the process with the shortest CPU burst
a.
b.
c.
A
0 8
A
0
D
8 11
A
0
D
8 11 13
E
*Property of STI J0024
Shortest Process First Algorithm (SPF)
d.
e.
WTA = 0 โ€“ 0 = 0 ms
WTB = 13 โ€“ 3 = 10 ms
WTC = 17 โ€“ 4 = 13 ms
WTD = 8 โ€“ 6 = 2 ms
WTE = 11 โ€“ 10 = 1 ms
The average waiting time is
(0 + 10 + 13 + 2 + 1)/5 = 26/5 = 5.2 ms
A
0
BD
8 11 13 17
E
A
0
B CD
8 11 13 17
E
22
*Property of STI J0024
Shortest Process First Algorithm (SPF)
TAA = 8- 0 = 8 ms
TAB = 17 - 3 = 14 ms
TAC = 22 - 4 = 18 ms
TAD = 11 - 6 = 5 ms
TAE = 13 - 10 = 3 ms
The average turnaround time is
(8 + 14 + 18 + 5 + 3)/5 = 48/5 = 9.6 ms
*Property of STI J0024
Shortest Remaining Time First Algorithm (SRTF)
- the preemptive version of SPF
a.
b.
c.
d.
Process ID Arrival Time CPU Burst
A 0 8
B 3 4
C 4 5
D 6 3
E 10 2
0
A
0
A
3
B
0
B
7
A
3
0
B
7
DA
3
*Property of STI J0024
Shortest Remaining Time First Algorithm (SRTF)
e.
f.
g.
h.
WTA = (0 โ€“ 0) + (12 โ€“ 3) = 9 ms
WTB = 3 โ€“ 3 = 0 ms
WTC = 17 โ€“ 4 = 13 ms
WTD = 7 โ€“ 6 = 1 ms
WTE = 10 โ€“ 10 = 0 ms
The average waiting time is
(9 + 0 + 13 + 1 + 0)/5 = 23/5 = 4.6 ms
0
B D
7 10
A
3
0
B D
7 10 12
EA
3
A
0
B D
7 10 12 17
EA
3
A
0
B CD
7 10 12 17
E
22
A
3
*Property of STI J0024
Shortest Remaining Time First Algorithm (SRTF)
TAA = 17 - 0= 17 ms
TAB = 7 - 3 = 4 ms
TAC = 22 - 4 = 18 ms
TAD = 10 - 6 = 4 ms
TAE = 12 - 10 = 2 ms
The average turnaround time is
(17 + 4 + 18 + 4 + 2)/5 = 45/5 = 9.0 ms
*Property of STI J0024
Round Robin Algorithm (RR)
- the process are selected on a first-come, first-served basis. However, each
process is given a time limit to execute at the CPU.
Assume a time quantum of 3 ms.
a.
b.
Process ID Arrival Time CPU Burst
A 0 8
B 3 4
C 4 5
D 6 3
E 10 2
0
A
3
0
B
6
A
3
*Property of STI J0024
Round Robin Algorithm (RR)
c.
d.
e
f.
g.
h
i.
0
B A
6 9
A
3
0
B A
6 9 12
CA
3
D
0
B A
6 9 12 15
CA
3
D
0
B A
6 9 12 15
CA
3
B
16
D
0
B A
6 9 12 15
CA
3
B
16
A
18
D
0
B A
6 9 12 15
CA
3
B
16
A
18
E
20
D
0
B CA
6 9 12 15
C
22
A
3
B
16
A
18
E
20
*Property of STI J0024
Round Robin Algorithm (RR)
WTA = (0 โ€“ 0) + (6 โ€“ 3) + (16 โ€“ 9) = 10 ms
WTB = (3 โ€“ 3) + (15 โ€“ 6) = 9 ms
WTC = (9 โ€“ 4) + (20 โ€“ 12) = 13 ms
WTD = 12 โ€“ 6 = 6 ms
WTE = 18 โ€“ 10 = 8 ms
The average waiting time is
(10 + 9 + 13 + 6 + 8)/5 = 46/5 = 9.2 ms
*Property of STI J0024
Round Robin Algorithm (RR)
TAA = 18 - 6= 18 ms
TAB = 16 - 3 = 13 ms
TAC = 22 - 4 = 18 ms
TAD = 15 - 6 = 9 ms
TAE = 20 - 10 = 10 ms
The average turnaround time is
(18 + 13 + 18 + 9 + 10)/5 = 68/5 = 13.6 ms
*Property of STI J0024
Priority Scheduling
- Each process is assigned a priority and the CPU scheduler selects the process in
the ready queue with the highest priority to execute next.
Using the non-preemptive priority algorithm:
a.
b.
Process ID Arrival
Time
CPU Burst Priority
A 0 8 4
B 3 4 3
C 4 5 1
D 6 3 2
E 10 2 2
A
0 8
A
0
C
8 13
*Property of STI J0024
Priority Scheduling
c.
d.
e.
WTA = 0 โ€“ 0 = 0 ms
WTB = 18 โ€“ 3 = 15 ms
WTC = 8 โ€“ 4 = 4 ms
WTD = 13 โ€“ 6 = 7 ms
WTE = 16 โ€“ 10 = 6 ms
The average waiting time is
(0 + 15 + 4 + 7 + 6)/5 = 32/5 = 6.4 ms
A
0
C D
8 13 16
A
0
C D
8 13 16 18
E
A
0
BC D
8 13 16 18
E
22
*Property of STI J0024
Priority Scheduling
TAA = 8 - 0= 8 ms
TAB = 22 โ€“ 3 = 19 ms
TAC = 13 - 4 = 9 ms
TAD = 16 - 6 = 10 ms
TAE = 18 - 10 = 8 ms
The average turnaround time is
(8 + 19 + 9 + 10 + 8)/5 = 54/5 = 10.8 ms
*Property of STI J0024
Priority Scheduling
Using the preemptive priority algorithm:
a.
b.
c.
d.
Process ID Arrival
Time
CPU Burst Priority
A 0 8 4
B 3 4 3
C 4 5 1
D 6 3 2
E 10 2 2
0
A
0
BA
3
0
B C
4 9
A
3
0
B C
4 9
A
3
D
*Property of STI J0024
Priority Scheduling
e.
f.
WTA = (0 โ€“ 0) + (17 โ€“ 3) = 14 ms
WTB = (3 โ€“ 3) + (14 - 4) = 10 ms
WTC = (4 โ€“ 4) = 0 ms
WTD = (9 โ€“ 6) = 3 ms
WTE = (12 โ€“ 10) = 2 ms
The average waiting time is
(14 + 10 + 0 + 3 + 2)/5 = 29/5 = 5.8 ms
0
B C D
4 9 12
A
3
A
0
B C D
4 9 12 14
E
22
A
3
B
17
*Property of STI J0024
Priority Scheduling
TAA = 22 โ€“ 0 = 22 ms
TAB = 17 - 3 = 14 ms
TAC = 9 - 4 = 5 ms
TAD = 12 - 6 = 6 ms
TAE = 14 - 10 = 4 ms
The average turnaround time is
(22 + 14 + 5 + 6 + 4)/5 = 51/5 = 10.2 ms
*Property of STI J0024
Multilevel Feedback Queues
Q0All processes enter
the queuing network
at the rear of the
highest priority
queue
Processes that
finish executing or
request for an I/O
operation within the
given time slice
leave the queuing
network
FCFS (time slice = 10 ms)
Q1
FCFS (time slice = 20 ms)
Processes that do not finish executing
within the given time slice move to the next
lower-priority queue
Processes that
finish executing or
request for an I/O
operation within the
given time slice
leave the queuing
network
.
.
.
Qn
RR
Processes that do not finish executing
within the given time slice move to the next
lower-priority queue
Q2
FCFS (time slice = 30 ms)
Processes that
finish executing or
request for an I/O
operation within the
given time slice
leave the queuing
network
Processes that
finish executing or
request for an I/O
operation within the
given time slice
leave the queuing
network

05 lcd slides 1 - CPU SCHEDULING (Powerpoint)

  • 1.
    CPU Scheduling ๏ฑ Classificationof CPU Scheduling ๏ฑ Performance Criteria of Good Scheduler ๏ฑ CPU Scheduling Algorithms
  • 2.
    *Property of STIJ0024 CPU scheduling may be classified as: ๏‚ง Non-preemptive scheduling CPU scheduling is non-preemptive if once the CPU has been assigned to a process and the process starts executing, the CPU cannot be taken away from that process. ๏‚ง Preemptive scheduling In preemptive CPU scheduling, even though the CPU has been assigned to a process and the process is already executing, the CPU scheduler may decide to assign the CPU to another process in the ready queue.
  • 3.
    *Property of STIJ0024 A good scheduler should optimize the following performance criteria: ๏‚ง CPU utilization ๏‚ง Throughput ๏‚ง Turnaround time ๏‚ง Response time ๏‚ง Waiting time
  • 4.
    *Property of STIJ0024 The different CPU scheduling algorithms are: ๏‚ง First-Come, First-Served Algorithm ๏‚ง Shortest Process First Algorithm ๏‚ง Shortest Remaining Time First Algorithm ๏‚ง Round Robin Algorithm ๏‚ง Priority Scheduling ๏‚ง Multilevel Feedback Queues
  • 5.
    *Property of STIJ0024 First-Come, First-Served Algorithm (FCFS) - the one that enters the Ready queue first gets to execute at the CPU first a. b. c. A 0 8 A 0 B 8 12 A 0 B C 8 12 17
  • 6.
    *Property of STIJ0024 First-Come, First-Served Algorithm (FCFS) d. e. WTA = 0 โ€“ 0 = 0 ms WTB = 8 โ€“ 3 = 5 ms WTC = 12 โ€“ 4 = 8 ms WTD = 17 โ€“ 6 = 11 ms WTE = 20 โ€“ 10 = 10 ms The average waiting time is (0 + 5 + 8 + 11 + 10)/5 = 34/5 = 6.8 ms A 0 B C D 8 12 17 20 A 0 B C D 8 12 17 20 E 22
  • 7.
    *Property of STIJ0024 First-Come, First-Served Algorithm (FCFS) TAA = 8 - 0= 8 ms TAB = 12 - 3 = 9 ms TAC = 17 - 4 = 13 ms TAD = 20 - 6 = 14 ms TAE = 22 - 10 = 12 ms The average turnaround time is (8 + 9 + 13 + 14 + 12)/5 = 56/5 = 11.2 ms
  • 8.
    *Property of STIJ0024 Shortest Process First Algorithm (SPF) - the process with the shortest CPU burst a. b. c. A 0 8 A 0 D 8 11 A 0 D 8 11 13 E
  • 9.
    *Property of STIJ0024 Shortest Process First Algorithm (SPF) d. e. WTA = 0 โ€“ 0 = 0 ms WTB = 13 โ€“ 3 = 10 ms WTC = 17 โ€“ 4 = 13 ms WTD = 8 โ€“ 6 = 2 ms WTE = 11 โ€“ 10 = 1 ms The average waiting time is (0 + 10 + 13 + 2 + 1)/5 = 26/5 = 5.2 ms A 0 BD 8 11 13 17 E A 0 B CD 8 11 13 17 E 22
  • 10.
    *Property of STIJ0024 Shortest Process First Algorithm (SPF) TAA = 8- 0 = 8 ms TAB = 17 - 3 = 14 ms TAC = 22 - 4 = 18 ms TAD = 11 - 6 = 5 ms TAE = 13 - 10 = 3 ms The average turnaround time is (8 + 14 + 18 + 5 + 3)/5 = 48/5 = 9.6 ms
  • 11.
    *Property of STIJ0024 Shortest Remaining Time First Algorithm (SRTF) - the preemptive version of SPF a. b. c. d. Process ID Arrival Time CPU Burst A 0 8 B 3 4 C 4 5 D 6 3 E 10 2 0 A 0 A 3 B 0 B 7 A 3 0 B 7 DA 3
  • 12.
    *Property of STIJ0024 Shortest Remaining Time First Algorithm (SRTF) e. f. g. h. WTA = (0 โ€“ 0) + (12 โ€“ 3) = 9 ms WTB = 3 โ€“ 3 = 0 ms WTC = 17 โ€“ 4 = 13 ms WTD = 7 โ€“ 6 = 1 ms WTE = 10 โ€“ 10 = 0 ms The average waiting time is (9 + 0 + 13 + 1 + 0)/5 = 23/5 = 4.6 ms 0 B D 7 10 A 3 0 B D 7 10 12 EA 3 A 0 B D 7 10 12 17 EA 3 A 0 B CD 7 10 12 17 E 22 A 3
  • 13.
    *Property of STIJ0024 Shortest Remaining Time First Algorithm (SRTF) TAA = 17 - 0= 17 ms TAB = 7 - 3 = 4 ms TAC = 22 - 4 = 18 ms TAD = 10 - 6 = 4 ms TAE = 12 - 10 = 2 ms The average turnaround time is (17 + 4 + 18 + 4 + 2)/5 = 45/5 = 9.0 ms
  • 14.
    *Property of STIJ0024 Round Robin Algorithm (RR) - the process are selected on a first-come, first-served basis. However, each process is given a time limit to execute at the CPU. Assume a time quantum of 3 ms. a. b. Process ID Arrival Time CPU Burst A 0 8 B 3 4 C 4 5 D 6 3 E 10 2 0 A 3 0 B 6 A 3
  • 15.
    *Property of STIJ0024 Round Robin Algorithm (RR) c. d. e f. g. h i. 0 B A 6 9 A 3 0 B A 6 9 12 CA 3 D 0 B A 6 9 12 15 CA 3 D 0 B A 6 9 12 15 CA 3 B 16 D 0 B A 6 9 12 15 CA 3 B 16 A 18 D 0 B A 6 9 12 15 CA 3 B 16 A 18 E 20 D 0 B CA 6 9 12 15 C 22 A 3 B 16 A 18 E 20
  • 16.
    *Property of STIJ0024 Round Robin Algorithm (RR) WTA = (0 โ€“ 0) + (6 โ€“ 3) + (16 โ€“ 9) = 10 ms WTB = (3 โ€“ 3) + (15 โ€“ 6) = 9 ms WTC = (9 โ€“ 4) + (20 โ€“ 12) = 13 ms WTD = 12 โ€“ 6 = 6 ms WTE = 18 โ€“ 10 = 8 ms The average waiting time is (10 + 9 + 13 + 6 + 8)/5 = 46/5 = 9.2 ms
  • 17.
    *Property of STIJ0024 Round Robin Algorithm (RR) TAA = 18 - 6= 18 ms TAB = 16 - 3 = 13 ms TAC = 22 - 4 = 18 ms TAD = 15 - 6 = 9 ms TAE = 20 - 10 = 10 ms The average turnaround time is (18 + 13 + 18 + 9 + 10)/5 = 68/5 = 13.6 ms
  • 18.
    *Property of STIJ0024 Priority Scheduling - Each process is assigned a priority and the CPU scheduler selects the process in the ready queue with the highest priority to execute next. Using the non-preemptive priority algorithm: a. b. Process ID Arrival Time CPU Burst Priority A 0 8 4 B 3 4 3 C 4 5 1 D 6 3 2 E 10 2 2 A 0 8 A 0 C 8 13
  • 19.
    *Property of STIJ0024 Priority Scheduling c. d. e. WTA = 0 โ€“ 0 = 0 ms WTB = 18 โ€“ 3 = 15 ms WTC = 8 โ€“ 4 = 4 ms WTD = 13 โ€“ 6 = 7 ms WTE = 16 โ€“ 10 = 6 ms The average waiting time is (0 + 15 + 4 + 7 + 6)/5 = 32/5 = 6.4 ms A 0 C D 8 13 16 A 0 C D 8 13 16 18 E A 0 BC D 8 13 16 18 E 22
  • 20.
    *Property of STIJ0024 Priority Scheduling TAA = 8 - 0= 8 ms TAB = 22 โ€“ 3 = 19 ms TAC = 13 - 4 = 9 ms TAD = 16 - 6 = 10 ms TAE = 18 - 10 = 8 ms The average turnaround time is (8 + 19 + 9 + 10 + 8)/5 = 54/5 = 10.8 ms
  • 21.
    *Property of STIJ0024 Priority Scheduling Using the preemptive priority algorithm: a. b. c. d. Process ID Arrival Time CPU Burst Priority A 0 8 4 B 3 4 3 C 4 5 1 D 6 3 2 E 10 2 2 0 A 0 BA 3 0 B C 4 9 A 3 0 B C 4 9 A 3 D
  • 22.
    *Property of STIJ0024 Priority Scheduling e. f. WTA = (0 โ€“ 0) + (17 โ€“ 3) = 14 ms WTB = (3 โ€“ 3) + (14 - 4) = 10 ms WTC = (4 โ€“ 4) = 0 ms WTD = (9 โ€“ 6) = 3 ms WTE = (12 โ€“ 10) = 2 ms The average waiting time is (14 + 10 + 0 + 3 + 2)/5 = 29/5 = 5.8 ms 0 B C D 4 9 12 A 3 A 0 B C D 4 9 12 14 E 22 A 3 B 17
  • 23.
    *Property of STIJ0024 Priority Scheduling TAA = 22 โ€“ 0 = 22 ms TAB = 17 - 3 = 14 ms TAC = 9 - 4 = 5 ms TAD = 12 - 6 = 6 ms TAE = 14 - 10 = 4 ms The average turnaround time is (22 + 14 + 5 + 6 + 4)/5 = 51/5 = 10.2 ms
  • 24.
    *Property of STIJ0024 Multilevel Feedback Queues Q0All processes enter the queuing network at the rear of the highest priority queue Processes that finish executing or request for an I/O operation within the given time slice leave the queuing network FCFS (time slice = 10 ms) Q1 FCFS (time slice = 20 ms) Processes that do not finish executing within the given time slice move to the next lower-priority queue Processes that finish executing or request for an I/O operation within the given time slice leave the queuing network . . . Qn RR Processes that do not finish executing within the given time slice move to the next lower-priority queue Q2 FCFS (time slice = 30 ms) Processes that finish executing or request for an I/O operation within the given time slice leave the queuing network Processes that finish executing or request for an I/O operation within the given time slice leave the queuing network