KeSynchronizeExecution vs Raise/Lower pair

Hello All!

Question about KeSynchronizeExecution:

ISR uses some data concurrently with many dispatch routines.
In the right world KeSynchronizeExecution must be called here.
But… this function requires me to make many small synch routines
having “context” adjusted depending on task to do and so on… But
it could be wonderful to insert some brace pairs in all the places…
Just to change code fast & to have it looking nice…

In other words, I want something like acquiring an interrupt spin
lock in the way the executive spin lock is acquired. (I mean syntax:
AcquireSmth … ReleaseSmth)… Without KeSynchronizeExecution.

So, if I have exactly one device object, exactly one interrupt object &
exactly one CPU in PC :), I expect Raise/Lower irql functions to render
me a service I need… With all these three conditions being true
is it right to rely on such synchronization ?.. or I’ve missed something…

Thank you,
Vladimir.


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

>

So, if I have exactly one device object, exactly one interrupt object &
exactly one CPU in PC :), I expect Raise/Lower irql functions to render
me a service I need… With all these three conditions being true
is it right to rely on such synchronization ?.. or I’ve missed
something…

Yes. ASSUMING you only have a single CPU in the system, this will work.
It’s a big assumption, and if I were you, I’d document this assumption
frequently, explicitly, and vividly in the code. I’d also add a check for
the number of CPUs in DriverEntry():

//
// This driver only works on a single CPU system!
//
if(*KeNumberProcessors > 1) {
DbgPrint(“*** %d CPUs in system! Can’t run!\n”,
*KeNumberProcessors);
return(STATUS_UNSUCCESSFUL);
}

Peter
OSR Open Systems Resources, Inc.


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

Vladimir,

I ran into much the same problem you are dealing with now.
KeSynchronizeExecution is a royal pain in the ass to have to use.
KeAcquire/ReleaseInterruptSpinLock would allow much more flexibility, but
those routines do not exist. They were probably rejected by the same eugenic
aberration(s) that decided to remove the DDKs from the MSDN Library. However
you can write your own, and although KINTERRUPT is an opaque structure,
IoConnectInterrupt allows you to pass a pointer to your own spinlock. A
quick step through the acquisition/release of a normal spinlock will then
give you the basic mechanism to use this new synchronization method. The
acquire looks like this in PDL:

Save current IRQL
Raise IRQL to DIRQL
While Hell is not frozen
Interlock compare and exchange the spinlock
If spinlock acquired
Exit while loop
End while

I had to have it since I have an API that I call and the API functions want
to synchronize to DIRQL internally. Since I write those sync functions, I
could write them as no-ops and then write a KSE and call back for all of
those API calls, or write an acquisition/release interrupt spinlock that
those API calls could use. My preference was the latter.

Gary

-----Original Message-----
From: Vladimir Kananovich [mailto:xxxxx@csie.nsys.by]
Sent: Wednesday, January 31, 2001 8:52 AM
To: NT Developers Interest List
Subject: [ntdev] KeSynchronizeExecution vs Raise/Lower pair

Hello All!

Question about KeSynchronizeExecution:

ISR uses some data concurrently with many dispatch routines.
In the right world KeSynchronizeExecution must be called here.
But… this function requires me to make many small synch routines
having “context” adjusted depending on task to do and so on… But
it could be wonderful to insert some brace pairs in all the
places…
Just to change code fast & to have it looking nice…

In other words, I want something like acquiring an interrupt spin
lock in the way the executive spin lock is acquired. (I mean syntax:
AcquireSmth … ReleaseSmth)… Without KeSynchronizeExecution.

So, if I have exactly one device object, exactly one interrupt
object &
exactly one CPU in PC :), I expect Raise/Lower irql functions to
render
me a service I need… With all these three conditions being true
is it right to rely on such synchronization ?.. or I’ve missed
something…

Thank you,
Vladimir.


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

> acquire looks like this in PDL:

Save current IRQL
Raise IRQL to DIRQL
While Hell is not frozen
Interlock compare and exchange the spinlock
If spinlock acquired
Exit while loop
End while

You actually want to test the spinlock value using a non-interlocked
operation and then only if the first test passes try it again with an
interlocked operation. This will avoid spinning excessively in a loop that
emits LOCKed operations:

While Hell is not frozen
If spinlock is available then
Interlock compare and exchange the spinlock
If spinlock acquired
Exit while loop
Endif
Endif
End While

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


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 Peter!
Hello Gary!
Hello Mark!

Thank you all! Unfortunately I could test it on single-cpu pc only… It
works, but…

Can you please tell me: to be sure, can I rely on the facts below?

  • KeSynchronizeExecution, calling ISR, will acquire/release two spin locks -
    interrupt own one & external spin lock from me…
  • released spin lock value is FALSE always.

swapirqls…
while (TRUE)
{
if (*pLock == FALSE) // if not acquired
{
if (FALSE == InterlockedCompareExchange((PLONG)pLock, TRUE, FALSE))
// exchange occurred
break;
}
}

What’s confusing me here is a very dangerous assuredness of internal
contents of KSPIN_LOCK.

Best regards,
Vladimir.


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

Vladimir said:

What’s confusing me here is a very dangerous assuredness of internal
contents of KSPIN_LOCK.

Best regards,
Vladimir.

Vladimir,

Look, if you are going to HACK new interfaces into the kernel then your life
is one of dangerous assumptions. If you want to live safely then I suggest
that you also write code that instead uses the defined interfaces. Right?

Cheers, and happy hacking,

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


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

> You actually want to test the spinlock value using a non-interlocked

operation and then only if the first test passes try it again with an
interlocked operation. This will avoid spinning excessively in a loop that
emits LOCKed operations:

While Hell is not frozen
If spinlock is available then
Interlock compare and exchange the spinlock

Done internally in KeAcquireSpinLock.

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