Hi everyone,
I have a very special spinlock question which I am not able to get an
appropriate answer by carefully reading any documentation.

Consider two different spinlocks: Spinlock A & Spinlock B (Systemspinlocks)
There is a hardware port that should be protected against multiple accesses:
Port

For accessing the port, i acquire let's say Spinlock A (Implying that i
release spinlock after access properly).
Due to different instances of the class that handles "Port out" and "Port
in" i also have different spinlock objects therefor it might happen that
concurrently accesses to the port are protected by different instances of the
spinlockobject.

The big question is: Is this approach practically save in a SMP environment?
The background: We are in need of a very high accurate port frequency near
to realtime, so using other dispatchobjects like mutex, events, asf. is
absolutely inadequate (we already tried them)
As i know, by acquiring the spinlock, priority is increased to
DISPATCH_LEVEL, but due to the nature of SMP paralleltasking i presume that
another CPU might get a different spinlock instance even though other CPU
owns the other spinlock instance.
Or is any spinlock instance atomically?

The other question is: Is process/thread scheduling in general prohibited
during spinlock holding or is this regarding just the CPU on which the
spinlock is held?

Re: Multiple Spinlock acquiration for protection of concurrent port ac by Maxim

Maxim
Mon Jul 21 10:09:40 CDT 2008

> The big question is: Is this approach practically save in a SMP environment?

No, you must have a single spinlock. Tie the 2 classes together.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com


Re: Multiple Spinlock acquiration for protection of concurrent por by DeStefan

DeStefan
Mon Jul 21 10:20:13 CDT 2008

Thank you for your answer, Maxim S. Shatskih.

I already found out that your approach is necessary.
I solved it by using the spinlockobject with singleton pattern.
When program is running in DISPATCH_LEVEL other CPUs may run in
DISPATCH-LEVEL too and indeed, they acquire the second spinlock (since it is
a different resource) and grant access to my port, which leads to crumble at
the output.

Nice Greetings

"Maxim S. Shatskih" wrote:

> > The big question is: Is this approach practically save in a SMP environment?
>
> No, you must have a single spinlock. Tie the 2 classes together.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>

Re: Multiple Spinlock acquiration for protection of concurrent por by Maxim

Maxim
Mon Jul 21 10:36:32 CDT 2008

> I solved it by using the spinlockobject with singleton pattern.

Just a KSPIN_LOCK field in the device extension will help. There is no need in
global spinlock.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com


Re: Multiple Spinlock acquiration for protection of concurrent por by DeStefan

DeStefan
Mon Jul 21 10:44:14 CDT 2008

Yes of course. This was my approach. I just said "singleton" since it is one
instance in the deviceobject and will be used in each "port" derivate.
But it is working well now.
Thank you for your information

"Maxim S. Shatskih" wrote:

> > I solved it by using the spinlockobject with singleton pattern.
>
> Just a KSPIN_LOCK field in the device extension will help. There is no need in
> global spinlock.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>