简体   繁体   English

如何在Linux中中断用户空间应用程序

[英]How to interrupt userspace application in Linux

I am developing a Linux DMA driver. 我正在开发Linux DMA驱动程序。 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? 更一般地说,如何在用户空间中处理Linux的中断?

The normal approach is to implement a poll function for your device driver. 通常的方法是为您的设备驱动程序实现poll功能。 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. 当用户空间任务调用pollselect与驱动程序关联的文件描述符时,将调用驱动程序的poll实现。 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. 实际上,这与磁盘或网络驱动程序用于唤醒等待I / O的进程的机制相同。

See http://www.xml.com/ldd/chapter/book/ch05.html#t3 for a fleshed-out example. 有关充实的示例,请访问http://www.xml.com/ldd/chapter/book/ch05.html#t3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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