Replying to mine and John&#39;s suggestion of moving the pump to the VM&#39;s check event loop.<br><br><div class="gmail_quote">On Wed, Feb 3, 2010 at 9:31 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div>[snip]</div><div>I think one interim solution to explore is to run the sound pump from the VM thread in the VM&#39;s check for events code.  In the Cog VMs a 1KHz heartbeat updates the wall clock and causes the VM to break out of native code and check for events (ideally the heartbeat is a separate thread).  An mentioned, on linux the heartbeat is a software signal from an interval timer.  The software interrupt serves also to interrupt any system calls (e.g. in relinquishProcessorForMilliseconds).  I can extend the heartbeat to set a flag saying &quot;run the sound pump&quot; which will be checked by the VM when checking for events and it will invoke the sound pump code.  The problem here is that any long-running activities that aren&#39;t interruptable by the software interrupt (OpenGL rendering?) will delay the sound pump.  So this is either doomed to failure or might just work depending on those other activities.  Comments?  Try it, waste of time?</div>
</div></blockquote><div><br></div>Obvious really, but this can&#39;t work.  See below.</div><div class="gmail_quote"><br><div class="gmail_quote">On Wed, Feb 3, 2010 at 9:44 PM, John M McIntosh <span dir="ltr">&lt;<a href="mailto:johnmci@smalltalkconsulting.com">johnmci@smalltalkconsulting.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
 <br><div style="word-wrap: break-word; ">Well mmm doesn&#39;t the checkForInterrupts code get called every 1 millisecond (or there about?)  <div><div>Can&#39;t you add something there to ensure your sound logic doesn&#39;t starve.</div>
<div><br></div><div>Hint if <span style="font-family: Menlo; font-size: 11px; ">checkForInterrupts is not being called every ms or so how do you ensure delay accuracy is to a ms boundary? </span></div></div></div></blockquote>
<div><br></div><div>There is no guarantee that checkForInterrupts is being called every millisecond.  There is only a guarantee that the VM will be asked to checkForInterrupts every millisecond.  It will actually check as soon as it next checks.  So if it is in a long-running primitive, or more importantly a full garbage collection it will check when this has finished.  The GC pauses are the killer.  For us every now and then there is a &gt;100ms pause for GC and so the sound pump will occasionally be starved.</div>
<div><br></div><div>Essentially the sound pump has to run as an interrupt or in another thread.</div><div><br></div><div>I am going to try one horrible hack.  Right now the deadlock I&#39;m seeing is in the sound pump&#39;s logging code that calls ctime_r to grab an ascii string of the local time to timestamp log entries.  The VM can keep a copy of ctime_r&#39;s result and update it synchronously every second or so, instead of calling ctime_r on every log entry.  This won&#39;t remove the possibility of lock-up due to other library calls, but it may reduce the probability low enough that our alpha demo will work sufficiently and give us time to work on a proper solution (i.e. investigating Bert&#39;s direction to improved linux schedulers) after the demo.</div>
<div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 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; "><div><div><font face="Menlo" size="3"><span style="font-size: 11px; "><br></span></font></div><div><font face="Menlo" size="3"><span style="font-size: 11px; ">next hint if checkForInterrupts is being called 10 times a millisecond then isn&#39;t that wasteful, should you be grinding smalltalk bytecodes or assembler instructions there of? </span></font></div>
</div></div></blockquote></div><div> </div></div>