[Vm-dev] Tasks of the heartbeat code

Holger Freyther holger at freyther.de
Wed Jul 27 14:35:56 UTC 2016

> On 01 Jan 2016, at 18:33, Holger Freyther <holger at freyther.de> wrote:

Good Evening Eliot, all,

I had to wait quite some time for my next flight and looked a bit at the more modern builtin atomic support.

>> -	if (((now = ioUTCMicroseconds())) >= GIV(nextPollUsecs)) {
>> +
>> +	if (doDispatch) {
>> +		doDispatch = 0;
>> 		GIV(statIOProcessEvents) += 1;
>> 		ioProcessEvents();
>> -
>> -		/* msecs to wait before next call to ioProcessEvents.  Note that strictly
>> -		   speaking we might need to update 'now' at this point since
>> -		   ioProcessEvents could take a very long time on some platforms */
>> -		GIV(nextPollUsecs) = now + 20000;
>> 	}
>> +	now = ioUTCMicroseconds();
>> 	if (GIV(interruptPending)) {
> could you please help me with getting the above right and help me to get it into the
> VMMaker? I wonder which atomic interface to use between the aioPoll code and
> the VMMaker without breaking the Windows/OSX build right now.
> 1.) I think I don't want the time based polling but only if something has happened

I think this still holds true. If we miss a SIGIO event I want it to fail miserably instead of being lucky by a periodic fix-up. :)

> 2.) In the SIGIO signal handler I will need to register an event. I'm wondering if I
> want to use:
> 	__sync_fetch_and_add 	to count the number of SIGIOs not handled?
> 	otherwise the classic loop with __sync_bool_compare_and_swap?

Unless I am completely tired I think we are fine with an atomic store of '1'

void sigIO_handler(int sig)
	__atomic_store_n(&doDispatch, 1, __ATOMIC_RELAXED)

> 3.) In the VMMaker and only if the SIGIO interface is present. I think I need to use
> sqCompareAndSwap to try to read the number of events?

A simple exchange seems to do?

void check_event()
	uint32_t should_dispatch;
	should_dispatch = __atomic_exchange_n(&doDispatch, 0, __ATOMIC_RELAXED);
	if (should_dispatch)

The integration into VMMaker and display interface is probably going to be more involved. I will try to hack together a "current" idle vm with these primitives.

kind regards

More information about the Vm-dev mailing list