Re: [ntdev] WDF: Handling interrupts from multiple sources

Please show your CreateFile call

Also, the way you are waiting for completion is inefficient and doesn’t check for failure properly

Sent from Surface Pro

From: Zvi Vered
Sent: ‎Thursday‎, ‎March‎ ‎26‎, ‎2015 ‎12‎:‎21‎ ‎PM
To: Windows System Software Devs Interest List

Hi Doron, All,

This is the code (in application) I’m using to send IOCTL:

int CMyDriver::WaitForEvent (int Channel,unsigned long *EventCounter,int
Timeout)
{
FIOA_INTERRUPT_REQUEST InBuf;
InBuf.Channel = Channel;
int rc;

rc=SendDeviceIoctl (FIOA_INTERRUPT_CODE,
&InBuf,
sizeof(FIOA_INTERRUPT_REQUEST),
EventCounter,
sizeof(FIOA_INTERRUPT_REPLY),
Timeout,
m_hEventIsr[Channel]);

return rc;
}

int CMyDriver::SendDeviceIoctl (UINT32 Code,
void *pInBuf,
int InBufSize,
void *pOutBuf,
int OutBufSize,
int Timeout,
HANDLE Event)
{
int rc;
unsigned long ByteCount;
OVERLAPPED Overlapped;

memset (&Overlapped,0,sizeof(Overlapped));
Overlapped.hEvent = Event;

DeviceIoControl(m_hDevice,
Code,
pInBuf,
InBufSize,
pOutBuf,
OutBufSize,
&ByteCount,
&Overlapped);

rc=WaitForSingleObject (Event,Timeout);
if (rc==WAIT_OBJECT_0)
return 0;
else if (rc==WAIT_TIMEOUT)
return FIO_ADAPTER_IOCTL_TIMEOUT;

return FIO_ADAPTER_IOCTL_FAILED;
}

As you can see, the method WaitForEvent calls SendDeviceIoctl with an
Event Parametr taken from m_hEventIsr.
The m_hEventIsr contains 4 events created in the Open method:

int CMyDriver::Open (void)
{

m_hEvent = CreateEvent (NULL,FALSE,FALSE,NULL);
if (m_hEvent == INVALID_HANDLE_VALUE)
return FIO_ADAPTER_CREATE_EVENT_FAILED;

for (int Channel=0;Channel<n_channels> {
m_hEventIsr[Channel] = CreateEvent (NULL,FALSE,FALSE,NULL);
if (m_hEventIsr == INVALID_HANDLE_VALUE)
return FIO_ADAPTER_CREATE_EVENT_FAILED;

m_hHeaderEventIsr[Channel] = CreateEvent (NULL,FALSE,FALSE,NULL);
if (m_hHeaderEventIsr == INVALID_HANDLE_VALUE)
return FIO_ADAPTER_CREATE_EVENT_FAILED;
}

return 0;
}

Can you tell what am I doing wrong ?

Best regards,
Z.V

From: Doron Holan
Sent: Wednesday, March 25, 2015 11:39 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDF: Handling interrupts from multiple sources

You need to open the handle as overlapped which will then allow simultaneous
IOs to be issued on the handle. Without overlapped the io requests are
serialized by the io manager. Why are you storing ISR state/data in a
global? You should put all state in the device extension and properly
synchronize access to the variable across DPCs and the ISR

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Zvi Vered
Sent: Wednesday, March 25, 2015 2:35 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] WDF: Handling interrupts from multiple sources

Hello,

My PCI FPGA creates an interrupt upon 2 kinds of events.

In the application I have 2 threads:

This is what I do in pseudo code:

Thread-A



Application

1. Wait For A Event and block

2. Send IOCTL Request with code A

Kernel

3. Put request in internal queue A

4. Upon ISR, read interrupt status register and clear it. Save status in a
global UINT32 variable

5. DPC callback for ISR: If BIT0==1, pull message in A internal queue

6. Complete IOCTL request

Application

7. Unblock Thread A

Thread-B



Application

1. Wait For B Event and block

2. Send IOCTL Request with code B

Kernel

3. Put request in internal queue B

4. Upon ISR, read interrupt status register and clear it. Save status in a
global UINT32 variable

5. DPC callback for ISR: If BIT1==1, pull message in B internal queue

6. Complete IOCTL request

Application

7. Unblock Thread B

But it seems this mechanism does not work well.

The device driver has only one IOCTL channel.

So if Thread-A is blocked, waiting for the IOCTL request to complete, how
can Thread-B wait for its event simultaneously without interfering Thead-A ?

What is the right way to handle this situation ?

In the real world, I have 8 different interrupt sources.

Best regards,

Z.V


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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</n_channels>