<div dir="ltr">It's a bit more complicated and what platform you are on does matter. Just hunt in the squeak mailing list 10 years back for <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 getNextWakeupTick() which returns</span></font> the next time the VM has to wake up to service a delay pop. </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 </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've never confirmed that. Anyway off then to call <span style="font-family:Menlo;font-size:11px">aioPoll() </span>where the bulk of the cpu is consumed. I note that obviously avoiding calling aioPoll() will affect socket performance of course. <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'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 <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'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"><<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>></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 <<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>>:</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 <<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>> wrote:<br><br>Sven,<br><br><blockquote type="cite">Am 10.02.2015 um 10:36 schrieb Sven Van Caekenberghe <<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>>:<br><br><blockquote type="cite"><br>On 10 Feb 2015, at 09:51, Norbert Hartl <<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>> wrote:<br><br><br><blockquote type="cite">Am 10.02.2015 um 09:23 schrieb Clément Bera <<a href="mailto:bera.clement@gmail.com" target="_blank">bera.clement@gmail.com</a>>:<br><br>Hello,<br><br>About the Morphic rendering loop, the delay between rendering is handled in WorldState>>#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'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 'WorldState serverMode: true'<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> </span><br>'From Pharo4.0 of 18 March 2013 [Latest update: #40484] on 10 February 2015 at 9:49:15.412839 am!ProcessorScheduler class methodsFor: 'background process' stamp: 'SvenVanCaekenberghe 2/10/2015idleProc[true] w[self relinquishProcessorForMicroseconds: 10000]! !<br><br>$ ./pharo Server.image eval "'ProcessorScheduler-class-idleProcess.st' asFileReference fileIn"<br>$ ./pharo Server.image eval '(ProcessorScheduler class>>#idleProcess) sourceCode'<br>'idleProcess<br><span style="white-space:pre-wrap">        </span>"A default background process which is invisible."<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]'<br><br>Run an image with a basic Zn HTTP server in background:<br><br>$ ./pharo Server.image eval --no-quit 'ZnServer startDefaultOn: 1701' &<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> </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> </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 </div><div><br></div><div>pharo-vm-nox --noevents --nohandlers --notimer --headless -vm-sound-null /opt/nted/image/NTed.image --no-quit eval "RFBServer stop; reset. ZnServer managedServers do: #stop. UIManager default uiProcess suspend. WorldState serverMode: true. ProcessorScheduler class compile: 'idleProcess',String cr,'[true] whileTrue: [self relinquishProcessorForMicroseconds: 10000]'. ProcessorScheduler startUp"</div><div><br></div><div>does not make a difference at all. My assumption here is to switch everything off, don't use sockets, try to sleep as much as possible. But….nothing. </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> </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> </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 <<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>>:<br><br><br><br>On Feb 9, 2015, at 10:41 PM, Sven Van Caekenberghe <<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>> wrote:<br><br><blockquote type="cite"><br><blockquote type="cite">On 10 Feb 2015, at 01:55, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>> wrote:<br><br>Hi Sven,<br><br>On Mon, Feb 9, 2015 at 1:43 PM, Sven Van Caekenberghe <<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>> wrote:<br>There is some timer thread between the image and the vm that ticks every millisecond, that is the cause. I don'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. 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. 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? 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 <<a href="mailto:norbert@hartl.name" target="_blank">norbert@hartl.name</a>> 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'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 <<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.com</a>> <a href="https://www.linkedin.com/in/smalltalk" target="_blank">https://www.linkedin.com/in/smalltalk</a><br>===========================================================================<br></div></div>
</div></div></div>