Provide occurrence of interrupt from kmdf driver to user mode application

Dear all,

I’m searching for the most effective and performance oriented way to trigger a specific user mode application from kernel mode drivers isr after a hardware interrupt occoured.
I would appreciate if you could point on some rudiments to make this work.

Thanks
Jan

Well the simple answer is you don’t want to do that. Since you
mentioned performance and signaling to user space in the same message
the bottom line is this is not going to happen. To signal from a KMDF
ISR you first need to queue a DPC, then have the DPC either signal an
event or complete an IRP. Now the problem with signaling an event is
you cannot tell if this is the first or the Nth interrupt that has
occurred when the application runs. If you use an inverted call you
pass back data relating to the interrupt and each interrupt can be a
separate response.

Why do you think you need this? You are not going to get performance at
all if you expect to have a user space application run on every
interrupt. I’ve done this for a client and the bottom line is expect a
very slow response rate, for example you can overwhelm this easily with
a serial port.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@web.de” wrote in message
news:xxxxx@ntdev:

> Dear all,
>
> I’m searching for the most effective and performance oriented way to trigger a specific user mode application from kernel mode drivers isr after a hardware interrupt occoured.
> I would appreciate if you could point on some rudiments to make this work.
>
> Thanks
> Jan

Let’s think about the following situation.
I have a external hardware that is connected via parralel port to my test machine. The external hardware is generatin interrupts continuously. A corresponding kmdf driver is handling the interrupts in kernel-mode. Now I would like to have a user mode application on the testmachine to provide some gui information like a blinking label or what ever to show the user that a interrupt occoured.
I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.
What would you do to handle this?

Create a queue in the driver that receives N IRP’s sent down from the application. When an interrupt occurs, one of those IRPs is “consumed”, completed, and returned to the app which then replenishes the consumed IRP. It’s called an inverted callback.

Gary Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

On Dec 7, 2011, at 8:19 AM, xxxxx@web.de wrote:

Let’s think about the following situation.
I have a external hardware that is connected via parralel port to my test machine. The external hardware is generatin interrupts continuously. A corresponding kmdf driver is handling the interrupts in kernel-mode. Now I would like to have a user mode application on the testmachine to provide some gui information like a blinking label or what ever to show the user that a interrupt occoured.
I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.
What would you do to handle this?


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 all this is for an activity indicator, an event being signaled will
be fine, since the is no difference on how many interrupts occurred,
just that an interrupt occurred.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@web.de” wrote in message
news:xxxxx@ntdev:

> Let’s think about the following situation.
> I have a external hardware that is connected via parralel port to my test machine. The external hardware is generatin interrupts continuously. A corresponding kmdf driver is handling the interrupts in kernel-mode. Now I would like to have a user mode application on the testmachine to provide some gui information like a blinking label or what ever to show the user that a interrupt occoured.
> I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.
> What would you do to handle this?

On 07-Dec-2011 16:19, xxxxx@web.de wrote:

Let’s think about the following situation.
I have a external hardware that is connected via parralel port to my test machine. The external hardware is generatin interrupts continuously. A corresponding kmdf driver is handling the interrupts in kernel-mode. Now I would like to have a user mode application on the testmachine to provide some gui information like a blinking label or what ever to show the user that a interrupt occoured.
I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.
What would you do to handle this?

Performance Counters?

– pa

> I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.

This is the best solution. Just pend this IOCTL in the driver and complete it (with data) when the HW event occurs.

The app will see the overlapped IO completed and react on it. The data is already there.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

On 07-Dec-2011 19:21, Maxim S. Shatskih wrote:

> I thought about IOCTL polling request to the driver, but this can’t be the best solution I think.

This is the best solution. Just pend this IOCTL in the driver and complete it (with data) when the HW event occurs.

The app will see the overlapped IO completed and react on it. The data is already there.

It is also the simplest. Few things are simpler than a ioctl.
But implementing a performance counter gives you free nice GUI of
perfmon. You can watch your interrupts/sec in real time :slight_smile:
–pa

Dear all,

thanks for your kind replys.

Don: is there really a way like implementing a signal in the kernel mode driver that can be caught by user mode app? I never heard about this.

Pavel: Performance counter is a user mode thechnic right? What is the driver component about to do?

Thanks
Jan

xxxxx@web.de wrote:

Don: is there really a way like implementing a signal in the kernel mode driver that can be caught by user mode app? I never heard about this.

He said an event. It is possible to share event handles between user
mode and kernel mode, so that the user-mode app does a
WaitForSingleObject and the kernel driver does KeSetEvent. However, the
inverted call ioctl approach is better, because you can pass data with
the request.

Pavel: Performance counter is a user mode thechnic right? What is the driver component about to do?

KeQueryPerformanceCounter is the exact kernel equivalent of
QueryPerformanceCounter. In fact, the UM version calls the KM version
to do its job.


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

Take a look at http://www.osronline.com/article.cfm?id=108 for how to
share events.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@web.de” wrote in message
news:xxxxx@ntdev:

> Dear all,
>
> thanks for your kind replys.
>
> Don: is there really a way like implementing a signal in the kernel mode driver that can be caught by user mode app? I never heard about this.
>
>
> Pavel: Performance counter is a user mode thechnic right? What is the driver component about to do?
>
> Thanks
> Jan

That sounds very interesting.
Actually the data part is not that important for me. I would need the faster solution.

xxxxx@web.de wrote:

That sounds very interesting.
Actually the data part is not that important for me. I would need the faster solution.

The speed difference is insignificant. How many interrupts per second
do you expect to be handling? Have you completely removed the standard
parallel port driver and installed your own? The default parallel port
driver doesn’t use interrupts under ordinary circumstances.

Remember that, if you are just updating a UI, it’s stupid to try to do
more than a few dozen per second. If you’re updating faster than the
monitor’s refresh rate, you’re just wasting time.


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

Tim,
using parallel port and display output was just an example.
I understand that there are several bottle necks in this case. I would like to make sure that the bottle neck is not the actually kernel mode to user mode part.

xxxxx@web.de wrote:

using parallel port and display output was just an example.
I understand that there are several bottle necks in this case. I would like to make sure that the bottle neck is not the actually kernel mode to user mode part.

If you think about it for a moment, you’ll realize that all possible
solutions have basically the same overhead here. An interrupt arrives
in kernel mode, and somehow you have to get back to user mode for the
application to run. The exact mechanism really doesn’t matter. The ISR
could set an event, which makes the application ready to run, which
allows it to be scheduled the next time the scheduler runs. Or, the ISR
could complete a pending ioctl, which again makes the application ready
to run and allows it to be scheduled.


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

You have two ways to do that , but try to think how you can avoid it at all.

  1. the first way is very easy NotificationEvent, or create Named Event in User mode and send it to the driver.In the driver you should reference to the event, or open there also by same name.
    then in ISR or DPC you can SetEvent() while the USer mode on WaitForSingleObject()
    This method is easy, I used it in WIN and it was very effective for me but you should care for some sync issues.

  2. The second way is to send several request to the driver (they sometimes called post calls) .
    the Driver pend the requestes and Complete them (one by one) in DPC.
    remember to send one more request each time the previous completed.
    I used this techniche in linux but , it should be Ok for win too.

It isn’t recommended ( performance, complexity) if you have many in sec INTs.

xxxxx@hotmail.com” wrote in message
news:xxxxx@ntdev:

> 2. The second way is to send several request to the driver (they sometimes called post calls) .
> the Driver pend the requestes and Complete them (one by one) in DPC.
> remember to send one more request each time the previous completed.
> I used this techniche in linux but , it should be Ok for win too.
>

This is called an “Inverted Call” in Windows, and has been around from
before Linux ever was released.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

Don Burn wrote:

This is called an “Inverted Call” in Windows, and has been around from
before Linux ever was released.

That’s not entirely clear. Although NT’s development began well before
Linux, the first public release of Linux happened before the first
public release of NT. I don’t know whether “inverted call” as a concept
was used in the very first drivers. If Cutler borrowed the concept from
VMS, then I would bow to your assertion.


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

Actually, Tim, I was using a form of this in 1974, on a MicroData system. No, we didn’t have “IRP’s” at that time, but we did have mechanisms in place for an interrupt to send data/notifications to an application that was waiting on it.

Gary Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

On Dec 7, 2011, at 3:56 PM, Tim Roberts wrote:

Don Burn wrote:
> This is called an “Inverted Call” in Windows, and has been around from
> before Linux ever was released.

That’s not entirely clear. Although NT’s development began well before
Linux, the first public release of Linux happened before the first
public release of NT. I don’t know whether “inverted call” as a concept
was used in the very first drivers. If Cutler borrowed the concept from
VMS, then I would bow to your assertion.


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


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

wrote in message news:xxxxx@ntdev…
>
> Pavel: Performance counter is a user mode thechnic right? What is the
> driver component about to do?

User mode implementation is more known, though IIRC it is possible to make a
kernel mode provider.
Here is an example of usermode provider (user mode service sending ioctls to
kernel driver):
http://software.intel.com/en-us/articles/intel-performance-counter-monitor/

Regards,
– pa