Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


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

What kind of event is IrpQueueEvent? Maybe it is set signaled and never
reset so you loop…

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


You are currently subscribed to ntdev as: xxxxx@osr.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

As long as your realtime thread is ready to run, and it is the highest
priority thread that is ready to run, it will run. It will only share the
cpu with other ready threads of greater than or equal realtime priority. You
have to specify a non-zero timeout value so it blocks, or move the thread
out of the realtime class as it will then drop in priority as it consumes
quantum.

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


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

Use a non-zero timeout value, a value of 0 never gives up the CPU.

Larry

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


You are currently subscribed to ntdev as: xxxxx@diebold.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

What’s the priority of the dispatch routine? isn’t it higher than
LOW_REALTIME_PRIORITY?

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Wednesday, October 10, 2001 6:41 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Cannot give up CPU in system thread

As long as your realtime thread is ready to run, and it is the highest
priority thread that is ready to run, it will run. It will
only share the
cpu with other ready threads of greater than or equal
realtime priority. You
have to specify a non-zero timeout value so it blocks, or
move the thread
out of the realtime class as it will then drop in priority as
it consumes
quantum.

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon
reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); //
pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but
it doesn’t! It
keeps looping, blocking the main thread (and the whole
machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


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: xxxxx@mysticom.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

If you really meant “dispatch routine” as in DispatchDeviceControl, then the
priority is whatever the priority of the thread that is running when your
dispatch routine is invoked. In other words, no, the priority of your
dispatch routine is indeterminate, and is most likely less than any realtime
thread priority.

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 1:05 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Cannot give up CPU in system thread

What’s the priority of the dispatch routine? isn’t it higher than
LOW_REALTIME_PRIORITY?

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Wednesday, October 10, 2001 6:41 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Cannot give up CPU in system thread

As long as your realtime thread is ready to run, and it is the highest
priority thread that is ready to run, it will run. It will only share
the cpu with other ready threads of greater than or equal
realtime priority. You
have to specify a non-zero timeout value so it blocks, or
move the thread
out of the realtime class as it will then drop in priority as
it consumes
quantum.

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon
reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); //
pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver
thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole
machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


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: xxxxx@mysticom.com 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

The problem is that the timeout is set to 0. This causes the WaitForxxx to
check the state of the event and return immediately. This loop is always
computable, hence it hogs the CPU.

Greg

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Mark Cariddi
Sent: Wednesday, October 10, 2001 11:42 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Cannot give up CPU in system thread

What kind of event is IrpQueueEvent? Maybe it is set signaled and never
reset so you loop…

-----Original Message-----
From: Aaron Elberg [mailto:xxxxx@mysticom.com]
Sent: Wednesday, October 10, 2001 12:38 PM
To: NT Developers Interest List
Subject: [ntdev] Cannot give up CPU in system thread

Hi all!
I’m using a system thread to poll a device upon reception of an irp
requesting so. On thread creation I set its priority to
LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

while(true) {
KeWaitForSingleObject(
&DevExtension->IrpQueueEvent,
Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

// do polling task
}

I expected the Wait call to give up the cpu and allow the main
driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
keeps looping, blocking the main thread (and the whole machine). What should
I do to make it give-up?

Thanks in advance,
Aaron


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


You are currently subscribed to ntdev as: xxxxx@pdq.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

Maybe it is a better idea to poll using KeSetTimer which restarts itself each time?

Max

----- Original Message -----
From: “Aaron Elberg”
To: “NT Developers Interest List”
Sent: Wednesday, October 10, 2001 8:37 PM
Subject: [ntdev] Cannot give up CPU in system thread

>
> Hi all!
> I’m using a system thread to poll a device upon reception of an irp
> requesting so. On thread creation I set its priority to
> LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):
>
> while(true) {
> KeWaitForSingleObject(
> &DevExtension->IrpQueueEvent,
> Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0
>
> // do polling task
> }
>
> I expected the Wait call to give up the cpu and allow the main
> driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
> keeps looping, blocking the main thread (and the whole machine). What should
> I do to make it give-up?
>
> Thanks in advance,
> Aaron
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.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

Hello Aaron,

Wednesday, October 10, 2001, 8:37:58 PM, you wrote:

AE> Hi all!
AE> I’m using a system thread to poll a device upon reception of an irp
AE> requesting so. On thread creation I set its priority to
AE> LOW_REALTIME_PRIORITY. Then, in an infinite loop (simplified here):

AE> while(true) {
AE> KeWaitForSingleObject(
AE> &DevExtension->IrpQueueEvent,
AE> Executive, KernelMode, FALSE, pTimeout ); // pTimeout = 0

AE> // do polling task
AE> }

AE> I expected the Wait call to give up the cpu and allow the main
AE> driver thread handle incoming DeviceIoControl requests, but it doesn’t! It
AE> keeps looping, blocking the main thread (and the whole machine). What should
AE> I do to make it give-up?

AE> Thanks in advance,
AE> Aaron

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

You can simply create your system thread and not to change a priority
of this thread. I figured out that a base priority of threads that are
created using PsCreateSystemThread() function is 8
(compare to LOW_REALTIME_PRIORITY == 16!!!). Many of threads in Windows
have such a base priority value == 8. I myself do it
like that and these threads perfectly work and switch to other threads
(under Windows 98 and Windows NT/2K). Though Art Baker in his book
“The Windows NT Device Driver Book” wrote that a priority of system
threads must be set to LOW_REALTIME_PRIORITY and that these threads
must contain a call to KeWaitFor…() with some of synch objetcs.
But I often needed to have a dead polling loops. You can check this
technique and if it really works in your task, you can use it on your
own risk.


Best regards,
Konstantin Manurin (aka NizeG) xxxxx@infpres.com
xxxxx@beep.ru
xxxxx@yandex.ru
xxxxx@mail.ru


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

I guess I’m doing something wrong, because even when I set the timeout to
100 ms, the main thread (running at a lower priority) never gets its time
slot. I finally did what Konstantin suggested: I left both threads running
at the same priority level.

-----Original Message-----
From: Konstantin Manurin [mailto:xxxxx@infpres.com]
Sent: Thursday, October 11, 2001 9:07 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Cannot give up CPU in system thread

Hello Aaron,

Wednesday, October 10, 2001, 8:37:58 PM, you wrote:

AE> Hi all!
AE> I’m using a system thread to poll a device upon
reception of an irp
AE> requesting so. On thread creation I set its priority to
AE> LOW_REALTIME_PRIORITY. Then, in an infinite loop
(simplified here):

AE> while(true) {
AE> KeWaitForSingleObject(
AE> &DevExtension->IrpQueueEvent,
AE> Executive, KernelMode, FALSE, pTimeout );
// pTimeout = 0

AE> // do polling task
AE> }

AE> I expected the Wait call to give up the cpu and
allow the main
AE> driver thread handle incoming DeviceIoControl requests,
but it doesn’t! It
AE> keeps looping, blocking the main thread (and the whole
machine). What should
AE> I do to make it give-up?

AE> Thanks in advance,
AE> Aaron

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

You can simply create your system thread and not to change a priority
of this thread. I figured out that a base priority of threads that are
created using PsCreateSystemThread() function is 8
(compare to LOW_REALTIME_PRIORITY == 16!!!). Many of threads
in Windows
have such a base priority value == 8. I myself do it
like that and these threads perfectly work and switch to other threads
(under Windows 98 and Windows NT/2K). Though Art Baker in his book
“The Windows NT Device Driver Book” wrote that a priority of system
threads must be set to LOW_REALTIME_PRIORITY and that these threads
must contain a call to KeWaitFor…() with some of synch objetcs.
But I often needed to have a dead polling loops. You can check this
technique and if it really works in your task, you can use it on your
own risk.


Best regards,
Konstantin Manurin (aka NizeG) xxxxx@infpres.com
xxxxx@beep.ru
xxxxx@yandex.ru
xxxxx@mail.ru


You are currently subscribed to ntdev as: xxxxx@mysticom.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