views:

102

answers:

2

Question 1:

Where exactly does the internal register and internal cache exist? I understand that when a program is loaded into main memory it contains a text section, a stack, a heap and so on. However is the register located in a fixed area of main memory, or is it physically on the CPU and doesn't reside in main memory? Does this apply to the cache as well?

Questions 2:

How exactly does a device controller use direct memory access without using the CPU to schedule/move datum between the local buffer and main memory?

+3  A: 

Basic answer:

  1. The CPU registers are directly on the CPU. The L1, L2, and L3 caches are often on-chip; however, they may be shared between multiple cores or processors, so they're not always "physically on the CPU." However, they're never part of main memory either. The general principle is that the closer memory is to the CPU, the faster and more expensive (and thus smaller) it is. Every item in the cache has a particular main memory address associated with it (however, the same slot can be associated with different addresses at different times). However, there is no direct association between registers and main memory. That is why if you use the register keyword in C (not that it's often necessary, since the compiler is usually a better optimizer), you can not use the & operator.
  2. The DMA controller executes the transfer directly. The CPU watches the bus so it knows when changes are made "behind its back", which invalidate its cache(s).
Matthew Flaschen
Thanks, I am still having a little trouble 'visualizing' how the DMA controller does the transfer. I guess in my head the CPU is the mover/shaker and somehow not using it feels like some kind of black magic.
Google
Of course, it depends on the memory controller. But the DMA controller basically sends or receives data from memory using whatever protocol the memory requires.
Matthew Flaschen
A bus is just a bunch of wires that all devices connect to. Usually a device uses it to know what piece of information the CPU wants and for sending that info back. However, with permission from the CPU, it can do the asking itself. It's already connected to the bus, it just has to make sure the CPU isn't talking on it. That's DMA.
Karl Bielefeldt
Thanks, helps a lot!
Google
+1  A: 

Even though the CPU is the central processing unit, it's not the sole "mover and shaker". Devices live on buses, along with CPUs, and also RAM. Modern buses allow devices to communicate with RAM without involving the CPU. Some devices are programmed simply by making changes to pieces of RAM which devices poll. Device drivers may poll pieces of RAM that a device is writing into, but usually a CPU receives an interrupt from the device telling it that there's something in a piece of RAM that's ready to read.

So, in answer to your question 2, the CPU isn't involved in memory transfers across the bus, except inasmuch as cache coherence messages about the invalidation of cache lines are involved. Bear in mind that the scenarios are tricky. The CPU might have modified byte 1 on a cache line when a device decides to modify byte 40. Getting that dirty cache line out of the CPU needs to happen before the device can modify data, but on x86 anyway, that activity is initiated by the bus, not the CPU.

pgod
Thanks, that helps understand DMA a bit more.
Google