<div dir="ltr">I looked at this six years back and altered the code base to pause the heart beat thread  until we know when we have to wakeup . <div><br></div><div>Results were inclusive, so more testing is welcome. </div><div><br></div><div>(a) how much overhead is there to pause and wakeup the thread? If you sleep for 2 ms, is it worth it? </div><div>(b) because of the morphic polling look we are woken every 16-20 milliseconds. </div><div>(c) There is a race? between what the VM thinks the next wakeup time, and what the <span style="font-size:13px">ioRelinquishProcessorForMicros</span><span style="font-size:13px">econds is expected. </span></div><div>Sometimes you are asked to sleep, yet the internal VM timer says you should wakeup to service a task right now or a millisecond in the past. Yet the VM had decided there was no runable tasks just microseconds ago. </div><div><br></div><div>(d) Do mouse/trackpad/keyboard/socket/FD events actually awake the paused program? </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 13, 2015 at 1:00 PM, Holger Freyther <span dir="ltr">&lt;<a href="mailto:holger@freyther.de" target="_blank">holger@freyther.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
&gt; On 13 Sep 2015, at 19:53, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;<br>
<br>
<br>
&gt; Hi Holger,<br>
<br>
Hi!<br>
<br>
thank you for the super quick reply!<br>
<span class=""><br>
<br>
&gt; You are correct for #1.  The main use is 1.  To cause a breakout from machine code at regular intervals (default every 2ms).  Backward jumps also perform the test.  Using counters instead does not work well; counters are expensive to update in every send and the frequency of breakout varies wildly depending on whether one is calling code containing slow primitives (eg LargeIntegerArithmetic) or not.<br>
&gt;<br>
&gt; For 2, getting the heartbeat to update the clock is for delay expiry.  Fetching the time is slow, and delays need only have about a millisecond resolution.  So having the heartbeat update the clock saves time when seeing if the active delay has fired.  At first it was used also to update the time seen through the time primitives but Dave had me change it.  This gives you much better (microsecond) clock resolution at the cost of a slower primitive.  That&#39;s probably a good default choice.  It does lessen the case for doing this at all though. That&#39;s an experiment that I&#39;m interested in the results of.<br>
<br>
<br>
</span>can you think of a strategy to stop the timer when nothing is running inside the<br>
image? I see getNextWakeupUsecs in ioRelinquishProcessorForMicroseconds<br>
but that does’t seem to disable the interval timer? E.g. if I look at the mac vm<br>
and ioRelinquishProcessorForMicroseconds it doesn’t appear to stop the itimer?<br>
<br>
<br>
I am looking at this from the aioPoll/SIGIO point of view. I was surprised how close<br>
we are to have a system that doesn’t consume CPU when nothing is running. Maybe<br>
there is something I am missing (I don’t know win32) but if the IdleProcess starts to<br>
run the system could:<br>
<br>
        * Stop the heartbeat timer<br>
        * Have the mac variant of ioRelinquishProcessorForMicroseconds for unix<br>
          and  get the time the next Delay expires.<br>
        * Set the heartbeat to expire at this time?<br>
        * Yield execution and wait for the SIGIO (or the timer)?<br>
        * On return to the image call aioPoll if the SIGIO occurred?<br>
<br>
<br>
Is there any general objection to this?<br>
<br>
<br>
<br>
kind regards<br>
<span class="HOEnZb"><font color="#888888">        holger</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">===========================================================================<br>John M. McIntosh. Corporate Smalltalk Consulting Ltd <a href="https://www.linkedin.com/in/smalltalk" target="_blank">https://www.linkedin.com/in/smalltalk</a><br>===========================================================================<br></div></div></div></div>
</div>