简体   繁体   中英

How does DMA affect CPU?

(I'm new to learning operating systems. This might be a stupid question)

I learned that DMA allows an I/O device like disks, to communicate with the main memory directly independent from the CPU. During the time of data transfer, it keeps the memory bus busy. But how does it affect the CPU? What if the CPU wanted to use the memory during this time? Does it have to wait even if it takes a very long time for data transfer?

Thank you.

It depends on the specifics of how the bus and (processor) caches are implemented. In a simple case the CPU would stall on load/store instruction or instruction fetch waiting for the bus to become inactive.

However, since most CPUs have a cache between the main memory bus and the cores this is often avoided. If the access hits the cache then no access may go out onto the bus. Alternatively, the cache may allow writes to main memory to be deferred until the bus is inactive, or a write may never go out to main memory at all. Some caching hardware "snoops" the memory bus, effectively listening for memory access that would hit a cache line in the cache, and then updates the cache automatically. This saves the CPU from having master a separate transaction to get the DMA'd data from RAM into the cache.

Additionally, some buses support a priority system for hardware, which would allow the DMA to be suspended if higher priority hardware needs to use the bus, such as the CPU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM