Sub topic 3
How a DMA Controller Works: Registers and Bus Handshake
This chapter assumes you know CPU registers, the memory bus, the instruction cycle, and binary and hexadecimal numbers.
Registers of a DMA controller
A direct memory access (DMA) controller is hardware that copies blocks of data between a device and memory. The CPU programs it once, and then the controller does the copying. Its registers hold:
- Source address: where the data starts.
- Destination address: where the data goes.
- Word count: how many words remain. It decrements after each transfer.
- Control: start, direction, and interrupt-on-completion flags.
The bus request and grant handshake
The DMA controller cannot drive the bus unless the CPU releases it. The sequence is:
- The device raises DMA request (DREQ) to the controller.
- The controller raises bus request (BR) to the CPU.
- The CPU finishes its current bus cycle and raises bus grant (BG).
- The controller drives the address and data buses and transfers the words.
- When the word count reaches zero, the controller releases the bus and may interrupt the CPU.
Burst, cycle stealing and transparent DMA
| Mode | CPU blocked? | Transfer speed | Typical use |
|---|---|---|---|
| Burst | Yes, for the whole block | Fastest | Large blocks when the CPU can wait |
| Cycle stealing | Briefly, once per word | Medium | Balanced systems |
| Transparent | No | Slowest | Real-time work that cannot stall |
Calculating CPU overhead and transfer rates
Use this formula:
CPU fraction = (blocks per second × CPU cycles per block) / CPU clock rate
Example: a device sends 1 MB/s (taken as 10^6 bytes). Blocks are 8192 bytes, each costs 3000 CPU cycles for setup and completion, and the CPU runs at 500 MHz.
- Blocks per second: 1,000,000 / 8192 ≈ 122.07
- CPU cycles per second: 122.07 × 3000 ≈ 366,211
- CPU fraction: 366,211 / 500,000,000 ≈ 0.073%
Always check the units a GATE question uses, because "MB" can mean 10^6 or 2^20 bytes.
Comparing the techniques and solving GATE-style problems
Polling and interrupt-driven I/O spend CPU cycles on every word. DMA spends them once per block. To solve a GATE-style problem, identify the unit of transfer (word or block), count the CPU cycles for each unit, multiply by the number of units per second, and divide by the clock rate. Confirm whether the question asks for CPU time or bus time before you finish.
Exercise
A device transfers 1 MB/s using 8192-byte blocks. Each block costs 3000 CPU cycles on a 500 MHz CPU. What fraction of CPU time does DMA use?
Show answer
About 0.073%. Blocks per second are 1,000,000 / 8192 ≈ 122.07, cycles per second are 122.07 × 3000 ≈ 366,211, and 366,211 / 500,000,000 ≈ 0.073%.