DeadLock in Filter Driver

Potential problem in volume filter driver.I have two different threads running at different IRQl’s.
But the different IRQLs are competing for the same resource.
For Ex: Thread on T1 is running at Dispatch level.
Thread two T2 is running at Passive level.
Both the thread are accessing the same resource upto some time but suddenly
T1 is preempting T2.also for very less time T2 is Preempting T1.
Due to that the sequence of operation getting failed and control is coming out of the loop abruptly.???
Is this a Deadlock kind of situation what can i do in this case???
How do i manage the IRQL levels for accessing the same resource.

Thanks.

Doesn’t sound like a DEADLOCK to me… Your problem seems to me to be more like a standard serialization problem.

You need to protect this shared resource with a spin lock. That will ensure only one thread access this data at a time.

Does that help?

Peter
OSR

> T1 is preempting T2.also for very less time T2 is Preempting T1.

T2 cannot preempt T1 till T1 will lower its IRQL.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

>You need to protect this shared resource with a spin lock.

I am using spin lock only to protect this shared resource.

T2 cannot preempt T1 till T1 will lower its IRQL.

This is what exactly happening. T1 lowering its IRQL and then preempting T2 :frowning:
Also during testing able to see T1 preempting T1 itself for some times.(is it possible)???
Explanation:: from T1 at passive level i got the packets keeping inside a buffer,once required dispatching them form buffer and completing them.mean while from T2 also got some packets,again keeping in a buffer and processing them further and completing. at some times T1 preempting T2 due to that loosing the sequential operation.access to shared resource is locked using spin lock’s. T2 processing breaking in between???
seeking for help thanks a lot.

If T1 acquires te spin lock, its IRQL is of no interest in te discussion.
T2, independent of its IRQL, will have to wait for T1 to release the lock.
Similarly, if T2 acquires the lock, then T1 must wait, independent of its
IRQL. T1 cannot “preempt” T2 while T2 holds the spin lock, because while
it is holding the spin lock, T2 is at DISPATCH_LEVEL, and therefore cannot
be scheduled (or descheduled). Now consider a muticore machine, where T1
is running one one core and T2 on another. T1, at DISPATCH_LEVEL, doesn’t
care about T2, and therefore the concept of “preemption” is irrelevant.
T1 can acquire the spin lock, which will prevent T2 from acquiring it, but
that does not constitute “preemption”. Similarly, if T2 acquires te spin
lock, T1 has to wait for it, and from the scheduler viewpoint, this cannot
constitute “preemption”. Note that as long as T2 holds the lock, it
cannot be touched by the scheduler, because it’s at DISPATCH_LEVEL There
is an issue where a *logically* lower-priority thread blocks a *logically*
higher-priority thread. If the lower-priority thread can be descheduled,
then the higher-priority thread is blocked, and in a pure
highest-priority-thread-wins model, you now have something known as
“priority inversion”. But this is not possible in Windows in the scenario
you present, because the “lower-priority” thread is made non-preemptible
by being raised to DISPATCH_LEVEL during the scope of the lock.

If you discover that the order of acquisition means your code doesn’t
work, it means your code is wrong.
joe

Potential problem in volume filter driver.I have two different threads
running at different IRQl’s.
But the different IRQLs are competing for the same resource.
For Ex: Thread on T1 is running at Dispatch level.
Thread two T2 is running at Passive level.
Both the thread are accessing the same resource upto some time but
suddenly
T1 is preempting T2.also for very less time T2 is Preempting T1.
Due to that the sequence of operation getting failed and control is coming
out of the loop abruptly.???
Is this a Deadlock kind of situation what can i do in this case???
How do i manage the IRQL levels for accessing the same resource.

Thanks.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> Also during testing able to see T1 preempting T1 itself for some times.(is it possible)???

Completion routines and DPCs (and everything called by them) run on “arbitrary thread context”, i.e. it can preempt any thread in the OS and the notion of “current thread” is null and void for them.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

I don’t understand the question.

If T1 and T2 are both holding a spin lock, they are by definition running at the spin lock’s IRQL (which will be DISPATCH_LEVEL, unless you’re using an interrupt spin lock). That means neither thread will be able to preempt the other.

And, yes… one thread can appear to “preempt” itself. It’s not actually being preempted, it’s being interrupted. For example, if T1 is running at IRQL PASSIVE_LEVEL when an interrupt occurs… that interrupt will run in the context of T1. If that interrupt queues a DPC, that DPC will run at IRQL DISPATCH_LEVEL in the context of T1.

Peter
OSR

Thank you very much for excellent explanation…:slight_smile: