OS Review Chapter 14 : I/O Systems
Chapter 14: I/O Systems
I/O Hardware
Common concepts :
- Port
- Bus (daisy chain or shared direct access)
- Controller (host adapter) 操作端口和总线的设备
Devices have addresses, used by :
- Direct I/O instructions
- Memory-mapped I/O
Polling:
Determines state of device:
- command-ready
- busy
- Error
Busy-wait cycle to wait for I/O from device(忙等待)
Direct Memory Access
- Used to avoid programmed I/O for large data movement
- Requires DMA controller
- Bypasses CPU to transfer data directly between I/O device and memory
Application I/O Interface
Kernel I/O Subsystem
Scheduling :
- Some I/O request ordering via per-device queue
- Some OSs try fairness
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”
Caching -:
fast memory holding copy of data
- Always just a copy
- Key to performance
Spooling(假脱机)
hold output for a device
- 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 deallocation
- Watch out for deadlock
I/O Protection
User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions.
- All I/O instructions defined to be privileged
- I/O must be performed via system calls
Performance
I/O a major factor in system performance:
- Demands CPU to execute device driver, kernel I/O code
- Context switches due to interrupts
- Data copying
- Network traffic especially stressful
Improving Performance:
- Reduce number of context switches
- Reduce data copying
- Reduce interrupts by using large transfers, smart controllers, polling
- Use DMA
- Balance CPU, memory, bus, and I/O performance for highest throughput
DMA原理
DMA原理:DMA 是所有现代电脑的重要特色,他允许不同速度的硬件装置来沟通,而不需要依于 CPU 的大量 中断 负载。否则,CPU 需要从来源把每一片段的资料复制到暂存器,然后把他们再次写回到新的地方。在这个时间中,CPU 对于其他的工作来说就无法使用。 DMA 传输重要地将一个内存区从一个装置复制到另外一个。当 CPU 初始化这个传输动作,传输动作本身是由 DMA 控制器 来实行和完成。典型的例子就是移动一个外部内存的区块到芯片内部更快的内存去。像是这样的操作并没有让处理器工作拖延,反而可以被重新排程去处理其他的工作。DMA 传输对于高效能 嵌入式系统 算法和网络是很重要的。
在实现DMA传输时,是由DMA控制器直接掌管总线,因此,存在着一个总线控制权转移问题。即DMA传输前,CPU要把总线控制权交给DMA控制器,而在结束DMA传输后,DMA控制器应立即把总线控制权再交回给CPU。
后记:至此,OS的主要课程就结束啦,感谢zwshen老师井井有条的线上教学,以及学长和同学们的帮助。很欢迎大家和我讨论关于OS的问题呀!联系方式 [email protected]