I/O Hardware
通用概念:
- port
- bus
- controller(连接bus和host CPU)
IO设备具有地址,可用于
- 特殊IO指令
- Memory-mapped I/O
IO Port Registers
四种概念寄存器:
- Data-in: read by the host to get input,CPU从IO设备中读数据
- Data-out: written by the host to send output,CPU向设备中写数据
- Status: device status read by the host
- Control: written by the host to start a command or change the mode of a device
polling(轮询)
- host反复读busy bit,直至其不再busy
- host将command寄存器中write bit置位,并向data-out寄存器写出一个字节。
- host将command-ready位置位
- 当设备的controller注意到command-ready置位后,它将busy位置位。
- controller读取command寄存器,发现write置位,于是它读取data-out中的字节,并在IO设备完成操作
- controller将command-ready清零;将command寄存器中的error清零来只是IO成功;将busy位清零来表示IO操作结束。
会产生忙等待
中断驱动的IO
各种终端:
- Page fault
- trap
- 低优先级会被高优先级的打断
DMA
提供更高的处理效率(针对磁盘等block-based设备)
Application I/O Interface
Kernel I/O Subsystem
- 缓存(caching)
- 假脱机(spooling):外部设备练级并行操作
Error Handling
错误恢复,返回错误代码,打印内核错误日志
I/O Protection
使用系统调用保护IO
Transforming I/O Requests to Hardware Operations
一个进程请求读磁盘的步骤(大体步骤):
- 决定持有文件的设备
- 将文件名转换为设备可识别的表示方式
- 将物理存储中的数据从磁盘读到buffer(涉及到内核空间和用户空间的buffer copy)
- 让读取的数据对请求进程可用
- 将控制权返回进程
Streams
Performance