Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is difficult to tell whether this is a bug or just normal timer variation between cores.</p> <p>An experiment you could try is to use native calls to force the thread to run on a specific core.</p> <p>Also, to rule out power management effects, try spinning in a loop as an alternative to <code>sleep()</code>:</p> <pre><code>import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.W32API; public class AffinityTest { private static void testNanoTime(boolean sameCore, boolean spin) throws InterruptedException { W32API.HANDLE hThread = kernel.GetCurrentThread(); final long sleepMillis = 5000; kernel.SetThreadAffinityMask(hThread, new NativeLong(1L)); Thread.yield(); long nanosBefore = System.nanoTime(); long millisBefore = System.currentTimeMillis(); kernel.SetThreadAffinityMask(hThread, new NativeLong(sameCore? 1L: 2L)); if (spin) { Thread.yield(); while (System.currentTimeMillis() - millisBefore &lt; sleepMillis) ; } else { Thread.sleep(sleepMillis); } long nanosTaken = System.nanoTime() - nanosBefore; long millisTaken = System.currentTimeMillis() - millisBefore; System.out.println("nanosTaken="+nanosTaken); System.out.println("millisTaken="+millisTaken); } public static void main(String[] args) throws InterruptedException { System.out.println("Sleeping, different cores"); testNanoTime(false, false); System.out.println("\nSleeping, same core"); testNanoTime(true, false); System.out.println("\nSpinning, different cores"); testNanoTime(false, true); System.out.println("\nSpinning, same core"); testNanoTime(true, true); } private static final Kernel32Ex kernel = (Kernel32Ex) Native.loadLibrary(Kernel32Ex.class); } interface Kernel32Ex extends Kernel32 { NativeLong SetThreadAffinityMask(HANDLE hThread, NativeLong dwAffinityMask); } </code></pre> <p>If you get very different results depending on core selection (e.g. 5000ms on the same core but 2200ms on different cores) that would suggest that the problem is just natural timer variation between cores.</p> <p>If you get very different results from sleeping vs. spinning, it is more likely due to power management slowing down the clocks.</p> <p>If <em>none</em> of the four results are close to 5000ms, then it might be a bug.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload