3
$\begingroup$

Regarding CPU cache, if the CPU does not find the data it needs in the cache, I understand it then looks for it in the main memory (RAM). (Let's assume we have only one level of cache in order to keep this question as simple as possible.)

My question is this: if the data is found in main memory, what happens? Does the processor use this data directly, or is the data loaded into the cache and then read from there?

$\endgroup$
  • 1
    $\begingroup$ It depends on the CPU. I would say that, generally, data is forwarded directly to the core while the cache is updated, particularly when the CPU/cache supports misaligned bursts. $\endgroup$ – TEMLIB Jun 12 '17 at 19:18
  • $\begingroup$ "Early restart" has been used to describe the feature of unstalling execution when the requested access is available but before the cache block has become fully available (often combined with "critical word first"). $\endgroup$ – Paul A. Clayton Jun 13 '17 at 2:38
2
$\begingroup$

Nobody can say what every computer will do, but there are some reasonable assumptions.

When you access data that is not in the cache, you want it to be in the cache afterwards. So the CPU will read the data from memory, and move it to the cache. That's one half of the job.

There is some part of the CPU that needs the data, and we want to get the data to that part of the CPU as fast and as cheap as possible. There is already a mechanism in place to provide the data if it is in the cache. So the CPU could just move the data to the cache, then use the existing mechanism. That's cheap and easy.

Or the CPU can move data from memory to the place where it is needed either simultaneously with the cache, or even before the data is moved to the cache. That has the advantage that the data may appear a little bit faster where it is needed. It has the disadvantage that now the two situations (in cache, not in cache) need to be handled by different hardware. That is likely more complicated and more expensive.

Which one is chosen depends on how much quicker the more complicated method is, how much it costs more, and how much the cost is compared to other possible improvements.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.