______ Input/Output (CS 273 (OS), Fall 2020)
Home
>>    




Input/Output

CS 273 (OS), Fall 2020

Layered architecture of I/O system

  • User level software.

    • System calls ("unbuffered I/O") such as open, read
    • Higher-level "buffered I/O" libraries such as stdio.h, with functions printf, scanf, etc.
    • Layers of buffering
    • Spooling

  • Device-independent OS software.

    • Naming; e.g., major/minor device numbers, file paths
    • Protection
    • Uniform block size
    • Low-level buffering
    • Identifying free blocks for file system
    • File locks (dedicated)
    • Higher error processing.

  • Device driver.

    • Interact concretely with obscure, cranky device
    • Most error handling

  • Interrupt handler.

    • An interrupt is a hardware signal notifying the CPU of a hardware event.
    • Interrupt handler code is executed when an interrupt occurs; different handlers for different interrupt numbers.
    • Interrupt vector
    • Precise interrupt:
      • PC is saved in a known place
      • All instructions before *PC have been fully executed
      • No instructions beyond *PC have been executed
      • Execution state of *PC is known
      Relevance: In a superscalar machine (e.g., Pentium), instructions (or parts of instructions) may be completed out of order.
      Note that any instructions that had been executed beyond *PC would have to be "undone."


  • Device controller.

    • Attached to bus; provides an interface for a specific device with all its technical details.
    • E.g.: Disk controller reads disk blocks, performs error correction, performs DMA (using more buffering)
    • E.g.: Video controller governs the CRT, accesses video memory
    • E.g.: Network controller implements low level protocols (e.g., Ethernet)

  • Device

    • Block devices, e.g., disks (including CD-ROM, DVD)
    • Character devices, e.g., keyboard, serial lines, mouse
    • Memory-mapped I/O (video RAM memory is another example of a buffer)
    • DMA
      1. CPU programs DMA controller
      2. DMA controller requests data transfer from disk controller
      3. Disk controller transfers data from disk to main memory
      4. Disk controller sends ACK to DMA controller
      5. DMA controller sends interrupt to CPU
    • Other, e.g., clocks

I/O software design models

  • Programmed I/O

    • OS polls (busy wait until device is ready) for each I/O action, using an OS-level buffer to store the data being input or output.
    • Advantages: Simple
    • Disadvantages: Busy wait

  • Interrupt-driven I/O

    • Block the process requesting I/O until the operation can be performed without polling.
    • Advantages: Better CPU utilization
    • Disadvantages: Handling an interrupt for each character

  • DMA

    • Move large quantities of data in a single operation, asynchronously with CPU
    • Advantages: Considerably less overhead per amount of data moved, for large quantities
    • Disadvantages: Slower (greater overhead) in the case of small amounts of data

Goals for I/O software

  • Device independence

  • Uniform naming

  • Handle errors as close to hardware as possible

  • Both synchronous (blocking) and asynchronous (interrupt-driven) transfers

  • Effective use of buffering (tradeoff)

  • Both sharable and dedicated devices