Top Banner
Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall
38

Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Mar 29, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Chapter 9Uniprocessor Scheduling

Operating Systems:Internals and Design Principles, 6/E

William Stallings

Patricia RoyManatee Community College, Venice, FL

©2008, Prentice Hall

Page 2: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Aim of Scheduling

• Assign processes to be executed by the processor(s)

• Response time• Throughput• Processor efficiency

Page 3: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Processor Scheduling

• Known as the dispatcher• Invoked when an event occurs

– Clock interrupts– I/O interrupts– Operating system calls– Signals

Page 4: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Processor Scheduling Criteria

• User-oriented– Response Time

• Elapsed time between the submission of a request until there is an output

– Turnaround Time• The time between the submission and the

completion of a process

• System-oriented– Effective and efficient utilization of the

processor

Page 5: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Decision Mode

• Nonpreemptive– Once a process is in the running state, it will

continue until it terminates or blocks itself for I/O

Page 6: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Decision Mode

• Preemptive– Currently running process may be interrupted

and moved to the Ready state by the operating system

– Allows for better service since any one process cannot monopolize the processor for very long

Page 7: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Priorities

• Scheduler will always choose a process of higher priority over one of lower priority

• Have multiple ready queues to represent each level of priority

Page 8: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Priority Queuing

Page 9: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Priorities

• Lower-priority may suffer starvation– Allow a process to change its priority based

on its age or execution history

Page 10: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

First-Come-First-Served

• Each process joins the Ready queue

• When the current process ceases to execute, the process that waits the longest in the Ready queue is selected

Page 11: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Process Scheduling Example

Page 12: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

First-Come-First-Served

• A short process may have to wait a very long time before it can execute

• Favors CPU-bound processes– I/O processes have to wait until CPU-bound

process completes– Low utilization for I/O devices– Possibly low utilization for processor

Page 13: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin

• Clock interrupt is generated at periodic intervals

• When an interrupt occurs, the currently running process is placed in the ready queue– Next ready job is selected

• Known as time slicing

Page 14: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin• Uses preemption based on a clock

Page 15: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin

• Time quantum is– The time interval between two clock interrupts– The maximum time allocated to a process’s

execution in each turn

Page 16: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin

• Which type of processes are favored by round robin scheduling?– CPU or I/O bound processes?

Page 17: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin

Example: A, C, D, E: CPU bound processes;

B: I/O bound process.

What should we do to treat

them fairly in terms of CPU allocation?

A

B

C

D

E

Page 18: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Round Robin

• Which type of processes are favored by round robin scheduling?– CPU or I/O bound processes?

• Favors CPU-bound processes– CPU-bound process gets more CPU time– I/O process has to wait for CPU-bound

processes to consume their quanta before its turn of executing on the CPU

Page 19: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Queuing Diagram

Virtual round robin

Use an auxiliary queue to hold processes that have I/O requests serviced

Process in auxiliary queue gets preference over those in the main ready queue

Process from the auxiliary queue runs for remaining time from last time-slice

Page 20: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Shortest Process Next

• Process with shortest expected processing time is selected next

• Short process jumps ahead of longer processes

• Nonpreemptive policy

Page 21: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Shortest Process Next

Page 22: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Shortest Process Next

• Possibility of starvation for longer processes• If estimated time for process not correct, the

operating system may abort it• How to estimate a process execution time?• Average of history?

• Simple average: Sn+1 = 1/n Ti

• Exponential average: Sn+1 = Tn + (1-)Sn

– Greater weights to more recent instances

Page 23: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Shortest Remaining Time• Preemptive version of shortest process next

policy

Page 24: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Highest Response Ratio Next

• Choose next process with the greatest ratio

– shorter processes are favored– aging without service increases the ratio so that

a longer process will eventually be served

Page 25: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Highest Response Ratio Next

• Choose next process with the greatest ratio

Page 26: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Feedback Scheduling• Don’t know remaining time process needs

to execute• Penalize jobs that have been running

longer: putting them into lower priority ready queues

Page 27: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Feedback Scheduling

Page 28: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Feedback Scheduling

Page 29: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Fair-Share Scheduling

• User’s application runs as a collection of processes (threads)

• User is concerned about the performance of the application

• Need to make scheduling decisions based on process sets

Page 30: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Fair-Share Scheduling

• CPUj(i) = CPUj(i-1)/2

• GCPUk(i) = GCPUk(i-1)/2

• Pj(i) = Basej + CPUj(i)/2 + GCPUk(i)/(4Wk)

Page 31: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Fair-Share Scheduler

Page 32: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

In-Class Exercise

• Prob. 9.2 Consider the following set of processes:

Perform FCFS, RR (q=4), SPN, SRT, HRRN, Feedback (q=2i) on them and get the Finish Time and Turnaround Time for each process.

Process Name Arrival Time Processing Time

ABCDE

013912

35255

Page 33: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Appendix

Page 34: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Exponential Smoothing Coefficients

Page 35: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Use Of Exponential Averaging

Page 36: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Use Of Exponential Averaging

Page 37: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Effect of Size of Preemption Time Quantum

Page 38: Chapter 9 Uniprocessor Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,

Effect of Size of Preemption Time Quantum