📝 Direct memory access in I/O Hardware (14 MCQs)
DMA Transfers Between Devices and Main Memory
Direct memory access, or DMA, is a hardware-assisted I/O mechanism that transfers data between a device and main memory without requiring the CPU to move every byte or word individually. The processor configures a DMA controller or DMA-capable device with transfer details. Hardware then manages the data movement, while the CPU remains available for other execution.
Why CPU Managed Transfers Become Inefficient
For large data blocks, programmed I/O can consume substantial processor time because the CPU repeatedly reads device data and writes it into memory. DMA reduces this per-unit involvement. It is especially valuable for storage, networking, and other high-throughput devices, although setup costs and memory-system contention still affect performance.
DMA Setup, Transfer and Completion
The CPU prepares a buffer, specifies the memory address, transfer direction, and byte or word count, then starts the DMA operation. The DMA hardware obtains control of the required bus or memory interface and performs transfers. On completion or error, it normally signals the processor through an interrupt so the kernel can update the request.
Example of a Storage Block Transfer
Suppose a storage controller must place 64 KB of data into a memory buffer. The driver supplies the buffer address and transfer length to DMA-capable hardware. The controller transfers the data into memory without a CPU copy for each byte. It then reports completion, allowing the kernel to make the buffer available to the requesting process.
Throughput Gains and Memory Coordination
DMA can reduce CPU overhead and improve throughput for large transfers. It does not eliminate all CPU work because requests still require preparation, completion handling, and buffer management. Devices and processors may compete for memory bandwidth, and systems must handle address translation, cache coherence, and safe buffer access correctly.
Misconceptions About DMA Operation
'DMA means the CPU has no involvement' is false because the CPU configures and manages requests. 'DMA always bypasses the cache' is architecture-dependent; coherence or cache-maintenance mechanisms may be required. 'DMA transfers data directly between two devices in every case' is misleading because common transfers use main memory as the data destination or source.
Exam Focus: Comparing Programmed I/O and DMA
Be able to describe DMA setup, hardware transfer, and completion notification. Compare CPU involvement in programmed I/O, interrupt-driven I/O, and DMA. Questions may provide a block size and ask why DMA is efficient for large transfers, or examine bus contention, cache coherence, and the role of the device driver.
Key Terms of DMA
- DMA - Hardware-assisted memory data transfer.
- DMA controller - Coordinates transfers between device and memory.
- Buffer - Memory area holding transferred data.
- Transfer count - Amount of data to transfer.
- Bus contention - Competition for shared transfer resources.
📝 All Direct memory access in I/O Hardware MCQs
Q1. A computer needs to copy a 4 MB file from a disk controller to main memory. Which benefit does using DMA provide over having the CPU copy each byte?
📖 Explanation: Using DMA moves the data directly between the controller and memory, freeing the CPU from the copy loop. While the transfer proceeds, the processor can perform other work or enter a low‑power state, improving overall efficiency. The other options are incorrect because DMA does not guarantee error‑free transfers, does not add verification, and does not compress data. This illustrates how DMA conserves CPU cycles in a typical copying task.
Q2. An embedded system reads sensor data at 1 kHz and stores it in a buffer. Which condition makes DMA the preferred method instead of programmed I/O?
📖 Explanation: DMA can move the sensor data directly into memory without the CPU fetching each sample, which frees the processor for other tasks. When the system must minimize CPU interruptions, using DMA lets the sensor write to the buffer autonomously, and the CPU only reacts to completion events. The other options are incorrect: single‑byte packets still benefit from DMA, a plentiful idle CPU does not require DMA, and a 16‑byte buffer is too small to justify the overhead of DMA setup. Thus DMA is chosen to reduce CPU load.
Q3. A motherboard has two DMA channels, one for the network card and one for the sound card. If both devices request the bus simultaneously, which mechanism decides which device gains access first?
📖 Explanation: When two devices request the bus at the same time, the system uses a priority‑based arbitration scheme stored in CPU registers. The controller examines these registers and grants the bus to the device with higher priority, ensuring deterministic access. Round‑robin would share time equally but is not typical for DMA, first‑come based on ID does not handle simultaneous requests, and random selection could cause unfairness. The correct answer reflects the standard method of using priority registers to resolve conflicts.
Q4. An audio player streams 48 kHz, 16‑bit stereo audio using DMA. To avoid buffer underrun, what is the minimum size of the circular buffer if the DMA interrupt latency is 0.5 ms? (Assume no other delays.)
📖 Explanation: The audio stream produces 48 kHz × 2 channels × 2 bytes = 192 000 bytes per second. With an interrupt latency of 0.5 ms, the DMA must have at least 192 000 × 0.0005 = 96 bytes ready before the CPU can service the next interrupt. A 96‑byte buffer is the minimum to avoid underrun; larger buffers add safety margin but are not required. The other options represent larger buffers that would work but are unnecessary, and the smallest option matches the calculated requirement.
Q5. Designing a DMA engine for a PCI Express device that must address up to 2 TiB of RAM, which bus width is required to transfer a full 64‑bit address in a single transaction?
📖 Explanation: To address up to 2 TiB (2 × 2⁴⁰ bytes), the address bus must be able to represent values up to 2⁴¹ − 1, which requires 64 bits of address information. A 64‑bit wide transfer can convey the entire address in one transaction, minimizing latency. A 32‑bit bus would need two cycles, a 128‑bit bus is wider than needed and adds complexity, and 256‑bit is excessive. Therefore a 64‑bit bus width satisfies the address range efficiently.
Q6. A file is stored in three non‑contiguous memory regions. Which DMA feature allows the controller to transfer the entire file without CPU intervention?
📖 Explanation: Scatter‑gather DMA lets the controller follow a list of memory segments, reading from or writing to each in turn without CPU involvement. This capability enables a file stored in non‑contiguous regions to be transferred as a single logical operation. Burst mode only speeds up transfers but does not handle disjoint addresses, handshake signaling manages flow control but not address lists, and cache write‑back concerns memory consistency, not segment selection. Hence scatter‑gather is the feature that meets the requirement.
Q7. When a DMA transfer completes, which technique reduces the latency of notifying the CPU compared to polling?
📖 Explanation: Polling forces the CPU to repeatedly check a status register, consuming cycles and introducing delay before the CPU notices completion. By raising an interrupt line, the DMA controller signals the CPU immediately, allowing the processor to suspend its current task and execute the interrupt handler promptly. Writing to a status register still requires the CPU to read it, and a software signal is essentially a form of polling. Therefore using an interrupt line provides the lowest latency notification.
Q8. What is the primary purpose of Direct Memory Access in a computer system?
📖 Explanation: DMA’s main role is to let peripherals transfer data to or from main memory without the CPU moving each byte. This off‑loads the data‑movement work, freeing the processor for other computations. Increasing CPU clock speed, adding error checking, or encrypting data are unrelated functions. Consequently, the correct description focuses on peripheral‑initiated memory access without CPU involvement.
Q9. How does DMA improve CPU utilization compared to programmed I/O?
📖 Explanation: With programmed I/O, the CPU must execute a loop that reads or writes each data element, occupying the processor for the entire transfer. DMA moves the data autonomously, allowing the CPU to continue executing unrelated instructions while the transfer proceeds. DMA does not affect the CPU clock, cache usage, or interrupt requirements directly. Hence the advantage lies in the CPU’s ability to perform other work concurrently.
Q10. Why must a DMA controller participate in bus arbitration, and how does this affect overall system performance?
📖 Explanation: DMA controllers are bus masters and must request control of the system bus, which is also used by the CPU and other devices. Arbitration ensures that only one master uses the bus at a time, preventing collisions. By sharing the bus fairly, the system avoids starving other devices, though occasional delays can occur when the DMA wins arbitration. The other options misstate the purpose: synchronizing caches, converting data formats, or exclusive access are not the primary reasons for arbitration. Fair sharing maintains overall performance.
Q11. What distinguishes single‑word DMA from block DMA transfers?
📖 Explanation: In single‑word DMA, the controller transfers one data unit per request and typically generates an interrupt after each word, incurring overhead. Block DMA groups many words into a burst, issuing only a single interrupt when the whole block finishes, reducing interrupt traffic. Both methods can be used with PCI devices, and cache flushing is a separate concern. Therefore the key distinction is the interrupt handling behavior between the two transfer modes.
Q12. When a DMA engine writes directly to main memory, which cache coherence issue can arise, and how is it typically resolved?
📖 Explanation: When DMA writes to a memory location that is also cached by the CPU, the cached copy can become stale, leading the processor to read outdated data. To maintain coherence, the system either invalidates the affected cache lines or writes back any modified data before the DMA write. The other statements are false: DMA does not double‑store data, it does affect caches, and DMA does not automatically update caches without explicit coherence mechanisms. Hence cache invalidation is the typical solution.
Q13. What does the acronym DMA stand for?
📖 Explanation: The abbreviation DMA stands for Direct Memory Access. This term describes the technique where a peripheral can read from or write to main memory without the central processor’s direct involvement. The other options represent different concepts: dynamic memory allocation pertains to software memory management, distributed memory architecture describes a multi‑computer system, and dual mode access is not a standard term. Therefore the correct expansion is Direct Memory Access.
Q14. Which common PC bus is typically used to carry DMA requests from peripherals to memory?
📖 Explanation: PCI (Peripheral Component Interconnect) is the common bus in PCs that carries DMA requests from devices such as network cards and storage controllers to main memory. USB is primarily for peripheral connectivity, SATA is a storage interface, and Ethernet is a network protocol, none of which directly provide DMA bus services. Consequently, PCI is the standard bus used for DMA operations in typical desktop systems.