<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Memory ordering--MFENCE instruction in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861908#M2455</link>
    <description>&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;I have a question about memory ordering instructions that I hope you can help me with. I am reading the &lt;/FONT&gt;&lt;A href="http://developer.intel.com/products/processor/manuals/index.htm"&gt;&lt;FONT face="Arial" size="2"&gt;Intel 64 and IA32 architectures software developer manual&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Arial" size="2"&gt;, and the entry on the mfence instruction says that: "This serializing operation guarantees that every load and store instruction that precedes in program order the MFENCE instruction is globally visible before any load or store instruction that follows the MFENCE instruction is globally visible."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;Can you be more clear about the definition of "program order"? Does this mean instructions with lower or higher memory addresses relative to the mfence instruction, or does this mean the set of all load store instructions that have been executed previously in time on this processor?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;I know it seems like a dumb question, but let me give you some background to help you understand why I'm bothering to ask you. I have the following scenario: my application has one thread supplying data, as many threads as there are processors processing data (the operation is quite computationally intensive) and another thread writing data to a disk. I observed a mysterious and very difficult to reproduce error that I attributed to memory ordering. The behavior was consistent with one of my processing threads processing uninitialized buffer contents. Anyway, here (finally) is the point of my asking the original question: my data reading/supplying thread calls a function that takes a pointer and fills a buffer. Provided of course that I have done a thorough job of thread synchronization aside from this, does it suffice to place an mfence instruction after this function call to ensure that that buffer contents are reflected in main memory, or do I need to modify the buffer-filling function itself to include the mfence instruction?&lt;BR /&gt;Any feedback would be greatly appreciated. I really want to be clear since this problem is so very difficult to reproduce. It is hard for me to tell whether I've fixed it or not, since even an extensive test *before* the attempted fix was applied did not reproduce the behavior.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;Ok... that's it. Thank you so very much in advance for your time helping me and reading this long message.&lt;BR /&gt;Oh- and just for your reference, I am testing/developing on my Core 2 Duo T5600 processor.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jan 2008 04:00:26 GMT</pubDate>
    <dc:creator>postaquestion</dc:creator>
    <dc:date>2008-01-23T04:00:26Z</dc:date>
    <item>
      <title>Memory ordering--MFENCE instruction</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861908#M2455</link>
      <description>&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;I have a question about memory ordering instructions that I hope you can help me with. I am reading the &lt;/FONT&gt;&lt;A href="http://developer.intel.com/products/processor/manuals/index.htm"&gt;&lt;FONT face="Arial" size="2"&gt;Intel 64 and IA32 architectures software developer manual&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Arial" size="2"&gt;, and the entry on the mfence instruction says that: "This serializing operation guarantees that every load and store instruction that precedes in program order the MFENCE instruction is globally visible before any load or store instruction that follows the MFENCE instruction is globally visible."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;Can you be more clear about the definition of "program order"? Does this mean instructions with lower or higher memory addresses relative to the mfence instruction, or does this mean the set of all load store instructions that have been executed previously in time on this processor?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;I know it seems like a dumb question, but let me give you some background to help you understand why I'm bothering to ask you. I have the following scenario: my application has one thread supplying data, as many threads as there are processors processing data (the operation is quite computationally intensive) and another thread writing data to a disk. I observed a mysterious and very difficult to reproduce error that I attributed to memory ordering. The behavior was consistent with one of my processing threads processing uninitialized buffer contents. Anyway, here (finally) is the point of my asking the original question: my data reading/supplying thread calls a function that takes a pointer and fills a buffer. Provided of course that I have done a thorough job of thread synchronization aside from this, does it suffice to place an mfence instruction after this function call to ensure that that buffer contents are reflected in main memory, or do I need to modify the buffer-filling function itself to include the mfence instruction?&lt;BR /&gt;Any feedback would be greatly appreciated. I really want to be clear since this problem is so very difficult to reproduce. It is hard for me to tell whether I've fixed it or not, since even an extensive test *before* the attempted fix was applied did not reproduce the behavior.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;Ok... that's it. Thank you so very much in advance for your time helping me and reading this long message.&lt;BR /&gt;Oh- and just for your reference, I am testing/developing on my Core 2 Duo T5600 processor.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2008 04:00:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861908#M2455</guid>
      <dc:creator>postaquestion</dc:creator>
      <dc:date>2008-01-23T04:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Memory ordering--MFENCE instruction</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861909#M2456</link>
      <description>&lt;P&gt;Have you had a chance yet to look at volume 3A: System Programming Guide, Vol. 1? t&lt;/P&gt;
&lt;P&gt;The section on Memory Ordering (in my copy, section 7.2) explains how it works in the several processor generations.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2008 22:45:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861909#M2456</guid>
      <dc:creator>robert-reed</dc:creator>
      <dc:date>2008-01-28T22:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Memory ordering--MFENCE instruction</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861910#M2457</link>
      <description>&lt;P&gt;Another response relayed from a differentengineer:&lt;/P&gt;
&lt;BLOCKQUOTE dir="ltr"&gt;
&lt;DIV align="left"&gt;&lt;SPAN class="063515523-25012008"&gt;&lt;FONT face="Arial" color="#0000ff" size="2"&gt;&amp;gt; &lt;SPAN&gt;Can you be more clear about the definition of "program order"? Does this mean instructions with lower or higher memory addresses relative to the mfence instruction, or does this mean the set of all load store instructions that have been executed previously in time on this processor?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV align="left"&gt;&lt;SPAN class="063515523-25012008"&gt;&lt;FONT face="Arial" color="#0000ff" size="2"&gt;Program orderin this case isthetime order of accesses as performed by one thread of execution (i.e., as performed by one processor).&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;DIV align="left"&gt;&lt;SPAN class="063515523-25012008"&gt;&lt;FONT face="Arial" size="2"&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV align="left"&gt;&lt;SPAN class="063515523-25012008"&gt;&lt;FONT face="Arial" color="#000000" size="2"&gt;==&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV align="left"&gt;&lt;SPAN class="063515523-25012008"&gt;&lt;FONT face="Arial" color="#000000" size="2"&gt;
&lt;P class="MsoNormal"&gt;&lt;SPAN&gt;Lexi S.&lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal"&gt;&lt;SPAN&gt;IntelSoftware NetworkSupport&lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal"&gt;&lt;SPAN&gt;&lt;A href="http://www.intel.com/software"&gt;&lt;FONT color="#800080"&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;A href="http://www.intel.com/software" target="_blank"&gt;http://www.intel.com/software&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P class="MsoNormal"&gt;&lt;SPAN&gt;&lt;A href="http://www.intel.com/cd/ids/developer/asmo-na/eng/58987.htm"&gt;Contact us&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Jan 2008 00:19:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861910#M2457</guid>
      <dc:creator>Intel_Software_Netw1</dc:creator>
      <dc:date>2008-01-29T00:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Memory ordering--MFENCE instruction</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861911#M2458</link>
      <description>&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;Can I make an update/clarification to my original question? I have had some more thoughts about my problem and I've done some more reading and research. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;I've been reading the &lt;/FONT&gt;&lt;A href="http://www.intel.com/products/processor/manuals/318147.pdf"&gt;&lt;FONT face="Arial" size="2"&gt;Intel 64 Architecture Memory Ordering White Paper&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Arial" size="2"&gt;(document # 318147-001, August 2007) and I believe that I have run into undesirable behavior that essentially is the content of section 2.4, entitled "Intra-processor forwarding is allowed". I have the following scenario: one thread provides data to buffers, then as many threads as there are processors process this data (== 2 on my machine, a T5600 core 2 duo) and this process is quite computationally intensive. Finally, another thread writes the processed data out to a disk.&lt;BR /&gt;Anyway, I believe what happens is that once in a while, processed data is stuck in the L1 cache of the processor that is not running the writer thread, and then when the writer thread copies this buffer, it is not up to date. Or perhaps it is just speculative reading that has mis-ordered memory? Anyway, can anyone give me guidelines on the best way to fix this? I have a number of solutions in mind, but I am having a little trouble with ambiguity in the documentation. For example according to the &lt;A href="http://developer.intel.com/products/processor/manuals/index.htm"&gt;Intel 64 and IA-32 Architectures Software Developer's Manual&lt;/A&gt;, the MFENCE instruction orders both stores and loads. The manual says "This serializing operation guarantees that every load and store instruction that precedes in program order the MFENCE instruction is globally visible before any load or store instruction that follows the MFENCE instruction is globally visible." But when two processors are running in parallel I do not know what "program order"means. Does MFENCE only serialize only for the processor that it is executed on, or does it do more and guarantee that all stores and loads *from all processors* are globally visible before subsequent loads and stores? The question is, is MFENCE enough to fix this problem, or do I need to use CLFLUSH, surrounded by MFENCE instructions? Or is there even a solution at all when the buffers are of memory type WB? Any information would be greatly appreciated. Thanks in advance.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2008 00:26:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861911#M2458</guid>
      <dc:creator>postaquestion</dc:creator>
      <dc:date>2008-01-29T00:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Memory ordering--MFENCE instruction</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861912#M2459</link>
      <description>Thanks a lot for you help, everyone. I've done some very extensive tests now, and I think I have everything straight. Thanks again!&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 07:11:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Memory-ordering-MFENCE-instruction/m-p/861912#M2459</guid>
      <dc:creator>w_e_s</dc:creator>
      <dc:date>2008-01-30T07:11:58Z</dc:date>
    </item>
  </channel>
</rss>

