I/O Systems
I/O systems 討論的是 OS 如何讓 application 可以安全、有效率地使用各種外部裝置。
問題是,I/O device 的差異非常大:keyboard 一次產生少量 byte、SSD 以 block 為單位高速傳輸、network 有不穩定延遲。如果 application 必須理解每種硬體的 register、bus protocol、interrupt 行為,程式會無法移植也很難保護系統。因此 OS 的 I/O subsystem 會把硬體細節封裝在 kernel 和 device driver 裡,對上提供比較一致的 system call 介面。
本章可以看成三層之間的橋接:
- Hardware layer:device、controller、bus、port、interrupt、DMA。
- Kernel layer:device driver 和 kernel I/O subsystem,負責 scheduling、buffering、caching、spooling、error handling、protection、power management。
- Application layer:application 看到的是 file descriptor、socket、read/write、timer、ioctl 等抽象介面。
I/O Hardware
Application I/O Interface
D-OS-Ch12b-Application_IO_Interface
Kernel I/O Subsystem
D-OS-Ch12c-Kernel_IO_Subsystem
Transforming I/O Requests
D-OS-Ch12d-Transforming_IO_Requests