dma vs cpu transfers
Posted: Fri Feb 28, 2014 8:53 pm
is a dma transfer from the HDD to memory faster than a cpu transfer? why?
The Place to Start for Operating System Developers
https://f.osdev.org/
Note that "faster" can mean several different things - latency (e.g. time between asking to start reading and the data starting to arrive), throughput (e.g. how many MiB per second for very large reads) and efficiency (overall effect on a system's performance).icealys wrote:is a dma transfer from the HDD to memory faster than a cpu transfer? why?
If they said the CPU is on hold, they're wrong. The CPU can't access that bus while a burst is happening, but it can still do processing and access its own caches. Also note that (assuming PCI) a large transfer would be broken into many relatively small bursts - if the CPU needs to access the bus then it might not have to wait (in between bursts) or might have to wait for the current burst to end (and not wait until the entire transfer finishes). Don't forget that a CPU will prefetch when it can (if a prefetch is delayed a little then the data can still arrive in CPUs caches before the CPU actually needs it) and most CPUs do "out of order execution" (where if some instructions can't be done because they depend on memory accesses that are stalled then the CPU can still do other instructions).icealys wrote:in the DMA burst mode, I was looking at stackoverflow and they said that the cpu is put on hold in this mode. What would be the advantage of using this mode?
For reading data from disk; for DMA the disk can start transferring the data as soon as it arrives (this is the fastest/lowest latency). For PIO the disk controller has to send an IRQ to the CPU, then wait for the CPU to acknowledge the IRQ, then wait for the IRQ handler to figure out what's going on and start requesting the data. All that waiting means that it takes longer before the data starts to be transferred for PIO.icealys wrote:It would still be slower in latency than PIO right?
In which way do the words "burst transfer" make you think "one byte at a time"? Surely you'd be expecting a burst of multiple bytes...icealys wrote:Also, how does the dma controller read and write to memory using this mode? Would it read a 4kb block from the HDD, store it in its cache, and then write to memory one byte at a time?
What exactly are you talking about? This sounds like the ancient ISA DMA controllers that nobody has used for hard disk transfers for about 30 years. If it is, forget about it - it's completely useless (excruciatingly slow compared to modern CPU and disk speeds, and no longer connected to the disk controller or usable for disk transfers in any way at all). Modern systems use PCI bus mastering and scatter-gather lists for DMA.icealys wrote:I say one byte at a time because it has a count register that keeps track of the number of bytes written to memory and it decrements from the total amount of bytes until it reaches 0.