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

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

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

Zvi Vered wrote:

Hi Doron, All,

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

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;

That tells you whether the request completed, but nothing about whether
it succeeded. Instead of WaitForSingleObject, you should use
GetOverlappedResultEx. That will wait for the request to complete, AND
tell you whether the request succeeded and how many bytes were returned.

Can you tell what am I doing wrong ?

No, because you’ve never told us what behavior you’re actually seeing.
Exactly what happens when you submit multiple requests?

You also didn’t show us the CreateFile call. Are you actually
specifying FILE_FLAG_OVERLAPPED?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Are you opening the handle with overlapped flag?

d

Bent from my phone


From: Zvi Veredmailto:xxxxx
Sent: ?3/?26/?2015 9:20 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] WDF: Handling interrupts from multiple sources

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></mailto:xxxxx></mailto:xxxxx>

Hi Doron,All,

The code for opening the handle is:

m_hDevice = CreateFile(DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

Should it be:

m_hDevice = CreateFile(DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

?

Best regards,
Z.V

From: Doron Holan
Sent: Thursday, March 26, 2015 6:35 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDF: Handling interrupts from multiple sources

Are you opening the handle with overlapped flag?

d

Bent from my phone
From: Zvi Vered
Sent: ý3/ý26/ý2015 9:20 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Handling interrupts from multiple sources

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


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>

Yes, and then all operations on the handle must then use an OVERLAPPED structure

d

Bent from my phone


From: Zvi Veredmailto:xxxxx
Sent: ?3/?26/?2015 8:58 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] WDF: Handling interrupts from multiple sources

Hi Doron,All,

The code for opening the handle is:

m_hDevice = CreateFile(DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

Should it be:

m_hDevice = CreateFile(DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

?

Best regards,
Z.V

From: Doron Holan
Sent: Thursday, March 26, 2015 6:35 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDF: Handling interrupts from multiple sources

Are you opening the handle with overlapped flag?

d

Bent from my phone
From: Zvi Vered
Sent: ?3/?26/?2015 9:20 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Handling interrupts from multiple sources

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


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></mailto:xxxxx></mailto:xxxxx>

Hi Doron and Tim,

Setting to FILE_FLAG_OVERLAPPED solved the problem.

Thank you for your help !

Best regards,
Z.V