processes and scheduling - fau college of …tami/cop4610m4slides.pdfmlfq - multilevel feedback...

26
Operating systems Module 4 Processes and Scheduling PART I 1 Tami Sorgente

Upload: lythuan

Post on 21-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Operating systemsModule 4

Processes and Scheduling

PART I

1Tami Sorgente

MODULE 4 – PROCESSES AND SCHEDULING

Process types

Context switch

System schedulers

CPU scheduling calculations

CPU scheduling algorithms

2Tami Sorgente

PROCESS TYPES

I/O-bound process – spends more time doing

I/O than computations, many short CPU bursts

CPU-bound process – spends more time

doing computations; few very long CPU bursts

3Tami Sorgente

CONTEXT SWITCH

When CPU switches to another process

o save the state of the old process and

o load the saved state for the new process

via a context switch

Context-switch time is overhead

4Tami Sorgente

SCHEDULERS

Long-term scheduler (or job scheduler)

o Selects which processes should be brought into

the ready queue

Short-term scheduler (or CPU scheduler)

o Selects which ready process should be

executed next and allocates CPU

Medium-term scheduler can be added

o Remove process from memory, store on disk,

bring back in from disk to continue execution:

swapping

5Tami Sorgente

CPU SCHEDULING

Short term scheduler (CPU scheduler)

selects from among the processes in

ready queue, and allocates the CPU to

one of them

6

ReadyWaiting

for CPU

admitted

dispatch

interrupt

I/O or event

completion

swapped

Running

Tami Sorgente

DISPATCHER

Dispatcher module gives control of the

CPU to the process selected by the

short-term scheduler, this involves:

o Context switching

o Jumping to the proper location to restart

that program

Dispatch latency – time it takes for the

dispatcher to stop one process and start

another running

7Tami Sorgente

CPU SCHEDULING CPU burst – time on the CPU

CPU scheduling Calculations –

CPU utilization-

o % CPU works - Sum of actual work time/total time

Throughput –

o number of processes completed in amount of time

Turnaround time -

o from time of admit to time of completion

o Sum of periods spent waiting, ready queue, I/0, CPU

Waiting time –

o sum of periods spent waiting (in ready state)

Response time –

o From time of submission until first response

8Tami Sorgente

PROCESS STATES

9

New

Ready

Running

TerminatedBlocked

admitted

dispatchexit

interrupt

I/O or event

I/O or event

completion

Response time – One time measurement

From admit to FIRST time on CPU

Wait time – amount (sum) of time spent

In the ready state

Turnaround time –

total time active –

from admit to exit

Tami Sorgente

CPU SCHEDULING ALGORITHMS

Nonpreempitve – Once a process is on the CPU it does not relinquish the CPU until the current CPU burst has been completed

FCFS –

SJF -

Priority -

Preemptive – a process on the CPU may be “kicked off “ for the arrival of a higher priority process or for time quantum

Round Robin (FCFS with Time Quantum)

SRT – shortest remaining time

Preemptive priority

Starvation – In priority based (SJF/SRT/priority) algorithm – lower priorities could starve for CPU time

Aging – raise the priority over time

10Tami Sorgente

Operating systemsModule 4

CPU Scheduling – FCFS and SJF

PART II

11Tami Sorgente

MODULE 4 – PROCESSES AND SCHEDULING

CPU scheduling algorithms

CPU scheduling Practice

o FCFS

o Shortest Job First (SJF)

SJF and the prediction formula

12Tami Sorgente

CPU SCHEDULING

CPU burst – time on the CPU

CPU scheduling Calculations –

CPU utilization-

o % CPU works - Sum of actual work time/total time

Turnaround time -

o from time of admit to time of completion

o Sum of periods spent waiting, ready queue, I/0, CPU

Waiting time –

o sum of periods spent waiting (in ready state)

Response time –

o From time of submission until first response

13Tami Sorgente

CPU SCHEDULING ALGORITHMS

Nonpreempitve Preemptive

FCFS – Round Robin

SJF - SRT – shortest remaining time

Priority - Preemptive priority

Combination algorithms (unit 5):

MLQ – Multilevel Queue

(stay in the same queue)

MLFQ - Multilevel Feedback Queue

(may migrate to another queue)

14Tami Sorgente

CPU SCHEDULING PRACTICE

Nonpreempitve examples (using Gantt chart):

FCFS – Process Burst Time WT TT

P1 24

P2 3

P3 3

15

Convoy effect - short process behind long

process

0

24

27

24

27

30

17 27 AVG

Tami Sorgente

CPU SCHEDULING PRACTICE

Nonpreempitve examples:

SJF – Process Burst Time WT TT

shortest P1 24

job P2 3

first P3 3

16

6

0

3

30

3

6

3 13 Avg

17 27 AVGFCFS

Tami Sorgente

SJF

Will give minimum average waiting time for a set of processes, 2 problems:

1. Do not know CPU burst length

2. Causes starvation (priority based)

How to implement algorithm similar to SJF:

1. Assign higher priorities to tasks that tend to have shorter CPU burst

2. Use Multilevel Feedback Queue implementation similar to the CPU scheduler programming assignment

3. Use prediction formula (exponential averaging):

T(n + 1 ) = a * tn + (1- a ) * T (n)

17Tami Sorgente

Prediction formula for SJF

18

Preemptive version called shortest-remaining-time- (SRT)

Formula : T(n + 1 ) = a * tn + (1- a ) * T (n)

T(n + 1 ) - The burst to be predicted

Use the length of previous CPU bursts, using exponential averaging

tn - The last actual burst

a – weight between 0 and 1 that determines

what is more important:

The last actual burst or the previous predictions

• If a is 0 , then T(n+1) = T(n), the last burst is NOT important

• If a is 1, then T(n+1) = tn, the last burst is most important

• Usually a is around 0.05

Tami Sorgente

Prediction formula for SJF

19

Preemptive version called shortest-remaining-time

Formula : T(n + 1 ) = a * tn + (1- a ) * T (n)

Use the length of previous CPU bursts, using exponential averaging

Predict T(3), when the following measurements are available:

t0 = 3, t1 = 4, t2 = 5, initial T(0) = 2 and a = 0.25

T(1) = 0.25 * 3 + 0.75 * 2 = (.75) + (1.5 ) = 2.25

T(2) = 0.25 * 4 + 0.75 * 2.25 = (1) + (1.685 ) = 2.685

T(3) = 0.25 * 5 + 0.75 * 2.685 = (1.25) + (2.01375 ) = 3.26 (answer)

Tami Sorgente

Operating systemsModule 4

Processes and Scheduling – Priority,

preemptive priority and Round Robin

PART III

20Tami Sorgente

MODULE 4 – PROCESSES AND SCHEDULING

CPU scheduling algorithms

CPU scheduling Practice

o Priority

o Preemptive Priority

o Round Robin

21Tami Sorgente

CPU SCHEDULING

CPU burst – time on the CPU

CPU scheduling Calculations –

CPU utilization-

o % CPU works - Sum of actual work time/total time

Turnaround time -

o from time of admit to time of completion

o Sum of periods spent waiting, ready queue, I/0, CPU

Waiting time –

o sum of periods spent waiting (in ready state)

Response time –

o From time of submission until first response

22Tami Sorgente

CPU SCHEDULING ALGORITHMS

Nonpreempitve Preemptive

FCFS – Round Robin

SJF - SRT – shortest remaining time

Priority - Preemptive priority

Combination algorithms (unit 5):

MLQ – Multilevel Queue

(stay in the same queue)

MLFQ - Multilevel Feedback Queue

(may migrate to another queue)

23Tami Sorgente

CPU SCHEDULING PRACTICE

Nonpreempitve example (using Gantt chart):

Priority – (1 is highest priority)

24

Process Burst Priority WT/RT TT

P1 10 3

P2 1 1

P3 2 4

P4 1 5

P5 5 2

6

0

16

18

1

16

1

18

19

6

8.2 12 Avg

Tami Sorgente

CPU SCHEDULING PRACTICE

preempitve example (using Gantt chart):

Priority – (1 is highest priority, add arrival time)

25

Process Burst Priority Arrival time WT RT TT

P1 10 3 0 0 + 6 = 6 0 16-0 = 16

P2 1 1 4 0 0 5 - 4 = 1

P3 2 4 2 14 14 18-2 =16

P4 1 5 6 12 12 19-6 = 13

P5 5 2 3 0 + 1 = 1 0 9 – 3 = 6

Tami Sorgente

CPU scheduling practice

26

preempitve examples (using Gantt chart):

Round Robin– (TQ - 4)

Process Burst Arrival time RT WT TT

P1 24 0

P2 9 0

P3 17 0

P1 –WT = 0 + 8 + 8 + 5 + 4 + 1 = 26 Tami Sorgente