Peripheral I/O: Coordinating Transfers
Peripheral I/O connects a running program with equipment outside the processor, such as a keyboard, sensor, or printer. Input brings information into the computer; output sends information out. The architectural challenge is coordination: a processor can execute instructions while a device is still preparing its next transfer. You need to understand how software discovers readiness, starts an operation, and moves data without confusing device speed with processor workload.
Communicating through an interface
The processor usually communicates with a device controller rather than directly controlling every electrical detail of the peripheral. Software called a device driver uses the controller's documented interface.
That interface commonly exposes three kinds of small, addressable storage locations called registers:
- A data register holds a value being received or transmitted.
- A status register reports conditions such as ready, busy, or error.
- A control register accepts commands or configuration settings.
For input, software might check a ready flag before reading the data register. For output, it might check whether space is available before writing. Reading a value does not, by itself, prove that the value is new: consecutive measurements can legitimately be identical.
With memory-mapped I/O, ordinary load and store instructions access device registers. Other architectures provide a separate I/O address space and special instructions. Either arrangement still requires the program to obey the controller's rules.
Readiness and data movement
Polling means repeatedly checking device status in software to determine whether service is needed. A tight polling loop keeps the CPU occupied while it waits. Polling can also occur periodically between other tasks, reducing checking work but increasing the possible delay before an event is noticed.
An interrupt lets a controller request attention when an event occurs. The CPU can perform other work between events, then execute a handler to service the request. Entry, service, and return still consume CPU time. Frequent interrupts can therefore create substantial overhead.
Direct memory access, abbreviated DMA, lets a controller transfer a block between a peripheral and main memory without CPU instructions copying each item. The CPU typically supplies the memory location, transfer size, and direction, then checks completion or receives an interrupt.
Notification and data movement are separate choices. An interrupt can notify the CPU that it should copy data, or notify it that a DMA transfer has finished.
Approach | How service is initiated | Who moves the payload? | Main consideration |
|---|---|---|---|
Polling with CPU copying | Software checks status | CPU instructions | Checks consume time even without new data |
Interrupt-driven CPU copying | Controller requests attention | CPU instructions | Each service event has handling overhead |
DMA | CPU configures a block transfer | Controller hardware | Setup and completion still require CPU work |
Accounting for time
For a payload of D bytes moving at an effective rate of R bytes per second, the payload transfer time is
If N checks or service events each consume c seconds of CPU time, their CPU cost is
where T is the observation interval. Add any separately specified setup, copying, and completion costs, counting each cost once.
CPU time and elapsed time measure different things. A transfer can occupy a device for several milliseconds while using the CPU for only a small part of that interval. Conversely, repeated status checks can occupy much of the CPU without transferring more useful data.
DMA also uses the computer's data pathways. A shared connection with insufficient bandwidth can still limit throughput, even when CPU overhead is small.
What to remember
- Use status, data, and control registers for their documented purposes.
- Polling checks readiness; interrupts request attention.
- DMA moves blocks after CPU setup and can use interrupts for completion.
- Calculate CPU workload and elapsed transfer time separately.
- Lower CPU overhead does not remove every bandwidth limit.
Example: Moving a Sensor Recording
A laboratory sensor transfers a 24,000-byte recording into main memory at an effective payload rate of 6.00 × 106 bytes/s. Compare two peripheral I/O designs. With programmed I/O, CPU instructions copy every byte; the total CPU cost is 0.100 μs per byte. With DMA, one block holds the whole recording; setup consumes 18.0 μs and completion handling consumes 6.00 μs.
Here, CPU time means time spent executing transfer-related instructions. Assume the effective payload rate is the same for both designs, CPU copying fits within the payload-transfer window, and there are no other CPU costs. DMA setup occurs before payload movement and completion handling afterward. Part (a) asks only about the payload-transfer window, excluding those surrounding activities.
a) How long does payload movement take, in milliseconds?
First express the effective rate in ordinary decimal form: it is ________. Divide the payload size by this rate:
Convert seconds to milliseconds:
The payload-transfer window is 4.00 ms for either design. This is not the complete DMA operation's elapsed time because setup and completion surround that window.
b) How much CPU time does programmed I/O consume, in milliseconds? What percentage of the payload-transfer window does this represent?
Multiply the byte count by the CPU time per byte:
Use the ________ payload window as the comparison interval:
Programmed I/O consumes 2.40 ms of CPU time, or 60.0% of the payload window. The copying time is less than the window, consistent with the supplied timing assumption. It overlaps payload movement, so it is not added to 4.00 ms.
c) How much CPU time does DMA consume, and what percentage of the programmed-I/O CPU time does it save?
Add setup and completion, since the CPU performs both activities:
The CPU-time saving is ________. Compare that saving with the original programmed-I/O cost:
DMA consumes 0.0240 ms of CPU time and saves 99.0% of the programmed-I/O CPU time. This saving concerns CPU work, not a 99% reduction in payload-transfer time. The payload still takes 4.00 ms to move at the stated rate.
A processor must select the intended input/output (I/O) controller when executing an access. Match each architectural term to its description.
Hardware examines address bits and control signals to select the intended register or device.
Device registers occupy a separate address space accessed using dedicated input and output instructions.
Device registers occupy locations in the same address space used for ordinary memory accesses.
Address decoder
Isolated I/O
Memory-mapped I/O
A student is documenting how a computer communicates with a measurement device. Match each technique or interface element with the description that identifies its role.
Software repeatedly reads device status to decide whether service is needed.
A controller-generated notification requests CPU attention for an event.
An addressable interface location accepts commands or configuration from the CPU.
A controller moves a block between a device and main memory after CPU setup.
Control register
Interrupt
Direct memory access
Polling