Linux 内核如何中断应用程序?
How does Linux kernel interrupt the application?
首先,我是一个设备驱动专家。这是我第一次处理用户态程序。
我曾经有一个中断服务例程来响应硬件中断。
换句话说,硬件使用中断服务程序来通知驱动程序进行服务。
我现在使用 ioctl 作为应用程序和设备驱动程序之间通信的通道,并轮询它以等待响应。
当设备驱动程序完成某些任务时,还有其他方法可以通知应用程序吗?
欢迎任何意见。
谢谢,
通常,内核从不通知应用程序,除非应用程序请求通知并正在等待通知。在 unix 系统上,这通常使用 select 或类似的例程来完成。一个提供 select 一组文件描述符,然后 select 将等待直到其中一个文件描述符上有 activity,此时它 returns。
鉴于在 unix 上所有设备都是文件,您应该能够利用此机制在某些硬件设备上出现中断时唤醒应用程序。
这有几种机制。第一种方法:user-space application makes poll() or select() system call, waiting for some event from kernel. Second approach is to use Netlink sockets。还有其他像 mmap()
或信号。 Google by kernel user-space IPC
你会看到整个列表。
至于你的情况(驱动程序开发),我会说采用下一种方法。在您的驱动程序中创建 sysfs 文件,并执行 sysfs_notify() (and maybe wait_for_completion_interruptible_timeout()
or something like that). In user-space do select() system call for your driver sysfs file. See how line discipline installed from user-space 例如。
除了 ioctl(信号、套接字等)之外,还有很多内核-用户空间通信接口。请参阅Kernel Space - User Space Interfaces教程以获得详细说明。
首先,我是一个设备驱动专家。这是我第一次处理用户态程序。 我曾经有一个中断服务例程来响应硬件中断。 换句话说,硬件使用中断服务程序来通知驱动程序进行服务。 我现在使用 ioctl 作为应用程序和设备驱动程序之间通信的通道,并轮询它以等待响应。 当设备驱动程序完成某些任务时,还有其他方法可以通知应用程序吗? 欢迎任何意见。 谢谢,
通常,内核从不通知应用程序,除非应用程序请求通知并正在等待通知。在 unix 系统上,这通常使用 select 或类似的例程来完成。一个提供 select 一组文件描述符,然后 select 将等待直到其中一个文件描述符上有 activity,此时它 returns。
鉴于在 unix 上所有设备都是文件,您应该能够利用此机制在某些硬件设备上出现中断时唤醒应用程序。
这有几种机制。第一种方法:user-space application makes poll() or select() system call, waiting for some event from kernel. Second approach is to use Netlink sockets。还有其他像 mmap()
或信号。 Google by kernel user-space IPC
你会看到整个列表。
至于你的情况(驱动程序开发),我会说采用下一种方法。在您的驱动程序中创建 sysfs 文件,并执行 sysfs_notify() (and maybe wait_for_completion_interruptible_timeout()
or something like that). In user-space do select() system call for your driver sysfs file. See how line discipline installed from user-space 例如。
除了 ioctl(信号、套接字等)之外,还有很多内核-用户空间通信接口。请参阅Kernel Space - User Space Interfaces教程以获得详细说明。