05. Input/Output System
The I/O system is an important part of the operating system responsible for external device management and data exchange. This chapter systematically explains the basic concepts of the I/O system, device classification and characteristics, I/O control methods, buffer management, device management and drivers, and typical I/O subsystem structures.
1. Basic Concepts of the I/O System
- I/O System (Input/Output System): The part of the OS responsible for managing various input/output devices and data exchange between the host and external devices.
- I/O Devices: Include input devices (e.g., keyboard, mouse), output devices (e.g., monitor, printer), and input/output devices (e.g., disk, USB drive).
2. Device Classification and Characteristics
- By data exchange method: block devices (e.g., disk), character devices (e.g., keyboard, serial port).
- By speed: high-speed devices (disk), low-speed devices (printer), medium-speed devices (terminal).
- By function: dedicated devices (e.g., printer), shared devices (e.g., disk).
3. I/O Control Methods
- Programmed I/O: CPU actively polls device status, low efficiency, high CPU usage.
- Interrupt-driven I/O: Device notifies CPU via interrupt when ready, CPU responds to interrupt for data transfer, improves efficiency.
- DMA (Direct Memory Access): Data is transferred directly between main memory and device without CPU intervention, suitable for large data transfers.
4. Buffer Management
- Purpose of buffers: Coordinate speed differences between CPU and I/O devices, improve data transfer efficiency.
- Single buffer: Only one data block at a time, simple but limited efficiency.
- Double/multiple buffers: Multiple buffers used in turn, improves concurrency and efficiency.
5. Device Management and Drivers
- Exclusive vs. shared devices: Some devices can only be used by one process at a time (e.g., printer), others can be shared (e.g., disk).
- Device allocation and release: OS is responsible for allocating and releasing device usage rights.
- Device drivers: Implement communication between OS and hardware devices.
6. Typical I/O Subsystem Structure
- User-level I/O interface: e.g., standard library functions (read/write, etc.).
- OS I/O management module: e.g., buffer management, device allocation, error handling, etc.
- Device drivers: Interact with specific hardware.
- Hardware controller: Electronic circuits that directly control devices.
Exercises
- Briefly describe the main functions of the I/O system.
- Compare the advantages and disadvantages of programmed I/O, interrupt-driven I/O, and DMA.
- Explain the purpose of buffer management and give an example of the advantages of multiple buffers.
- What is the role of a device driver?
- Draw the hierarchical structure of a typical I/O subsystem and briefly describe the function of each layer.
Reference Answers
1. Main functions of the I/O system
Answer: The main functions of the I/O system include: managing and controlling various I/O devices, realizing data exchange between the host and external devices, allocating and releasing devices, providing a unified I/O interface, buffer management, error handling, etc.
2. Compare programmed I/O, interrupt-driven I/O, and DMA
Answer:
- Programmed I/O: simple to implement, but low CPU utilization and poor efficiency.
- Interrupt-driven I/O: improves CPU utilization, suitable for frequent but small data I/O.
- DMA: CPU is almost not involved in data transfer, high efficiency, suitable for large data transfers, but hardware is more complex.
3. Purpose of buffer management and advantages of multiple buffers
Answer: Buffer management is used to coordinate the speed difference between CPU and I/O devices and improve data transfer efficiency. Multiple buffers allow one buffer to transfer data while another prepares data, enabling concurrency and improving overall efficiency. For example, using multiple buffers in disk read/write can reduce CPU waiting time.
4. Role of device driver
Answer: Device drivers implement communication between the OS and hardware devices, abstract hardware details, and provide a unified interface for upper layers.
5. Hierarchical structure of a typical I/O subsystem
Answer: (Can be drawn as follows)
- User-level I/O interface: provides standard I/O calls for applications.
- OS I/O management module: responsible for buffering, allocation, error handling, etc.
- Device drivers: implement specific communication with hardware.
- Hardware controller: directly controls the device.