<div dir="ltr">It&#39;s a bit more complicated and what platform you are on does matter. Just hunt in the squeak mailing list 10 years back for&nbsp;<span style="color:rgb(0,0,0);white-space:pre-wrap">getNextWakeupTick</span><div><br></div><div><font color="#000000"><span style="white-space:pre-wrap">Possibly the mac vm still calls&nbsp;getNextWakeupTick() which returns</span></font>&nbsp;the next time the VM has to wake up to service a delay pop.&nbsp;</div><div><font color="#000000"><span style="white-space:pre-wrap">Normally that is less than 1/50 of a second out due to the Morphic polling cycle, say 16 - 20 milliseconds. </span></font></div><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">The idea I had was to sleep until the VM needs to wakeup since when the&nbsp;</span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">ioRelinquishProcessorForMicroseconds  is made we know we can sleep and the VM knows exactly when the next time to wake up is. </span><span style="white-space:pre-wrap;color:rgb(0,0,0)">Unfortunately we have to deal with user interrupts (i/o sockets ui)</span></div><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div>Some platforms might use nanosleep() (<span style="color:rgb(0,0,0);white-space:pre-wrap">#if defined(HAVE_NANOSLEEP)) </span>which might wake when a socket interrupt arrives, but I&#39;ve never confirmed that.&nbsp; Anyway off then to call&nbsp;<span style="font-family:Menlo;font-size:11px">aioPoll()&nbsp;</span>where the bulk of the cpu is consumed. I note that obviously avoiding calling aioPoll() will affect socket performance of course.&nbsp;<div><a href="http://www.squeakvm.org/svn/squeak/branches/Cog/platforms/unix/vm/aio.c">http://www.squeakvm.org/svn/squeak/branches/Cog/platforms/unix/vm/aio.c</a><br><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">I note you can&#39;t properly calculate  next wakeup tick in smalltalk code due to the rather brittle code base in the Delay logic. Attempts I made a decade back always resulted in a deadlock situation, which is why that calculation is done in the VM. I had last taken a serious look at this back in 2010 and found very strange oddities such as calling </span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">ioRelinquishProcessorForMicroseconds yet a wakeup time is now, or in the past.. Obviously one needed to explore the stack traces to understand why no process was runnable, yet a process was scheduled to be woken... </span></div><div><br></div><div><font color="#000000"><span style="white-space:pre-wrap">Anyway compare </span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">ioRelinquishProcessorForMicroseconds</span></div><div><a href="http://www.squeakvm.org/svn/squeak/branches/Cog/platforms/iOS/vm/Common/Classes/sqMacV2Time.c">http://www.squeakvm.org/svn/squeak/branches/Cog/platforms/iOS/vm/Common/Classes/sqMacV2Time.c</a><br></div><div><br></div><div>Against whatever is being compiled for your target platform VM and what exactly&nbsp;<span style="color:rgb(0,0,0);white-space:pre-wrap">HAVE_NANOSLEEP is when the VM is compiled. </span></div><div><font color="#000000"><span style="white-space:pre-wrap">Also check idle CPU usage for say a OS X Squeak 4.2.5 VM against I&#39;m assume a unix vm flavor as you can run both on the same os-x machine for comparison using the same image/etc.</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 10, 2015 at 3:03 AM, Norbert Hartl <span dir="ltr">&lt;<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>Am 10.02.2015 um 11:23 schrieb Sven Van Caekenberghe &lt;<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>&gt;:</div><div><div><br><div><blockquote type="cite" style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>On 10 Feb 2015, at 11:19, Norbert Hartl &lt;<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>&gt; wrote:<br><br>Sven,<br><br><blockquote type="cite">Am 10.02.2015 um 10:36 schrieb Sven Van Caekenberghe &lt;<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>&gt;:<br><br><blockquote type="cite"><br>On 10 Feb 2015, at 09:51, Norbert Hartl &lt;<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>&gt; wrote:<br><br><br><blockquote type="cite">Am 10.02.2015 um 09:23 schrieb Clément Bera &lt;<a href="mailto:bera.clement@gmail.com" target="_blank">bera.clement@gmail.com</a>&gt;:<br><br>Hello,<br><br>About the Morphic rendering loop, the delay between rendering is handled in WorldState&gt;&gt;#interCyclePause:. The best solution to reduce the cost of the Morphic rendering loop is to put it in server mode by executing in Pharo: WorldState serverMode: true. In squeak you have to set that in the Preferences.<br><br></blockquote>I&#39;ll play with it and see what can be gained.<br></blockquote><br>I tried the following on an otherwise idle DigitalOcean VM running Ubuntu 13.10<br><br>$ mkdir pharo4<br>$ curl <a href="http://get.pharo.org/40+vm" target="_blank">get.pharo.org/40+vm</a> | bash<br>$ ./pharo Pharo.image save Server<br><br>First patch (slower event handling, extra delay of 50ms):<br><br>$ ./pharo Server.image eval --save &#39;WorldState serverMode: true&#39;<br><br>Second patch (give time back to OS while idle for 10ms instead of for 1ms):<br><br>$ cat ProcessorScheduler-class-idleProcess.st<span>&nbsp;</span><br>&#39;From Pharo4.0 of 18 March 2013 [Latest update: #40484] on 10 February 2015 at 9:49:15.412839 am!ProcessorScheduler class methodsFor: &#39;background process&#39; stamp: &#39;SvenVanCaekenberghe 2/10/2015idleProc[true] w[self relinquishProcessorForMicroseconds: 10000]! !<br><br>$ ./pharo Server.image eval &quot;&#39;ProcessorScheduler-class-idleProcess.st&#39; asFileReference fileIn&quot;<br>$ ./pharo Server.image eval &#39;(ProcessorScheduler class&gt;&gt;#idleProcess) sourceCode&#39;<br>&#39;idleProcess<br><span style="white-space:pre-wrap">        </span>&quot;A default background process which is invisible.&quot;<br><br><span style="white-space:pre-wrap">        </span>[true] whileTrue:<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>[self relinquishProcessorForMicroseconds: 10000]&#39;<br><br>Run an image with a basic Zn HTTP server in background:<br><br>$ ./pharo Server.image eval --no-quit &#39;ZnServer startDefaultOn: 1701&#39; &amp;<br>$ curl <a href="http://localhost:1701" target="_blank">http://localhost:1701</a><br><br>Overall load is 0.01% but this is virtual/shared hardware, so who knows.<br><br>CPU load of the pharo process hovers around a couple of %, I am not seeing much difference, maybe it is a bit lower, but that might be wishful thinking.<br><br></blockquote>my findings are similar. I have a CPU usage of 6%. WorldState serverMode adds a Delay for 50ms. Setting a higher number in the idle process does not seem to have any effect until the number is too high, then the image does not start anymore.<span>&nbsp;</span><br>I tuned all of these things and it is not faster sometimes it appears to take more CPU which probably is not true.<span>&nbsp;</span><br></blockquote><br style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I am afraid that we as a community do not fully understand what is happening or how we can control it.</span><br style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">On the other hand, on a machine with many images running, things are still totally fine, so we should not worry too much. It is only in specific case like yours where it becomes a concern.</span><br style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></div></div></blockquote>I can say that&nbsp;</div><div><br></div><div>pharo-vm-nox --noevents --nohandlers &nbsp;--notimer --headless -vm-sound-null /opt/nted/image/NTed.image --no-quit eval &quot;RFBServer stop; reset. ZnServer managedServers do: #stop. UIManager default uiProcess suspend. WorldState serverMode: true. ProcessorScheduler class compile: &#39;idleProcess&#39;,String cr,&#39;[true] whileTrue: [self relinquishProcessorForMicroseconds: 10000]&#39;. ProcessorScheduler startUp&quot;</div><div><br></div><div>does not make a difference at all. My assumption here is to switch everything off, don&#39;t use sockets, try to sleep as much as possible. But&hellip;.nothing.&nbsp;</div><div><div><div><br></div><div>Norbert</div><div><br><blockquote type="cite"><div><blockquote type="cite" style="font-family:HelveticaNeue;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">But as it was discussed, the cpu consumption most probably does not come from Morphic but comes from the idle loop, which can be solved by doing an event-driven VM.<span>&nbsp;</span><br><br>I am particularly willing to have an event-driven VM because it then means that the VM performance would then be directly proportional to the cpu consumption. For example, theoretically, with an event-driven VM, having the VM twice faster with Spur would also mean that the VM consumes twice less energy. Go Green IT :-)<br><br></blockquote>That is exactly my point. While consumed energy is turned into heat the act of saving energy is the same as having a cool device (pun intended).<span>&nbsp;</span><br><br>So I would like to take my consortium hat to state my upvote on this.<br><br>Norbert<br><br><blockquote type="cite">2015-02-10 8:00 GMT+01:00 Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;:<br><br><br><br>On Feb 9, 2015, at 10:41 PM, Sven Van Caekenberghe &lt;<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>&gt; wrote:<br><br><blockquote type="cite"><br><blockquote type="cite">On 10 Feb 2015, at 01:55, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt; wrote:<br><br>Hi Sven,<br><br>On Mon, Feb 9, 2015 at 1:43 PM, Sven Van Caekenberghe &lt;<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>&gt; wrote:<br>There is some timer thread between the image and the vm that ticks every millisecond, that is the cause. I don&#39;t know what it does but it is apparently needed.<br><br>Anyway, that is how I understood it from Igor and Eliot, long ago.<br><br>So basically, the VM is always slightly busy.<br><br>Yet the VM is always slightly busy with the heartbeat thread, but this is very cheap.&nbsp; The actual idle cost comes form the idle loop in the background process that sends relinquishProcessorForMicroseconds:, which is a primitive that eventually calls the select system call.&nbsp; This is the source of the cost.<br></blockquote><br>Can we change something about that ?<br>Maybe just as an experiment to prove your point ?<br></blockquote><br>What do you think halving or doubling the argument to relinquishProcessorForMicroseconds: should do if this is the major source of overhead?&nbsp; Processor usage at idle should be closely inversely proportional right?<br><br><blockquote type="cite"><br><blockquote type="cite"><blockquote type="cite">On 09 Feb 2015, at 21:11, Norbert Hartl &lt;<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>&gt; wrote:<br><br>I have an installation where a pharo powered hardware is used in a closed case. Over time that collects quite some heat. One reason for this is that the pharo vm is taking approx. 6% CPU all the time. The only thing that happens is network/sockets. I suspended the ui thread in the image but on this platform it doesn&#39;t help.<br>Are there any tweaks to lower the polling and the activity of the image/vm even more?<br><br>thanks,<br><br>Norbert<br></blockquote>--<br>best,<br>Eliot</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></div></blockquote></div><br></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">===========================================================================<br>John M. McIntosh &lt;<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.com</a>&gt;&nbsp;<a href="https://www.linkedin.com/in/smalltalk" target="_blank">https://www.linkedin.com/in/smalltalk</a><br>===========================================================================<br></div></div>
</div></div></div>