How to interrupt userspace application in Linux

2.3k views Asked by At

I am developing a Linux DMA driver. The userspace application want the driver to perform asynchronous operation(Data transfer) and get informed only when the operation is completed. How does the userspace application get informed asynchronously?

I know in kernel space, an interrupt handler can be installed to handle the completion interrupt. My question is for userspace because my data has to be processed in userspace. What I can think of is to create a thread in userspace and wait for the driver to complete the task. Is there better way of handling this? or am I thinking in the wrong direction?

More generally, how to handle interrupt for Linux in userspace?

1

There are 1 answers

0
Nemo On BEST ANSWER

The normal approach is to implement a poll function for your device driver. This function should add the task to one or more wait queues. Your interrupt handler can then wake up the task(s) waiting on the queue(s).

Your driver's poll implementation is invoked when a userspace task invokes poll or select on a file descriptor associated with your driver. So from a userspace process's point of view, this works just like waiting on anything else (like a network socket). In fact this is the same mechanism a disk or network driver would use to wake up a process waiting for I/O.

See http://www.xml.com/ldd/chapter/book/ch05.html#t3 for a fleshed-out example.