用户空间中的 Linux 中断处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7986260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux Interrupt Handling in User Space
提问by Brandon E Taylor
In Linux, what are the options for handling device interrupts in user space code rather than in kernel space?
在 Linux 中,在用户空间代码而不是内核空间中处理设备中断的选项是什么?
回答by ninjalj
回答by Maxim Egorushkin
You may like to take a look at CHAPTER 10: Interrupt Handlingfrom Linux Device Drivers, Third Editionbook.
你可能想看看第10章:中断处理从Linux设备驱动程序,第三版书。
回答by Dan Aloni
Experience tells it is possible to write good and stable user-space drivers for almost any PCI adapter. It just requires some sophistication and a small proxying layer in the kernel. UIO is a step in that direction, but If you want to correctly handle interrupts in user-space then UIO might not be enough, for example if the device doesn't support the PCI-spec's interrupt disable bit which UIO relies on.
经验告诉我们可以为几乎所有 PCI 适配器编写良好且稳定的用户空间驱动程序。它只需要一些复杂性和内核中的一个小的代理层。UIO 是朝这个方向迈出的一步,但是如果您想正确处理用户空间中的中断,那么 UIO 可能还不够,例如,如果设备不支持 UIO 所依赖的 PCI 规范的中断禁用位。
Notice that process wakeup latencies are a few microsecs so if your implementation requires very low latency then user-space might be a drag on it.
请注意,进程唤醒延迟是几微秒,因此如果您的实现需要非常低的延迟,那么用户空间可能会拖累它。
If I were to implement a user-space driver, I would reduce the kernel ISR to just a "disable & ack & wakeup-userpace" operation, handle the interrupt inside the waked-up process, and then re-enable the interrupt (of course, by writing to mapped PCI memory from the userspace process).
如果我要实现一个用户空间驱动程序,我会将内核 ISR 减少到一个“禁用 & 确认 & 唤醒用户空间”操作,在唤醒过程中处理中断,然后重新启用中断(当然,通过从用户空间进程写入映射的 PCI 内存)。
回答by renonsz
Have to trigger userland code indirectly.
必须间接触发用户空间代码。
Kernel ISR indicates interrupt by writing file / setting register / signalling. User space application polls this and goes on with the appropriate code. Edge cases: more or less interrupts than expected (time out / too many interrupts per time interval)
内核 ISR 通过写文件/设置寄存器/信令来指示中断。用户空间应用程序对此进行轮询并继续使用适当的代码。边缘情况:比预期更多或更少的中断(超时/每个时间间隔的中断太多)
Linux file abstraction is used to connect kernel and user space. This is performed by character devices and ioctl()
calls. Some may prefer sysfs entries for this purpose.
Linux 文件抽象用于连接内核和用户空间。这是由字符设备和ioctl()
调用执行的。为此,有些人可能更喜欢 sysfs 条目。
This can look odd because event triggered device notifications (interrupts) are hooked with 'time triggered' polling, but it is actually asyncronous blocking (read/select). Anyway some questions are arising according to performance.
这看起来很奇怪,因为事件触发的设备通知(中断)与“时间触发”轮询挂钩,但它实际上是异步阻塞(读取/选择)。无论如何,根据性能会出现一些问题。
So interrupts cannot be directly handled outside the kernel. E.g. shared memory can be in user space and with some I/O permission settings addresses can be mapped, so U-I/O works, but not for direct interrupt handling.
所以中断不能直接在内核之外处理。例如,共享内存可以在用户空间中,并且可以映射具有某些 I/O 权限设置的地址,因此 UI/O 可以工作,但不能用于直接中断处理。
I have found only one 'minority report' in topic vfio (http://lxr.free-electrons.com/source/Documentation/vfio.txt): https://stackoverflow.com/a/21197797/5349798
我在 vfio ( http://lxr.free-electrons.com/source/Documentation/vfio.txt)主题中只找到了一份“少数派报告” :https: //stackoverflow.com/a/21197797/5349798
Similar questions:
类似问题:
Running user thread in context of an interrupt in linux
Is it possible in linux to register a interrupt handler from any user-space program?
在 linux 中是否可以从任何用户空间程序注册中断处理程序?
Linux Kernel: invoke call back function in user space from kernel space
How do I inform a user space application that the driver has received an interrupt in linux?