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?

  1. ATemporarily lower the CPU clock frequency
  2. BInvalidate the cache for that range so the data is reread from main memory
  3. 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.
Practice this topic Back to topic

More OS & Hardware questions

  1. What is the main role of an IOMMU?
  2. What is the role of a device driver?
  3. Why do typical operating systems prevent applications from directly reading and writing device registers?
  4. What is the software called that runs multiple operating systems simultaneously on one computer, each as an independent virtual machine?
  5. Which correctly describes the types of hypervisors?