- I/O is critical to computer system to interact with other systems.
- Issue :
- How should I/O be integrated into systems?
- What are the general mechanisms?
- How can we make the efficiently?
input devices(from user): keyboard, touchpad, mouse,
output devices: display, printer,
both: NIC(Network Interface Card), Disk,
I/O Device (Peripherals)
CPU is attached to the main memory of the system via some kind of memory bus.
Some devices are connected to the system via a general I/O bus.
bus (data passes) : Data paths that provided to enable information between CPU(s), RAM, and I/O devi
ces.
- I/O bus
- Data path that connects a CPU to an I/O device.
- I/O bus is connected to I/O device by hardware components: I/O ports, interfaces and device controllers.
thick arrows both they are high bandwidth
others low bandwidths
Canonical Device
가상의 표준장치
- Canonical Devices has two important components.
- Hardware interface allows the system software to control its operation.
- 다른 구성요소에게 제공하는 하드웨어 인터페이스
- Internals (
내부구조
) which is implementation specific.
firmware(소프트웨어)가 하드웨어 내부의 동작을 정의
Hardware interface of Canonical Device
- status register
- See the current status of the device
- command register
- Tell the device to perform a certain task
- data register
- Pass data to the device, or get data from the device
By reading and writing above three registers,
the operating system can control device behavior
표준 방식
while ( STATUS == BUSY)
;
write data to data register
write command to command register
Doing so starts the device and executes the command
while ( STATUS == BUSY)
;
Polling
p Operating system waits until the device is ready by repeatedly
reading the status register.
w Positive aspect is simple and working.
w However, it wastes CPU time just waiting for the device.
¢ Switching to another ready process is better utilizing the CPU
반복적으로 장치의 상태 레지스터를 읽어서 명령의 수신가능여부를 확인한다.
간단하지만 비효율적
Using Interrupt
- Put the I/O request process to sleep and context switch to another.
p When the device is finished, wake the process waiting for the I/O by
interrupt.
w Positive aspect is allow to CPU and the disk are properly utilized.
디바이스를 폴링하는 대신 운영체제는 입출력 작업을 요청한 프로세스를 블록시키고 CPU를 양도
Polling vs interrupts
However, “interrupts is not always the best solution”
w If, device performs very quickly, interrupt will “slow down” the system.
w Because context switch is expensive (switching to another process)
If a device is fast -> poll is best.
If it is slow -> interrupts is better
CPU is once again over-burdened
CPU wastes a lot of time to copy the a large chunk of data from memory to the device.
해법?
DMA (Direct Memory Access)
- Copy data in memory by knowing “where the data lives in memory, how much data to copy”
- When completed, DMA raises an interrupt, I/O begins on Disk.
직접 메모리 접근망식 -> DMA엔진은 시스템 내에 있는 특수장치
Device interaction
- I/O instructions
- in, out (x86) 명령어를 사용하여 장치들과 통신
I/O 명령을 명시적으로 사용하는 것
- more general, more popular
memory mapped I/O(맵 입출력)
physical address space load and store
하드웨어는 장치의 레지스터들이 마치 메모리상에 존재하는 것 처럼 만듬
- How the OS interact with different types of interfaces?
- Ex) We’d like to build a file system that worked on top of SCSI disks, IDE disks, USB keychain drivers, and so on.
- Solutions: Abstraction(
추상화
)
- Abstraction encapsulate any specifics of device interaction
Disk
- HDD
- SSD
Device driver
- A piece of software in the OS must know in detail how a device works.
- This piece of software is called a device driver, in which and any
specifics of device interaction are encapsulated
파일 시스템 스택
운영체제 최하위 계층의 일부 소프트웨어(디바이스 드라이버)는 장치의 동작 방식을 알고 있다.
Summary
- To save the CPU cycles for IO
- To access the device registers
- Memory mapped IO
- Explicit IO instruction