简体   繁体   中英

How to interrupt userspace application in Linux

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM