none
userspace to get event from driver and get 4-bytes of data from kernel RRS feed

  • Question

  • Hi,

    Need a procedure - for application to get a notification from kernel very frequently. 

    e.g kernel need to notify the 4bytes information in every ~20ms.

    Tuesday, May 31, 2016 11:27 AM

Answers

  • it should be as simple as pending multiple instances of the same IOCTL to the driver and the driver completes each io request at the expected interval with the data.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, May 31, 2016 8:19 PM
  • Use an IOCTL pended in the driver, and return the 4 bytes of data in the Information field of the IoStatus structure.   Using METHOD_NEITHER you can achieve very fast performance, depending on the approach you use, I've gotten as much a 1,400,000 events this way on a old dual core system.

    For best performance pend multiple IOCTL requests.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, June 14, 2016 6:54 PM

All replies

  • First seriously consider changing your model, you are asking a lot of the system.  You can share memory between user space and kernel space and create a circular buffer using InterlockedXXX operations to ensure the values are ok.   You can also, use FAST I/O with METHOD_NEITHER returning the value in the information field of the IoStatus block.

    But before you do any of this:

          1.  Look seriously at your overall algorithm.  Is delivering things in 4 byte chunks really needed?  Can you buffer a bunch of these and return a block instead?

          2.  See what kind of performance you get with a simple driver, versus what your application really needs.  One of the worst mistakes new driver writers do, is to try to prematurely optimize the code before they understand what is really the problem.

          3.  In general, look at what other drivers are doing and see if there is a model that works for you to avoid the 4 bytes at a time requirement.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, May 31, 2016 1:00 PM
  • it should be as simple as pending multiple instances of the same IOCTL to the driver and the driver completes each io request at the expected interval with the data.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, May 31, 2016 8:19 PM
  •  Thx for your response. 


    We need the some decision algorithm to be implemented in user-space, and we need some real-time data in regular/frequent interval.
    In Linux, we can pass 4-bytes of data with signal from Kernel to userspace task. 
    siginfo.si_int =0x1234;
    send_sig_info(SIGNAL, &siginfo, task); //send signal and data to userspace
    Hence we can avoid the additional read from kernel memory.

    Right now i have implemented in Windows as follows -
    1/  Create named event that will be shared between the driver and application
    2/ Create a Sharing Memory Between Drivers and Applications 

    Step#1: Userspace wait for the driver to signal the event
    Step#2: followed by read the data from kernel shared memory.

    However it takes ~1ms in above two steps.


    Tuesday, June 14, 2016 6:49 PM
  • Use an IOCTL pended in the driver, and return the 4 bytes of data in the Information field of the IoStatus structure.   Using METHOD_NEITHER you can achieve very fast performance, depending on the approach you use, I've gotten as much a 1,400,000 events this way on a old dual core system.

    For best performance pend multiple IOCTL requests.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, June 14, 2016 6:54 PM