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]