Sub topic 10
Calculating CPU overhead and transfer rates
This chapter assumes you know the instruction cycle, clock cycles and clock frequency, and the basic ideas of polling, interrupt-driven I/O and DMA from the earlier chapters. It also assumes you can convert between seconds, milliseconds, microseconds and nanoseconds.
GATE questions on this topic follow one pattern. Each question gives a device rate, a CPU speed and a cost per event, and asks what fraction of CPU time the I/O technique consumes. This chapter gives you one formula that covers all three techniques, shows how to fill it in for each, and lists the unit traps that cost marks.
The one formula
Every technique costs the CPU some number of cycles each time something happens. So:
CPU fraction = (events per second × cycles per event) ÷ CPU clock rate
What counts as an event depends on the technique.
| Technique | Event | Events per second | Cycles per event |
|---|---|---|---|
| Polling | One poll of the status register | Polling rate (set by the device's deadline) | Cycles for one poll, or one poll plus the transfer |
| Interrupt-driven | One interrupt | Data rate ÷ bytes per interrupt | Interrupt entry + ISR body + return |
| DMA | One block transfer | Data rate ÷ block size | Setup + completion interrupt |
If the cost is given as time instead of cycles, use "seconds per event" and drop the clock rate:
CPU fraction = events per second × seconds per event
A fraction above 100% means the CPU cannot sustain the device. The maximum sustainable rate is the point where the fraction reaches 100%.
Polling
With polling, the CPU decides how often to look at the device. The device sets the minimum rate, because data must be read before the next item overwrites it.
- A device that delivers one byte at a time and has no buffer must be polled at least once per byte. A 100 KB/s device needs at least 100,000 polls per second.
- A device with an n-byte buffer can be polled once per n bytes. The deadline is the time the device takes to fill the buffer.
- A device that is naturally slow, such as a mouse, is polled at a fixed rate chosen by the designer. A mouse polled 30 times per second is a common example.
Worked example: byte device
A device delivers 100 KB/s, one byte at a time. One poll, including the transfer when the data is ready, costs 400 cycles. The CPU runs at 1 GHz.
- Polls per second = 100,000.
- Cycles per second spent polling = 100,000 × 400 = 40,000,000.
- Fraction = 40,000,000 ÷ 1,000,000,000 = 4%.
Worked example: mouse
A mouse is polled 30 times per second. Each poll costs 100 cycles on a 500 MHz CPU.
Fraction = (30 × 100) ÷ 500,000,000 = 0.0006%.
Polling a slow device costs almost nothing. The weakness of polling appears with fast devices, or when the CPU polls a device that is idle most of the time.
Interrupt-driven I/O
With interrupts, the device decides when the CPU is involved. The CPU pays only when data arrives, but each interrupt carries a fixed cost.
Cycles per interrupt = hardware response (finish instruction, save PC and flags, fetch vector) + ISR body + return (restore state, return from interrupt).
If the question gives one total, use it. If it gives parts, add them.
Worked example: per-byte interrupts
A device transfers 10 KB/s, one byte per interrupt. Each interrupt costs 4 µs in total.
Fraction = 10,000 × 4 µs = 40,000 µs per second = 40 ms per second = 4%.
Maximum sustainable rate
If one interrupt costs t seconds, the CPU can handle at most 1 ÷ t interrupts per second. With t = 4 µs the limit is 250,000 interrupts per second. For a byte-per-interrupt device that is 250 KB/s, and at that rate the CPU does nothing else.
Duty cycle
Some devices transfer only part of the time. If the device is active 10% of the time and the 100% active overhead is 50%, the average overhead is 5%. Questions phrase this as "the device is busy for 20% of the time" or "data arrives in bursts". Multiply the active-time fraction by the overhead during activity.
DMA
DMA changes the unit of work from the word to the block. The CPU pays only to set up the transfer (write the address, count and control registers) and to handle the completion interrupt. During the transfer itself, the CPU is not involved. It may be briefly held off the bus, which is covered below.
Events per second = data rate ÷ block size.
Cycles per event = setup cycles + completion-interrupt cycles.
The three-technique comparison in code
The program below uses one device rate of 1 MB/s and a 500 MHz CPU. It compares per-word interrupts with block DMA.
# CPU time used by a 1 MB/s device on a 500 MHz CPU
rate_bytes_per_s = 1_000_000
word_bytes = 4
cpu_hz = 500_000_000
# Interrupt-driven: one interrupt per word, ISR costs 1000 cycles
words_per_s = rate_bytes_per_s / word_bytes
interrupt_fraction = words_per_s * 1000 / cpu_hz
# DMA: one transfer per 4096-byte block, 2000 cycles setup + 1000 cycles completion interrupt
block_bytes = 4096
blocks_per_s = rate_bytes_per_s / block_bytes
dma_fraction = blocks_per_s * (2000 + 1000) / cpu_hz
print(f"Interrupt-driven: {interrupt_fraction:.2%} of CPU time")
print(f"DMA: {dma_fraction:.4%} of CPU time")It prints Interrupt-driven: 50.00% of CPU time and DMA: 0.1465% of CPU time.
The interrupt line is 250,000 interrupts per second × 1000 cycles = 250 million cycles per second, which is half of the 500 million available. The DMA line is about 244 blocks per second × 3000 cycles = about 732,000 cycles per second. DMA is roughly 340 times cheaper here (50% ÷ 0.1465%). The gain comes from paying the fixed cost once per 1024 words instead of once per word, with a slightly larger fixed cost per event.
Bus cost during DMA
The CPU fraction above counts only instructions the CPU spends on I/O. During the transfer, the DMA controller also uses the memory bus. If the CPU needs the bus at the same moment, it waits. The size of this penalty depends on the DMA mode.
Cycle stealing
The controller takes the bus for one memory cycle per word and then gives it back. Each word steals exactly one memory cycle.
A device delivers 1 MB/s in 4-byte words. Memory cycle time is 100 ns.
- Words per second = 1,000,000 ÷ 4 = 250,000.
- Stolen time per second = 250,000 × 100 ns = 25 ms.
- Fraction of memory cycles stolen = 25 ms ÷ 1 s = 2.5%.
Burst mode
The controller keeps the bus for the whole block, and the CPU is locked out for that duration. For a 4096-byte block with 4-byte words and 100 ns memory cycles:
- Words per block = 4096 ÷ 4 = 1024.
- Bus held per burst = 1024 × 100 ns = 102.4 µs.
If the device supplies 4 MB/s on average, there are 4,000,000 ÷ 4096 ≈ 976.6 bursts per second, and the bus is held for 976.6 × 102.4 µs = 0.1 s per second, which is 10%.
The 10% matches the cycle-stealing calculation for the same data rate (1,000,000 words per second × 100 ns = 10%). The total number of memory cycles used by DMA does not depend on the mode. The mode changes how those cycles are spread over time. Burst mode produces long stalls (102.4 µs here). Cycle stealing produces many one-cycle delays. This is the useful point in questions that ask which mode delays the CPU more in a single stretch.
Transparent DMA
The controller uses the bus only in cycles where the CPU does not need it. The CPU sees no delay, so the stolen-cycle cost is zero. The price is that transfers are slower and need hardware that can tell when the CPU is not using the bus.
Maximum DMA transfer rate
The upper limit on DMA speed is the memory bandwidth: word size ÷ memory cycle time. With 32-bit words and 100 ns cycles it is 4 bytes ÷ 100 ns = 40 MB/s. In cycle stealing, if the CPU also needs every other memory cycle, the DMA gets half of that, 20 MB/s.
Unit traps
Most lost marks in this topic come from units, not from the method.
- K, M, G. GATE answers usually treat 1 KB/s as 1000 bytes per second when speaking of data rates, and 1 KB of memory as 1024 bytes. Follow the question. If a block size is given as "4 KB" and a rate as "1 MB/s", check whether the answer options distinguish 1000 from 1024. When in doubt, compute both and see which matches an option.
- Bits and bytes. A rate in Mbps is in bits. Divide by 8 to get bytes per second before dividing by the word size.
- Cycles and time. Cycles ÷ clock rate = time. A 500 MHz clock has a 2 ns cycle. Do not mix a CPU cycle time with a memory cycle time.
- Per word and per byte. A device sending 4-byte words has a quarter as many events as one sending bytes at the same byte rate.
- Setup counted once or per word. DMA setup is per block. Per-word costs are only the stolen memory cycles.
- Percent of what. "CPU time" for polling and interrupts means CPU cycles. "Memory cycles stolen" for DMA is a share of memory bandwidth. Answer the quantity asked.
Quick checklist for any question
- Write the device rate in bytes per second and the word size in bytes.
- Decide the event: poll, interrupt or block.
- Compute events per second.
- Compute the cost per event in cycles, or in seconds if the clock rate is not given.
- Apply the formula, then apply any duty-cycle factor.
- Check whether the result is above 100%.
Exercise
A device delivers 200 KB/s (1 KB = 1000 bytes), one byte per interrupt. Each interrupt costs 1000 cycles on a 500 MHz CPU. (a) What fraction of CPU time do interrupts use? (b) With DMA using 8000-byte blocks and 4000 cycles per block for setup plus completion, what fraction is used?
Show answer
(a) Interrupts per second = 200,000. Cycles per second = 200,000 × 1000 = 200,000,000. Fraction = 200,000,000 ÷ 500,000,000 = 40%. (b) Blocks per second = 200,000 ÷ 8000 = 25. Cycles per second = 25 × 4000 = 100,000. Fraction = 100,000 ÷ 500,000,000 = 0.02%.
Exercise
A disk supplies 2 MB/s (1 MB = 1,000,000 bytes) to memory through DMA in 32-bit words. Memory cycle time is 50 ns. (a) What fraction of memory cycles does cycle-stealing DMA take? (b) If the controller uses burst mode with 4000-byte blocks, how long is the CPU locked out per burst?
Show answer
(a) Words per second = 2,000,000 ÷ 4 = 500,000. Stolen time = 500,000 × 50 ns = 25 ms per second, which is 2.5%. (b) Words per block = 4000 ÷ 4 = 1000. Lockout = 1000 × 50 ns = 50 µs per burst.
Exercise
An interrupt costs 5 µs in total (entry, ISR, return). What is the highest byte-per-interrupt data rate the CPU can sustain, and what fraction of CPU time does a 50 KB/s device (1 KB = 1000 bytes) use?
Show answer
The CPU can handle 1 ÷ 5 µs = 200,000 interrupts per second, so the maximum is 200 KB/s with one byte per interrupt. For a 50 KB/s device, 50,000 × 5 µs = 250 ms per second, which is 25% of CPU time.