[Autogenerated] given what we've seen for a single CPU system.
Let's see the basic scheduling algorithm for multi
processing systems not taking into consideration power
considerations or numerous systems.
So let's say we have a threat that is ready means it's ready to go.
It just needs a processor and the system's role here is
to find the processor for this thread.
So the first question the schedule ask is whether there is at
least one CPU which is idle meaning doing nothing.
If there is one, then we'll go to the right here,
otherwise we'll go to the left.
Let's start with the case that there's at least one processor doing nothing.
So the next question is whether the previous processor that thread was running
on is one of those idle processors And if the answer is yes,
then great.
Let's use it.
Why?
Because the previous processor is likely to have
some data related to that threat.
Maybe the part of the thread stack in the cash in its cash.
So we get better performance if this is not the case and that
particular processor is busy running some other thread,
then the next next check is what about the ideal processor?
Remember the ideal processor is the way to kind of very roughly
provide a load balancing scheme so that threads kind of spread
out roughly evenly across processor.
Unless there's some other more compelling factor.
And so the next thing is to ask whether the ideal
processor happens to be idle doing nothing.
If this is the case.
Great,
let's grab let's grab it because that's the next best thing we
want to use the ideal processor in some way,
use that parameter in some way, if this is not the case.
So the ideal processor is busy running some other thread,
then the next question is, is the current process or idle.
And so the process or in question might be the one that was walking up
because the threat became ready but it wasn't doing anything before
that was just idling and doing nothing.
So since this process is already running some code,
the scheduled code is not for free,
it has to run some instructions which is doing right now.
So if this threat is this process or really is not doing anything,
it wasn't doing anything previously before some interrupt kicked in,
then let's just use this processor and be done with it.
We're just already here.
The process is already awake.
Otherwise let's just find the first processor that is idle and just use it.
And of course we are guaranteed to find it because we started with the
assumption with the first question whether there's at least one processor
which is idle and so we must find one of those and then that processor will
be used to run this particular threat.
The other option going back the beginning of this
diagram is that all processors are busy.
So no processor is either everyone is doing something is
running some code for some thread.
So in this case there's a check that looks whether the
ideal processor is running a lower priority thread then the
priority of the current threat.
We're trying to find a home for if this is the case,
we're going to preempt that other thread and make a context
switch so that other thread goes back into the ready state and
our thread goes into the running state.
But if the ideal processor is currently running a thread
with a higher priority or equal priority,
then we're not going to continue searching for another processor that
may be running a thread with a lower priority Instead,
we're just going to add that thread into the ridicule for the ideal processor.
Let things continue in a natural manner.
So once the uh other thread goes into a weight set for example,
then our thread will perhaps get some time there.
And the idea here is that all these scheduling code is really wasted time.
We can have more elaborate algorithms used by they take more
time and you have to balance these things out.
And so trying to look for another process.
So that might be running a thread with a priority might be
perhaps the right thing to do in an ideal world,
but this is not an ideal world.
And so it's better to say, well,
let's just minimize the code that the schedule is executing and let's
continue on and let the particular CPU that was running the scheduling
code go about the it's business running some other thread that was
interrupted at this point in time.
So this is just to give you a sense of how complex things are.
And we have to,
when I say we I mean Microsoft uh people that are building the schedule
has to balance these two different kind of factors.
One of them is to try to run uh things in the more I would say correct way
based on priorities and things like that as they should.
However, there is the other thing to look at,
such as power consumption and running code that perhaps we can minimize in
some way and that's another reason why these algorithms are continually
being tweaked to make things better in some sense.