OS & Hardware
In a system where hardware does not keep caches coherent, what must software do before the CPU reads data a device wrote to main memory via DMA?
- ATemporarily lower the CPU clock frequency
- BInvalidate the cache for that range so the data is reread from main memory
- CWrite the whole cache back to main memory and then discard the data the DMA delivered
Show answer and explanation
Answer: B. Invalidate the cache for that range so the data is reread from main memory
DMA transfers data between devices and main memory without the CPU, so on non-coherent systems the CPU's cache may still hold stale data for that range. Reading it directly would return old values rather than the newly arrived data. The driver therefore invalidates that range of the cache before reading so fresh values come from memory. Conversely, data to be sent to a device is written back from the cache before the DMA starts.
- A. The clock frequency has nothing to do with coherence.
- B. Correct. Invalidating stale cache contents makes the CPU read the new data.
- C. Discarding the DMA results would defeat the purpose.