Preemptive scheduling

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

Preemptive scheduling

J J-6
Hi all,

Does the Squeak VM do preemptive scheduling or regular yield style
scheduling.  This may sound like a silly question, but I know Erlang is
language that does mainly green threads and they are preemptive in nature.  
They accomplish this by allowing a given thread to execute no more then 100
VM instructions before it is preempted (obviously if a thread makes a
primitive call that is a voluntary yield).

Does Squeak do this already?  I suspect not, and if I am correct, would
there be any benefit in doing something like this or would it actually slow
things down?

Thanks,
Jason

_________________________________________________________________
Don’t quit your job – Take Classes Online and Earn your Degree in 1 year.
Start Today!
http://www.classesusa.com/clickcount.cfm?id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

johnmci
Interpreter>>transferTo: is the place in the VM were we transfer  
control from one process to another. This is invoked via

primitiveSuspend
primitiveWait
primitiveYield
resume:

for wait and yield it follows the pattern

                self addLastLink: activeProc toList: processList.
                self transferTo: self wakeHighestPriority

which means we stick the process at the end of the linked list of  
processes in the same priority, thus if there was a higher process or
process at the same priority ready to run it will run instead of the  
process that has the wait or yield.  It could of course wake the same
process if the process is the only one in it's priority group and  
it's ready to run of course.

for suspend, we don't do the addLastLink because the process is being  
suspended.

In all of this the ProcessorScheduler does not do preemptive  
scheduling, thus if you have a high priority smalltalk process that  
runs away it will block all other
processes from running.  You could of course and I've seen change  
sets for Visualworks write your own scheduler that modifies what  
wakeHighestPriority means by suspending processes that normally would  
be runnable.  That would be overhead, and what is the problem you are  
trying to solve?


On May 1, 2007, at 10:48 AM, J J wrote:

> Hi all,
>
> Does the Squeak VM do preemptive scheduling or regular yield style  
> scheduling.  This may sound like a silly question, but I know  
> Erlang is language that does mainly green threads and they are  
> preemptive in nature.  They accomplish this by allowing a given  
> thread to execute no more then 100 VM instructions before it is  
> preempted (obviously if a thread makes a primitive call that is a  
> voluntary yield).
>
> Does Squeak do this already?  I suspect not, and if I am correct,  
> would there be any benefit in doing something like this or would it  
> actually slow things down?
>
> Thanks,
> Jason
>
> _________________________________________________________________
> Don’t quit your job – Take Classes Online and Earn your Degree in 1  
> year. Start Today! http://www.classesusa.com/clickcount.cfm?
> id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%
> 2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144
>
>

--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

Philippe Marschall
In reply to this post by J J-6
http://groups.google.com/group/strongtalk-general/msg/5e36e34c2f91eb23

2007/5/1, J J <[hidden email]>:

> Hi all,
>
> Does the Squeak VM do preemptive scheduling or regular yield style
> scheduling.  This may sound like a silly question, but I know Erlang is
> language that does mainly green threads and they are preemptive in nature.
> They accomplish this by allowing a given thread to execute no more then 100
> VM instructions before it is preempted (obviously if a thread makes a
> primitive call that is a voluntary yield).
>
> Does Squeak do this already?  I suspect not, and if I am correct, would
> there be any benefit in doing something like this or would it actually slow
> things down?
>
> Thanks,
> Jason
>
> _________________________________________________________________
> Don't quit your job – Take Classes Online and Earn your Degree in 1 year.
> Start Today!
> http://www.classesusa.com/clickcount.cfm?id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

J J-6
In reply to this post by johnmci
Aha, Interpreter!  I was looking in process for the "swap" method. :)

At the moment, I am not looking to solve a problem per se.  I was just
thinking that Smalltalk tries to be it's own OS, kind of.  I wonder what
would happen if it went a bit further.

On a real OS, a processes are only allowed to run for a certain amount of
time before the CPU interupts them and puts the OS back in control to decide
what to do next.  In any kind of "green threads" system this (normally)
isn't doable because it is actually just one running process and if a "green
thread" doesn't want to yield, then the threading system never gets back in
control to stop it.  The threading system could, of course, have the OS send
it some kind of signal ever so many milliseconds but how that is done is
very platform specific (not to mention a host of other problems with it).

But with an interpreter it would be possible to do the same things an
advanced OS does, let a process only run for a specific amount of VM
instructions, penilize processes that keep using their whole "quantum",
promote processes that don't, etc.

The question is, would this have any benifit? If I ever have time, maybe I
will find out (unless of course Squeak already does most of this). :)

>From: John M McIntosh <[hidden email]>
>Reply-To: [hidden email],The general-purpose Squeak
>developers list<[hidden email]>
>To: The general-purpose Squeak developers
>list<[hidden email]>
>Subject: Re: Preemptive scheduling
>Date: Tue, 1 May 2007 11:21:38 -0700
>
>Interpreter>>transferTo: is the place in the VM were we transfer  control
>from one process to another. This is invoked via
>
>primitiveSuspend
>primitiveWait
>primitiveYield
>resume:
>
>for wait and yield it follows the pattern
>
> self addLastLink: activeProc toList: processList.
> self transferTo: self wakeHighestPriority
>
>which means we stick the process at the end of the linked list of  
>processes in the same priority, thus if there was a higher process or
>process at the same priority ready to run it will run instead of the  
>process that has the wait or yield.  It could of course wake the same
>process if the process is the only one in it's priority group and  it's
>ready to run of course.
>
>for suspend, we don't do the addLastLink because the process is being  
>suspended.
>
>In all of this the ProcessorScheduler does not do preemptive  scheduling,
>thus if you have a high priority smalltalk process that  runs away it will
>block all other
>processes from running.  You could of course and I've seen change  sets for
>Visualworks write your own scheduler that modifies what  
>wakeHighestPriority means by suspending processes that normally would  be
>runnable.  That would be overhead, and what is the problem you are  trying
>to solve?
>
>
>On May 1, 2007, at 10:48 AM, J J wrote:
>
>>Hi all,
>>
>>Does the Squeak VM do preemptive scheduling or regular yield style  
>>scheduling.  This may sound like a silly question, but I know  Erlang is
>>language that does mainly green threads and they are  preemptive in
>>nature.  They accomplish this by allowing a given  thread to execute no
>>more then 100 VM instructions before it is  preempted (obviously if a
>>thread makes a primitive call that is a  voluntary yield).
>>
>>Does Squeak do this already?  I suspect not, and if I am correct,  would
>>there be any benefit in doing something like this or would it  actually
>>slow things down?
>>
>>Thanks,
>>Jason
>>
>>_________________________________________________________________
>>Don’t quit your job – Take Classes Online and Earn your Degree in 1  year.
>>Start Today! http://www.classesusa.com/clickcount.cfm?
>>id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%
>>2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144
>>
>>
>
>--
>========================================================================
>===
>John M. McIntosh <[hidden email]>
>Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
>========================================================================
>===
>
>
>

_________________________________________________________________
Don’t quit your job – Take Classes Online and Earn your Degree in 1 year.
Start Today!
http://www.classesusa.com/clickcount.cfm?id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

J J-6
In reply to this post by Philippe Marschall
Cool, thanks.  I'll check out the thread.


>From: "Philippe Marschall" <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: "The general-purpose Squeak developers
>list"<[hidden email]>
>Subject: Re: Preemptive scheduling
>Date: Tue, 1 May 2007 20:25:23 +0200
>
>http://groups.google.com/group/strongtalk-general/msg/5e36e34c2f91eb23
>
>2007/5/1, J J <[hidden email]>:
>>Hi all,
>>
>>Does the Squeak VM do preemptive scheduling or regular yield style
>>scheduling.  This may sound like a silly question, but I know Erlang is
>>language that does mainly green threads and they are preemptive in nature.
>>They accomplish this by allowing a given thread to execute no more then
>>100
>>VM instructions before it is preempted (obviously if a thread makes a
>>primitive call that is a voluntary yield).
>>
>>Does Squeak do this already?  I suspect not, and if I am correct, would
>>there be any benefit in doing something like this or would it actually
>>slow
>>things down?
>>
>>Thanks,
>>Jason
>>
>>_________________________________________________________________
>>Don't quit your job – Take Classes Online and Earn your Degree in 1
>>year.
>>Start Today!
>>http://www.classesusa.com/clickcount.cfm?id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144
>>
>>
>>


>

_________________________________________________________________
Mortgage rates near historic lows. Refinance $200,000 loan for as low as
$771/month*
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f8&disc=y&vers=689&s=4056&p=5117


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

timrowledge
In reply to this post by J J-6

On 1-May-07, at 12:05 PM, J J wrote:

>
> At the moment, I am not looking to solve a problem per se.  I was  
> just thinking that Smalltalk tries to be it's own OS, kind of.  I  
> wonder what would happen if it went a bit further.
We did this at Interval. We could schedule Smalltalk process threads,  
native code threads, interrupt between them etc. It wasn't  easy and  
I'm not at all convinced that it was worth the work.

>
> On a real OS

...interesting definition of 'real' here. I can assure you there are  
OSs I've used that didn't do any such thing...

> , a processes are only allowed to run for a certain amount of time  
> before the CPU interupts them and puts the OS back in control to  
> decide what to do next.  In any kind of "green threads" system this  
> (normally) isn't doable because it is actually just one running  
> process and if a "green thread" doesn't want to yield, then the  
> threading system never gets back in control to stop it.  The  
> threading system could, of course, have the OS send it some kind of  
> signal ever so many milliseconds but how that is done is very  
> platform specific (not to mention a host of other problems with it).
You can easily do this in Smalltalk in a portable way; just a high  
priority process that cycles on a time interrupt to shuffle the  
process scheduler. You can manually shuffle the processes at the  
various priorities if you want to.

>
> But with an interpreter it would be possible to do the same things  
> an advanced OS does, let a process only run for a specific amount  
> of VM instructions, penilize processes that keep using their whole  
> "quantum", promote processes that don't, etc.


If you want to do some sort of count of bytecodes or prim calls  
instead of a simple timer, that is not difficult to arrange. I think  
John put some timer/counter stuff in a few years ago that would  
support this.

>
> The question is, would this have any benifit?
I'm not sure; to be honest there seems little point in trying to make  
'Smalltalk be the OS' for practical systems. What is probably much  
more sensible is to make Smalltalk do much better at integrating into  
the OS so it has more general value. In some respects Spoon is making  
a very good pass at this. The cost is that for every bit of OS  
integration you provide the cost of porting goes up enormously.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: PBF: Pay Bus Fare



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

johnmci
In reply to this post by J J-6

On May 1, 2007, at 12:05 PM, J J wrote:

> Aha, Interpreter!  I was looking in process for the "swap" method. :)
>
> At the moment, I am not looking to solve a problem per se.  I was  
> just thinking that Smalltalk tries to be it's own OS, kind of.  I  
> wonder what would happen if it went a bit further.
>
> On a real OS, a processes are only allowed to run for a certain  
> amount of time before the CPU interupts them and puts the OS back  
> in control to decide what to do next.  In any kind of "green  
> threads" system this (normally) isn't doable because it is actually  
> just one running process and if a "green thread" doesn't want to  
> yield, then the threading system never gets back in control to stop  
> it.  The threading system could, of course, have the OS send it  
> some kind of signal ever so many milliseconds but how that is done  
> is very platform specific (not to mention a host of other problems  
> with it).
>
> But with an interpreter it would be possible to do the same things  
> an advanced OS does, let a process only run for a specific amount  
> of VM instructions, penilize processes that keep using their whole  
> "quantum", promote processes that don't, etc.
>
> The question is, would this have any benifit? If I ever have time,  
> maybe I will find out (unless of course Squeak already does most of  
> this). :)


Ok, well as noted in http://groups.google.com/group/strongtalk- 
general/msg/5e36e34c2f91eb23

> But, as David pointed out, some
> > subtle bugs will turn up if you do this.

Right now processing switching occurs at known times, what they are  
I'll let someone else point out.  Those "safe points" David aludes to.

However if you were to alter the VM such that say that a process  
switch could  occur between the execution of any two bytecodes, then  
well subtle bugs in how Class methods assume control is theirs for a  
certain quantum of time would be violated.

In general the Smalltalk class library isn't written with such  
interesting side effects in mind.


Now as for experimenting, you'll find that transferTo: is the only  
place in the VM where the process switch happens.
Years ago I constructed a VM where we would collect clock time ticks  
into slots in Process instances based on doing
the calculations in transferTo:   You likely could do the same here  
by counting byte codes executed in the interpreter loop, then
collecting that data into slots in Process.

Then having a high priority task wake up and look at that data you  
could I think do some experiments. Likely then you could
distribute bytecode time equally then between N processes that are  
doing [true] whileTrue: []

mmm maybe consider priority inversion well you are tinkering too?

http://en.wikipedia.org/wiki/Priority_inversion

--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

johnmci
In reply to this post by timrowledge

>> But with an interpreter it would be possible to do the same things  
>> an advanced OS does, let a process only run for a specific amount  
>> of VM instructions, penilize processes that keep using their whole  
>> "quantum", promote processes that don't, etc.
>
>
> If you want to do some sort of count of bytecodes or prim calls  
> instead of a simple timer, that is not difficult to arrange. I  
> think John put some timer/counter stuff in a few years ago that  
> would support this.

Ah that would be
[ENH] CPU time for Processes.
        Date: March 8, 2001 7:49:42 PM PST (CA)

I've stuck the CaptureProcessTimeJMM.6.cs on my idisk experimental  
folder via http:/www.smalltalkconsulting.com/squeak.html  as a clue



--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

J J-6
In reply to this post by timrowledge
>From: tim Rowledge <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: The general-purpose Squeak developers
>list<[hidden email]>
>Subject: Re: Preemptive scheduling
>Date: Tue, 1 May 2007 13:24:30 -0700
>
>>On a real OS
>
>...interesting definition of 'real' here. I can assure you there are  OSs
>I've used that didn't do any such thing...

Ok fine, change the word 'real' for 'modern'.  Of course there used to be
batch systems, cooperative systems, and so on, but modern server/desktop
OS'es behave this way.  Better? :)

>You can easily do this in Smalltalk in a portable way; just a high  
>priority process that cycles on a time interrupt to shuffle the  process
>scheduler. You can manually shuffle the processes at the  various
>priorities if you want to.

I'm good with a time interrupt, but how is that done in a remotely
portable/safe way?  I'm not asking about process shuffling, I'm asking how a
process that consists of:

[ [ true ] whileTrue: [ true ] ] fork

can ever be taken off the processor.  Unless you do either (a) instruction
count based preemption or (b) time based (i.e. what CPU's use), it can't be
done afaik.

>If you want to do some sort of count of bytecodes or prim calls  instead of
>a simple timer, that is not difficult to arrange. I think  John put some
>timer/counter stuff in a few years ago that would  support this.

I only suggested bytecode count because I didn't realize there was a good
way to do timebased (which would actually be the prefered method if
possible).

>I'm not sure; to be honest there seems little point in trying to make  
>'Smalltalk be the OS' for practical systems. What is probably much  more
>sensible is to make Smalltalk do much better at integrating into  the OS so
>it has more general value. In some respects Spoon is making  a very good
>pass at this. The cost is that for every bit of OS  integration you provide
>the cost of porting goes up enormously.

This is what I am wondering though.  If integrating Smalltalk better into
the OS is taken to the extreme you end up with a Ruby with prettier syntax.  
I think a lot of power is there to be had by having a mini-OS.  As you
mentioned, portability is one of these benifits.

Looking at things from the point of view of writing scripts, it may seem a
bit inconvenient having a mini-OS VM.  But looked at from a very large,
distributed, multi-core, multi-OS architechture point of view, I personally
see a different picture.  I see Yaws (a system that doesn't seem to
integrate so well with other systems) absolutely smoking Apache (a system
that integrates with anything) at the high end.

_________________________________________________________________
Get a FREE Web site, company branded e-mail and more from Microsoft Office
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

"Martin v. Löwis"
In reply to this post by J J-6
> Does the Squeak VM do preemptive scheduling or regular yield style
> scheduling.  This may sound like a silly question, but I know Erlang is
> language that does mainly green threads and they are preemptive in
> nature.  They accomplish this by allowing a given thread to execute no
> more then 100 VM instructions before it is preempted (obviously if a
> thread makes a primitive call that is a voluntary yield).
>
> Does Squeak do this already?

Yes, the Squeak scheduler implements preemptive scheduling. An active
process is given a quantum of such-and-such many byte codes, and when
the quantum expires, a scheduling decision is made. The scheduler
attempts to make each quantum a (tunable) period of time (by default
1ms), and adjusts the number of byte code operations to account for
differences in CPU speed.

Regards,
Martin

Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

johnmci
Ah, well as one of the authors of that piece of code let me comment,  
assuming Martin and I are talking about the same piece of code.

There is a checkForInterrupts method that is called by the  
interpreter every so often and under certain conditions.

It

- deals with the lowspace pending signal
- ensures VM event polling occurs in a timely manner.
- deals with the interrupt pending signal
- deals with clock rollover
- deals with the finalization logic
- takes any external semaphore index number signal requests off a  
dual queue set and signals the actual semaphore
- executes the next pending process on a semaphore if the semaphore  
should be woken and it's priority is > than the current process.

So if any process that is waiting on a timer, or a semphore is  
signaled, and if the process involved is a *higher* priority than the  
current one we would transfer control.

Now this routine was originally called when we executed a new method,  
and when we  did a long unconditional jump bytecode backwards. Those  
so called  "safe points"

Many years ago when we moved from 25Mhz 68030 motorola macintoshs to  
powerpc machines I discovered that this routine could be called upwards
5,000 a second and contribute to much of the cpu usage of Squeak  
since it was being called on the basis of a number (1000?) being  
decremented.
I altered this logic to ensure it would be called every N  
milliseconds by fiddling with the interruptCheckCounter by  
incrementing, decrementing the value
to reach a steady state to limit the calling frequency to a target  
value.

Later we added the ability to force an interrupt check, say after an  
incremental GC, or after a signal semphore, plus some other  
interesting places to ensure the check for interrupt would very  
quickly process a pending interrupt.

This does not mean the routine is called exactly every N  
milliseconds, rather it's *usually* called every N milliseconds.  How  
many bytecodes that is, is well anyone's guess since reliant on  
method sends, and backward long unconditional jumps.

Exceptions are I believe the Windows VM forces an interrupt check  
every millisecond due to an external timer to ensure it's called more  
closely to the 1 millisecond goal.

On May 1, 2007, at 1:56 PM, Martin v. Löwis wrote:

>> Does the Squeak VM do preemptive scheduling or regular yield style
>> scheduling.  This may sound like a silly question, but I know  
>> Erlang is
>> language that does mainly green threads and they are preemptive in
>> nature.  They accomplish this by allowing a given thread to  
>> execute no
>> more then 100 VM instructions before it is preempted (obviously if a
>> thread makes a primitive call that is a voluntary yield).
>>
>> Does Squeak do this already?
>
> Yes, the Squeak scheduler implements preemptive scheduling. An active
> process is given a quantum of such-and-such many byte codes, and when
> the quantum expires, a scheduling decision is made. The scheduler
> attempts to make each quantum a (tunable) period of time (by default
> 1ms), and adjusts the number of byte code operations to account for
> differences in CPU speed.
>
> Regards,
> Martin
>

--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

timrowledge
In reply to this post by J J-6

On 1-May-07, at 1:51 PM, J J wrote:

>
>> You can easily do this in Smalltalk in a portable way; just a  
>> high  priority process that cycles on a time interrupt to shuffle  
>> the  process scheduler. You can manually shuffle the processes at  
>> the  various priorities if you want to.
>
> I'm good with a time interrupt, but how is that done in a remotely  
> portable/safe way?  I'm not asking about process shuffling, I'm  
> asking how a process that consists of:
>
> [ [ true ] whileTrue: [ true ] ] fork
>
> can ever be taken off the processor.  Unless you do either (a)  
> instruction count based preemption or (b) time based (i.e. what  
> CPU's use), it can't be done afaik.

The VM theoretically does a process switch check in between each  
bytecode and so if there were a higher priority process ready to run  
then it would get to take over the cpu at such a time.  If there is  
no such process then of course the loop gets to keep running.
In practise, a long time ago we moved away from that super-
finegrained approach because it was very expensive for typical cpus;  
for WCS/microcodable machines it was generally perfectly ok. It is  
still possible to implement the check for every bytecode with  
reasonable efficiency if you're clever.
In general these days the VM (logically) does a process switch check  
anytime there is a backward branch (see , we caught the whileTrue  
loop) or a message send. This is less frequent than every bytecode  
but only by about an order of magnitude or so. When you're able to  
run 400,000,000 bytecodes per second this is not likely to be a big  
worry.  (That's the performance on my $1000 low-end macbook by the way).
To further amortise the cost of the somewhat longwinded process  
switch checks whilst still attempting to keep good interactivity, we  
actually have a counter that is decremented for each sorta-check and  
we do a real check on that counter hitting 0. It's a bit more complex  
in detail but that will do for now. We had a long mail thread and a  
lot of work about three years ago on this subject. You might like to  
search og
    Re: [BUG] User interrupts no longer interrupt locked UI process
on the mailing list archives.

We *can* interrupt that whileTrue loop (I just did); I don't know who  
told you it wasn't possible but they simply said it wrong. One case  
that can appear to be intractable is a very fast recursion, where it  
is quite possible (as in I have documented cases) to use up all of  
memory so quickly that you can't hit the interrupt key(s) before  
you're dead.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Asking whether machines can think is like asking whether submarines  
can swim.



Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

J J-6
In reply to this post by "Martin v. Löwis"
Aha.  Ok.  Thanks everyone who answered.  This is what I was wondering.  I
suppose looking back, it seems silly not to realize that since all
instructions are passing through the VM that the VM would watch what a
process is doing and preempt them if necassary.  But all the VM's I have
been exposed to were purely cooperative (for speed reasons I suppose), so it
didn't occur to me that it wouldn't be the same here.

>From: "Martin v. Löwis" <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: The general-purpose Squeak developers
>list<[hidden email]>
>Subject: Re: Preemptive scheduling
>Date: Tue, 01 May 2007 22:56:38 +0200
>
> > Does the Squeak VM do preemptive scheduling or regular yield style
> > scheduling.  This may sound like a silly question, but I know Erlang is
> > language that does mainly green threads and they are preemptive in
> > nature.  They accomplish this by allowing a given thread to execute no
> > more then 100 VM instructions before it is preempted (obviously if a
> > thread makes a primitive call that is a voluntary yield).
> >
> > Does Squeak do this already?
>
>Yes, the Squeak scheduler implements preemptive scheduling. An active
>process is given a quantum of such-and-such many byte codes, and when
>the quantum expires, a scheduling decision is made. The scheduler
>attempts to make each quantum a (tunable) period of time (by default
>1ms), and adjusts the number of byte code operations to account for
>differences in CPU speed.
>
>Regards,
>Martin
>

_________________________________________________________________
Don’t quit your job – Take Classes Online and Earn your Degree in 1 year.
Start Today!
http://www.classesusa.com/clickcount.cfm?id=866146&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866144


Reply | Threaded
Open this post in threaded view
|

Re: Preemptive scheduling

J J-6
In reply to this post by johnmci
Ausome, thanks for the break down.  It sounds like all processes get about
the same quatum at the moment.  I wonder what would happen with an "event
driven" scheduler (I believe that's what it's called) [1].  I suppose for
what most people are using Squeak for at this point it wouldn't matter so
much, but if Squeak ever started doing massive green threads it might be
more important.

[1] By this I mean the kind of scheduler (I believe invented by Sun) that
gives high priority processes a very short quantum and very low priority
processes a longer one (400ms is max as I recall).  If a process actually
uses it's whole quantum it gets dropped in priority and if it yields early
it gets promoted to higher priority.  With this style of scheduling,
interactive processes always go quickly to top (non-real time) priority
because they spend most of their time waiting on IO.

>From: John M McIntosh <[hidden email]>
>Reply-To: [hidden email],The general-purpose Squeak
>developers list<[hidden email]>
>To: The general-purpose Squeak developers
>list<[hidden email]>
>Subject: Re: Preemptive scheduling
>Date: Tue, 1 May 2007 14:54:12 -0700
>
>Ah, well as one of the authors of that piece of code let me comment,  
>assuming Martin and I are talking about the same piece of code.
>
>There is a checkForInterrupts method that is called by the  interpreter
>every so often and under certain conditions.
>
>It
>
>- deals with the lowspace pending signal
>- ensures VM event polling occurs in a timely manner.
>- deals with the interrupt pending signal
>- deals with clock rollover
>- deals with the finalization logic
>- takes any external semaphore index number signal requests off a  dual
>queue set and signals the actual semaphore
>- executes the next pending process on a semaphore if the semaphore  should
>be woken and it's priority is > than the current process.
>
>So if any process that is waiting on a timer, or a semphore is  signaled,
>and if the process involved is a *higher* priority than the  current one we
>would transfer control.
>
>Now this routine was originally called when we executed a new method,  and
>when we  did a long unconditional jump bytecode backwards. Those  so called
>  "safe points"
>
>Many years ago when we moved from 25Mhz 68030 motorola macintoshs to  
>powerpc machines I discovered that this routine could be called upwards
>5,000 a second and contribute to much of the cpu usage of Squeak  since it
>was being called on the basis of a number (1000?) being  decremented.
>I altered this logic to ensure it would be called every N  milliseconds by
>fiddling with the interruptCheckCounter by  incrementing, decrementing the
>value
>to reach a steady state to limit the calling frequency to a target  value.
>
>Later we added the ability to force an interrupt check, say after an  
>incremental GC, or after a signal semphore, plus some other  interesting
>places to ensure the check for interrupt would very  quickly process a
>pending interrupt.
>
>This does not mean the routine is called exactly every N  milliseconds,
>rather it's *usually* called every N milliseconds.  How  many bytecodes
>that is, is well anyone's guess since reliant on  method sends, and
>backward long unconditional jumps.
>
>Exceptions are I believe the Windows VM forces an interrupt check  every
>millisecond due to an external timer to ensure it's called more  closely to
>the 1 millisecond goal.
>
>On May 1, 2007, at 1:56 PM, Martin v. Löwis wrote:
>
>>>Does the Squeak VM do preemptive scheduling or regular yield style
>>>scheduling.  This may sound like a silly question, but I know  Erlang is
>>>language that does mainly green threads and they are preemptive in
>>>nature.  They accomplish this by allowing a given thread to  execute no
>>>more then 100 VM instructions before it is preempted (obviously if a
>>>thread makes a primitive call that is a voluntary yield).
>>>
>>>Does Squeak do this already?
>>
>>Yes, the Squeak scheduler implements preemptive scheduling. An active
>>process is given a quantum of such-and-such many byte codes, and when
>>the quantum expires, a scheduling decision is made. The scheduler
>>attempts to make each quantum a (tunable) period of time (by default
>>1ms), and adjusts the number of byte code operations to account for
>>differences in CPU speed.
>>
>>Regards,
>>Martin
>>
>
>--
>========================================================================
>===
>John M. McIntosh <[hidden email]>
>Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
>========================================================================
>===
>
>
>

_________________________________________________________________
Mortgage refinance is Hot. *Terms. Get a 5.375%* fix rate. Check savings
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2bbb&disc=y&vers=925&s=4056&p=5117