<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 26, 2014 at 4:36 PM, Ben Coman <span dir="ltr"><<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><u></u>
<div bgcolor="#ffffff" text="#000000">
Eliot Miranda wrote:
<blockquote type="cite">
<pre> </pre>
<hr size="4" width="90%"><br>
<div dir="ltr">Hi Ben,
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Jul 25, 2014 at 7:56 AM, Ben Coman <span dir="ltr"><<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0px 0px 0px 0.8ex;padding-left:1ex"> <br>
<div bgcolor="#ffffff" text="#000000">Over the last few days I have
been looking deeper into the image
locking when suspending a process. It is an
interesting rabbit hole [1] that leads to pondering the Delay
machinery, that leads to some VM questions. <br>
<br>
When pressing the interrupt key it seems to always opens
the debugger with the following call stack. <br>
Semaphore>>critical: 'self wait'<br>
BlockClosure>>ensure: 'self valueNoContextSwitch'<br>
Semaphore>>critical: 'ensure: [ caught ifTrue: [self signal]]<br>
Delay>>schedule 'AccessProtect critical: ['<br>
Delay>>wait 'self schedule'<br>
WorldState>>interCyclePause:<br>
<br>
I notice...<br>
Delay class >> initialize <br>
TimingSemaphore := (Smalltalk specialObjectsArray at: 30).<br>
and...<br>
Delay class >> startTimerEventLoop<br>
TimingSemaphore := Semaphore new.<br>
which seems incongruous that TimingSemaphore is set in differently. So
while I presume this critical stuff all works fine, just in an exotic
way, my entropy-guarding-neuron would just like confirm this is so.<br>
</div>
</blockquote>
<div><br>
</div>
<div>The TimingSemaphore gets installed in the specialObjectsArray via</div>
<div><br>
</div>
<div>primSignal: aSemaphore atMilliseconds: aSmallInteger</div>
<div><span style="white-space:pre-wrap"> </span>"Signal the
semaphore when the millisecond clock reaches the value of the second
argument. Fail if the first argument is neither a Semaphore nor nil.
Essential. See Object documentation whatIsAPrimitive."</div>
<div><span style="white-space:pre-wrap"> </span><primitive:
136></div>
<div><span style="white-space:pre-wrap"> </span>^self
primitiveFailed</div>
<div> </div>
<div>and from that the VM sets the nextWakeupUsecs:</div>
<div><br>
</div>
<div>
<div>primitiveSignalAtMilliseconds</div>
<div><span style="white-space:pre-wrap"> </span>"Cause the
time semaphore, if one has been registered, to be</div>
<div><span style="white-space:pre-wrap"> </span> signalled
when the microsecond clock is greater than or equal to</div>
<div><span style="white-space:pre-wrap"> </span> the given
tick value. A tick value of zero turns off timer interrupts."</div>
<div><span style="white-space:pre-wrap"> </span>| msecsObj
msecs deltaMsecs sema |</div>
<div><span style="white-space:pre-wrap"> </span><var:
#msecs type: #usqInt></div>
<div><span style="white-space:pre-wrap"> </span>msecsObj :=
self stackTop.</div>
<div><span style="white-space:pre-wrap"> </span>sema := self
stackValue: 1.</div>
<div><span style="white-space:pre-wrap"> </span>msecs := self
positive32BitValueOf: msecsObj.</div>
<div><span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>self
successful ifTrue:</div>
<div><span style="white-space:pre-wrap"> </span>[(objectMemory
isSemaphoreOop: sema) ifTrue:</div>
<div><span style="white-space:pre-wrap"> </span>[<b>objectMemory
splObj: TheTimerSemaphore put: sema</b>.</div>
<div><span style="white-space:pre-wrap"> </span> deltaMsecs :=
msecs - (self ioMSecs bitAnd: MillisecondClockMask).</div>
<div><span style="white-space:pre-wrap"> </span> deltaMsecs
< 0 ifTrue:</div>
<div><span style="white-space:pre-wrap"> </span>[deltaMsecs :=
deltaMsecs + MillisecondClockMask + 1].</div>
<div><span style="white-space:pre-wrap"> </span> <b>nextWakeupUsecs
:= self ioUTCMicroseconds + (deltaMsecs * 1000)</b>.</div>
<div><span style="white-space:pre-wrap"> </span> ^self pop: 2].</div>
<div><span style="white-space:pre-wrap"> </span> sema =
objectMemory nilObject ifTrue:</div>
<div><span style="white-space:pre-wrap"> </span>[objectMemory</div>
<div><span style="white-space:pre-wrap"> </span>storePointer:
TheTimerSemaphore</div>
<div><span style="white-space:pre-wrap"> </span>ofObject:
objectMemory specialObjectsOop</div>
<div><span style="white-space:pre-wrap"> </span>withValue:
objectMemory nilObject.</div>
<div><span style="white-space:pre-wrap"> </span> <b>nextWakeupUsecs
:= 0</b>.</div>
<div><span style="white-space:pre-wrap"> </span> ^self pop:
2]].</div>
<div><span style="white-space:pre-wrap"> </span>self
primitiveFailFor: PrimErrBadArgument</div>
</div>
<div><br>
</div>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0px 0px 0px 0.8ex;padding-left:1ex">
<div bgcolor="#ffffff" text="#000000"><br>
--------------<br>
<br>
In Delay class >> handleTimerEvent the comment says... <br>
"Handle a timer event.... <br>
-a timer signal (not explicitly specified)"<br>
...is that event perhaps a 'tick' generated periodically by the VM via
that item from specialObjectArray ? Or is there some other mechanism ?<br>
</div>
</blockquote>
<div><br>
</div>
<div>Every time the VM checks for interrupts, which, in the Cog.Stack
VMs is controlled by the heartbeat frequency, which defaults to 2
milliseconds, the VM checks if the current time has progressed to or
beyond nextWakeupUsecs and signals the timer semaphore if so.</div>
</div>
</div>
</div>
</blockquote>
<br>
Thanks Eliot. Just so I'm clear... the signals to the TimingSemaphore
from the VM depend entirely on the Delays scheduled by the Image? The
VM never signals the TimingSemaphore independently?<br></div></blockquote><div><br></div><div>Right, yes and yes.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#ffffff" text="#000000"><blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0px 0px 0px 0.8ex;padding-left:1ex">
<div bgcolor="#ffffff" text="#000000">--------------<br>
<br>
[1] <a href="http://www.urbandictionary.com/define.php?term=Rabbit+Hole" target="_blank">http://www.urbandictionary.com/define.php?term=Rabbit+Hole</a></div>
</blockquote>
<div><br>
</div>
<div>and the problem here is not in the VM. <br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Yep. Just looking to understand the interaction between VM and image. <br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div>So climb out and breath some fresh air ;-)</div>
</div>
</div>
</div>
</blockquote>
<br>
Soon :) but for the moment its a puzzle thats got hold of me, like a
dog on a bone. This is a "hard" problem for me, and I like hard
problems. It provides an opportunity to hold my attention to dig deeper
and learn stuff that I otherwise might not. <br>
cheers -ben<br></div></blockquote></div>-- <br>Aloha,<div>Eliot</div>
</div></div>