[Vm-dev] Tasks of the heartbeat code

Eliot Miranda eliot.miranda at gmail.com
Sun Sep 13 17:53:11 UTC 2015


Hi Holger,

> On Sep 13, 2015, at 10:37 AM, Holger Freyther <holger at freyther.de> wrote:
> 
> 
> Dear Eliot,
> 
> I tried to understand the basic load of the VM and I have two questions for the heartbeat
> code. Is it right that there are two concerns for the code?
> 
> 
> 1.) Call forceInterruptCheckFromHeartbeat periodically
> 
> 2.) Update the clock as seen by the image
> 
> 
> 1st is useful to interrupt Processes like […] repeat with a pre-emptive scheduler? On
> a different note do backwards jumps generate interrupt checks too?

Yes

> 2nd is this an optimization to not have to generate the clock when the primitive is being
> used?

Nearly.

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.

There is another use of the heartbeat in the threaded FFI.  When a call out releases the VM the heartbeat is used to detect that the VM is free and that another thread should attempt to run it.

Sent from my iPhone
> 
> thanks
>    holger


More information about the Vm-dev mailing list