Process scheduling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Process scheduling

raffaello.giulietti
Hi,

I can't find a description on how ProcessorScheduler in Pharo (i.e.,
Cog) is supposed to do context switches in absence of other
synchronization points.

Is it following the BlueBook spec? Just to recall that model, the VM,
when about to execute the current bytecode instruction of the current
Process, checks whether a strictly higher priority Process is ready to
run and if so, switches to (one of) the highest priority among them.

Thanks in advance for clarifications.

Greetings
Raffaello

Reply | Threaded
Open this post in threaded view
|

Re: Process scheduling

Ben Coman


On Sun, Apr 30, 2017 at 10:11 PM, <[hidden email]> wrote:
Hi,

I can't find a description on how ProcessorScheduler in Pharo (i.e.,
Cog) is supposed to do context switches in absence of other
synchronization points.

Is it following the BlueBook spec? Just to recall that model, the VM,
when about to execute the current bytecode instruction of the current
Process, checks whether a strictly higher priority Process is ready to
run and if so, switches to (one of) the highest priority among them.

Thanks in advance for clarifications.


This topic is probably a bit advanced pharo-users list.
You'll likely get better answers in vm-dev list of pharo-dev list.
Can you post any follow ups there?

ProcessScheduler doesn't have much to do with context switching,
except providing the #yield primitive for a user to invoke manually.
As you noted, the actual context switching happens in the VM.  

The charts here [1] might be useful to get an overview of the execution loop.
Keep in mind though Its a very rough view of a novice exploring the Cog execution engine
and may not be entirely accurate.  But it will give you a starting point.
  
For another example, look at CoInterpreterPrimitives>>primitiveEnterCriticalSection

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Process scheduling

raffaello.giulietti
On 30/04/17 17:01, Ben Coman wrote:

>
>
> On Sun, Apr 30, 2017 at 10:11 PM, <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>
>     I can't find a description on how ProcessorScheduler in Pharo (i.e.,
>     Cog) is supposed to do context switches in absence of other
>     synchronization points.
>
>     Is it following the BlueBook spec? Just to recall that model, the VM,
>     when about to execute the current bytecode instruction of the current
>     Process, checks whether a strictly higher priority Process is ready to
>     run and if so, switches to (one of) the highest priority among them.
>
>     Thanks in advance for clarifications.
>
>
> This topic is probably a bit advanced pharo-users list.
> You'll likely get better answers in vm-dev list of pharo-dev list.
> Can you post any follow ups there?
>
> ProcessScheduler doesn't have much to do with context switching,
> except providing the #yield primitive for a user to invoke manually.
> As you noted, the actual context switching happens in the VM.  
>
> The charts here [1] might be useful to get an overview of the execution
> loop.
> Keep in mind though Its a very rough view of a novice exploring the Cog
> execution engine
> and may not be entirely accurate.  But it will give you a starting point.
>  
> For another example, look at
> CoInterpreterPrimitives>>primitiveEnterCriticalSection
> in VMMaker (http://source.squeak.org/VMMaker).  
>
> cheers -ben

Hi Ben,

of course, I can post the question on the pharo-dev mailing list and
certainly will if nobody on this one can answer my question.

However, Process is a Pharo user level class, not something private to
the implementation of the vm. Any programmer should know what to expect
and what to not expect when different Processes are started, and how
they behave and interact. It's part of the general knowledge of the
Smalltalk programming model, on par with Object, Class and Behavior.

So, before I switch to the pharo-dev list, let's wait and see...

BTW, it seems that reference [1], containing the charts you mention,
could not find its way in your reply. Can you please make it available?

Greetings
Raffaelo

Reply | Threaded
Open this post in threaded view
|

Re: Process scheduling

raffaello.giulietti
In reply to this post by raffaello.giulietti
Hi Ben,



On 01/05/17 15:23, Ben Coman wrote:

>
>
> I was responding to your literal question about ProcessScheduler and
> what part of the system does the context switching.
> Now I'm guessing your interest is more about user-level
> multi-threaded behaviour of Processes,
> so I hunted down some discussions you may find  be interesting
>
> * http://forum.world.st/The-Trunk-Kernel-mt-1009-mcz-td4887889.html
>     (search for preemptionYields)
>    
> * http://forum.world.st/threading-in-Pharo-td4750534.html
>
> * http://forum.world.st/threading-in-Pharo-td4750534.html
>
> * http://forum.world.st/VM-Maker-VMMaker-oscog-eem-942-mcz-td4790993.html
>
>

Quite interesting, indeed, and very detailed.



> However I didn't quite follow where you said...  "in absence of
> other synchronization points."
> Do you mean without suspend/resuming Processes or waiting/signalling
> Semaphore
> and something else?  
>

Yes, I mean this.



> I'm not sure if this is what your looking for, but in summary...
> Processes at the same priority are scheduled cooperatively. they must
> deliberately yield or sleep to be put at the back of their priority's
> run-queue.before another process of same priority can run.

Right, this is the part explicitly controlled by the programmer and
which is synchronous from the Process' own perspective.



Higher
> priority processes pre-empt lower priority processes only when they are
> woken (i.e. signalled or resumed). The pre-empted process stays at the
> front of its priority's run-queue so that the higher-priority-preemption
> is transparent to the same-priority-cooperative scheduling.  
>  

This is the most synthetic explanation I've seen so far! Clear and concise.


Thanks and greetings
Raffaello