Salta al contenuto
Note per Studenti Direct Memory Access Report

Direct Memory Access

In questa pagina 6
In questa pagina 4

With programmed I/O and with interrupt-drivenClasses of interrupts; interrupt-driven I/O; hardware and software handling sequence with context saving on the stack; identifying the source (multiple lines, polling, daisy chain, vector); priorities and nested interrupts; exceptions and modes in ARM.Interrupts and Exceptions → I/O every word passes through the CPU (from the module to a register and from the register to memory). For large blocks (disks, network) this is a waste: the DMA module transfers the data directly between device and memory.

Operation

Definition (DMA operation)

  1. The CPU programs the DMA module, indicating: read or write, device address, starting address in memory, number of words to transfer.
  2. The CPU goes on with other work.
  3. The DMA transfers the block one word at a time, using the bus: for each word it increments the address and decrements the counter.
  4. At the end it sends a single interrupt to the CPU.

Example. For 10241024 words the DMA increments the address and decrements the counter 10241024 times, then sends one interrupt.

The CPU intervenes only at the start and at the end of the block.

Use of the bus

The DMA must use the system bus, which is also the CPU's:

Definition (cycle stealing and burst)

  • cycle stealing: the DMA takes the bus for one cycle, transfers a word and releases it. The CPU slows down slightly;
  • burst (block mode): the DMA holds the bus for the whole block. Faster transfer, but the CPU cannot access memory in the meantime.

Example. For 10241024 words, with cycle stealing the DMA takes the bus 11 cycle at a time (10241024 times); in burst mode it holds it for 10241024 consecutive cycles.

The CPU is not interrupted (there is no context switch): it is only suspended while waiting for the bus, at the points where it needs it (instruction fetch or operand fetch, result write). With caches the CPU can often keep working without using the bus.

Configurations

  • Single bus, separate DMA: every word crosses the bus twice (device to DMA to memory). Simple but inefficient.
  • DMA integrated with the devices, or connected to several devices through a dedicated I/O bus: every word uses the system bus only once (DMA to memory).

Channels and I/O processors

Later evolution: the I/O module becomes a processor with its own instruction set (I/O channel), which executes I/O programs in memory without CPU intervention; then a true I/O processor with local memory. Today disk, network and GPU controllers have their own DMA (bus mastering on PCI Express).

Quantitative comparison

Formula (interrupts versus DMA). Transferring 4 KB in 4-byte words = 1024 words.

  • Interrupt: 1024 interrupts; if each costs 200 cycles between context saving, routine and return, about 205 000 CPU cycles.
  • DMA: initial programming (for example 100 cycles) + one final interrupt (200 cycles) is about 300 CPU cycles, plus any cycles taken on the bus.

Example. With one interrupt per word about 1024⋅200≈205 0001024\cdot200\approx205\,000 CPU cycles are needed, with DMA 100+200=300100+200=300 cycles.

Typical mistakes

  • Saying the DMA "interrupts the CPU for every word": it suspends it for one bus cycle at most, and interrupts it only at the end.
  • Forgetting coherence with the cache: if the DMA writes to memory a block that is also in the cache, the cached copy must be invalidated.

Versione ripasso

The DMA module moves data directly between device and memory, without passing through the CPU (see Interrupts and ExceptionsClasses of interrupts; interrupt-driven I/O; hardware and software handling sequence with context saving on the stack; identifying the source (multiple lines, polling, daisy chain, vector); priorities and nested interrupts; exceptions and modes in ARM.Interrupts and Exceptions →, Input-Output Modules and Programmed Input-OutputWhy I/O modules are needed; functions of the module and status, control and data registers; memory-mapped and isolated I/O with examples; programmed I/O with busy waiting and its cost; comparison of the three techniques.Input-Output Modules and Programmed Input-Output →).

Operation

CPU programs: read or write, device address, starting memory address, number of words; continues other work. DMA transfers word by word (address incremented, counter decremented) and sends one interrupt at the end.

Bus

  • Cycle stealing: bus for one cycle per word; CPU slows slightly.
  • Burst: bus held for the whole block; faster, CPU cannot access memory meanwhile. The CPU is only suspended while waiting for the bus (no context switch); caches let it keep working.

Configurations and channels

Single bus with separate DMA: each word crosses the bus twice. DMA integrated or on a dedicated I/O bus: once. Evolution: I/O channel (own instruction set), I/O processor; modern controllers use bus mastering.

Comparison

4 KB = 1024 words: interrupts 1024⋅200≈205 0001024 \cdot 200 \approx 205\,000 cycles; DMA 100+200=300100 + 200 = 300 cycles.

Typical mistakes: DMA suspends the CPU for at most one bus cycle and interrupts only at the end; cache copies of DMA-written blocks must be invalidated.

Teoria collegata