Brief

  • Memory
    • Volatile, not persistent
    • Poweroff => info lost

Persistence

 -----                --------
| CPU | <----------> | Memory |
 -----       |        --------
           ------
math: true
net <---- | I/O  |------> Hard drive,
      PCI | Chip | SATA   SSD
           ------
             |
             | USB
           mice, keyboards

Today:

  • Device interaction (I/O)
    • How?
    • Efficient?
  • Specific Device: Hard Drive

Future:

  • Device up => OS: File Systems

Generic Device:

  • Hardware interface (generalization)
    • Command Register (What to do)
    • Data Register
    • Status register
    • How does OS read and write these?
        OS: Send commands
               |
               |
             Device
|--------------------------------|
|  -----    ------    --------   |
| | CMD |  | Data |  | Status |  |
|  -----    ------    --------   |
|                                |
|  .... Varying levels of .....  |
|  ....    Complexity     .....  |
| Simple: mouse to complex: RAID |
|--------------------------------|

2 Methods of Access

  1. Special I/O instructions
  2. Memory-mapped I/O

Protocol of Access

  1. Check if device is available
    while (status == busy)
        ; // spin
    
  2. Move data
    for (size of data)
        move data => data register
    
  3. Move CMD
    Write command => cmd register
  4. Wait:
    while (status == busy)
        ; //spin
    

Problems:

  1. Lot of spinning (polling the device)
  2. Data movement: CPU intensive
    Data move from Hard drive => CPU => Memory
    Ideal: Hard drive => Memory

Solutions:

  1. Instead of spinning, go to sleep (block)
    while (status == busy)
        sem_wait(&io);
    
    What wakes it up?
    • Interrupt:
      • Signal to system that device is done
      • Run interrupt handler
      • sem_post(&io);
  • (Replace step #1 and #4)
  1. DMA engine: hardware
    OS can program the h/w to move data directly between memory/device

Old Approach

                         data
       spinning        transfer      spinning
CPU  -------------||--------------||-----------|

Device                             |-----------|

New Approach

       (int, sleep)
CPU  P1 P2.......P2||P2........P2..........P2|P1 run again
DMA                 |-----------|
Device                           |----------|

Hard Drive: How?

  • Rotate
    • Fixed speed
    • 3600 RPM ~ 15000 RPM
  • Platter
    • Can have 1 or more
    • 2 sides (read/write)
  • Track:
    • Consists of sectors (512 bytes)
  • To read or write:
    • e.g. read a sector
    • address, (size) (how many sectors)
    • To OS
      • linear array of blocks
    • Disk Controller:
      • internal action to read or write
      • To do an I/O:
        • Seek: moves disk arm to correct track
        • Wait (Rotation): Wait for sector to rotate under head
        • Transfer: read/write
      • Example:
        • avg seek: ~7ms
        • avg rotate: ~3ms
        • transfer: ~200MB/s
        • Random I/Os: dominated by seek/rotation
        • Throughput: 512b10ms×1000msseconds = 0.5MB/s
        • Random I/O is slow, sequential I/O is fast
    • Disk Scheduler