LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How linux driver notify asynchrnous events to user space (https://www.linuxquestions.org/questions/linux-general-1/how-linux-driver-notify-asynchrnous-events-to-user-space-4175491326/)

akv1412 01-15-2014 01:47 AM

How linux driver notify asynchrnous events to user space
 
Hi All,

I am looking methods to implements asynchronous events handing in kernel & send data to userspace.
I saw there are many ways to handle asynchrnous event in linux eg. fasync, poll etc.
My requirement is as soon as receive the event in kernel space, send event notification along with the data to user space.

Can any one send the best mechanism/ sample code use in linux?

Regards,
akv

prabhuraj 01-15-2014 04:59 AM

Hi,
The following link provides a snippet of code that may help you get started. Have a look.
http://www.compsoc.man.ac.uk/~moz/ke...s/asyncio.html

akv1412 01-15-2014 11:12 AM

Thanks.

I use fasync asynchronous method and getting the event in user space.

In kernel, when kill_fasync(&fasync_my_queue, SIGIO, POLL_IN) invoke, receiving SIGIO (29) event in user space.

Is it possible to change SIGIO to some other value? so that I can differentiate events in user space.

Regards,
akv

sundialsvcs 01-15-2014 06:02 PM

As far as I am aware ... no.

The purpose of any such signal, if you want to think of it this way, is merely "to wake the process up, if it is asleep," and to notify it (asynchronously ...) that it might have something to do. The signal is not associated with any particular request, and it might in fact turn out to be a false alarm.

The timing of such things is entirely fluid: the signal itself is nothing more and nothing less than a ringing bell that will wake-up a sleeping process and (whether or not it was sleeping ...) send it into a subroutine.

The user-land process, having been thusly informed that it might have work-to-do, must now issue whatever system calls may be required to find out if it (still) has work-to-do, and to do that work. It's entirely possible that said process may discover that, in any particular cycle, it has none. (Waking up a process "too often" is not a concern: "sorry to have bothered you." For the process to "go to sleep when still it has work to do," is.)

And this is pretty much the way that it is with every operating-system on the planet.


All times are GMT -5. The time now is 02:58 AM.