CPU Virtualization

  1. Mechanisms: How
  2. Policies: Scheduling

How to “Time-Share”

  1. Problem: What if process P wants to do something restricted?

    • See prev Note
  2. 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)
  3. Problem: What if Process does something “Slow”?

    • Desire: switch to other process when IO
    • Mark Pa as Blocked -> Switch to Pb -> I/O completes -> Mark Pa as Ready

Scheduler

Scheduler Policy: How?

  • Assumptions about “workload”
    1. start: all jobs arrive at once
    2. just use CPU (no I/O)
    3. fixed length (runs for time T)
    4. length is known ahead of time
    5. metric: turnaround time T=TcompletesTarrives
  • Algorithm #1: Fist In First Out, First Come First Serve
    • TA=10,TB=10,TC=10
      • Tavg=20
    • Relax Assumption #3 (TA=10,TB=100,TC=10)
      • Tavg=80
  • Algorithm #2: SJF (shortest job first)
    • TA=10,TB=100,C=T10
      • Tavg=50
    • Relax Assumption #1 (All jobs don’t arrive at once)
  • Algorithm #3: STCF (Shortest time to completion first)