- the thread context switch time
- Posted by Andrew on December 9th, 2003
Hi All,
How much time does it take to switch between threads in different processes
assuming PASSIIVE_LEVEL and the same priority?
Another words is it a very bad/good idea to have the working thread to
simplify life?
TIA
Andrew
- Posted by Bryan on December 9th, 2003
"Andrew" <universalkludge@hotmail.com> wrote in message
news:OMEsj8mvDHA.3196@TK2MSFTNGP11.phx.gbl...
this depends on many things the user thread has no control over and are
normally counted to the threads quantum. (e.g., anything that happens when
irql greater than passive such as dpc, priority boosting, hardware
interrupts, this list goes on).
-bryan
- Posted by Andrew on December 9th, 2003
For the sake of the argument let's assume there are no interrupts, but a
bunch of PASSIVE _LEVEL system threads waiting on hSynchronizationEvent and
performing KeSetEvent (hSynchronizationEvent, 0, FALSE). So what are
expenses on context switching in these circumstances?
Regards
Andrew
"Bryan" <the_bullardsREMOVETHIS@sbcglobal.net> wrote in message
news:eI7UcdovDHA.1872@TK2MSFTNGP09.phx.gbl...
- Posted by Bryan on December 9th, 2003
"Andrew" <universalkludge@hotmail.com> wrote in message
news:emOAC6ovDHA.3216@TK2MSFTNGP11.phx.gbl...
so in your impossible scenario, the only way the scheduler is invoked is if
you wait on an object (non-preemptive but cooperative). the windows
scheduler places the current thread at the end of the run queue of it's
priority level and grabs the next queued thread of one of possibly 30 higher
priority run queues. the scheduler issues a context switch to the highest
priority thread and so on until it gets back to your thread. so you
question depends on how many threads will be scheduled before yours. how
many times will they be scheduled before your thread, and how long (quantum)
will each of the higher priority threads run.
of course if any higher priority thread once running, never waits, your
thread will never run again anyway because there are no interrupts (no
thread preemption).
now as far as the context switch itself. i can't really tell you. you
might look at the windows ce source to get an idea of how its done in the nt
kernel for example (how many cpu cycles are needed). i would guess that the
cpu state is saved on the ring0 stack, the page directory is reloaded, the
task state segment is updated. then the cpu registers are loaded from the
next thread ring0 stack. in a best case the context switch it's self
probably take about 300 cycles.
why does any of this matter to you anyway?
-bryan
- Posted by Andrew on December 9th, 2003
thank you Bryan,
I am just trying to estimate the overhead of introducing an intermediate
system working thread to simplify the driver logic.
"Bryan" <the_bullardsREMOVETHIS@sbcglobal.net> wrote in message
news:OD#Xp5pvDHA.2472@TK2MSFTNGP09.phx.gbl...