CPU Scheduling
CPU Scheduling
Earlier, said dispatcher can choose any thread on the ready list
to run. But how is OS to decide, when it has a choice?
These assume:
one program per user
one thread per program
programs are independent
10.3.1 FIFO
Different names for the same thing:
FCFS -- first come first serve
FIFO -- first in first out
Run until done
Later, FIFO just means, keep CPU until thread blocks (this is
what I'll assume).
FIFO pros&cons:
+ simple
- short jobs get stuck behind long jobs
Both round robin and FIFO finish at the same time, but
average response time is much worse under RR than under
FIFO.
10.3.3 STCF/SRTCF
Idea is get short jobs out of the system. Big effect on short
jobs, small effect on short jobs. Result is better a v e r a g e
response time
Three jobs:
A, B: both CPU bound, infinite length
C: I/O bound, loop
1 ms of CPU
10 ms of disk I/O
With FIFO:
once A or B get in, keep CPU forever.
C's I/O
RR, 100 ms time slice
CABAB CA
..
C A C A C A
C's I/O
SRCTF
Effect of RR time quanta and SRTCF on I/O bound jobs
SRTCF pros&cons:
+ optimal (average response time)
- hard to predict the future
- unfair
To stop cheating, if your job takes more than what you said,
system kills your job. Start all over. Like with the Banker's
algorithm -- hard to predict resource usage in advance.
Instead, can't really know how long things will take, but can
use SRTCF as a yardstick, for measuring other policies. Optimal,
so can't do any better than that!
2 2
3 4
4 8
Multilevel feedback queues
Could give each queue a fraction of the CPU, but this isn't
always fair. What if there's one long-running job, and 100
short-running ones?