I/O
Refers to the communication between the computer and the outside world, such as users, storage devices, or other computers. Can be handled in several ways:
- Programmed I/O
The CPU is responsible for checking the status of an I/O device and transferring data. This method is simple but inefficient, as the CPU spends time waiting for the device to be ready. - Interrupt-driven I/O
The CPU initiates an I/O operation and continues executing other instructions. When the I/O device is ready, it sends an interrupt signal to the CPU, which temporarily halts its current task to handle the I/O operation. This improves efficiency by allowing the CPU to perform other work instead of waiting. - Direct Memory Access (DMA)
A special controller manages data transfer between memory and I/O devices, freeing the CPU from involvement in the actual data transfer.
Operating systems are interrupt-driven. Because this approach allows the CPU to respond quickly to important events (such as I/O completion, hardware failures, or user actions) without constantly checking the status of devices.
Interrupts
A type of signals. Sent to the processor by hardware or software indicating an event that needs immediate attention. Allows the CPU to be alerted to important events, such as input from a keyboard, arrival of data from a network, or completion of a disk operation, without the need for constant polling. Operating system is interrupt-driven.
Trap
Aka. exception. A software-generated interrupt. Usually caused by an error or a user request.
Interrupt Service Routine
Aka. ISR, interrupt handler. When an interrupt occurs, the processor temporarily pauses its current execution, saves the context, and transfers control to ISR. The event is processed by the ISR. Once that’s done, the processor resumes its previous activity.
Interrupt Vector
A memory address or a table of addresses that the processor uses to locate the appropriate Interrupt Service Routine (ISR) for a given interrupt. Each type of interrupt has its own unique vector, allowing the system to respond correctly to different sources of interrupts.
Types
I/O can be handled in 2 ways.
Blocking
After I/O starts, control returns to user program only upon I/O completion. CPU stays idle (waiting) until I/O completion. No simulataneous I/O processing.
Non-blocking
After I/O starts, control returns to user program without waiting for I/O completion. Device status table is maintained to track the id, type, address and state of each I/O device.
Direct Memory Access
Each device controller has an internal buffer. Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention. Only one interrupt is generated per block, rather than the one interrupt per byte. Used for high-speed I/O devices able to transmit information at close to memory speeds.