I have a basic question:
On a multiprocessor machine, how many dispatcher threads does Windows have?
Is it one, or = the # of processors?
AP
I have a basic question:
On a multiprocessor machine, how many dispatcher threads does Windows have?
Is it one, or = the # of processors?
AP
What is “dispatcher threads”?
If you mean the work queue threads- their number varies.
If you mean the Idle thread(s) - the first thread(s) created by the system, then their number is equal to the number of logical CPUs.
–
Slava Imameyev, xxxxx@hotmail.com
“A P” wrote in message news:xxxxx@ntdev…
I have a basic question:
On a multiprocessor machine, how many dispatcher threads does Windows have? Is it one, or = the # of processors?
AP
I believe he is asking about scheduling and dispatching of threads. - it
is my belief there is no thread that actually invokes
a different thread based on what the scheduler says, instead both are
distributed all threw out the kernel.
Then again, I obviously haven’t learned a whole lot in the last several
months…
m.
Slava Imameyev wrote:
What is “dispatcher threads”?
If you mean the work queue threads- their number varies.
If you mean the Idle thread(s) - the first thread(s) created by the
system, then their number is equal to the number of logical CPUs.–
Slava Imameyev, xxxxx@hotmail.com mailto:xxxxx
>
>
>
> “A P” >
> wrote in message news:xxxxx@ntdev…
> I have a basic question:
>
> On a multiprocessor machine, how many dispatcher threads does
> Windows have? Is it one, or = the # of processors?
>
> AP
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx>
beg ur pardon. yes i was talking abt how threads are scheduled across
processors.
are there as many schedular threads as there are processors>
On 9/6/06, MM wrote:
>
> I believe he is asking about scheduling and dispatching of threads. - it
> is my belief there is no thread that actually invokes
> a different thread based on what the scheduler says, instead both are
> distributed all threw out the kernel.
>
> Then again, I obviously haven’t learned a whole lot in the last several
> months…
>
> m.
>
> Slava Imameyev wrote:
>
> > What is “dispatcher threads”?
> >
> > If you mean the work queue threads- their number varies.
> > If you mean the Idle thread(s) - the first thread(s) created by the
> > system, then their number is equal to the number of logical CPUs.
> >
> > –
> > Slava Imameyev, xxxxx@hotmail.com mailto:xxxxx
> >
> >
> >
> > “A P” >
> > wrote in message news:xxxxx@ntdev…
> > I have a basic question:
> >
> > On a multiprocessor machine, how many dispatcher threads does
> > Windows have? Is it one, or = the # of processors?
> >
> > AP
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
></mailto:xxxxx>
>how threads are scheduled across processors
In some predefined points( return from hardware and software interrupt handlers, wait functions etc. ) the check is made whether the current thread must be scheduled out.
The current CPU context( the registers’ content and the memory map ) is replaced by the new context. The context switch is performed in the context of the thread which is going to be scheduled out.
There is no special dedicated thread that switches other threads.
–
Slava Imameyev, xxxxx@hotmail.com
“A P” wrote in message news:xxxxx@ntdev…
beg ur pardon. yes i was talking abt how threads are scheduled across processors.
are there as many schedular threads as there are processors>
On 9/6/06, MM wrote:
I believe he is asking about scheduling and dispatching of threads. - it
is my belief there is no thread that actually invokes
a different thread based on what the scheduler says, instead both are
distributed all threw out the kernel.
Then again, I obviously haven’t learned a whole lot in the last several
months…
m.
Slava Imameyev wrote:
> What is “dispatcher threads”?
>
> If you mean the work queue threads- their number varies.
> If you mean the Idle thread(s) - the first thread(s) created by the
> system, then their number is equal to the number of logical CPUs.
>
> –
> Slava Imameyev, xxxxx@hotmail.com <mailto: xxxxx>
>
>
>
> “A P” >
> wrote in message news:xxxxx@ntdev…
> I have a basic question:
>
> On a multiprocessor machine, how many dispatcher threads does
> Windows have? Is it one, or = the # of processors?
>
> AP
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:>
To add to Slava’s comments, I just located the quote from “inside
windows 2000” - took a while to remember where I had read this. If you
have the book, it’s described in detail in chapter 6, section 5
specifically.
“The Windows 2000 scheduling code is implemented in the kernel. There’s
no single “scheduler” module or routine, however—the code is spread
throughout the kernel in which scheduling-related events occur. The
routines that perform these duties are collectively called the kernel’s
/dispatcher.”
m.
/
Slava Imameyev wrote:
>how threads are scheduled across processors
In some predefined points( return from hardware and software interrupt
handlers, wait functions etc. ) the check is made whether the current
thread must be scheduled out.
The current CPU context( the registers’ content and the memory map )
is replaced by the new context. The context switch is performed in the
context of the thread which is going to be scheduled out.
There is no special dedicated thread that switches other threads.–
Slava Imameyev, xxxxx@hotmail.com mailto:xxxxx
>
> “A P” >
> wrote in message news:xxxxx@ntdev…
> beg ur pardon. yes i was talking abt how threads are scheduled
> across processors.
> are there as many schedular threads as there are processors>
>
> On 9/6/06, MM > mailto:xxxxx> wrote:
>
> I believe he is asking about scheduling and dispatching of
> threads. - it
> is my belief there is no thread that actually invokes
> a different thread based on what the scheduler says, instead
> both are
> distributed all threw out the kernel.
>
> Then again, I obviously haven’t learned a whole lot in the
> last several
> months…
>
> m.
>
> Slava Imameyev wrote:
>
> > What is “dispatcher threads”?
> >
> > If you mean the work queue threads- their number varies.
> > If you mean the Idle thread(s) - the first thread(s) created
> by the
> > system, then their number is equal to the number of logical
> CPUs.
> >
> > –
> > Slava Imameyev, xxxxx@hotmail.com
> mailto:xxxxx <mailto: xxxxx>> mailto:xxxxx>
> >
> >
> >
> > “A P” > mailto:xxxxx mailto:xxxxx> mailto:xxxxx>>
> > wrote in message news:xxxxx@ntdev…
> > I have a basic question:
> >
> > On a multiprocessor machine, how many dispatcher threads does
> > Windows have? Is it one, or = the # of processors?
> >
> > AP
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>
yes i read that book. it doesnt make sense to me. Who decided on which
processor the kernel will be running at a point in time? some ISR?
The kernel runs as needed on a many processors as needed. The scheduler
deals with what threads are available to run, not whether the thread is in
the kernel or user space.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
“A P” wrote in message news:xxxxx@ntdev…
> yes i read that book. it doesnt make sense to me. Who decided on which
> processor the kernel will be running at a point in time? some ISR?
>
“The kernel runs as needed on a many processors as needed. The scheduler
deals with what threads are available to run”
…and who decided which CPU teh scheduler is to run on? Who decided that it
is time to load the scheduler’s thread, and how? Is it an interrupt?
The scheduler runs on any / all CPU’s, there are a number of actions that
trigger scheduling, including waits by threads, preemption, etc.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
“A P” wrote in message news:xxxxx@ntdev…
> “The kernel runs as needed on a many processors as needed. The scheduler
> deals with what threads are available to run”
>
> …and who decided which CPU teh scheduler is to run on? Who decided that
> it
> is time to load the scheduler’s thread, and how? Is it an interrupt?
>
there is no “the scheduler’s thread”
the sequence of commands for the CPU_N are
CPU_N{
or
CPU_N{
}
each CPU has a queue ot the threads that are ready to run
–
Slava Imameyev, xxxxx@hotmail.com
“A P” wrote in message news:xxxxx@ntdev…
“The kernel runs as needed on a many processors as needed. The scheduler
deals with what threads are available to run”
…and who decided which CPU teh scheduler is to run on? Who decided that it is time to load the scheduler’s thread, and how? Is it an interrupt?
there is no “the scheduler’s thread”
the sequence of commands for the CPU_N are
CPU_N{
************* AT THIS STAGE, where the the return take the CPU to, which
thread? WHo decides IF the thread needs to be scheduled out?
Does this mean that after each ISR, some special code executes which checks
all these?
if( Thread A must be scheduled out ){
switch this CPU_N to a new thread B
or
CPU_N{
}
each CPU has a queue ot the threads that are ready to run
From my understanding, the scheduler and dispatcher don’t have threads.
Perhaps this is an overly simple and horrible analogy, but think of the
kernel
as having a set of global variables and periodically ‘adjusting’ them in
different routines. When the IRQL is below dispatch, it test these
global var’s to
determine the best next thread to run, and then switches too it.
Since ntoskrnl is executing threads on both processors - the schedular
isn’t located on either.
That is my understanding of it, if that is incorrect I’m sure someone
will chime in.
m.
A P wrote:
“The kernel runs as needed on a many processors as needed. The scheduler
deals with what threads are available to run”…and who decided which CPU teh scheduler is to run on? Who decided
that it is time to load the scheduler’s thread, and how? Is it an
interrupt?— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
“but think of the kernel as having a set of global variables and
periodically ‘adjusting’ them in
different routines.”
all this is fine, but to adjust these global variables, some code needs to
run!!! if at that time another thread is running, and this update operation
needs to take place how is it done? is that through timer inperrupt and it’s
ISR???
" When the IRQL is below dispatch, it test these
global var’s to determine the best next thread to run, and then switches too
it."
who is this ‘it’? and for ‘it’ to test…‘it’ needs to be in memory first?
This is what I am unable to understand!
“Since ntoskrnl is executing threads on both processors - the schedular
isn’t located on either.”
Ntoskernel needs to be in one processor then, ‘alive and kicking’ that makes
this a master slave architechure, or is that ntoskernel can be at any place
anywhere like in the movie matrix!!! sort of an interloper!!! Who governs
that all these things are systematic???
>AT THIS STAGE, where the the return take the CPU to, which thread?
Thread A
Does this mean that after each ISR, some special code executes which checks all these?
I think yes, when the IRQL drops to DISPATCH_LEVEL.
–
Slava Imameyev, xxxxx@hotmail.com
“A P” wrote in message news:xxxxx@ntdev…
there is no “the scheduler’s thread”
the sequence of commands for the CPU_N are
CPU_N{
- Thread A is executing
- Interrupt( software or hardware )
- ISR
- return from interrupt
************* AT THIS STAGE, where the the return take the CPU to, which thread? WHo decides IF the thread needs to be scheduled out?
Does this mean that after each ISR, some special code executes which checks all these?
if( Thread A must be scheduled out ){
switch this CPU_N to a new thread B
- Thread B is executing
} else {
continue thread A execution on this CPU_N
-Thread A is executing
}
}
or
CPU_N{
- Thread A is executing
- Thread A wants to wait for some event(s) and calls KeWaitFor…()
- KeWaitFor…( event(s) ){
if( event(s) in a signal state )
Continue the thread A executing
- Thread A is executing
else
switch processor to another thread B
- Thread B is executing
}
}
each CPU has a queue ot the threads that are ready to run
Albert…
I think you may be missing an important concept. Windows is what’s called a “thread stealing” operating system. Each thread has a user-mode stack and a kernel-mode stack and will spend part of its life running in each mode.
Let’s take an example of how this works: When a thread (a typical, user-mode, application for example) requests a system service that thread switches from user-mode to kernel-mode via the system service dispatcher (switching from its user-mode stack to its kernel-mode stack), and then starts executing the O/S code that performs the system service. When the processing is complete, the thread will go back to running in user-mode.
The same type of thing happens in Windows when an interrupt occurs. Whatever thead that happens to be running when the interrupt occurs transitions to kernel mode and runs the ISR of the interrupting device.
So… NOW read the (very excellent and clear) pseduo-code description by Slava with this in mind…
Cool huh?
Peter
OSR
The scheduler takes the responsibility to determine which thread should
own the the CPU. It’s not a dedicated thread. Scheduler is a subsystem
as IO manager or memory management manager. It spreads around the NT
kernel. It’s the “dispatch point” when scheduler is invoked.
Best Regards,
hanzhu
A P дµÀ:
yes i read that book. it doesnt make sense to me. Who decided on which
processor the kernel will be running at a point in time? some ISR?
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
What is “dispatcher thread”?
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “A P”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, September 06, 2006 11:18 AM
Subject: [ntdev] Windows Dispatcher Threads
> I have a basic question:
>
> On a multiprocessor machine, how many dispatcher threads does Windows have?
> Is it one, or = the # of processors?
>
> AP
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Albert-
who is this ‘it’? and for ‘it’ to test…‘it’ needs to be in memory first?
This is what I am unable to understand!
I believe this is your fundamental issue?
You are confusing the processor and the memory. Ignoring NUMA for the moment (please), there is only one memory, and all of the processors have access to it. The kernel is loaded into memory early in the boot process, and it never goes away.
Threads and processes are abstractions provided by the OS kernel. The processor has registers, and examines and modifies memory (and accesses I/O space for reads and writes) based upon what is in those registers. It never has a “program” inside it (ignoring the fact that it’s actually microprogrammed itself).
The OS is (one concept, anyway) one big program that makes all the other programs run. So yes, it is like the Matrix, and it IS a master slave architecture (pretty accomodating master, though). You could even argue that it’s the only program that ever runs and that all the other things that you think of as programs are just extensions [plugins, say] of it, if you would like.
One other minor correction to some earlier statements. Thread dispatching decisions are made at dispatch level. That’s actually why it’s called dispatch level.
A P wrote:
“but think of the kernel as having a set of global variables and
periodically ‘adjusting’ them in
different routines.”all this is fine, but to adjust these global variables, some code
needs to run!!! if at that time another thread is running, and this
update operation needs to take place how is it done? is that through
timer inperrupt and it’s ISR???
Even though we think of our computers as doing many things at once,
that’s just an illusion. The fact is that a processor can only do one
thing at a time. Only one thread is running in each processor at any
given instant, and the processor is either running user-mode code or
running kernel code. So, when user-mode code is running, there is no
kernel code running to know that scheduling is needed, and there is no
“supervisor” watching over things. All of the changes in the
processor’s state happen because of interrupts. That is the ONLY mechanism.
Now, EVERY interrupt causes the processor to switch to kernel mode and
jump to somewhere in the operating system’s kernel. Once we’re in the
operating system, we can do whatever we want. We have to handle the
interrupt, of course, but we can also examine the real-time clock and
use that to decide whether the thread that WAS running has used up its
time slice. If it has run out, then we save the current thread’s state,
and go through the process of choosing another. The new thread won’t
actually start until the kernel has run out of things to do and returned
from the interrupt. At that point, the old thread is frozen, and the
new thread starts to run. The kernel is also frozen, until another
interrupt comes in.
" When the IRQL is below dispatch, it test these
global var’s to determine the best next thread to run, and then
switches too it."who is this ‘it’? and for ‘it’ to test…‘it’ needs to be in memory
first? This is what I am unable to understand!
The kernel code is always in memory. Most of it is locked there.
However, it doesn’t actually run until an interrupt comes in and gives
it the opportunity to re-evaluate the priorities.
“Since ntoskrnl is executing threads on both processors - the schedular
isn’t located on either.”Ntoskernel needs to be in one processor then, ‘alive and kicking’ that
makes this a master slave architechure, or is that ntoskernel can be
at any place anywhere like in the movie matrix!!! sort of an
interloper!!! Who governs that all these things are systematic???
It’s all based on time. When the kernel gets a chance to run as the
result of an interrupt, it has a long list of time-based events that
might need to be handled. As each time expires, the event is handled
(which might include choosing a new thread), and execution continues.
That’s really the fundamental basis of a pre-emptive operating system.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.