Professional Documents
Culture Documents
Rami Abielmona
94.571 (ELG 6171)
Monday March 27, 2000
Prof. T. W. Pearce
Scheduling Algorithms
Introduction
• Problem definition:
– “One CPU with a number of processes. Only
one process can use the CPU at a time and each
process is specialized in one, and one task.
What’s the best way to organize the processes
(schedule them) ?” [1]
– “How will the CPU time be divided among the
processes and threads competing to use it ?” [2]
Scheduling Algorithms
Embedded OS Architecture
• Kernel:
– The executor
• Executive:
– The manager
• Application Programs:
– The programmer tasks
• Real World Interfacing:
– S/W handling the H/W
Scheduling Algorithms
Basic Assumptions
• A pool of runnable processes are contending for one CPU;
• The processes are independent and compete for resources;
• The job of the scheduler is to distribute the scarce resource
of the CPU to the different processes “fairly” and in an
optimal way;
• The job of the dispatcher is to provide the mechanism for
running the processes;
• The OS is a multitasking, but not a multiprocessor, one;
• Only CPU scheduling is considered (the lowest level of
scheduling).
Scheduling Algorithms
Evaluation Characteristics
CPU utilization Keep it as high as
possible
Throughput Number of processes
completed per unit
time
Waiting time Amount of time spent
ready to run but not
runnin
Response time Amount of time
between submission of
requests and first
response to the request
Scheduler efficiency Minimize the
overhead
Turnaround time Mean time from
submission to
Scheduling Algorithms
Processes and Resources
• Resources: • Processes:
– Preemptible: – IO bound:
• Take resource away, use • Perform lots of IO
it for something else, operations.
then give it back. (e.g. • IO burst ---- short CPU burst
processor or I/O channel) to process IO --- IO burst
– Non-preemptible: – CPU bound:
• Once give, it can’t be • Perform lots of
reused until process gives computation and do
it back. (e.g. file space or little IO
terminal) • CPU burst ----------- Small IO
burst ----------- CPU burst
Scheduling Algorithms
Process State Transitions
• The states of a process, at any
given time, is comprised of the
following minimal set:
– Running:
• The CPU is currently executing
the code belonging to the
process.
– Ready:
• The process could be running,
but another process has the
CPU.
– Waiting:
• Before the process can run,
some external event must
occur.
Scheduling Algorithms
Types of Schedulers
• Long-term scheduler:
– admits new processes to the system;
– required because each process needs a portion of the
available memory for its code and data.
• Medium-term scheduler:
– is not found in all systems;
– required to control the temporary removal from memory of a
process when the latter is extractable.
• Short-term scheduler:
– determines the assignment of the CPU to ready processes;
– required because of IO requests and completions.
Scheduling Algorithms
The Contestants (1)
• First-Come First-Serve (FCFS)
– One ready queue;
– OS runs the process at head of the queue;
– New processes come in at the end of the queue;
– Running process does not give up the CPU until it terminates
or it performs IO.
• Round Robin
– Process runs for one time slice, then moved to back of the
queue;
– Each process gets equal share of the CPU.
Scheduling Algorithms
The Contestants (2)
• Shortest Time to Completion (STCF)
– Process with shortest computation time left is picked;
– Varianted by preemption;
– Requires knowledge of the future.
• Exponential Queue (Multi-level Feedback)
– Gives newly runnable processes a high priority and a very
short time slice;
– If process uses up the time slice without blocking then
decrease priority by one and double time slice for next time;
– Solves both efficiency and response time problems.
Scheduling Algorithms
The Contestants (3) - Priorities
• Priority Systems
– The highest priority ready process is selected
– In case of a tie, FCFS can be used
– Priorities could be assigned:
• Externally (e.g. by a system manager)
• Internally (e.g. by some algorithm)
• Combination of external and internal
– Preemptive schemes:
• Once a process starts executing, allow it to continue until it
voluntarily yields the CPU
– Non-preemptive schemes:
• A running process may be forced to yield the CPU by an external
event rather than by its own action
Scheduling Algorithms
First-Come First-Serve