CPU Scheduling
Tom Kelliher, CS 318
Mar. 6, 1998
Announcements:
From last time:
- Types of CPU schedulers.
- Context switching.
- Process creation issues.
Outline:
- Types of scheduling.
- Comparison criteria.
- Priority functions.
- Gantt chart examples.
Assignment:
Motivation:
- Traditionally: keep the CPU busy.
- Now:
- Promote modular design.
- Increase throughput (a multi-threaded server).
What are the three schedulers, and how do they function?
Model of a process: CPU-I/O burst cycles:
Distribution of bursts.
CPU bursts terminate due to:
- Process waits on event (blocked, suspended).
- Process' quantum expires (back to ready Q).
- Non-Preemptive scheduling.
Context switches occur:
- Running process terminates.
- Running process blocks.
I.e., running process controls the show.
New process takes over if running process blocks.
- Preemptive scheduling.
Principle: Highest priority ready process runs.
Quantum timers come into play.
Additional context switches:
- Higher priority process changes state from blocked to ready,
preempting running process.
- Quantum expires (kernel preempts).
Higher overhead.
- Selective preemptive scheduling.
User oriented, performance related criteria.
- Response time --- time from submission of request to receipt of first
output.
- Turnaround time --- time from submission of request to its
completion.
- Waiting time --- turnaround time minus CPU time; time spent waiting
for resources.
- Deadlines --- When deadlines are specified, percentage of deadlines
which are met.
User oriented, other criteria
- Predictability --- the same job should run in about the same amount
of time and cost regardless of other system activity.
System oriented, performance related criteria
- Throughput --- number of processes completed per unit of time.
- CPU utilization --- percentage of time CPU is performing
actual work.
System oriented, other criteria
- Fairness --- processes should generally be treated the same, with no
process starving.
- Priority enforcement --- when priorities are assigned, they should be
adhered to.
- Balancing Resources --- keep all system resources busy, adjust
priorities accordingly. This can come in at the long-term scheduler level.
- CPU time --- usually the most important factor
- memory requirements --- a major criterion in batch systems; in
timesharing systems give a good measure of swapping overhead
- wall time --- important for process ``aging'' --- increase priority
of older jobs.
- total required CPU time --- specify max runtime for job (batch) or
take some average of previous runtimes.
- external priorities --- batch, interactive, realtime, VIP, etc. Let
user pick priority and charge for higher priorities.
- system load --- increasing quantum may offset swapping overhead,
increasing utilization. Continue giving good response to high priority
jobs, making others suffer. Graceful degradation.
Implemented using queues or priority queues.
- FCFS, FIFO --- non-preemptive. Run oldest process. Standard batch
priority function
- Implemented with a simple queue for the ready Q
- New jobs, jobs previously in wait or running state put at end of
ready Q
- Next job to run taken from head of ready Q
- Priority function: time in ready Q
- LIFO --- non-preemptive. Run newest process. Not real useful.
- SJF --- shortest job first. Non-preemptive. Run process with
shortest required CPU time.
Provably optimal from turnaround/waiting point of view:
- SRT --- (shortest remaining time) preemptive version of SJF.
- RR --- (round robin) preemptive FCFS with a time quantum limitation.
Used in time sharing systems.
- Uses FCFS's priority function
- Additional factor in decision epoch: expiration of quantum timer
- Multi-level queues --- prioritized set of queues, to .
- Processes in queue i always have priority over queues >
i.
- A process remains within the same queue.
- Each queue may have its own scheduling algorithm.
- Alternative: each queue gets some fixed slice of the total CPU
cycles.
- Example: Queue for interactive jobs, RR scheduling; queue for
batch jobs, FCFS.
- Multi-level feedback queues --- similar to multi-level queues, except
that a process can move between different queues, based upon CPU usage.
- Must specify rules for moving the processes between queues.
- Ordinarily, lower priority queues have greater quantums, etc.
- Unix uses this method, with a 100ms quantum for all
queues. 128 priorities, with 32 queues.
Suppose the following jobs arrive for processing at the times indicated and
run with the specified CPU bursts (at the end of a burst a process waits
for one time unit on a resource). Assume that a just-created job enters
the ready queue after any job entering the ready queue from the wait queue.
Calculate the average turnaround time for each of the scheduling
disciplines listed:
- First Come First Served.
- Shortest Remaining Time (assume that the running time
is the sum of the CPU bursts).
- Round robin with a quantum of 1.
Don't forget the ``bubble'' cycles (where no process is runnable), if
required.
Thomas P. Kelliher
Thu Mar 5 21:46:58 EST 1998
Tom Kelliher