Chapter 13
Chapter 13
Chapter 13:
I/O Systems
Zhi Wang
• I/O hardware
• Application I/O interface
• Kernel I/O subsystem
• I/O performance
Objectives
synchronous! asynchronous!
Kernel I/O Subsystem
• I/O scheduling
• to queue I/O requests via per-device queue
• to schedule I/O for fairness and quality of service
• Buffering - store data in memory while transferring between devices
• to cope with device speed mismatch
• to cope with device transfer size mismatch
• to maintain “copy semantics”
• to improve performance (double buffering in video)
Kernel I/O Subsystem
• Caching: hold a copy of data for fast access
• key to performance
• sometimes combined with buffering
• Spooling: hold output if device can serve only one request at a time
• i.e., printing
• Device reservation: provides exclusive access to a device
• system calls for allocation and de-allocation
• watch out for deadlock
Device-status Table
Sun Enterprise 6000 Device-Transfer Rates
Error Handling
• Some OSes try to recover from errors
• e.g., device unavailable, transient write failures
• sometimes via retrying the read or write
• some systems have more advanced error handling
• track error frequencies, stop using device with high error frequency
• Some OSes just return an error number or code when I/O request fails
• system error logs hold problem reports
I/O Protection
• OS need to protect I/O devices
• e.g., keystrokes can be stolen by a keylogger if keyboard is not protected
• always assume user may attempt to obtain illegal I/O access
• To protect I/O devices:
• define all I/O instructions to be privileged
• I/O must be performed via system calls
• memory-mapped I/O and I/O ports must be protected too
Use System Call to Perform I/O
Kernel Data Structures
• Kernel keeps state info for I/O components
• e.g., open file tables, network connections, character device state
• many data structures to track buffers, memory allocation, “dirty” blocks
• sometimes very complicated
• Some OS uses message passing to implement I/O, e.g., Windows
• message with I/O information passed from user mode into kernel
• message modified as it flows through to device driver and back to process
UNIX I/O Kernel Structure
I/O Requests to Hardware
• System resource access needs to be mapped to hardware
• Consider reading a file from disk for a process:
• determine device holding file
• translate name to device representation
• physically read data from disk into buffer
• make data available to requesting process
• return control to process
Life Cycle of An I/O Request
Streams
• Stream is a full-duplex communication channel between a user-level process
and a device in Unix systems
• A stream consists of:
• stream head interfaces with the user process
• driver end interfaces with the device
• zero or more stream modules between them (stacked)
• each module contains a read queue and a write queue
• Message passing is used to communicate between queues
• asynchronous internally, synchronous for user interface
Streams Structure
Performance
• I/O is a major factor in system performance:
• CPU to execute device driver, kernel I/O code
• context switches due to interrupts
• data buffering and copying
• network traffic especially stressful
Intercomputer Communications
Performance
• To improve performance
• reduce number of context switches
• reduce data copying
• reduce interrupts by using large transfers, smart controllers, polling
• use DMA
• use smarter hardware devices
• move user processes to kernel threads
Device-Functionality Progression
End of Chapter 13