[Vm-dev] Tasks of the heartbeat code

Holger Freyther holger at freyther.de
Sun Sep 13 20:00:53 UTC 2015


> On 13 Sep 2015, at 19:53, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> 


> Hi Holger,

Hi!

thank you for the super quick reply!


> 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.
> 
> 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's probably a good default choice.  It does lessen the case for doing this at all though. That's an experiment that I'm interested in the results of.


can you think of a strategy to stop the timer when nothing is running inside the
image? I see getNextWakeupUsecs in ioRelinquishProcessorForMicroseconds
but that does’t seem to disable the interval timer? E.g. if I look at the mac vm
and ioRelinquishProcessorForMicroseconds it doesn’t appear to stop the itimer?


I am looking at this from the aioPoll/SIGIO point of view. I was surprised how close
we are to have a system that doesn’t consume CPU when nothing is running. Maybe
there is something I am missing (I don’t know win32) but if the IdleProcess starts to
run the system could:

	* Stop the heartbeat timer
	* Have the mac variant of ioRelinquishProcessorForMicroseconds for unix
	  and  get the time the next Delay expires.
	* Set the heartbeat to expire at this time?
	* Yield execution and wait for the SIGIO (or the timer)?
	* On return to the image call aioPoll if the SIGIO occurred?


Is there any general objection to this?



kind regards
	holger


More information about the Vm-dev mailing list