電腦不是在做 I/O 就是在做計算
I/O devices: tape, HD, mouse, joystick, network card, screen, flash disks, etc
I/O subsystem: the methods to control all I/O devices
Two conflicting trends
Device drivers: a uniform device-access interface to the I/O subsystem
⇒ Similar to system calls between apps and OS
Device categories
Port: A connection point between I/O devices and the host. 每個 port 都有自己的 ID,那就是 device 對於電腦的 identifier。
→ E.g.: USB ports
Controller: A collection of electronics that can operate a port, a bus, or a device
⇒ A controller could have its own processor, memory, etc. (E.g.: SCSI controller)
Bus: A set of wires and a well-defined protocol that specifies messages sent over the wires(連接的方式,除了物理相接,還有 protocol 的部分)
→ E.g.: PCI bus
port address
做 什麼事
Depending on how to address a device
Port-mapped I/O
IN
, OUT
)Memory-mapped I/O
MOV
)🙂 More efficient for large memory I/O (e.g. graphic card)
☹️ Vulnerable to accidental modification, error
Depending on how to interact with a device:
Poll (busy-waiting): processor periodically check status register of a device. 不停地確認好了沒,啥時可以作下一個
→ 如果量不多,用這個
Interrupt: device notify processor of its completion. I/O 好了他會直接 call interrupt 跟你的程式講。
⇒ 通常會 Memory-mapped I/O + Interrupt 或是另外兩個相加,不然會互相抵銷好處。