[Vm-dev] CogMT

Eliot Miranda eliot.miranda at gmail.com
Thu Jul 29 15:55:29 UTC 2021



> On Jul 29, 2021, at 8:49 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> 
> 
> 
>>> On Jul 29, 2021, at 8:47 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>>> 
>> Hi Marcel,
>> 
>>>> On Jul 29, 2021, at 7:29 AM, Marcel Taeumel <marcel.taeumel at hpi.de> wrote:
>>>> 
>>> 
>>> Hi all!
>>> 
>>> Here is a rather broad question: What is "CogMT" about? For whom are those multiple threads (MT)? :-)
>> 
>> CogMT is the version of the CoInterpreter that implements the Threaded FFI.  This is David Simmons’ implementation of the Python VM threading model where
>> - every FFI call is non-blocking
>> - any number of threads can run the VM but only one is running the VM at any one time
>> - thread switches occur on FFI call out and call back, and, if one binds a Smalltalk process to a specific thread, on process switch
>> - Smalltalk real-time scheduling semantics (preemptive across priorities, cooperative within a priority) are maintained
>> - VM “locking” is light weight, using a single integer variable to indicate ownership and using a lock free algorithm using test-and-set instructions to acquire ownership
>> - an FFI call “disowns” the VM by saving its id, copying the value in the vmOwner variable to a local variable and zeroing vmOwner.  On return it attempts to test-and-set the vmOwner variable back to the value stashed in the local variable, which will succeed if it is still zero, entering the priority queue of threads waiting to take ownership if vmOwner is non-zero (if the VM is owned by another thread)
>> - the heartbeat checks for a zero vmOwner and ensures a thread runs to attempt to take ownership of the VM
>> 
>> Hence on any FFI call the VM is released and if the call returns before the heartbeat beats, will regain ownership with the overhead of a handful of instructions and no waiting in OS semaphores or thread switches.  In an FFI call on average the VM is blocked for half the heartbeat period before another thread runs the VM (currently the heartbeat is 500 Hz).
> 
> I meant to point you to the main implementation classes in VMMaker.oscog:
>    CoInterpreterMT
>    CoInterpreterMTPrimitives
>    CogThreadManager

And point out that the interpreterProxy disownVM/ownVM pair of API functions for releasing and reacquiring the VM can also be used inside primitives, allowing us to eliminate threads in plugins, such as that inside the SocketPlugin used to achieve non-blocking name lookup.

>>> 
>>> The only build configuration I can find is build.linux64ARMv8/squeak.cogmt.spur. There is an issue with the type of sqOSSemaphore. That got me interested in the idea of CogMT ... which predates ARMv8 by a lot, right?
>> 
>> Yes. There is a build for MacOS, but because of the GUI thread issue it crashes very soon.
>> 
>> I had a prototype of the Threaded FFI running in 2010.  It is frustrating that I have not been able to finish this work, that the Pharo team chose to go their own way, implementing a slow heavy weight locking and thread switch mechanism similar to Pythons Global Interpreter Lock (GIL) rather than choosing to collaborate.  Etc.
>> 
>>> 
>>> Best,
>>> Marcel
>>> 
>>> *** 
>>> 
>>> 2021-07-29T11:17:34.6297654Z In file included from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogitARMv8.c:16,
>>> 2021-07-29T11:17:34.6305778Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogit.c:11:
>>> 2021-07-29T11:17:34.6312562Z /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/platforms/unix/vm/sqPlatformSpecific.h:75:4: error: conflicting types for 'sqOSSemaphore'
>>> 2021-07-29T11:17:34.6323676Z   } sqOSSemaphore;
>>> 2021-07-29T11:17:34.6324255Z     ^~~~~~~~~~~~~
>>> 2021-07-29T11:17:34.6325724Z In file included from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/platforms/Cross/vm/sqMemoryAccess.h:472,
>>> 2021-07-29T11:17:34.6327528Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/platforms/unix/vm/sqPlatformSpecific.h:35,
>>> 2021-07-29T11:17:34.6329210Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogitARMv8.c:16,
>>> 2021-07-29T11:17:34.6330958Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogit.c:11:
>>> 2021-07-29T11:17:34.6332629Z /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/platforms/unix/vm/sqPlatformSpecific.h:75:4: note: previous declaration of 'sqOSSemaphore' was here
>>> 2021-07-29T11:17:34.6333826Z   } sqOSSemaphore;
>>> 2021-07-29T11:17:34.6334219Z     ^~~~~~~~~~~~~
>>> 2021-07-29T11:17:34.9588384Z In file included from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/platforms/Cross/vm/dispdbg.h:8,
>>> 2021-07-29T11:17:34.9589908Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogitARMv8.c:19,
>>> 2021-07-29T11:17:34.9591283Z                  from /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogit.c:11:
>>> 2021-07-29T11:17:34.9593124Z /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogitARMv8.c: In function 'allMachineCodeObjectReferencesValid':
>>> 2021-07-29T11:17:34.9605356Z /home/runner/work/opensmalltalk-vm/opensmalltalk-vm/spur64src/vm/cogitARMv8.c:7855:52: warning: passing argument 2 of 'mapForperformUntilarg' from incompatible pointer type [-Wincompatible-pointer-types]
>>> 2021-07-29T11:17:34.9607673Z     if (!(asserta((mapForperformUntilarg(cogMethod, checkIfValidOopRefAndTargetpccogMethod, cogMethod)) == 0))) {
>>> 2021-07-29T11:17:34.9608918Z                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> 
>> Eliot
>> _,,,^..^,,,_ (phone)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20210729/16d4bd56/attachment.html>


More information about the Vm-dev mailing list