<p>By the way, only thing I can think of as being a possible issue is the pause instruction killing (or reducing) out of order/pipelined execution of the rest of the loop body.  But then I don&#39;t know if this is such an issue as the loop exit will probably have a branch misprediction anyway, killing whatever is in the pipeline.</p>

<p>At any rate, would be interesting to see an explanation.</p>
<p>Cheers</p>
<p>Sent from my phone</p>
<div class="gmail_quote">On Aug 29, 2012 8:23 AM, &quot;Vitaly Davidovich&quot; &lt;<a href="mailto:vitalyd@gmail.com">vitalyd@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>I&#39;m actually curious to know if Eric can explain a bit more why pause is an issue here, possibly with some benchmark results.</p>
<p>David&#39;s point earlier was that he doesn&#39;t think there&#39;s benefit to it in the way hotspot spins, but removing pause implies it can actually do harm rather than simply being unhelpful.</p>
<p>I&#39;m also assuming this is not AMD specific but Intel as well?</p>
<p>Thanks</p>
<p>Sent from my phone</p>
<div class="gmail_quote">On Aug 29, 2012 8:04 AM, &quot;Peter Levart&quot; &lt;<a href="mailto:peter.levart@marand.si" target="_blank">peter.levart@marand.si</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Here&#39;s an interesting explanation about the impact of pause instruction in spin-wait loops:<br>
<br>
<a href="http://software.intel.com/en-us/articles/long-duration-spin-wait-loops-on-hyper-threading-technology-enabled-intel-processors/" target="_blank">http://software.intel.com/en-us/articles/long-duration-spin-wait-loops-on-hyper-threading-technology-enabled-intel-processors/</a><br>


<br>
4 years later: It may be that newer CPUs are more clever now.<br>
<br>
Regards, Peter<br>
<br>
On Tuesday, August 28, 2012 11:36:23 AM Eric Caspole wrote:<br>
&gt; Hi everybody,<br>
&gt; I have made a webrev making a one-line change to remove use of PAUSE<br>
&gt; in linux x64. This will bring linux into sync with windows where<br>
&gt; SpinPause is just &quot;return 0&quot; as Dan indicates below.<br>
&gt;<br>
&gt;   <a href="http://cr.openjdk.java.net/~ecaspole/nopause/webrev.00/webrev/" target="_blank">http://cr.openjdk.java.net/~ecaspole/nopause/webrev.00/webrev/</a><br>
&gt;<br>
&gt; We find that it is better not to use PAUSE in this kind of spin<br>
&gt; routine. Apparently someone discovered that on windows x64 years ago.<br>
&gt; Thanks,<br>
&gt; Eric<br>
&gt;<br>
&gt; On Aug 16, 2012, at 5:07 PM, Daniel D. Daugherty wrote:<br>
&gt; &gt; On Win64, SpinPause() has been &quot;return 0&quot; since mid-2005. Way back<br>
&gt; &gt;<br>
&gt; &gt; when Win64 code was in os_win32_amd64.cpp:<br>
&gt; &gt;     SCCS/s.os_win32_amd64.cpp:<br>
&gt; &gt;<br>
&gt; &gt;     D 1.9.1.1 05/07/04 03:20:45 dice 12 10  00025/00000/00334<br>
&gt; &gt;     MRs:<br>
&gt; &gt;     COMMENTS:<br>
&gt; &gt;     5030359 -- back-end synchonization improvements - adaptive<br>
&gt; &gt;<br>
&gt; &gt; spinning, etc<br>
&gt; &gt;<br>
&gt; &gt; When the i486 and amd64 cpu dirs were merged back in 2007, the code<br>
&gt; &gt;<br>
&gt; &gt; became like it is below (#ifdef&#39;ed):<br>
&gt; &gt;     D 1.32 07/09/17 09:11:33 sgoldman 37 35 00264/00008/00218<br>
&gt; &gt;     MRs:<br>
&gt; &gt;     COMMENTS:<br>
&gt; &gt;     5108146 Merge i486 and amd64 cpu directories.<br>
&gt; &gt;     Macro-ized register names. Inserted amd64 specific code.<br>
&gt; &gt;<br>
&gt; &gt; Looks like on Linux-X64, the code has used the PAUSE instruction<br>
&gt; &gt;<br>
&gt; &gt; since mid-2005:<br>
&gt; &gt;     D 1.3 05/07/04 03:14:09 dice 4 3        00031/00000/00353<br>
&gt; &gt;     MRs:<br>
&gt; &gt;     COMMENTS:<br>
&gt; &gt;     5030359 -- back-end synchonization improvements - adaptive<br>
&gt; &gt;<br>
&gt; &gt; spinning, etc<br>
&gt; &gt;<br>
&gt; &gt; We&#39;ll have to see if Dave Dice remember why he implemented<br>
&gt; &gt; it this way...<br>
&gt; &gt;<br>
&gt; &gt; Dan<br>
&gt; &gt;<br>
&gt; &gt; On 8/16/12 12:01 PM, Eric Caspole wrote:<br>
&gt; &gt;&gt; Hi everybody,<br>
&gt; &gt;&gt; Does anybody know the reason why SpinPause is simply &quot;return 0&quot; on<br>
&gt; &gt;&gt; Win64 but uses PAUSE on Linux in a .s file?<br>
&gt; &gt;&gt; We would like to remove PAUSE from linux too.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Thanks,<br>
&gt; &gt;&gt; Eric<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; ./src/os_cpu/windows_x86/vm/os_windows_x86.cpp<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;     548 extern &quot;C&quot; int SpinPause () {<br>
&gt; &gt;&gt;     549 #ifdef AMD64<br>
&gt; &gt;&gt;     550    return 0 ;<br>
&gt; &gt;&gt;     551 #else<br>
&gt; &gt;&gt;     552    // pause == rep:nop<br>
&gt; &gt;&gt;     553    // On systems that don&#39;t support pause a rep:nop<br>
&gt; &gt;&gt;     554    // is executed as a nop.  The rep: prefix is ignored.<br>
&gt; &gt;&gt;     555    _asm {<br>
&gt; &gt;&gt;     556       pause ;<br>
&gt; &gt;&gt;     557    };<br>
&gt; &gt;&gt;     558    return 1 ;<br>
&gt; &gt;&gt;     559 #endif // AMD64<br>
&gt; &gt;&gt;     560 }<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; src/os_cpu/linux_x86/vm/linux_x86_64.s<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;      63         .globl SpinPause<br>
&gt; &gt;&gt;      64         .align 16<br>
&gt; &gt;&gt;      65         .type  SpinPause,@function<br>
&gt; &gt;&gt;      66 SpinPause:<br>
&gt; &gt;&gt;      67         rep<br>
&gt; &gt;&gt;      68         nop<br>
&gt; &gt;&gt;      69         movq   $1, %rax<br>
&gt; &gt;&gt;      70         ret<br>
</blockquote></div>
</blockquote></div>