17
Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com , or www.amazon.com

Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Embed Size (px)

Citation preview

Page 1: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Operating System Concepts and

Techniques Lecture 5

Scheduling-1

M. Naghibzadeh

ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011.

To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com

Page 2: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

2

TermsScheduling policy describes the guideline for selecting the next process to use a computer

resource such as CPU. Scheduling algorithm is a finite set of clearly

stated unambiguous stepwise operations that when applied to a finite set of processes waiting

to use a resource, either one or more of these processes are selected or a time table for the

resource usage is producedScheduling mechanism determines how to do

every step of the scheduling algorithm For example, the exact steps to be taken to modify a

process-queue and process state

Page 3: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Scheduling CriteriaProperties which influence the order in

which active entities are selected to run  request Time

Processing Time Priority

Static priority dynamic priority 

Deadline Wait Time

Preemptability

3

Page 4: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Scheduling ObjectivesThroughput

Deadline hard real-time soft real-time

Turnaround Time Average turnaround time

Normalized

Response TimePriority

Processor UtilizationSystem Balance

Fairness

4

Page 5: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Scheduling levelsHigh-Level: select requests

Medium-level: decide on process swapping

Low-level: decide on giving CPU time to ready processes

Input/output scheduling: decide on disk read/write order

5

Page 6: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

First-Come-First-Served (FCFS)FCFS: take the request which arrived

earliest Nonpreemptive

Most natural, link banks, airport check-ins, post offices, and barber shops

Irregularity in arrival requires a queue Simple to implement

A single-linked list with two pointers; each link points from each node to the node of the previous

request

Ddisadvantages: a long request can increase others wait time

6

Page 7: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Shortest Job Next (SJN)SJN (SPN): take the request which

needs the least execution time Non-preemptive

Executes higher number of requests in one unit of time

To implement, a double-linked list with two pointers; keeps requests ordered

Disadvantages: need to know execution time, update overhead time

of the list, and starvation

7

Page 8: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

SRTN & HRRNShortest Remaining Time Next (SRTN)

Nonpreemptive Scheduling decision right after a process is completed

Disadvantages similar to SPN

Highest Response Rattio Next (HRRN) RR=(w+e)/e; it increases as w increases

Nonpreemptive Scheduling decision right after a process is completed

Disadvantages similar to SPN

8

Page 9: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Two moreFair-Share Scheduling

All users get equal shares of CPU Prevents a user to get a big chunk of CPU

time by creating many child processes or threads

Priority scheduling Processes have priorities; A higher priority

is executed before a lower priority one Preemptive

Disadvantage: starvation of low priority request

9

Page 10: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Round Robin (RR)The most widely used scheduling policy

A time quantum is defined and an interval timer is set to send an interrupt whenever the time quantum has passed, since the timer is set or

reset Time quantum (slice) is very small, one

millisecond or less Upon timer interrupt a process switching is done

If a process cannot use its slice, processor switches to the next process and resets timer

All (same priority) processes share CPU time

10

Page 11: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

RR advantages/disadvantages

Advantages: Quick response to interactive requests Longer waiting time for a process that

requires longer CPU time Possibility of defining many priority levels,

Disadvantage: Task switching overhead

11

Page 12: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Process Scheduling in Linux

Many levels of priorities (100 or more)Three schedulers

SCHED_FIFO: Nonpreemptive, highest priority, say from 70-100, for different processes.

SCHED_RR: Preemptive, second highest priority, say from 40-69

Same level highest priority RR processes are scheduled using round robin

Priorities are assigned so that any SCHED_FIFO process has higher priority than

any SCHED_RR; any SCHED_RR has higher priority than any SCHED_OTHER

12

Page 13: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

Process Scheduling in Linux…

SCHED_OTHER Every process has a static priority

Time is divided into variable size frames called epoch

At start of every epoch, scheduler calculates every SCHED_OTHER process’ CPU share in

integer number of scheduling-clock ticks; called credit, epoch length is calculated

Credit is related to static priority Epoch length is related to how many processes are

ready, what their priorities are etc.

13

Page 14: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

SCHED_OTHER...If a process cannot use its credit it

is saved for the next time (see details in the book)

Goodness shows which process is executed next

For SCHED_FIFO and SCHED_RR, goodness=priority+1000

For SCHED_OTHER, goodness=credit

14

Page 15: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

SummaryIt is not always the case that every service request arrives after the previous service request has been

completely served.Service requests may pile up, in which case we

would like to serve requests in such an order so as to increase some metrics.

This process is called scheduling. Scheduling methodologies and algorithms for single-processor

systems are consideredMany scheduling strategies are studied, FCFS, SJN,

SRTN, HRRN, and RRThe Linux operating system was selected to present

real-world schedulers

15

Page 16: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

16

Find outWhat an interactive process is

The block structure of an interval timerThe time slice of your computer’s

processorWhether Linux scheduler is a complete

one for real-time tasksWhy epoch length is not fixedThe goals of Linux schedulers

The difference between SCHED_FIFO and SCHED_RR

Page 17: Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First

17

Any questions?