Programmed I/O (PIO)
Programmed I/O (PIO), often called Polling, is the simplest and oldest method for data transfer between a CPU and a peripheral device.
In this model, the CPU is entirely responsible for the transfer. It doesn't just start the process; it stays involved for every single byte of data moved.
The Polling Handshake
In PIO, the CPU 'polls' the device. This means the CPU repeatedly reads the device's Status Register to see if it is ready for the next operation.
Imagine a person standing by a mailbox, opening it every 10 seconds to see if a letter has arrived. That is essentially what the CPU does during Polling.
Step-by-Step Execution
Let's look at how the CPU writes a block of data to a disk using PIO:
- The OS reads the device's Status Register in a loop until the Busy bit is 0.
- The OS writes a byte of data into the Data-Out Register.
- The OS sets the Command-Ready bit in the Control Register.
- The Device Controller sets the Busy bit and performs the physical write to hardware.
- The OS goes back to Step 1 for the next byte.
The Busy-Waiting Problem
The biggest drawback of PIO is Busy-Waiting. Because the CPU is stuck in a loop checking the status register, it cannot switch to another process or do any other useful calculation.
For slow devices (like a mechanical printer), the CPU might waste millions of clock cycles just 'watching' the status bit. This severely degrades system performance in multitasking environments.
Comparison: PIO vs Interrupt-Driven I/O
| Feature | Programmed I/O (Polling) | Interrupt-Driven I/O |
|---|---|---|
| CPU Involvement | CPU is 100% busy during the entire transfer. | CPU is free to work on other tasks while I/O happens. |
| Complexity | Very simple hardware and software logic. | Requires specialized interrupt hardware and handlers. |
| Performance | Incredibly inefficient for slow devices. | High efficiency; multitasking is preserved. |
| Use Case | Simple embedded systems or legacy ports. | Modern high-performance operating systems. |
When is PIO Still Used?
While inefficient, PIO isn't completely extinct. It is used in:
1. Very Simple Embedded Systems: Where there is only one task to run and no need for complex interrupt hardware.
2. Extremely Fast Devices: If a device can finish its task faster than the time it takes to handle an interrupt, Polling might actually be faster.
3. Device Driver Initialization: Drivers often use short bursts of polling when first initializing a hardware card.
Programmed I/O Efficiency
Question 1 of 1Test your understanding of the primary flaw in Polling.
