Re: Never seen a driver that uses a KSEMAPHORE ???

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Feb 20, 8:21 am, "Maxim S. Shatskih" <ma...@xxxxxxxxxxxxxxxx>
wrote:
My understanding is that this is the only available synchronization
mechanism to handle serialized access to a cancel-safe IRP queue.

I think that these queues are usually protected by spinlock.


Indeed, this is what I am using in the CsqAcquireLock and the
CsqReleaseLock routines themselves.

However, the semaphore is **in addition** to the spinlock and is
intended to let the waiting thread track the number of IRPs in the
queue. I did not invent this - this is the exact method depicted in
the CSQ sample that comes with WDK.

CancelRoutine can be fired on DISPATCH_LEVEL, which makes any sync
objects other then spinlocks unusable in this context.


That semaphore, both in my driver and in the cancel.c sample, is:

1. Being WaitedFor in a system thread only.
2. KeReleaseSemaphore in dispatch routines only (always called at
PASSIVE_LEVEL, right? despite the confusing naming...)
3. KeInitializeSemaphore in a DRIVER_ADD_DEVICE routine (always
called at
PASSIVE_LEVEL).

Can't go wrong with that, right?

Thanks,
Don
.



Relevant Pages

  • On Jon Skeets threadpool
    ... The routines OnBeforeWorkItem and OnAfterWorkItem do not have a try-catch ... detected by logic in the Threadpool. ... the queue; why not pulse it after adding it to the queue? ...
    (microsoft.public.dotnet.general)
  • Re: 2.6.15rc5git1 cfq related spinlock bad magic
    ... I may have also been experimenting at the time with Pete Zaitcev's ... If CFQ is around, it keeps the queue pinned and uses ... > spinlock located in its data structure, ...
    (Linux-Kernel)
  • Re: 2.6.15rc5git1 cfq related spinlock bad magic
    ... I may have also been experimenting at the time with Pete Zaitcev's ... it only decrements its refcount. ... it keeps the queue pinned and uses the queue's spinlock. ...
    (Linux-Kernel)
  • Re: [patch] generic rwsems
    ... think your suggestion to instead move everyone to the spinlock version ... for the slowpath. ... extra flag in the counter to indicate there's stuff waiting on the queue, ... Note that the contention flag may only be set or cleared in the slow path ...
    (Linux-Kernel)
  • Re: Macros for Spinlocks, Mutexes, Semaphores, etc
    ... > keywords to B0, for OS development work. ... not spinlock. ... back on the run queue when the thing they are waiting on occurs. ...
    (alt.lang.asm)