Virtualization

Build an illusion (as many CPU & RAM as you want)

Goals

  • Efficiency
  • Security
  • Isolation

Abstraction

What changes when a program runs?

  • registers
  • memory
  • I/O

CPU: How to Virtualize

  • Run N proceses “at once” even though we have M CPUs (N>M)
  • General idea:
    • If 1 CPU, 2 processes (A, B)
    • Run as ABABABAB… (interleave) aka “time sharing”
  • Mechanisms: low-level how
  • Policies: whilch process to run?

First Attempt: Direct Execution

Boottime: (Start up)

OS is the first program to run

  • Set up:
    • free list (to track memory)
    • process list (etc.)

Want: Run One Program

  • alloc entry on process list
  • alloc some memory
  • load the program (from disk) into memory (code, static)
  • jump to main of the prgram & start running

Obersavation

  • Only one thing running at at time

Problems

  1. What if process P wants to do something restricted? (e.g., issue a read to disk)
    Hardware Support
    1. Modes of Opertaion - User mode / Kernel mode
      • Bit: 0 or 1 => which modes
    2. Transition between modes
      Instructions:
      • user mode -> kernel mode: trap
      • kernel mode -> user mode: return-from-trap
      • Set up trap handlers
  2. What if OS wants to stop Pa, and run Pb?
  3. What if P does something that is “slow”? (I/O)

Timeline

  • OS @ boot
    Set up
    • trap handlers
    • free list (to track memory)
    • process list (etc.)
  • Process @ run time
    • issue system calls (func written in asm that calls trap)