<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Eliot Miranda wrote:
<blockquote
cite="mid:CAC20JE2cnMJAYWGymjZZ=XsV+aHMyChtY4j8d2MzJxa1=_LMsg@mail.gmail.com"
type="cite">
<pre wrap=""> </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 moz-do-not-send="true"
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 class="" style="white-space: pre;"> </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 class="" style="white-space: pre;"> </span><primitive:
136></div>
<div><span class="" style="white-space: pre;"> </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 class="" style="white-space: pre;"> </span>"Cause the
time semaphore, if one has been registered, to be</div>
<div><span class="" style="white-space: pre;"> </span> signalled
when the microsecond clock is greater than or equal to</div>
<div><span class="" style="white-space: pre;"> </span> the given
tick value. A tick value of zero turns off timer interrupts."</div>
<div><span class="" style="white-space: pre;"> </span>| msecsObj
msecs deltaMsecs sema |</div>
<div><span class="" style="white-space: pre;"> </span><var:
#msecs type: #usqInt></div>
<div><span class="" style="white-space: pre;"> </span>msecsObj :=
self stackTop.</div>
<div><span class="" style="white-space: pre;"> </span>sema := self
stackValue: 1.</div>
<div><span class="" style="white-space: pre;"> </span>msecs := self
positive32BitValueOf: msecsObj.</div>
<div><span class="" style="white-space: pre;"> </span></div>
<div><span class="" style="white-space: pre;"> </span>self
successful ifTrue:</div>
<div><span class="" style="white-space: pre;"> </span>[(objectMemory
isSemaphoreOop: sema) ifTrue:</div>
<div><span class="" style="white-space: pre;"> </span>[<b>objectMemory
splObj: TheTimerSemaphore put: sema</b>.</div>
<div><span class="" style="white-space: pre;"> </span> deltaMsecs :=
msecs - (self ioMSecs bitAnd: MillisecondClockMask).</div>
<div><span class="" style="white-space: pre;"> </span> deltaMsecs
< 0 ifTrue:</div>
<div><span class="" style="white-space: pre;"> </span>[deltaMsecs :=
deltaMsecs + MillisecondClockMask + 1].</div>
<div><span class="" style="white-space: pre;"> </span> <b>nextWakeupUsecs
:= self ioUTCMicroseconds + (deltaMsecs * 1000)</b>.</div>
<div><span class="" style="white-space: pre;"> </span> ^self pop: 2].</div>
<div><span class="" style="white-space: pre;"> </span> sema =
objectMemory nilObject ifTrue:</div>
<div><span class="" style="white-space: pre;"> </span>[objectMemory</div>
<div><span class="" style="white-space: pre;"> </span>storePointer:
TheTimerSemaphore</div>
<div><span class="" style="white-space: pre;"> </span>ofObject:
objectMemory specialObjectsOop</div>
<div><span class="" style="white-space: pre;"> </span>withValue:
objectMemory nilObject.</div>
<div><span class="" style="white-space: pre;"> </span> <b>nextWakeupUsecs
:= 0</b>.</div>
<div><span class="" style="white-space: pre;"> </span> ^self pop:
2]].</div>
<div><span class="" style="white-space: pre;"> </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>
<br>
<blockquote
cite="mid:CAC20JE2cnMJAYWGymjZZ=XsV+aHMyChtY4j8d2MzJxa1=_LMsg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<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>
[1] <a moz-do-not-send="true"
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
cite="mid:CAC20JE2cnMJAYWGymjZZ=XsV+aHMyChtY4j8d2MzJxa1=_LMsg@mail.gmail.com"
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>
<br>
</body>
</html>