synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would probably generate different DIRQL in a machine. In other words, a ISR will be called in different DIRQL. The driver need access some shared data in ISR and other place. So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );

InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;

//=========================================
InterruptConfig.SpinLock = spinlock;
//=========================================

status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );

if( !NT_SUCCESS(status) ) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
“WdfInterruptCreate failed: %!STATUS!”, status);
}

3). other routine

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

  1. Can the code work?

  2. In ISR, Does I need to use the following code?

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

thanks!

Yes the code will work, and no your interrupt routines do not need to
acquire the lock it is acquired before they are called.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@hotmail.com [mailto:xxxxx@hotmail.com]
Posted At: Friday, April 30, 2010 5:52 AM
Posted To: ntdev
Conversation: synchronization in the DIRQL of WDF driver
Subject: synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would
probably
generate different DIRQL in a machine. In other words, a ISR will be
called in
different DIRQL. The driver need access some shared data in ISR and
other
place. So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );

InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;

//=========================================
InterruptConfig.SpinLock = spinlock;
//=========================================

status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );

if( !NT_SUCCESS(status) ) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
“WdfInterruptCreate failed: %!STATUS!”, status);
}

3). other routine

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

  1. Can the code work?

  2. In ISR, Does I need to use the following code?

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

thanks!

__________ Information from ESET Smart Security, version of virus
signature
database 5074 (20100430) __________

The message was checked by ESET Smart Security.

http://www.eset.com

You do not need the global spinlock. Remove it. In fact if you used the global spinlock as you show below when 2 of your cards are plugged in, you would eventually hang the machine.

d

sent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: April 30, 2010 2:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would probably generate different DIRQL in a machine. In other words, a ISR will be called in different DIRQL. The driver need access some shared data in ISR and other place. So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );

InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;

//=========================================
InterruptConfig.SpinLock = spinlock;
//=========================================

status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );

if( !NT_SUCCESS(status) ) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
“WdfInterruptCreate failed: %!STATUS!”, status);
}

3). other routine

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

1. Can the code work?

2. In ISR, Does I need to use the following code?

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

thanks!


NTDEV is sponsored by OSR

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

If I can not use a global spin lock and just use a spin lock defined in device extension, how can I access driver-defined shared data ? such as a global var which would be accessed in ISR or other routine.

thanks!


You do not need the global spinlock. Remove it. In fact if you used the global
spinlock as you show below when 2 of your cards are plugged in, you would
eventually hang the machine.

d

sent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: April 30, 2010 2:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would probably
generate different DIRQL in a machine. In other words, a ISR will be called in
different DIRQL. The driver need access some shared data in ISR and other place.
So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );

InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;

//========================3D=================
InterruptConfig.SpinLock = spinlock;
//========================3D=================

status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );

if( !NT_SUCCESS(status) ) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
“WdfInterruptCreate failed: %!STATUS!”, status);
}

3). other routine

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

1. Can the code work?

2. In ISR, Does I need to use the following code?

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

thanks!


NTDEV is sponsored by OSR

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

The code will work?
Your idea is different from Doron.
He means I can not use a global spin lock as an interrupt spin lock.

The ISR has already held interrupt spin lock acquired by OS?
The result is coherent with my guess. The ISR always holds interrupt spin lock automatically.


Yes the code will work, and no your interrupt routines do not need to
acquire the lock it is acquired before they are called.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@hotmail.com [mailto:xxxxx@hotmail.com]
Posted At: Friday, April 30, 2010 5:52 AM
Posted To: ntdev
Conversation: synchronization in the DIRQL of WDF driver
Subject: synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would
probably
generate different DIRQL in a machine. In other words, a ISR will be
called in
different DIRQL. The driver need access some shared data in ISR and
other
place. So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

<…excess quoted lines suppressed…>
signature

database 5074 (20100430) __________

The message was checked by ESET Smart Security.

http://www.eset.com

1 the wdfinterrupt has its own internal spinlock
2 you do not need to provide a spinlock to do what you want
3 the isr is invoked with the internal spinlock held
4 to synchronize non isr code with the isr you wrap the code in WdfInterruptAcquire/ReleaseLock, do not call these functions in the isr

d

sent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: April 30, 2010 8:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] synchronization in the DIRQL of WDF driver

If I can not use a global spin lock and just use a spin lock defined in device extension, how can I access driver-defined shared data ? such as a global var which would be accessed in ISR or other routine.

thanks!

------------------------------------------------------------

You do not need the global spinlock. Remove it. In fact if you used the global
spinlock as you show below when 2 of your cards are plugged in, you would
eventually hang the machine.

d

sent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: April 30, 2010 2:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] synchronization in the DIRQL of WDF driver

I am writing a PCIe function driver. As we now, The data cards would probably
generate different DIRQL in a machine. In other words, a ISR will be called in
different DIRQL. The driver need access some shared data in ISR and other place.
So, I plan to realize the synchronization as follows:

WDFSPINLOCK spinlock = NULL; // It is a global var.

1). DriverEntry
WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &spinlock);

2). DeviceAdd
WDF_INTERRUPT_CONFIG InterruptConfig;

WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );

InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;

//========================3D=================
InterruptConfig.SpinLock = spinlock;
//========================3D=================

status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );

if( !NT_SUCCESS(status) ) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
“WdfInterruptCreate failed: %!STATUS!”, status);
}

3). other routine

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

1. Can the code work?

2. In ISR, Does I need to use the following code?

WdfInterruptAcquireLock(DevExt->Interrupt);
//access shared data
WdfInterruptReleaseLock(DevExt->Interrupt);

thanks!


NTDEV is sponsored by OSR

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


NTDEV is sponsored by OSR

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

I see, thanks very much!


1 the wdfinterrupt has its own internal spinlock
2 you do not need to provide a spinlock to do what you want
3 the isr is invoked with the internal spinlock held
4 to synchronize non isr code with the isr you wrap the code in
WdfInterruptAcquire/ReleaseLock, do not call these functions in the isr

d

Does the ISR always run in the same DIRQL of a machine, no matter how many cards it supports?
In other words, Is there such situation: the ISR runs in different DIRQL of a machine at the same time?

thanks!

Once assigned, dirql remains the same until reboot or pnp restart. Multiple instances of your card each have their own dirql. You should not share state across multiple instances, don’t even think about synchronizing the isrs from multiple instances. Basically the dirql value should not matter, just treat it as an opaque value that is unique to your pnp instance.

d

sent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: April 30, 2010 10:24 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] synchronization in the DIRQL of WDF driver

Does the ISR always run in the same DIRQL of a machine, no matter how many cards it supports?
In other words, Is there such situation: the ISR runs in different DIRQL of a machine at the same time?

thanks!


NTDEV is sponsored by OSR

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

thanks!
Your comment is very clear. thanks again! thanks!


Once assigned, dirql remains the same until reboot or pnp restart. Multiple
instances of your card each have their own dirql. You should not share state
across multiple instances, don’t even think about synchronizing the isrs from
multiple instances. Basically the dirql value should not matter, just treat it
as an opaque value that is unique to your pnp instance.

d

sent from a phpne with no keynoard