Introduction
Direct memory access (DMA) lets an I/O interface move a block of data between a device and main memory without the processor handling each word. The processor programs a DMA controller with a memory address, a word count and a direction, and goes back to other work; the controller takes control of the system bus when it needs it, transfers the words, and normally raises one completion interrupt when enabled; completion may instead be polled.
GATE asks you to compute the fraction of time the processor is held off the bus under burst and cycle-stealing DMA, to compare DMA with interrupt-driven and programmed I/O for the same device, to work out block transfer times, and to describe how the bus is handed between the processor and the DMA controller. Programmed and interrupt-driven I/O are covered in I/O Interface and Interrupts.
Prerequisites
- I/O Interface and Interrupts: device registers, interrupt handling and the cost of an interrupt.
Core concepts
The DMA controller
| Register | Role |
|---|---|
| Address register | Memory address of the next word; incremented after each transfer |
| Word count register | Words still to transfer; decremented after each transfer |
| Control and status register | Direction (read or write memory), mode, interrupt enable, done flag |
A controller may have several channels, each with its own set of registers, so several devices can share it.
A DMA transfer, step by step
- The processor writes the starting address, the word count and the command into the controller, then continues with other work (often another process).
- When the device has data, the controller asserts bus request (BR, or HOLD).
- The processor (or the bus arbiter) finishes its current bus cycle and asserts bus grant (BG, or HLDA), releasing the bus.
- The controller places the address on the bus and moves the word between device and memory; it updates its address and count.
- Depending on the mode, it releases the bus after one word or after the whole block.
- When the count reaches zero, the controller sets its done flag and interrupts the processor once if enabled; otherwise completion can be polled.
The processor can be held off the bus in the middle of an instruction, at any bus cycle boundary, unlike an interrupt, which waits for the instruction to finish: DMA only borrows bus cycles and does not need the processor's registers.
Modes
| Mode | Bus use by the controller | Effect on the processor |
|---|---|---|
| Burst (block) | Keeps the bus for the whole block | Blocked from the bus for the entire transfer; fastest for the device |
| Cycle stealing | Takes the bus for one word at a time, then releases it | Loses one bus cycle per word, spread out; the processor keeps running between steals |
| Transparent (hidden) | Uses the bus only in cycles when the processor does not need it | No slowdown; needs logic to detect free cycles, and the transfer may be slow |
Bus arbitration
When several masters (the processor and DMA controllers) can drive the bus, an arbiter decides who gets it. In centralised arbitration, one arbiter receives the requests; the grant may be daisy-chained, so the controller nearest the arbiter has the highest priority, exactly as with interrupt acknowledge. In distributed arbitration, the masters compare their priority codes on shared lines and the highest wins without a central arbiter.

How it works
Why DMA scales to fast devices
With interrupt-driven I/O the processor pays for an interrupt per unit of transfer; with DMA it pays one set-up per block and normally one completion interrupt when enabled (or a polling cost instead). The only remaining cost is bus contention: each word moved by DMA occupies one bus cycle that the processor might have wanted.
Algorithms and pseudocode
This pseudocode uses word addresses, so +1 advances one word; count is in words. For byte-addressable memory, advance the address by the number of bytes per word instead.
DMA-CONTROLLER(address, count, direction, mode) // mode is BURST or CYCLE-STEALING only
while count > 0
wait until the device has a word ready (or, in burst mode, the block is buffered)
assert BR; wait for BG // processor releases the bus
repeat
transfer one word between device and memory[address]
address <- address + 1; count <- count - 1
until mode = CYCLE-STEALING or count = 0 // burst keeps the bus
release the bus (drop BR)
set done; raise a completion interrupt if enabled (otherwise completion may be polled)Mathematical explanation
Cycle stealing. If the device transfers at bytes per second in words of bytes, and each steal holds the bus for seconds, the fraction of bus time taken is
That is the processor's worst-case slowdown, reached only if it needs the bus in every cycle.
Burst mode with a buffered device. If the device fills a buffer of bytes at rate (taking ) and the controller then empties it in a burst taking , the processor is blocked for
of the time, when preparation and transfer do not overlap.
Overlapped preparation. If the device prepares the next unit while the controller moves the previous one (and the move is the shorter of the two), a new unit is ready every , so the cycle length is and the processor is blocked for
of the time. The same two formulas apply per word in cycle-stealing mode, with the time the device needs per word and one stolen bus cycle. Read whether the question lets preparation and transfer overlap: the two answers are close when but are not equal.
Processor cost per block. Set-up cycles completion interrupt cycles, paid times per second; as a fraction of a clock of Hz:
Worked examples
Example 1: DMA against interrupts for a disk
A disk delivers 8 MB/s ( bytes per second) to a 2 GHz processor. With interrupts per 16-byte unit at 1000 cycles each, the processor spends 25% of its time (see I/O Interface and Interrupts). With DMA in 4 KB (4096-byte) blocks, 1000 cycles of set-up and 500 cycles for the completion interrupt:
Example 2: cycle-stealing slowdown
A device transfers 2 MB/s in 4-byte words by cycle stealing; each steal takes one 100 ns bus cycle. Steals per second: , occupying ns s per second, so 5% of bus time. If the processor needs the bus in only 40% of its cycles and the steals fall independently of its bus use, about 40% of the steals collide with a processor bus cycle, so it loses about of its cycles; 5% is the worst case.
Example 3: burst mode with a buffer
A device fills a 2000-byte buffer at 1 MB/s ( bytes per second), then the controller empties it into memory over a 100 MB/s bus in burst mode. Preparation: ms. Transfer: s. The processor is blocked for of the time. If the device keeps filling a second buffer while the first is being emptied, a burst starts every 2 ms and the blocked fraction is .
The same device-paced reasoning per word: a device that prepares one word every 2 s, with each steal taking 50 ns, blocks the processor for of the time if preparation overlaps the steal, and if the device waits for each steal to finish before preparing the next word.
Example 4: the three modes on one timeline (Figure 1)
A block of 4 words is moved during 16 bus cycles. The processor needs the bus in every cycle except 3, 7, 11 and 15 (when it is executing internally).
| Mode | Cycles taken by DMA | Processor bus cycles lost |
|---|---|---|
| Burst | 1, 2, 3, 4 | 3 (cycle 3 was free anyway), all at the start |
| Cycle stealing | 1, 5, 9, 13 | 4, one every 4 cycles |
| Transparent | 3, 7, 11, 15 | 0 |
Burst delivers the block soonest (by cycle 4); transparent delivers it last (cycle 15) but costs the processor nothing.
Example 5: transfer time of a block
A 512-word block moves by cycle stealing, one word every 10 bus cycles of 50 ns (the device's pace). The last word moves 511 periods after the first, so the transfer spans bus cycles s, of which only 512 cycles (25.6 s) are taken from the processor.
Example 6: DMA and caches (Related material)
Related material. DMA reads and writes main memory directly. If a cache holds a copy of a line that DMA overwrites, the processor would read stale data; if a write-back cache holds a dirty line that DMA reads from memory, the device would get stale data. Systems either flush or invalidate the affected lines in software before and after DMA, or let the cache snoop DMA bus traffic.
Important properties and observations
- Normally one enabled completion interrupt per block, not per word, is what makes DMA cheap for the processor.
- The processor can be held off between bus cycles, even mid-instruction; interrupts wait for the instruction to end.
- Burst is fastest for the transfer and worst for processor latency; cycle stealing spreads the cost.
- Transparent DMA has no processor cost but depends on free bus cycles.
- The bus-time fraction taken by cycle stealing is , an upper bound on the slowdown.
- Daisy-chained bus grant gives priority by position, as in interrupt acknowledge.
- Common misconceptions.
- "The processor is idle during DMA." It runs; it only loses the bus cycles the controller takes.
- DMA need not interrupt for each word. Normally it raises one completion interrupt per block when enabled; completion may instead be polled.
- "Cycle stealing is slower for the processor than burst." It costs the same number of bus cycles, spread out.
GATE examination perspective
- CYCLE STEALING. Words per second times bus cycle time gives the fraction of bus time taken.
- BURST. Blocked fraction when the device prepares and then bursts.
- OVERLAP OR NOT. If preparation of the next unit overlaps the transfer, the blocked fraction is instead; decide from the wording before computing.
- DMA AGAINST INTERRUPTS. Per-unit interrupt cost against per-block set-up plus one interrupt.
- SEQUENCE. Program the controller, BR, BG, transfer, update address and count, completion interrupt at count zero if enabled, otherwise poll.
- UNITS. Keep KB as 1024 or 1000 exactly as the question states; mixing them shifts answers.
- MODES. Burst: whole block at once; cycle stealing: one word per grant; transparent: only free cycles.
Summary
Sources
- C. Hamacher, Z. Vranesic, S. Zaky, Computer Organization, 5th ed., McGraw-Hill, 2002: Chapter 4, Section 4.4 (Direct Memory Access, including 4.4.1 Bus Arbitration).
- W. Stallings, Computer Organization and Architecture, 10th ed., Pearson: Section 7.5 (Direct Memory Access).