Computer Systems: Processor Scheduling
Computer Systems: Processor Scheduling
Chapter 6
Processor Scheduling
.
Program n
OS routines
memory?
• Why?
6.2 Programs and Processes
• What resources are required to run:
Hello, World!
• What is a scheduler?
Program Properties Process/System Properies
Expected running time Available system memory
Expected memory usage Arrival time of a program
Expected I/O requirements Instantaneous memory requirements
Process 1
Process 2
scheduler Processor
.
. winner
.
Process n
6.2 Programs and Processes
Program Process
• On disk • In memory (and disk)
• Static • Dynamic – changing
• No state • State
– No PC – PC
– No register usage – Registers
• Fixed size • May grow or shrink
• Fundamental unit of
scheduling
One program may
yield many processes
6.2 Programs and Processes
Name Usual Connotation Use in this chapter
Job Unit of scheduling Synonymous with process
Process Program in Synonymous with job
execution; unit of
scheduling
Thread Unit of scheduling Not used in the scheduling algorithms
and/or execution; described in this chapter
contained within a
process
New Halted
Admitted Exit
Interrupt
Ready Running
Scheduler Dispatch
Wait for an
Interrupt Occurs
Interrupt
6.4 Scheduling Basics
Name Description
CPU burst Continuous CPU activity by a process before requiring an I/O
operation
I/O burst Activity initiated by the CPU on an I/O device
PCB Process context block that holds the state of a process (i.e.,
program in execution)
Ready queue Queue of PCBs that represent the set of memory resident processes
that are ready to run on the CPU
I/O queue Queue of PCBs that represent the set of memory resident processes
that are waiting for some I/O operation either to be initiated or
completed
Non-Preemptive Algorithm that allows the currently scheduled process on the CPU
algorithm to voluntarily relinquish the processor (either by terminating or
making an I/O system call)
Preemptive Algorithm that forcibly takes the processor away from the currently
algorithm scheduled process in response to an external event (e.g. I/O
completion interrupt, timer interrupt)
Thrashing A phenomenon wherein the dynamic memory usage of the
processes currently in the ready queue exceed the total memory
capacity of the system
6.5 Performance Metrics
• System Centric.
– CPU Utilization: Percentage of time the processor is
busy.
– Throughput: Number of jobs executed per unit time.
– Average turnaround time: Average elapsed time for
jobs entering and leaving the system.
– Average waiting time: Average of amount of time
each job waits while in system
• User Centric
– Response time: Time until system responds to user.
6.5 Performance Metrics
• Two other qualitative issues
– Starvation: The scheduling algorithm prevents a
process from ever completing
– Convoy Effect: The scheduling algorithm allows
long-running jobs to dominate the CPU
6.5 Performance Metrics
P1 P2 P3
w1 e1 e2 e3
t1
w2
t2
w3
t3
wi, ei, and ti, are respectively the wait time, execution time,
and the elapsed time for a job ji
6.5 Performance Metrics
P1 P2 P3
2 3 4 3 2 5
5
9
12
14
19
Multi-
Level
Feedback
q4
Queue
6.9 Meta Schedulers
Meta
scheduler
Time slices
IJ/BJ
ready_q
PCB1 PCB2 … PCBn
Q Q
ready_q
PCB1 PCB2 … PCBn
6.10 Evaluation
• Evaluate considering domain of application
– Desktop: Personal computing.
– Servers: Mail servers, file servers, and web servers.
– Business: E-commerce and Wall Street style applications.
– High-Performance Computing (HPC): Solving scientific and
engineering problems.
– Grid: HPC with geographically distribution
– Embedded: Low-end devices such as cell phones, PDA’s and hybrid
combinations as well as sophisticated computing systems found in
automobiles and aircraft.
– Pervasive: Emerging domain combining elements of HPC and
embedded computing.
6.10 Evaluation
Domains Environment Workload Types of schedulers
characteristics
Desktop Timeshared, interactive, I/O bound Medium-term, short-
multiprogrammed term, dispatcher
Servers Timeshared, Computation bound Medium-term, short-
multiprogrammed term, dispatcher
Business Timeshared, I/O bound Medium-term, short-
multiprogrammed term, dispatcher
HPC Timeshared, Computation bound Medium-term, short-
multiprogrammed term, dispatcher
Grid Batch-oriented, Computation bound Long-term, Medium-
timeshared, term, short-term,
multiprogrammed dispatcher
Embedded Timeshared, interactive, I/O bounds Medium-term, short-
multiprogrammed term, dispatcher
Pervasive Timeshared, interactive, Combination of I/O Medium-term, short-
multiprogrammed bound and term, dispatcher
computation bound
6.11 Summary and a Look ahead
Name Property Scheduling criterion Pros Cons
FCFS Intrinsically non- Arrival time Fair; no starvation; high variance in
preemptive; could (intrinsic property) response time;
accommodate preemption convoy effect
at time of I/O completion
events
SJF Intrinsically non- Expected execution Preference for short jobs; Potential for
preemptive; could time of jobs provably optimal for starvation; bias
accommodate preemption (intrinsic property) response time; low variance against long running
at time of new job arrival in response times computations
and/or I/O completion
events
Priority Could be either non- Priority assigned to Highly flexible since priority Potential for
preemptive or preemptive jobs (extrinsic is not an intrinsic property, starvation
property) its assignment to jobs could
be chosen commensurate
with the needs of the
scheduling environment
SRTF Similar to SJF but uses Expected remaining Similar to SJF Similar to SJF
preemption execution time of
jobs
Round Preemptive allowing equal Time quantum Equal opportunity for all Overhead for context
Robin share of the processor for jobs; switching among
all jobs jobs
6.12 Linux Scheduler – A case study
• Scheduler designed to match personal computing and
server domains
• Goals
– High efficiency
• Spending as little time as possible in scheduler, important goal for
server environment
– Support for interactivity
• Important for the interactive workload of the desktop environment
– Avoid starvation
• Ensure that computational workload do not suffer as a result of
interactive workloads
– Support for soft real-time scheduling
• Meet the demands of interactive applications with real-time
constraints
6.12 Linux Scheduler – A case study
• Linux scheduler recognizes three classes of
tasks:
– Real-time FCFS
– Real-time round robin
– Timeshared
• Scheduler has 140 priority levels.
– Levels 0-99 for real-time tasks
– Remaining levels for timeshared tasks.
6.12 Linux Scheduler – A case study
6.12 Linux Scheduler – Algorithm
• Pick first task with highest priority from active array and
run it.
• If task blocks (due to I/O) put it aside and pick next
highest one to run.
• If time quantum runs out (does not apply to FCFS tasks)
for currently scheduled task then place it in expired array.
• If a task completes its I/O then place it in active array at
right priority level adjusting its remaining time quantum.
• If there are no more tasks to schedule in active array,
simply flip active and expired array pointers and continue
with scheduling algorithm (i.e., expired array becomes the
active array and vice versa).
6.13 Historical Perspective
• Babbage
• ENIAC
• FORTRAN/FMS
• IBSYS /IBM 7094/JCL
• Scientific/Business Users…IBM S/360
• Timesharing/MULTICS
• Unix
• Personal Computing/Windows/Linux
Questions?