Chapter 5 -- Scheduling
Basic Concepts
-
CPU-IO Burst
-
Processes cycle between requiring CPU and requiring I/O.
-
Can be lots of variation depending on task (editor different from math
package).
-
Tends to follow curve as shown in fig 5-2. Mode is just 3ms!!!
-
Preemptive Scheduling
-
Normally, scheuling occurs at four places
-
Process switches from running to wait (I/O)
-
Process switches from running to ready (timer interrupt)
-
Process switches from wait to ready (I/O completes (interrupt))
-
Process terminates
-
Must switch on #1 and #4.
-
If switch on #2 or #3, then you are preemptive.
-
Means processes can be taken away from you without your permission.
-
Can be a problem for thread programming with shared data structures. Locks
might be required on these data structures.
Scheduling Criteria
-
Important Measures
-
CPU Utilization -- always do something if you have free CPU. (BTW, 40%
is NOT a light load for a workstation).
-
Throughput -- number of tasks per unit time.
-
Turnaround time -- how long the average process must wait. (Not the inverse
of throughput!)
-
Wait time -- Time spend in the wait queue -- (Turnaround - CPU - I/O).
-
Variance in responce -- said to be important for human interaction.
-
Note: Sometimes the goal is not to optimize the averae, but to minimize
the worst case (RTOS are that way).
-
Subjective Measures
-
Fairness -- Does each process get his/her share of the CPU?
-
Priority -- Does the boss get more than his share?
-
Starvation -- is each process guarenteed to finish?
Short Term Scheduling Algorithms
-
FCFS -- First come first serve (The McDonalds algorithm)
-
Choose the first process -- run till it finishes -- move on.
-
Can be used with or without preemption.
-
GOOD, it's fair.
-
BAD, no priorities.
-
GOOD, starvation is avoided.
-
GOOD, CPU always busy.
-
BAD, wait times not minimized.
-
BAD, high variation.
-
GOOD, it's simple.
-
BAD, there can sometimes be a convoy effect, which reduces I/O and
throughput.
-
Question: What happens if there is more than one entry of the same
process in the queues?
-
Shortest Job Next -- just run the shortest job
-
Somtimes has preemption, then called shortest job remaining next.
-
BAD, no priorities
-
BAD, starvation is possible.
-
GOOD, wait times optimal
-
BAD, high variation.
-
Question: How do you predict run time?
-
Ask the prorgram (and punish liers, or everyone will lie).
-
Use past data to predict the future.
-
Round Robin
-
Do each process for one time slice. Then move to the next. Always
preemptive.
-
GOOD, no starving.
-
GOOD, fair.
-
GOOD, low variation.
-
MEDIUM, wait times average.
-
Question: What should the time slice be set at.
-
Question: Should long running programs get a larger or smaller time
slice, and more or less of them?
-
Priority Scheduling
-
Assign each job a priority. Run in priority order.
-
If a job has been waiting a long time, then age it to temporarily
increase it's priority.
-
Useful for real time systems.
-
Can be preemptive or non-preemptive. Normally preemptive.
-
GOOD, has priorities.
-
BAD, starvartion possible.
-
BAD, wait times not minimized. Can be worse than FCFS.
-
BAD, high variation.
-
Priority Scheduling with Aging (The Standard scheduler)
-
All processes get a fixed and a current priority.
-
When computing current priority, add a minor amount to the current process,
and to all processes that last ran on THIS CPU.
-
Run the process with the highest current prioity.
-
When done, reduce it's current priority to the fixed priority,
-
(Some OS's) If it uses it's whole time slice, reduce the current priority
somewhat.
-
Every once in a while, raise the current priority of all processes that
have not run for a while.
-
GOOD, has priorities.
-
GOOD, starvation not possible.
-
BAD, wait times not minimized.
-
MEDIUM variation. (Better that straight priority, but not as good
as round robin.)
-
RTOS Scheduling
-
Generally consists of events and deadlines.
-
It can be proved that if a schedule is possible, that scheduling the closest
deadline first will find it.
-
This translates to priority scheduling, with no aging, and priorities set
by deadline.
Long Term Scheduling
-
Goal -- Avoid overload by delaying jobs
-
Criterea
-
Memory Usage
-
I/O usage
-
CPU usage
-
Prioity
-
Length of time already run