<br><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:0 0 0 .8ex;border-left:1px #ccc 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><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><br></div><div>Damn right :)  But it is only called at a maximum of once every millisecond or two (I think 2ms is an adequate delay resolution). On current machines one can&#39;t run the heartbeat at much more than 100 usecs because thats how long it takes each heartbeat (which does a thread switch, updates the clock and sets some flags).</div>
<div><br></div><div>Of course Cog is grinding out those bytecodes a lot faster than the normal Squeak VM so a 500Hz heartbeat is reasonably affordable :)</div><div><br></div><div>Perhaps I should explain how this works in Cog.  Cog does not call checkForInterrupts in normal processing of bytecodes.  Instead it checks the stack limit on every frame-building send (i.e. not quick methods that answer constants &amp; inst vars, and not primitives that succeed).  It has to check the stack limit because the VM runs Smalltalk code on small stack pages (~64 pages, 4k bytes each), &quot;paging out&quot; a stack page worth of frames to heap contexts when there is no free page available.  When stack overflow occurs it breaks out of machine code to handle the switch from the current stack page to a new one, and as part of that processing it checks for events.  The heartbeat works by setting the stack limit to a value that will cause all stack limit checks to fail (this being 16rFFFFFFFF because stacks grow down).</div>
<div><br></div><div>The HotSpot Java VM uses a similar technique, but their stacks are not organized as pages (because Java doesn&#39;t have contexts one can map the java stack to a native thread stack quite easily, whereas the paged organization works well for marrying contexts and stack frames).  On frame build they write to a location on a guard page.  Since there is no load dependency for a write the write doesn&#39;t stall the processor.  When they want to break out of Java machine code they remove write permission from the page and handle the protection violation exception.  Of course this only works on systems where changing a page&#39;s protection is very cheap compared to the breakout frequency.  It wouldn&#39;t work for a 1Khz beat; you&#39;d spend all of your time twiddling page protections.  But a neat technique all the same.</div>
<div><br></div><div>best</div><div>Eliot</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 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><br></div><div><div><div>On 2010-02-03, at 6:01 PM, Eliot Miranda wrote:</div><br><blockquote type="cite"><div><span style="white-space:pre">        </span>I&#39;ve been trying to get our sound framework going on linux and have got stuck.  I wondered whether anyone has any experience getting round this problem on linux.  It is complicated so excuse the lengthy explanation.</div>

<div><br></div><div>Our sound processing depends on a high-prirority thread running for a short time every 20 milliseconds to push data through the sound processing paths (microphone recording, OpenAL for spatialization, and so on).  On linux this approach is not immediately applicable because (*)</div>
<div>
</div>
</blockquote></div><br><div>
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font face="Helvetica" size="3">--</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3">===========================================================================</font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3">John M. McIntosh &lt;<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.com</a>&gt;   Twitter:  squeaker68882</font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3">Corporate Smalltalk Consulting Ltd.  <a href="http://www.smalltalkconsulting.com" target="_blank">http://www.smalltalkconsulting.com</a></font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3">===========================================================================</font></div><div><br></div></div></div>
</div></div></div></span></div></span><br></span><br>
</div>
<br></div></div></div><br></blockquote></div><br>