0% found this document useful (0 votes)
2 views

Operating System_scheduling

...

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Operating System_scheduling

...

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Operating

Systems

processor
Scheduling

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table

Types of Scheduling

Long-term scheduling The decision to add to the pool of processes to be


executed

Medium-term scheduling The decision to add to the number of processes that


are partially or fully in main memory

Short-term scheduling The decision as to which available process will be


executed by the processor

I/O scheduling The decision as to which process's pending I/O


request shall be handled by an available I/O device

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Processor Scheduling
◼ Aim is to assign processes to be executed by the
processor in a way that meets system objectives, such as
response time, throughput, and processor efficiency
◼ Broken down into three separate functions:

Medium
Long term Short term
term
scheduling scheduling
scheduling

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


CPU Scheduler
◼ The CPU scheduler selects from among the processes in ready
queue, and allocates a CPU core to one of them
◼ Queue may be ordered in various ways

◼ CPU scheduling decisions may take place when a process:


1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates

◼ For situations 1 and 4, there is no choice in terms of


scheduling. A new process (if one exists in the ready queue)
must be selected for execution.

◼ For situations 2 and 3, however, there is a choice.


Scheduling Criteria
◼ CPU utilization – keep the CPU as busy as possible

◼ Throughput – # of processes that complete their execution per time


unit

◼ Turnaround time – amount of time to execute a particular process

◼ Waiting time – amount of time a process has been waiting in the


ready queue

◼ Response time – amount of time it takes from when a request was


submitted until the first response is produced.

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights


reserved.
Scheduling Algorithm
Optimization Criteria
◼ Max CPU utilization

◼ Max throughput

◼ Min turnaround time

◼ Min waiting time

◼ Min response time

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights


reserved.
Long-Term Scheduler
◼ Determines which Creates processes
programs are admitted to from the queue
the system for processing when it can, but
must decide:
◼ Controls the degree of
multiprogramming
◼ The more processes
that are created, the When the operating
Which jobs to
system can take on
smaller the one or more
accept and turn into
percentage of time processes
additional processes
that each process can
be executed
◼ May limit to provide
satisfactory service to
Priority, expected
the current set of First come, first
execution time, I/O
processes served
requirements

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Medium-Term Scheduling
◼ Part of the swapping function

◼ Swapping-in decisions are based on the need to


manage the degree of multiprogramming
◼ Considers the memory requirements of the
swapped-out processes

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Short-Term Scheduling
◼ Known as the dispatcher

◼ Executes most frequently

◼ Makes the fine-grained decision of which process to execute next

◼ Invoked when an event occurs that may lead to the blocking of the
current process or that may provide an opportunity to preempt a
currently running process in favor of another
Examples:

• Clock interrupts
• I/O interrupts
• Operating system calls
• Signals (e.g., semaphores)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Round
FCFS SPN SRT H
robin
Selection
max[w] constant min[s] min[s – e] max
function
Characteristics of Various Preemptive
Decision Non- Non- Preemptive
(at time
mode preemptive preemptive (at arrival) pre
quantum)
Scheduling Policies May be
Through- Not low if
quantum High High
Put emphasized
is too
small
May be
high,
Provides Provides
especially if
good good Provides
there is a
Response response response good Prov
large
time time for time for response resp
variance in time
short short
process
processes processes
execution
times
Overhead Minimum Minimum Can be high Can be high Can
Penalizes
short
Penalizes Penalizes
Effect on processes; Fair
long long Goo
processes penalizes treatment
processes processes
I/O bound
processes
Starvation No No Possible Possible

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Selection Function
◼ Determines which process, among ready processes, is
selected next for execution
◼ May be based on priority, resource requirements, or
the execution characteristics of the process
◼ If based on execution characteristics, then important
quantities are:
▪ w = time spent in system so far, waiting
▪ e = time spent in execution so far
▪ s = total service time required by the process,
including e; generally, this quantity must be
estimated or supplied by the user

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Decision Mode
▪ Specifies the ▪ Two categories:
instants in time at ▪ Nonpreemptive
which the ▪ Preemptive
selection function
is exercised

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Nonpreemptive vs Preemptive

Nonpreemptive Preemptive
◼ Currently running process
may be interrupted and
◼ Once a process is in the moved to ready state by
running state, it will the OS
continue until it terminates ◼ Decision to preempt may
or blocks itself for I/O be performed when a new
process arrives, when an
interrupt occurs that
places a blocked process in
the Ready state, or
periodically, based on a
clock interrupt
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Process Scheduling Example

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


execution pattern
0 5 10 15 20

A
First-Come-First B
Served (FCFS) C
D
E

A
Round-Robin B
(RR), q = 1 C
D
E

A
Round-Robin B
(RR), q = 4 C
D
E

A
Shortest Process B
Next (SPN) C
D
E

A
Shortest Remaining B
Time (SRT) C
D
E

A
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Highest Response B
A Comparison
of Scheduling
Policies

Process A B C D E
Arrival Time 0 2 4 6 8
Service Time (Ts) 3 6 4 5 2 Mean
FCFS
Finish Time 3 9 13 18 20
Turnaround Time (Tr) 3 7 9 12 12 8.60
Tr/Ts 1.00 1.17 2.25 2.40 6.00 2.56
RR q = 1
Finish Time 4 18 17 20 15
Turnaround Time (Tr) 4 16 13 14 7 10.80
Tr/Ts 1.33 2.67 3.25 2.80 3.50 2.71
RR q = 4
Finish Time 3 17 11 20 19
Turnaround Time (Tr) 3 15 7 14 11 10.00
Tr/Ts 1.00 2.5 1.75 2.80 5.50 2.71
SPN
Finish Time 3 9 15 20 11
Turnaround Time (Tr) 3 7 11 14 3 7.60
Tr/Ts 1.00 1.17 2.75 2.80 1.50 1.84
SRT
Finish Time 3 15 8 20 10
Turnaround Time (Tr) 3 13 4 14 2 7.20
Tr/Ts 1.00 2.17 1.00 2.80 1.00 1.59
HRRN
Finish Time 3 9 13 20 15
Turnaround Time (Tr) 3 7 9 14 7 8.00
Tr/Ts 1.00 1.17 2.25 2.80 3.5 2.14
FB q = 1
© Finish Time
2017 Pearson Education, Inc., Hoboken, NJ.4All rights reserved.
20 16 19 11
First-Come-First-Served
(FCFS)
◼ Simplest scheduling policy
◼ Performs much better for long
◼ Also known as first-in-first-out processes than short ones
(FIFO) or a strict queuing
scheme ◼ Tends to favor processor-bound
processes over I/O-bound
◼ As each process becomes ready, processes
it joins the ready queue

◼ When the currently running


process ceases to execute, the
process that has been in the
ready queue the longest is
selected for running

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Round Robin
◼ Uses preemption based on a clock ◼ Particularly effective in a
general-purpose time-sharing
◼ Also known as time slicing system or transaction processing
because each process is given a system
slice of time before being
preempted ◼ One drawback is its relative
treatment of processor-bound
◼ Principal design issue is the length and I/O-bound processes
of the time quantum, or slice, to
be used

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Shortest Process Next
(SPN)
◼ Nonpreemptive policy in which ◼ One difficulty is the need to
the process with the shortest know, or at least estimate, the
expected processing time is required processing time of each
selected next process
◼ A short process will jump to the ◼ If the programmer’s estimate is
head of the queue substantially under the actual
running time, the system may
◼ Possibility of starvation for longer
abort the job
processes

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Shortest Remaining Time
(SRT)
◼ Preemptive version of SPN
◼ Should give
◼ Scheduler always chooses the superior
process that has the shortest turnaround time
expected remaining processing performance to
time SPN because a
short job is given
◼ Risk of starvation of longer
immediate
processes
preference to a
running longer job

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Performance Comparison
◼ Any scheduling discipline that chooses the next item to be served
independent of service time obeys the relationship:

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Priority Scheduling
◼ A priority number (integer) is associated with each process

◼ The CPU is allocated to the process with the highest priority (smallest integer 
highest priority)
◼ Preemptive
◼ Nonpreemptive

◼ SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time

◼ Problem  Starvation – low priority processes may never execute

◼ Solution  Aging – as time progresses increase the priority of the process


Example of Priority Scheduling
Process Burst Time Priority

P1 10 3

P2 1 1

P3 2 4

P4 1 5

P5 5 2

◼ Priority scheduling Gantt Chart

◼ Average waiting time = 8.2


Priority Scheduling w/ Round-Robin

◼ Run the process with the highest priority. Processes with the same priority run round-
robin

◼ Example:

Processa Burst Time Priority

P1 4 3

P2 5 2

P3 8 2

P4 7 1

P5 3 3

◼ Gantt Chart with time quantum = 2


Multilevel Queue
◼ The ready queue consists of multiple queues

◼ Multilevel queue scheduler defined by the following


parameters:
◼ Number of queues
◼ Scheduling algorithms for each queue
◼ Method used to determine which queue a process will enter
when that process needs service
◼ Scheduling among the queues
Multilevel Queue
◼ With priority scheduling, have separate queues for each priority.

◼ Schedule the process in the highest-priority queue!


Multilevel Queue
◼ Prioritization based upon process type
Multilevel Feedback Queue
◼ A process can move between the various queues.

◼ Multilevel-feedback-queue scheduler defined by the following


parameters:
◼ Number of queues
◼ Scheduling algorithms for each queue
◼ Method used to determine when to upgrade a process
◼ Method used to determine when to demote a process
◼ Method used to determine which queue a process will enter when
that process needs service

◼ Aging can be implemented using multilevel feedback queue


Example of Multilevel Feedback Queue

◼ Three queues:
◼ Q0 – RR with time quantum 8 milliseconds
◼ Q1 – RR time quantum 16 milliseconds
◼ Q2 – FCFS

◼ Scheduling
◼ A new process enters queue Q0 which is served in
RR
◼ When it gains CPU, the process receives 8
milliseconds
◼ If it does not finish in 8 milliseconds, the process is
moved to queue Q1
◼ At Q1 job is again served in RR and receives 16
additional milliseconds
◼ If it still does not complete, it is preempted and
moved to queue Q2

You might also like