0

I have read online that you cant register interrupts in user space. The way to go about doing something similar is to - 1) have the Linux kernel module / driver send an asynchronous event to the user space on the interrupt detection 2) having a thread in user space that polls on the device node for that event.

I have written a kernel module that registers events on the rising edge of GPIO pin and I now want to convey this to user space.

Can anyone show me how to - 1) send an event from kernel space to user space 2) make a thread in user space to poll for that event

Thanks!

Siddharth
  • 145
  • 1
  • 3
  • 9

1 Answers1

1

You can use Netlink sockets in order to send an event from kernel space to user space. You can then spawn a thread in user space which listens to this Netlink socket. This can be done using select() or epoll() function in your user-space application. http://www.linuxjournal.com/article/7356 is a good reference.

iqstatic
  • 2,322
  • 3
  • 21
  • 39
  • @Siddharth This might also help http://stackoverflow.com/questions/3299386/how-to-use-netlink-socket-to-communicate-with-a-kernel-module – iqstatic Aug 28 '14 at 11:17
  • I wanted to ask if there is an added advantage to using Netlink sockets over something like - send_sig(int sig, struct task_struct *p, int priv) – Siddharth Aug 28 '14 at 11:28
  • @Siddharth Netlink socket provides a full-duplex communication link between the two by way of standard socket APIs for user-space processes and special kernel API for kernel modules. It allows you to send custom messages over the socket. Whereas, using `send_sig()` may only allow you to send a valid SIGNAL to the user-space process. It totally depends on your implementation. – iqstatic Aug 28 '14 at 11:41
  • @iqstatic- I wanted to ask you - is there any way to set-up a handler that gets called when the user space application receives a msg from kernel space through a socket just as we can do in kernel space? – Siddharth Aug 29 '14 at 09:28
  • @Siddharth By msg do you mean a signal or a custom message like a string? If your requirement is to send a string like message to or from kernel space Netlink is the best solution. You can directly create a socket buffer and send it over your Netlink socket. – iqstatic Sep 04 '14 at 11:50