CPU Virtualization
- Mechanisms: How
- Policies: Scheduling
How to “Time-Share”
Problem: What if process
wants to do something restricted?- See prev Note
Problem: Process may run for a long time
- Q: How does OS regain control of CPU?
- A: timer interrupt
- @Boot:
- set this up
- interrupt the CPU every X milliseconds
- Why not shorter?
- A: Context switch overhead, Cache miss
- OS responsibility
- for each process: track current state
- Running
- Ready (Not running, but could be)
- for each process: track current state
- @Boot:
Problem: What if Process does something “Slow”?
- Desire: switch to other process when IO
- Mark
asBlocked-> Switch to -> I/O completes -> Mark asReady 
Scheduler
Scheduler Policy: How?
- Assumptions about “workload”
- start: all jobs arrive at once
- just use CPU (no I/O)
- fixed length (runs for time
) - length is known ahead of time
- metric: turnaround time
- Algorithm #1: Fist In First Out, First Come First Serve
- Relax Assumption #3 (
)
- Algorithm #2: SJF (shortest job first)
- Relax Assumption #1 (All jobs don’t arrive at once)
- Algorithm #3: STCF (Shortest time to completion first)