05 lcd slides 1 - cpu scheduling (powerpoint)

Post on 17-Feb-2017

340 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CPU Scheduling

Classification of CPU Scheduling Performance Criteria of Good Scheduler CPU Scheduling Algorithms

*Property of STI J0024

Classification of CPU SchedulingCPU 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 schedulingIn 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

Performance Criteria of a Good SchedulerA good scheduler should optimize the following performance criteria:

CPU utilization Throughput Turnaround time Response time Waiting time

*Property of STI J0024

CPU Scheduling AlgorithmsThe 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

CPU Scheduling AlgorithmsFirst-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

CPU Scheduling AlgorithmsFirst-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

CPU Scheduling AlgorithmsFirst-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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsShortest 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

CPU Scheduling AlgorithmsRound 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

CPU Scheduling AlgorithmsRound 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

CPU Scheduling AlgorithmsRound 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

CPU Scheduling AlgorithmsRound 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsPriority 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

CPU Scheduling AlgorithmsMultilevel 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

top related