Sub topic 11
Comparing I/O Techniques and Solving GATE-Style Problems
Prerequisites and the comparison model
This chapter assumes that you know CPU instruction cycles, registers, buses, binary numbers, and subroutine calls. You should also know that an I/O device usually exposes data, status, and control registers through an interface module.
The three main I/O techniques differ in who waits for the device and who moves the data:
| Technique | Who checks readiness? | Who moves each data item? | Typical CPU cost |
|---|---|---|---|
| Programmed I/O | CPU repeatedly polls status | CPU | High while waiting |
| Interrupt-driven I/O | Hardware requests service | CPU, inside an ISR | One cost per interrupt |
| DMA | DMA controller and hardware | DMA controller | Setup and block-completion costs |
Programmed I/O is simple but can waste cycles. Interrupt-driven I/O allows the CPU to do other work between events. Direct memory access, or DMA, is usually best for large blocks because the controller transfers data directly between the device and memory.
A decision diagram
This is a performance guideline, not an absolute rule. A small transfer with strict timing requirements may use programmed I/O, while a slow device may use interrupts even when each transfer is simple.
CPU-time formulas
For a polling loop, the CPU may remain occupied for the entire waiting period. If the device is continuously active and the loop does not perform useful work, the CPU utilization caused by polling is approximately:
CPU fraction = 1
For interrupt-driven I/O, calculate the number of interrupts per second and multiply by the cycles needed for each interrupt service routine:
CPU fraction = interrupts per second × ISR cycles / CPU cycles per second
If a device transfers one word per interrupt, then:
interrupts per second = transfer rate in bytes per second / bytes per word
For DMA, the CPU usually pays for setup and completion. If one DMA block contains B bytes:
CPU fraction = blocks per second × CPU cycles per block / CPU cycles per second
Here, CPU cycles per block can include DMA setup, descriptor handling, and the completion interrupt.
Worked calculation
Suppose a device transfers 1 MB/s. The CPU runs at 500 MHz. An interrupt occurs for every 4-byte word, and each ISR costs 1,000 cycles.
The device generates:
1,000,000 / 4 = 250,000 interrupts per second
The interrupt CPU fraction is:
250,000 × 1,000 / 500,000,000 = 0.5
Therefore, interrupt handling consumes 50% of the CPU.
Now suppose DMA transfers 4,096-byte blocks. Each block costs 2,000 setup cycles and a 1,000-cycle completion interrupt.
The number of blocks per second is approximately:
1,000,000 / 4,096 = 244.14
The DMA CPU fraction is:
244.14 × 3,000 / 500,000,000 ≈ 0.001465
DMA consumes about 0.1465% of the CPU under these assumptions.
rate_bytes_per_s = 1_000_000
word_bytes = 4
cpu_hz = 500_000_000
words_per_s = rate_bytes_per_s / word_bytes
interrupt_fraction = words_per_s * 1_000 / cpu_hz
block_bytes = 4_096
blocks_per_s = rate_bytes_per_s / block_bytes
dma_fraction = blocks_per_s * (2_000 + 1_000) / cpu_hz
print(f"Interrupt-driven: {interrupt_fraction:.2%}")
print(f"DMA: {dma_fraction:.4%}")Common GATE problem patterns
Converting a transfer rate
Always make the units consistent. Convert KB, MB, and GB to bytes according to the convention stated in the question. If no convention is given, computer-organization questions often use powers of two, such as 1 KB = 1,024 bytes. Check whether the answer choices reveal the intended convention.
Then divide the byte rate by the number of bytes transferred per event. This gives interrupts per second or DMA blocks per second.
Counting DMA requests
A DMA request usually represents a block, not one byte. If a transfer contains N bytes and each DMA block contains B bytes, the number of blocks is:
number of blocks = ceiling(N / B)
Use the ceiling when a partial final block still requires a transaction. Do not use the total byte count as the number of DMA requests.
Distinguishing DMA modes
In burst mode, DMA keeps the bus until the block finishes. This gives high transfer speed but can delay the CPU.
In cycle-stealing mode, DMA transfers one word or a small unit, then releases the bus. The CPU loses occasional bus cycles but continues executing.
In transparent mode, DMA transfers only when the CPU is not using the bus. CPU interference is low, but the DMA transfer can take longer.
A question asking which mode minimizes CPU interruption usually points toward transparent DMA. A question asking which mode gives the highest DMA throughput usually points toward burst mode, assuming the device and memory can sustain it.
A reliable solving procedure
- Identify the technique: polling, interrupt-driven I/O, or DMA.
- Identify the event size: byte, word, record, or block.
- Convert the device rate into events per second.
- Multiply by the CPU cost per event.
- Divide by the CPU frequency.
- Express the result as a fraction or percentage.
- Check whether setup, completion, and partial-block costs are included.
Exercise
A 2 MB/s device sends one interrupt for every 8-byte word. The CPU runs at 400 MHz, and each ISR costs 800 cycles. What fraction of CPU time is used?
Show answer
The interrupt rate is 2,000,000 / 8 = 250,000 interrupts per second. CPU use is 250,000 × 800 / 400,000,000 = 0.5, or 50%.