[Autogenerated] in order to show some aspects of scheduling.
I'm going to use a tool called CPU stress.
You can find that as part of the downloads for this course
or in one of my guitar repositories.
The purpose of CPU stress is to well stress the CPU to burn
CPU cycles when you initially run it.
You'll see that we have four threats here being created by the
tool automatically and only one of them is currently active
consuming some CPU some cycles.
We can of course take another thread here and make it
active as well by pressing this button,
we can change the activity level by using these _______
here from 25% to all the way up to 100%.
Let me put this thread in a busy state, which this is just a name.
But in fact,
75% of the time supposed to be running and 25% of the
time it's supposed to be waiting.
Now.
We will use this tool for several demos to see how things behave.
In order to see the thread states, we need to use another tool,
which I'm going to show you now, which is called Performance Monitor.
Performance Monitor is a tool you can look for just by
using the normal start button or you can just type perform
in here in the run dialog box.
This opens some E Y, which is called Performance monitor.
But technically this is performance here.
That's the name of the note.
And Performance monitor being just one of these tools.
Let me select Performance monitor here because this
is the tool I'm really after.
Once I do that we can see something here that changes as
the CPU time generally on my system.
Performance monitor is one of these tools that allows us to
see something called performance counters.
Performance counters is a built in Windows feature that
allows applications drivers almost anything to expose these
entities called performance counter, which essentially are always numbers.
They can mean anything you want and Windows comes built in with
many performance counters out of the box to show information that
is easy to see in the miracle form.
Performance counters are very easy to use and easy to
consume also and in general very useful to get a sense of
what's going on in several areas, especially related to CPU um memory I.
O.
And things like that.
Now what we want to do here is to look at a
particular set of performance counters.
So normally what we see here is the performance counter shown by default,
which is the total process or time,
which is not really interesting for our purposes.
I'm going to just select that and press the delete button or
right click and press delete to make it go away.
Then we can click this add button to add other performance counters of interest.
What we get here is the building.
Windows,
dialogue for performance counter selection and performance
counters are grouped into these categories.
So for example there's a category called process and for process we have a
bunch of performance counters such as privileged time.
That's kernel mode time.
Using more time.
The total time and some other properties such as the
handle count elapsed time and so on.
We can select any number of these counters by pressing
control while clicking and then at the bottom of these
kinds of counters we have instances,
we can look at the total instance or to speak,
kind of taking everything together or selects particular processes of
interest in this particular case because these counters are based on
instances because processes are different.
Some counters are global in nature don't have really
any instances associated with them.
Once you select what you want you can click the add button
to get the counters that you care about.
And then just press OK to see this starting to run here and updated
every second and for now I don't want these counters.
This just random counters for testing purposes.
Let me just remove them and look at what we really
want to use for this particular case.
I just want to say that there are lots of interesting categories
here that might be useful in other scenarios.
I really suggest you look that up if that might be interesting for
whatever you're doing on Windows in our case.
I want to see what's going on with thread.
So there's a category for that.
That is called thread.
Let me find that this is all arranged alphabetically.
So here's threat and we have a bunch of counters here.
I'm going to select two counters which is going to be
the current priority of the thread.
Whatever threat we're going to focus in next.
And then the also the thread state,
this is where those numbers in parentheses in the previous slide
will come in handy and you can see here there's lots of threads
really here in the in the system.
So we have to search I'm going to just click here and search for CPU stress
and press enter will get all the threats from CPU stress.
You notice CPU stress has four threats here that are numbered 1 to 4.
These are exactly the same numbers you should be looking at right here.
This is not a threat idea.
This just some kind of index representing the order of thread creation.
Thread zero is not shown here because this is the one managing the y in fact,
you can click this button to see the other threats,
you can see the threat zero here.
And some other threats that might be available as well.
Also has to doesn't refresh automatically.
So thread zero is handling the green, we don't care about that.
We only care about these four threads.
So let me just grab the first two threads for demonstration purposes
that we grab thread one and thread to using the control button as I'm
clicking and then I'm going to click add.
So we have four counters here,
The current priority and the thread state of each of these two threads.
So four counters in total and we'll press OK.
And you can see numbers start to uh to the graph start to run and
there's something here happening To make it easier to see.
We can change the scale here of the graph because we're
talking here about thread priorities,
which we know are limited to 31 and thread states are also very small numbers.
Let me rightly here in the graph and select properties go to graph
and change the maximum vertical scale to 16.
That's going to be good enough.
We're not going to use any priorities above 15 but of course we could
change that to a different number if if we need to do so now you notice the
red line here has the priority for thread number one and the green line has
the priority for thread number two.
As you can see right here.
Now notice we don't see any green line and that's because
it's completely hidden behind the red line because these
threats have the same priority.
Notice the priorities eight here as you can see in CPU stress itself,
let me just click CPU stress for a moment.
You notice the proteins have jumped to 10 and this is one of those booths
that is happening because a message has arrived and in fact there are some
other reasons that these boosts might occur.
So things change.
If I go back and use performance monitor as my current
application by clicking each title bar,
you can see the priority has decayed back to eight.
And this happens for both of these threats.
That's why we don't see any kind of change.
If we want.
We can make some change like going to the first thread,
right clicking and changing the priority to above normal.
You can see here the seven possible values we can use where
normal just means go back to the default.
So if I do above normal or let's go with highest just for fun.
This should just now raised by two.
So it was 10, it's now 12.
If I go back to selecting performance monitor here it's
going to go back to 10 verses eight.
And again, the reason is because of the lack of boost now,
but we actually increase the thread priority by two explicitly by using the
priority API behind the scenes that is used by CPU stress.
Now, the other lines here,
the blue and the yellow represent the thread state and you notice that the
blue line which is the thread state for thread number one,
you notice that the thread state here has um has or
is being changed from 2 to 5.
It's mostly in five but sometimes it's in state number two and if you go back
to the diagram we've seen state number two is running and state number five
is waiting so you can see the activity is low,
so 25% of the time on average,
it's going to be running in the state number two here but 70 5% of
the time it's going to be in a waiting state.
So this is on average because performance monitor
only updates once every second.
So lots of changes are happening between each update.
But on average it should have that kind of feel if you
look at the yellow thread and by the way,
if you don't see the color very well,
you can rightly can change the color to something else by going to the
properties you can change the color to something perhaps a bit easier
to to see maybe this science color here.
So you can see here that the actual opposite is what is happening.
We can see here that most of the time the science threat here
is in state to running most of the time,
but sometimes it instead number five, waiting and again we can make that change.
Let's change busy here to maximum with maximum,
the threat is always running at least, it always wants to run.
So the science threat is always going to be in ST
number two or to be more precise,
it will never go to state number five because it is
essentially in an infinite loop,
it could still go to a different state which could be a ready state
but because I have enough processors to go around,
it doesn't really have any problem running all the time.
The system is not completely saturated with CPU based activity.
We can do the same thing for the first thread just for fun.
We can see that now both of these lines are going to show as just blew,
the sign being hidden behind the blue because they're
running all the time right now,
there's no stress in the system so they can run at
the same time without any issue.
Will stress things out later on and see what that looks like once we add some
more interesting aspects to the mix related to affinity.