scheduling strategies

16
Scheduling Strategies Operating Systems Spring 2004 Class #10

Upload: alodie

Post on 05-Jan-2016

44 views

Category:

Documents


3 download

DESCRIPTION

Scheduling Strategies. Operating Systems Spring 2004 Class #10. Scheduling Strategies. The job of the scheduling strategy is to select the next Ready process to enter the Running state. Preemption or voluntary yield. Scheduler. Strategy. New Process. Ready List. CPU. Done. process. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Scheduling Strategies

Scheduling Strategies

Operating Systems

Spring 2004

Class #10

Page 2: Scheduling Strategies

Scheduling StrategiesThe job of the scheduling strategy is to select

the next Ready process to enter the Running state.

ReadyList

ReadyList CPUCPU

ResourceManager

ResourceManager

ResourcesResources

Preemption or voluntary yield

Allocate Request

DoneNewProcess

process

“Ready” “Running”

“Blocked”

processprocess

process

processprocess

process

Scheduler

Strategy

Page 3: Scheduling Strategies

Some Scheduling Strategies

Non-Preemptive Strategies:First-Come-First-Served (FCFS)Priority*

Shortest Job Next (SJN)*

* These also come in a preemptive flavor.

Preemptive Strategies:Round RobinMulti-level QueueMulti-level Feedback Queue

Page 4: Scheduling Strategies

Evaluating Scheduling Strategies

Some metrics that are useful in evaluating scheduling strategies: CPU Utilization: The percentage of time that the CPU spends executing code on

behalf of a user. Throughput: The average number of processes completed per time unit. Turnaround Time*: The total time from when a process first enters the Ready state to

last time it leaves the Running state. Wait Time*: The time a process spends in the Ready state before its first transition to

the Running state. Waiting Time*: The total time that a process spends in the Ready state. Response Time*: The average amount of time that a process spends in the Ready

state.

* These metrics are typically averaged across acollection of processes.

Page 5: Scheduling Strategies

Comparing Scheduling Strategies

There are many techniques for comparing scheduling strategies:Deterministic ModelingQueuing ModelsSimulationImplementation

Page 6: Scheduling Strategies

Deterministic ModelingIn deterministic modeling we’ll ignore I/O

operations and voluntary yields.

ReadyList

ReadyList CPUCPU

ResourceManager

ResourceManager

ResourcesResources

Preemption or voluntary yield

Allocate Request

DoneNewProcess

process

“Ready” “Running”

“Blocked”

processprocess

process

processprocess

process

Scheduler

Strategy

Page 7: Scheduling Strategies

FCFS ExampleArrival CPUOrder Burst0 3501 1252 4753 2504 75

p0 p1 p2 p3 p4

127512009004753500

Gantt Chart:

Throughput =5 jobs

1275 tu= 0.004 jobs

tu

Turnaround =(350 + 475 + 900 +1200 +1275) tu

5 jobs= 850 tu

job

Wait =(0 + 350 + 475 + 900 +1200) tu

5 jobs= 595 tu

job

Page 8: Scheduling Strategies

SJN Example

SJN:Guaranteed minimum average wait time.May result in starvation of large jobs.Need to know the CPU burst times.

Arrival CPUOrder Burst0 3501 1252 4753 2504 75

p0p1 p2p3p4

1275800450200750

Gantt Chart:

Wait =(0 + 75 + 200 + 450 + 800) tu

5 jobs= 305 tu

job

Turnaround =(75 + 200 + 450 + 800 +1275) tu

5 jobs= 560 tu

job

Page 9: Scheduling Strategies

RR Example (w/ 50tu Time Slice)Arrival CPUOrder Burst0 3501 1252 4753 2504 75

p0

4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2

550 650

650 750 850 950 1050 1150 1250 1275

Gantt Chart:

Wait =(0 + 50 +100 +150 + 200) tu

5 jobs=100 tu

job

Response p0 =Waiting p 0

7 visits=

750 tu

7 visits=107 tu

visit

Waiting p0 = (0 + 200 +175 +125 +100 +100 + 50) tu = 750 tu

Page 10: Scheduling Strategies

RR Example (w/ 50 tu Overhead)

p0

5404803602401200p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2

575 790

910 1030 1150 1270 1390 1510 1535

635 670

790

Gantt Chart:

CPU =(350 +125 + 475 + 250 + 75) tu

1535 tu×100 =

1275

1535×100 = 83%

Throughput, turnaround, wait, waiting and response time calculations must now include the overhead.

Page 11: Scheduling Strategies

Multi-Level Queues

For i < j All processes at level i run before any process at level j.

Each list may use its own strategy.

Ready List0Ready List0

Ready List1Ready List1

Ready List2Ready List2

Ready ListN-1Ready ListN-1

SchedulerScheduler CPUCPU

Preemption or voluntary yield

Done

NewProcess

Page 12: Scheduling Strategies

Linux SchedulingLinux uses a multi-level queue scheduling strategy:

All threads in FIFO run before any in RR which run before any in OTHER. Within each queue a priority scheme is used with higher priority threads running

first. User threads run in the OTHER queue. All queues are preemptive.

FIFO

RR

OTHER

SchedulerScheduler CPUCPUDoneNew

Process

Preemption or voluntary yield

Page 13: Scheduling Strategies

Linux OTHER Queue SchedulingThe OTHER queue uses the following strategy:

Each thread, i, has a priority piEvery new thread is given a default priority, K.

A countdown timer is used to create time slices.On each timer interrupt the priority of the running thread is decremented

(pi--).• When a thread’s priority reaches 0, it is blocked.

The highest priority thread is selected to run for the next time slice.• If no threads are available (i.e. all threads are blocked on a resource or because

they have 0 priority), then a recrediting operation is performed.• During recrediting, every thread in the system is assigned priority using

the following formula:

• Threads blocked for 0 priority nowreturn to the ready queue.

pi =pi

2+ K

Page 14: Scheduling Strategies

Multi-Level Feedback Queues

For i < j All processes at level i run before any process at level j.

Processes are inserted into queues by priority. Process priorities are updated dynamically. Each queue typically uses a RR strategy.

Popular in Modern OS: Windows BSD

Ready List0Ready List0

Ready List1Ready List1

Ready List2Ready List2

Ready ListN-1Ready ListN-1

SchedulerScheduler CPUCPU

Preemption or voluntary yield

Done

NewProcess

Page 15: Scheduling Strategies

Scheduling Simulations

Scheduling simulations account for several important factors that are frequently ignored by deterministic modeling:Scheduling OverheadI/O OperationsProcess Profiles:

CPU BoundI/O Bound

Variable process arrival times.

Page 16: Scheduling Strategies

Project

Implement the RR and Linux OTHER scheduling strategies and compare their performance on:I/O Bound ProcessesCPU Bound ProcessesA mix of CPU and I/O Bound Processes