RE: [NtDev] Re: Things to be done at DISPATCH Level!

Max is right … you can’t wait at D_L … but you needn’t worry about being
a t D_L to long. You do what you have to do and return, or lower the IRQL if
you raised it.

Gary

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Tuesday, May 08, 2001 12:03 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Things to be done at DISPATCH Level!

a priceless resource like ISR processing time? or can i do a major
workload
(like
waiting for a resource to be released) at DISPATCH LEVEL. This might be a

No, you cannot wait on DISPATCH_LEVEL.
Register a callback routine (to be called when the event occurs) instead.

Max


You are currently subscribed to ntdev as: xxxxx@delphieng.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Thanks Max for the answer. But I have some more clarifications.

Actually I am registering for a routine which gets invoked at
DISPATCH_LEVEL, when
a particualr routine occurs. (I am writing a WDM driver).
Now I need to do some processing which might take some time and which also
involves waiting for a resource.
Would anybody please suggest me whether it is fine to do the following:

NotificationRoutine () /* This is called at DISPATCH_LEVEL */
{
Invoke IoAllocateWorkItem
Invoke IoQueueWorkItem passing a routine func1 and queueType as
DelayedWorkQueue.
/* This func1 will perform the processing which takes some time and which
also
* involves waiting for a resource.
*/
}

Now func1 gets called at PASSIVE_LEVEL, so I can do the processing
leisurely. I hope this is ok.

Now when two such notification routines invoke IoQueueWorkItem at the same
time,
will the invocation of func1 be serialised, one after the other OR will
func1 be invoked
in two separate system worker thread contexts?

IOW, is there a single system worker thread which caters to all the work
items queued ? or is a system worker thread spawned for every such call made
to IoQueueWorkItem?

Eagerly Awaiting a reply,
Thanks
Venky

[venky]-----Original Message-----
[venky]From: xxxxx@lists.osr.com
[venky][mailto:xxxxx@lists.osr.com]On Behalf Of Maxim
[venky]S. Shatskih
[venky]Sent: Tuesday, May 08, 2001 12:33 PM
[venky]To: NT Developers Interest List
[venky]Subject: [ntdev] Re: Things to be done at DISPATCH Level!
[venky]
[venky]
[venky]> a priceless resource like ISR processing time? or can i do a major
[venky]workload
[venky]> (like
[venky]> waiting for a resource to be released) at DISPATCH LEVEL.
[venky]This might be a
[venky]
[venky]No, you cannot wait on DISPATCH_LEVEL.
[venky]Register a callback routine (to be called when the event
[venky]occurs) instead.
[venky]
[venky] Max
[venky]
[venky]
[venky]—
[venky]You are currently subscribed to ntdev as: xxxxx@tataelxsi.co.in
[venky]To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

[venky]Actually I am registering for a routine which gets invoked at
[venky]DISPATCH_LEVEL, when
[venky]a particualr routine occurs. (I am writing a WDM driver).

I am sorry! there was a typo here… I meant when a particular situation
occurs…


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

After calling Spin lock u have observed we should Release Spin lock as soon
as possible. The time is mentioned somwhere in DDK. Same rule u should
follow here. U cant wait for some resouce in DISPATCH_LEVEL it will degrade
performance and it may lead to other problem also. Better u put some logic
which works in System Worker Thread only.

Regards,
Satish K.S

Thanks Max for the answer. But I have some more clarifications.

Actually I am registering for a routine which gets invoked at
DISPATCH_LEVEL, when
a particualr routine occurs. (I am writing a WDM driver).
Now I need to do some processing which might take some time and which also
involves waiting for a resource.
Would anybody please suggest me whether it is fine to do the following:

NotificationRoutine () /* This is called at DISPATCH_LEVEL */
{
Invoke IoAllocateWorkItem
Invoke IoQueueWorkItem passing a routine func1 and queueType as
DelayedWorkQueue.
/* This func1 will perform the processing which takes some time and which
also
* involves waiting for a resource.
*/
}

Now func1 gets called at PASSIVE_LEVEL, so I can do the processing
leisurely. I hope this is ok.

Now when two such notification routines invoke IoQueueWorkItem at the same
time,
will the invocation of func1 be serialised, one after the other OR will
func1 be invoked
in two separate system worker thread contexts?

IOW, is there a single system worker thread which caters to all the work
items queued ? or is a system worker thread spawned for every such call
made
to IoQueueWorkItem?

Eagerly Awaiting a reply,
Thanks
Venky

[venky]-----Original Message-----
[venky]From: xxxxx@lists.osr.com
[venky][mailto:xxxxx@lists.osr.com]On Behalf Of Maxim
[venky]S. Shatskih
[venky]Sent: Tuesday, May 08, 2001 12:33 PM
[venky]To: NT Developers Interest List
[venky]Subject: [ntdev] Re: Things to be done at DISPATCH Level!
[venky]
[venky]
[venky]> a priceless resource like ISR processing time? or can i do a
major
[venky]workload
[venky]> (like
[venky]> waiting for a resource to be released) at DISPATCH LEVEL.
[venky]This might be a
[venky]
[venky]No, you cannot wait on DISPATCH_LEVEL.
[venky]Register a callback routine (to be called when the event
[venky]occurs) instead.
[venky]
[venky] Max
[venky]
[venky]
[venky]—
[venky]You are currently subscribed to ntdev as: xxxxx@tataelxsi.co.in
[venky]To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@aalayance.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The operating system maintains pools of worker threads. In some cases it may
create new threads to satisfy new work requests. In general only N threads
will be active in any pool at any time, where N is the number of CPUs in the
system and ‘active’ means executing a worker routine and not in a wait
state.

Handing off work that blocks or takes a long time to a worker thread is
exactly what the NT architecture requires your DISPATCH_LEVEL operations to
do. The ‘takes a long time’ part is negotiable in your design - it is a
trade off you have to make between good overall system performance and good
performance for your specific device subsystem. As blocking using any
mechanism other than a spinlock is illegal at DISPATCH_LEVEL, and as it will
crash the system, if you need to use events, semaphores, resource locks etc.
or call any function that might use any of these, you have no choice, you
must arrange for a PASSIVE_LEVEL thread to perform these activities for you.

Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
603 321 1032
WindowsNT Windows 2000 Consulting Services

-----Original Message-----
From: Varadan Venkatesh [mailto:xxxxx@tataelxsi.co.in]
Sent: Wednesday, May 09, 2001 7:04 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Things to be done at DISPATCH Level!

Thanks Max for the answer. But I have some more clarifications.

Actually I am registering for a routine which gets invoked at
DISPATCH_LEVEL, when
a particualr routine occurs. (I am writing a WDM driver).
Now I need to do some processing which might take some time and which also
involves waiting for a resource.
Would anybody please suggest me whether it is fine to do the following:

NotificationRoutine () /* This is called at DISPATCH_LEVEL */
{
Invoke IoAllocateWorkItem
Invoke IoQueueWorkItem passing a routine func1 and queueType as
DelayedWorkQueue.
/* This func1 will perform the processing which takes some time and
which
also
* involves waiting for a resource.
*/
}

Now func1 gets called at PASSIVE_LEVEL, so I can do the processing
leisurely. I hope this is ok.

Now when two such notification routines invoke IoQueueWorkItem at the same
time,
will the invocation of func1 be serialised, one after the other OR will
func1 be invoked
in two separate system worker thread contexts?

IOW, is there a single system worker thread which caters to all the work
items queued ? or is a system worker thread spawned for every such call made
to IoQueueWorkItem?

Eagerly Awaiting a reply,
Thanks
Venky

[venky]-----Original Message-----
[venky]From: xxxxx@lists.osr.com
[venky][mailto:xxxxx@lists.osr.com]On Behalf Of Maxim
[venky]S. Shatskih
[venky]Sent: Tuesday, May 08, 2001 12:33 PM
[venky]To: NT Developers Interest List
[venky]Subject: [ntdev] Re: Things to be done at DISPATCH Level!
[venky]
[venky]
[venky]> a priceless resource like ISR processing time? or can i do a major
[venky]workload
[venky]> (like
[venky]> waiting for a resource to be released) at DISPATCH LEVEL.
[venky]This might be a
[venky]
[venky]No, you cannot wait on DISPATCH_LEVEL.
[venky]Register a callback routine (to be called when the event
[venky]occurs) instead.
[venky]
[venky] Max
[venky]
[venky]
[venky]—
[venky]You are currently subscribed to ntdev as: xxxxx@tataelxsi.co.in
[venky]To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

[venky]The operating system maintains pools of worker threads. In
[venky]some cases it may
[venky]create new threads to satisfy new work requests. In general
[venky]only N threads
[venky]will be active in any pool at any time, where N is the
[venky]number of CPUs in the
[venky]system and ‘active’ means executing a worker routine and not
[venky]in a wait
[venky]state.
Does this mean that for a single CPU. there can be M pools of worker threads
with one thread active in any of the M pools at a given point of time?
so if IoQueueWorkItem gets invoked from two different contexts at almost the
same
time, it is quite possible that the respective registered routines arent
serialised in execution and there will be two different worker threads
invoking
these routines simultaneously!

Thanks
– Venky


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

There are three global pools of worker threads: delayed, critical, and
hypercritical. Some number of threads are allocated to each pool, at
least one thread per pool. As I said, the OS has some algorithm for
deciding how many threads in each pool to activate at any point in time.
The algorithm might be different for each pool, but it is something like
N threads active (per pool) where N is the nubmer of CPUs. On a single
processor system N=1, so in any given pool only one thread will be
active. However, I said that ACTIVE included not blocked on a dispatcher
object. So yes you could queue two work items in the same pool on a
single processor system and the first item could start, block on an
event, the second item could then start, your first item could wake up
and both could be executing concurrently (due to preemption that would
be virtual concurrency on a single CPU.) You must write your worker
routines to be re-entrant and SMP-safe.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Varadan
Venkatesh
Sent: Thursday, May 10, 2001 12:11 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Things to be done at DISPATCH Level!

[venky]The operating system maintains pools of worker
threads. In [venky]some cases it may [venky]create new
threads to satisfy new work requests. In general [venky]only
N threads [venky]will be active in any pool at any time,
where N is the [venky]number of CPUs in the [venky]system and
‘active’ means executing a worker routine and not [venky]in a
wait [venky]state. Does this mean that for a single CPU.
there can be M pools of worker threads with one thread active
in any of the M pools at a given point of time? so if
IoQueueWorkItem gets invoked from two different contexts at
almost the same time, it is quite possible that the
respective registered routines arent serialised in execution
and there will be two different worker threads invoking these
routines simultaneously!

Thanks
– Venky


You are currently subscribed to ntdev as: xxxxx@tellink.net
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> IOW, is there a single system worker thread which caters to all the work

items queued ? or is a system worker thread spawned for every such call
made
to IoQueueWorkItem?

There is a pool of such threads which is auto-expanded.
But beware! In NT4, this auto-expansion is limited. So, if you’re running
under the filesystem (a disk driver or such) and use ExQueueWorkItem - then
you will possibly deadlock if the OS runs off the worker thread pool size.
The reason is that FSDs and the cache manager use ExQueueWorkItem
extensively, and if you use ExQueueWorkItem in your disk driver and thus
consume a thread in the pool - this can be in the context of another
ExQueueWorkItem request.

So, do NOT use ExQueueWorkItem from under the FSD in NT4. Write your own
implementation of ExQueueWorkItem which will be based on
PsCreateSystemThread.

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> -----Original Message-----

From: Gary Little [SMTP:xxxxx@Broadstor.com]
Sent: Tuesday, May 08, 2001 8:29 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Things to be done at DISPATCH Level!

First rule of thumb … You NEVER waste resources.

The second rule of thumb is “You do what you have to do …” (Peter, and
Tony, think they invented that phrase, but us old guys were using it in
the '70s. :)) If you’re writing a proprietary driver, you take as much
time as is needed regardless where you are. True, Oh-My-God’s smash bang
Widget might quit working because your driver is hogging all the
resources, but if you don’t care about Widgets working, then tell your
customers, or your boss, that Widgets are incompatible with your hardware
and driver.

Now if widgets do have to work … you still take the time you need. You
just bust your ass to make sure you don’t take anymore time than is
needed.

Gary

-----Original Message-----
From: Varadan Venkatesh [mailto:xxxxx]
> Sent: Monday, May 07, 2001 9:21 PM
> To: NT Developers Interest List
> Subject: [ntdev] Things to be done at DISPATCH Level!
>
>
> Hello
>
> I have some of my notification routines running at DISPATCH LEVEL.
> I need to know how much of processing time can be wasted at DISPATCH
> LEVEL.
> is it
> a priceless resource like ISR processing time? or can i do a major
> workload
> (like
> waiting for a resource to be released) at DISPATCH LEVEL. This might be a
>
> novice
> question! please bear with me if it is so!
>
> Thanks
> Venky
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@delphieng.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@nai.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</mailto:xxxxx>

> > I have some of my notification routines running at DISPATCH LEVEL.

> I need to know how much of processing time can be wasted at DISPATCH
> LEVEL.
> is it
> a priceless resource like ISR processing time? or can i do a major
> workload
> (like
> waiting for a resource to be released) at DISPATCH LEVEL.

Running at DISPATCH_LEVEL will preempt all normal threads and other DPC’s
queued to run. You can’t really wait (giving the CPU to something else than
needs it) at DISPATCH_LEVEL, you can spin the CPU doing nothing useful.
What has to happen to free up the resource your waiting for? Hopefully not
something that needs the CPU at DISPATCH_LEVEL or lower, or you will be
waiting a long time.

You could queue another DPC at the end of waiting DPC list, essentially
doing cooperative multitasking. If no other DPC’s are queued, you will get
immediately activated again. This would prevent CPU starvation to DPC’s
that can’t wait too long.

  • Jan

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com