operating systems {week 06b}

18
Operating Systems {week 06b} Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.

Upload: elisa

Post on 24-Feb-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 06b}. Short-term (CPU) scheduling (i). The short-term scheduler decides which process the CPU executes next - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Operating Systems {week 06b}

Operating Systems{week 06b}

Rensselaer Polytechnic InstituteCSCI-4210 – Operating SystemsDavid Goldschmidt, Ph.D.

Page 2: Operating Systems {week 06b}

Short-term (CPU) scheduling (i) The short-term scheduler decides which

process the CPU executes next The dispatcher gives control of the CPU

to the process selected by the CPU scheduler: Performs context switch Switches to user mode Jumps to the proper location in the user

program to resume program execution

Page 3: Operating Systems {week 06b}

Short-term (CPU) scheduling (ii)

the dispatcher operates here

Page 4: Operating Systems {week 06b}

CPU scheduling algorithms (i) CPU scheduling requires an algorithm to

determine which process to dispatch next

Scheduling algorithms include: First-Come, First-Served (FCFS) Shortest-Job-First (SJF) Round-Robin (RR) Priority Multilevel Queue (MQ)

Page 5: Operating Systems {week 06b}

CPU scheduling algorithms (ii) Preemptive scheduling preempts a

running process before itstime slice expires Or it preempts a process

because its time slice has expired

Non-preemptive scheduling gives a process exclusive uninterrupted access to the CPU for the entirety of its execution

process

process process process

Page 6: Operating Systems {week 06b}

CPU scheduling algorithms (iii) Compare scheduling algorithms by

measuring CPU utilization – keep CPU as busy as possible Throughput – maximize the number of

processes that complete their execution per unit time

Turnaround time – minimize the elapsed time to fully execute a particular process

Waiting time – minimize the elapsed time a process waits in the ready queue

Page 7: Operating Systems {week 06b}

First-Come-First-Served (FCFS) FCFS dispatches processes

in the order they enterthe ready queue FCFS is non-preemptive

time

P1 P2 P3

24 27 300

Process

CPU Burst Time

P1 24 msP2 3 msP3 3 ms

Page 8: Operating Systems {week 06b}

Shortest-Job-First (SJF)

SJF dispatches processes byselecting the process withthe lowest CPU burst time SJF is non-preemptive (and predictive)

time

Process

CPU Burst Time

P1 24 msP2 3 msP3 3 ms

P1P3P2

63 300

Page 9: Operating Systems {week 06b}

Preemptive SJF

Same as SJF, but anew process maypreempt therunning process

time

Process

Arrival Time

CPU Burst Time

P1 0 7 msP2 2 ms 4 msP3 4 ms 1 msP4 5 ms 4 ms

P1 P3P2

42 110

P4

5 7

P2 P1

16

Page 10: Operating Systems {week 06b}

Limitations of SJF (i)

SJF is the optimal solution The problem with SJF is the inability to

predict required CPU burst times Apply a prediction algorithm that uses

previous CPU burst times Algorithm uses exponential averaging:▪ tn = actual length of the nth CPU burst▪ τn+1 = predicted value for the next CPU burst▪ τn+1 = α tn + (1 – α) τn , where 0 < α < 1

Page 11: Operating Systems {week 06b}

Limitations of SJF (ii)

Page 12: Operating Systems {week 06b}

Round-Robin (RR)

RR is a preemptive algorithmthat gives all ready processesa fair time slice of CPU time Using a time slice of 2 ms....

time

Process

CPU Burst Time

P1 6 msP2 2 msP3 5 ms

P1 P3P2

62 130

P3

8 124

P1

10

P1 P3

Page 13: Operating Systems {week 06b}

Priority Scheduling (i)

Associate a priority number with each process The dispatcher selects the process

with the highest priority For multiple ready processes with

identical priority numbers, use FCFS Key problem is starvation ▪ Overcome starvation by aging, increasing

the priority of a process as it ages

Page 14: Operating Systems {week 06b}

Priority Scheduling (ii)

(use this one for Project #1)

Is priority scheduling preemptive or non-preemptive? Non-preemptive priority scheduling

places higher-priority processes at the head of the queue

Preemptive priority scheduling requires a running process to be interrupted and preempted upon the arrival of a higher-priority process

process

Page 15: Operating Systems {week 06b}

Multiclass systems

Operating systems that support priority schemes are often called multiclass systems use a separate scheduling

algorithm for each queue

Page 16: Operating Systems {week 06b}

Multilevel Queue (MQ)

Assign processes to multiple queues,each with its own scheduling algorithm

Page 17: Operating Systems {week 06b}

Multilevel Feedback Queue (MFQ) Dynamically assign processes to

multiple queues based on actual CPU burst times i.e. feedback

quantum is synonymouswith time slice

Page 18: Operating Systems {week 06b}

Practice! Apply the FCFS, SJF, RR, and Preemptive

Priority scheduling algorithms to this table:

For RR, use a time slice of 10 ms Calculate the wait and turnaround times of

each process, as well as overall averages

Process

Arrival Time

CPU Burst Time

Priority

P1 0 45 ms 5P2 0 5 ms 3P3 20 ms 15 ms 1P4 60 ms 25 ms 2

lower number indicatesa higher priority

recalculate usingcontext switchtime tcs = 20 μs