[Vm-dev] Tasks of the heartbeat code

Eliot Miranda eliot.miranda at gmail.com
Mon Sep 14 20:43:26 UTC 2015


Hi Holger,

On Sun, Sep 13, 2015 at 1:00 PM, Holger Freyther <holger at freyther.de> wrote:

>
>
> > 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?
>

You've read what John has said.  I think the easiest thing to do is not to
stop and start the heartbeat thread, but merely to set a flag when entering
ioRelinquishProcessorForMicroseconds, clearing it on exit, and have the
heartbeat test this flag before doing anything that could disturb the VM
thread(s).  The overhead of the heartbeat thread is very low.  It doesn't
call select or anything like that.  All it does is spin, calling nanosleep,
polling the clock and then setting a variable.  For example, avoiding
polling the clock when in ioRelinquishProcessorForMicroseconds might save a
few cycles.


> 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
>

or set the flag that gets it to do nothing.  It may be more efficient to
set this flag an have it tested than stop and start the heartbeat thread.


>         * Have the mac variant of ioRelinquishProcessorForMicroseconds for
> unix
>           and  get the time the next Delay expires.
>         * Set the heartbeat to expire at this time?
>

Make sure that the blocking call to poll or whatever will time out at or
shortly before the next delay expiry.

        * Yield execution and wait for the SIGIO (or the timer)?
>         * On return to the image call aioPoll if the SIGIO occurred?
>

I think blocking in epoll and the like is the right approach.  That gives
control to the kernel for the most efficient possible wait state.

Is there any general objection to this?
>

Absolutely not.  Quite the opposite.  It would be great to see the VM block
efficiently.  Great to have your energy!!  Thank you!



> kind regards
>         holger


_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150914/e0a39b0c/attachment.htm


More information about the Vm-dev mailing list