What happens in CPU, cache and memory when CPU is instructed to store data to memory?

Multi tool use
Multi tool use












0















Let's suppose the memory hierarchy is 1 cpu with L1i, L1d ,L2i L2d,L3, DRAM.



I'm wondering what happens at the lower levels of the computer when I use MOV/store instruction (or any other instruction that will cause CPU transfer data to memory)? I know what happens if there is just CPU and memory, but with the caches I'm a bit confused. I've searched for this, but it only yielded information about data transfer between:




  • registers and memory

  • CPU and cache,

  • cache and memory


I'm trying to understand more about this, like when cache will write through, when will write back? I just know write through is that update cache line and corresponding memory line immediately and write back is that update until replacement.Can they coexist? Is it the data will transfer directly to memory in write through? and in write back the data will through cache hierarchy?



What caused my confusion is that the Volatile in C/C++.As I known those type of variable will store in memory directly which means don’t through cache.Am I right? So what if I define a Volatile variable and a normal variable like int . how can the CPU distinguish that write directly to memory or through cache hierarchy.



Is there any instruction that can control cache? If not, how is cache
controlled? Some other hardware? OS? Cache controller(if such a thing exists)?










share|improve this question




















  • 1





    Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

    – Margaret Bloom
    Dec 30 '18 at 13:15











  • Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

    – tuffy chow
    Jan 1 at 12:44











  • MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

    – Margaret Bloom
    Jan 1 at 21:01
















0















Let's suppose the memory hierarchy is 1 cpu with L1i, L1d ,L2i L2d,L3, DRAM.



I'm wondering what happens at the lower levels of the computer when I use MOV/store instruction (or any other instruction that will cause CPU transfer data to memory)? I know what happens if there is just CPU and memory, but with the caches I'm a bit confused. I've searched for this, but it only yielded information about data transfer between:




  • registers and memory

  • CPU and cache,

  • cache and memory


I'm trying to understand more about this, like when cache will write through, when will write back? I just know write through is that update cache line and corresponding memory line immediately and write back is that update until replacement.Can they coexist? Is it the data will transfer directly to memory in write through? and in write back the data will through cache hierarchy?



What caused my confusion is that the Volatile in C/C++.As I known those type of variable will store in memory directly which means don’t through cache.Am I right? So what if I define a Volatile variable and a normal variable like int . how can the CPU distinguish that write directly to memory or through cache hierarchy.



Is there any instruction that can control cache? If not, how is cache
controlled? Some other hardware? OS? Cache controller(if such a thing exists)?










share|improve this question




















  • 1





    Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

    – Margaret Bloom
    Dec 30 '18 at 13:15











  • Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

    – tuffy chow
    Jan 1 at 12:44











  • MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

    – Margaret Bloom
    Jan 1 at 21:01














0












0








0








Let's suppose the memory hierarchy is 1 cpu with L1i, L1d ,L2i L2d,L3, DRAM.



I'm wondering what happens at the lower levels of the computer when I use MOV/store instruction (or any other instruction that will cause CPU transfer data to memory)? I know what happens if there is just CPU and memory, but with the caches I'm a bit confused. I've searched for this, but it only yielded information about data transfer between:




  • registers and memory

  • CPU and cache,

  • cache and memory


I'm trying to understand more about this, like when cache will write through, when will write back? I just know write through is that update cache line and corresponding memory line immediately and write back is that update until replacement.Can they coexist? Is it the data will transfer directly to memory in write through? and in write back the data will through cache hierarchy?



What caused my confusion is that the Volatile in C/C++.As I known those type of variable will store in memory directly which means don’t through cache.Am I right? So what if I define a Volatile variable and a normal variable like int . how can the CPU distinguish that write directly to memory or through cache hierarchy.



Is there any instruction that can control cache? If not, how is cache
controlled? Some other hardware? OS? Cache controller(if such a thing exists)?










share|improve this question
















Let's suppose the memory hierarchy is 1 cpu with L1i, L1d ,L2i L2d,L3, DRAM.



I'm wondering what happens at the lower levels of the computer when I use MOV/store instruction (or any other instruction that will cause CPU transfer data to memory)? I know what happens if there is just CPU and memory, but with the caches I'm a bit confused. I've searched for this, but it only yielded information about data transfer between:




  • registers and memory

  • CPU and cache,

  • cache and memory


I'm trying to understand more about this, like when cache will write through, when will write back? I just know write through is that update cache line and corresponding memory line immediately and write back is that update until replacement.Can they coexist? Is it the data will transfer directly to memory in write through? and in write back the data will through cache hierarchy?



What caused my confusion is that the Volatile in C/C++.As I known those type of variable will store in memory directly which means don’t through cache.Am I right? So what if I define a Volatile variable and a normal variable like int . how can the CPU distinguish that write directly to memory or through cache hierarchy.



Is there any instruction that can control cache? If not, how is cache
controlled? Some other hardware? OS? Cache controller(if such a thing exists)?







caching memory architecture operating-system cpu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 14:35









Mavi Domates

1,66511022




1,66511022










asked Dec 30 '18 at 12:35









tuffy chowtuffy chow

11




11








  • 1





    Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

    – Margaret Bloom
    Dec 30 '18 at 13:15











  • Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

    – tuffy chow
    Jan 1 at 12:44











  • MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

    – Margaret Bloom
    Jan 1 at 21:01














  • 1





    Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

    – Margaret Bloom
    Dec 30 '18 at 13:15











  • Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

    – tuffy chow
    Jan 1 at 12:44











  • MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

    – Margaret Bloom
    Jan 1 at 21:01








1




1





Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

– Margaret Bloom
Dec 30 '18 at 13:15





Yeah, the cache subsystem can be pretty complex in practice. Implementations details are often hard to find. A proper answer to your question will probably be too long so this site. Have you tried searching for a specific architecture? WB and WT can coexist in the sense that different mem regions can have different caching policy. I'd leave volatile completely out, it's hard to understand an a C++ concept anyway. You can try reading the Intel and AMD reference and optimisation manuals then search Google for specific terms.

– Margaret Bloom
Dec 30 '18 at 13:15













Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

– tuffy chow
Jan 1 at 12:44





Thanks for your advice,and i tried to search some specific architecture,but i just get something that are not what i wanted. Could you tell me what key words should i search that can find a description about specific architecture .Appreciate

– tuffy chow
Jan 1 at 12:44













MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

– Margaret Bloom
Jan 1 at 21:01





MIPS has many open implementations, you can Google along the lines "mips caches schematics" to get some results with an HW point of view. Removing "schematics" gives a more SW oriented POV. For x86 Googling "x86 cache lfb superqueue" for some implementation details. Eventually add "storebuffer". Information at the ISA level can be found in the manuals. In general googling "archname" + "cache hierarchy" (e.g. "arm cache hierarchy") is good starting point. Finally, patents are the last source of information if needed.

– Margaret Bloom
Jan 1 at 21:01












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977629%2fwhat-happens-in-cpu-cache-and-memory-when-cpu-is-instructed-to-store-data-to-me%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977629%2fwhat-happens-in-cpu-cache-and-memory-when-cpu-is-instructed-to-store-data-to-me%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







bwXQlNmi FoGoSxlWhGZCYxPA35Ef5 0,Kva4OVRXY00rB oeiO7stL
KZaS9M WNAZ PQnTc51qU2kkfE,6JynzpQoYE4v3 qAt9o7afm3w,LrYCqqLI95RA yv

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas