CS170 Lecture notes -- Scheduling
- The basics
- keep several processes in memory at once
- system goal: is to maximize cpu utilization
- simple if all jobs are CPU bound => non-preemption.
- run one job after another
- CPU utilization is maximized
- turn around time for set of jobs is minimized
- why doesn't Unix work this way?
- burst-cycle: processes tend to have very short bursts of processing
followed by bursts of i/o. characterizing this helps decide how long each
process will have the cpu.
- user goals:
- minimize turn-around time
- minimize response time
- both of the above
- four cases when scheduler makes a decision
- when a process pauses because it is initiating
I/O
- when an interrupt is serviced
- when a process is about to be re-instated because
I/O has completed
- when a process terminates
- Scheduling Criteria
- CPU Utilization - the percentage of time the cpu is kept occupied
- Throughput - measure of the number of processes completed in a time
quantum
- Turnaround Time - the length of time from a processes starting to its
completion
- Waiting Time - the amount of time a process spends on the ready
queue
- Response Time - the amount of time it takes a process to respond to the
user
- Fairness - the degree to which the schedule allocates resources
according to weighted priority scheme.
- We want to maximize the first two, and minimize the other three
- might also be important to control variance
- Algorithms
- First Come, First Served
- non-preemptive
- first job in runs to completion, and then the next one runs
- consider following example
- p1 is 24s, p1 is 3s and p3 is 3s
- jobs arrive p1, p2, p3 => average waiting time 17s
- jobs arrive p2, p3, p1 => average waiting time 3s
- moral: the waiting time of FCFS is determined by the length of
the jobs and the order in which they arrive.
- I/O => convoy effect - when one job has to wait for the longest job to
finish before it can respond.
- processes with extremely long bursts, such as computationally intensive
programs, will hold the cpu for a very long time.
- optimal: Shortest-Job First
- run the job that will end the soonest first
p1: 6
p2: 8
p3: 7
p4: 3
FCFS
--------------------------------------
| p1 | p2 | p3 | p4 |
--------------------------------------
0 6 14 21 24
avg. waiting time: (0+6+14+21) / 4 == 10.25
SJF
--------------------------------------
| p4 | p1 | p3 | p2 |
--------------------------------------
0 3 9 16 24
avg. waiting time: (0+3+9+16) / 4 == 7
provably optimal
realistic?
we can try to predict the burst time of the next cpu process
- last CPU burst
- exponential average
in non-preemptive case => as good as the prediction
preemptive case: shortest remaining time first
again, predictions are needed to determine the future job behavior
Priority Scheduling
- processes are selected based on some criteria
- SJF is a priority algorithm where job length is priority
- there is a possibility of indefinite block, where a low priority
process is never run
- shortest time remaining first: what is short jobs keep arriving
and a long job is never run?
- aging can be used to gradually increase the priority of a process
- the longer the job waits in the ready queue, the higher its
priority
- this is the basis of the Unix nice command
FCFS + time slicing = Round-Robin Scheduling
Multi-Level Queue
Multi-Level Feedback Queue: processes move between levels
Multi-Processor