- Can I use something like Mutex or Spinlock in ISR rountine?
- Posted by Elliott on October 3rd, 2003
Hi All,
Is it possible to use somehting like Mutex or Spinlock in a ISR rountine
to lock a buffer/variable?
I read DDK, and it said that ExAcquireFastMutex and KeAcquireSpinLock
can only run at IRQL <= DISPATCH_LEVEL. But I need to write something into a
buffer when interrupted, and read out the buffer in a DISPATCH_LEVEL. Can I
do that? Thanks,
Best Regards,
Elliott
A WDM driver beginner
- Posted by Don Burn on October 3rd, 2003
For Win2k look at KeSynchronizeExecution this allows you to acquire a
spinlock
in normal code that will properly coodinate with an interrupt routine. In
Win2k3
you can use KeAcquireInterruptSpinLock.
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
"Elliott" <elliott@hknetmail.com> wrote in message
news:%23%23ZSUzViDHA.2212@TK2MSFTNGP09.phx.gbl...
- Posted by Calvin Guan on October 3rd, 2003
To amplify what Don has said, interrupt spinlock can be acquired only in
NORMAL code at IRQL<DIRQL by KeSynchronizeExecution or
KeAcquireInterruptSpinlock.
To OP, remember, you don't want to acquire interrupt spinlock in the ISR
routine since the lock is already held before the ISR got executed.
Calvin
"Don Burn" <burn@acm.org> wrote in message
news:vnqm5kmhgoc50d@corp.supernews.com...
- Posted by Elliott on October 4th, 2003
Thanks in advance,
And I want to ask, Is it properly that I should request a DPC in the ISR
routine for doing those things?
But I have next question that how long would it take to raise up a DPC
function to run? Is it just spend several ms or less? My interrupt interval
time is around 30ms...
And furthermore, however I'm just a beginner, what is the different
between IoDPC and CustomDPC? Would your guys introduce me a very simple
sample about the usage of DPC? Thanks very much,
Best Regards,
Elliott
A WDM Driver Beginner
"Calvin Guan" <ndisnewREMOVE_THE_CAPITALS@yahoo.com> wrote in message
news:ur2uvhbiDHA.1956@TK2MSFTNGP10.phx.gbl...
- Posted by Alexander Grigoriev on October 4th, 2003
For most scenarios, when your ISR recognizes that the interrupt is requested
by your device, it should disable the device interrupt and request a DPC.
When DPC is done servicing the device, it should reenable the device
interrupt.
It doesn't make much difference whether it's IoRequestDpc or KeQueueDpc. The
DPC will be executed as soon as your ISR and any other ISRs returns.
IoRequestDpc is just a wrapper around KeQueueDpc.
"Elliott" <elliott@hknetmail.com> wrote in message
news:eAWKTxjiDHA.1168@tk2msftngp13.phx.gbl...
- Posted by Mark Roddy on October 4th, 2003
On Sat, 4 Oct 2003 13:58:52 +0800, "Elliott" <elliott@hknetmail.com>
wrote:
I assume by 'these things' you mean the task of reading data from a
device into a buffer and then processing the contents of that buffer.
There are two choices:
1) your ISR fills the buffer directly, and then queues a dpc routine
to process the buffer, with the dpc routine possible signal ling other
threads or, more likely completing an IO request.
2) your ISR just queues the dpc. The dpc routine both fills the buffer
and processes it.
The choice usually is determined by soft real-time constraints with
your hardware device. The latency between queueing a dpc in your ISR
and the invocation of your dpc routine is indeterminate. Generally the
latency is small, frequently it is negligible, but sometimes on some
platforms under some conditions it can be rather large (0.5 seconds
for example.)
A classic case where you have to do the fill operation in the ISR is
where the hardware provides a fifo of some sort, and if you don't
empty the fifo in the isr then you will get a data overrun condition.
Essentially your ISR is extending the FIFO onto host memory and thus
providing sufficient buffering to avoid overruns barring exceptional
conditions.
Generally you should be fine with the 'do it in the dpc approach'. But
you have to consider what happens to your data stream if you ever miss
your 30ms window.
Your device object gets one DPC object gratis from the OS. You use the
Io routines to manipulate this dpc. If you decide that your device
needs more than one dpc object, those are custom dpcs and are
manipulated using the Ke routines. Otherwise there really is not much
difference. The Ke routines give you more control.
=====================
Mark Roddy
Windows XP/2000/NT Consulting, Microsoft DDK MVP
Hollis Technology Solutions 603-321-1032
www.hollistech.com
markr@hollistech.com
For Windows Device Driver Training: see www.azius.com
- Posted by Elliott on October 5th, 2003
Thankyou very much for yours help,
But I want to ask more once, How can I measure the Interrupt interval
time in the ISR routine(For debug use). I have tried to use
KeQueryTimeIncrement and KeQueryInterruptTime before, but they always return
a same value in the ISR. Then what can I do? Thanks,
Best Regards,
Elliott
A WDM Driver Beginner
"Elliott" <elliott@hknetmail.com> wrote in message
news:eAWKTxjiDHA.1168@tk2msftngp13.phx.gbl...
- Posted by Maxim S. Shatskih on October 6th, 2003
RDTSC only.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com