How kernel notify a user space program an interrupt occurrs

北慕城南 提交于 2020-01-03 16:45:00

问题


I'm writing a user space program and a kernel space device driver.

Goal: Once an interrupt occurs, user space program needs to do something quickly.

My naive method: User space program uses ioctl to call wait_event_interruptible(), kernel ISR calls wake_up_interruptible() to wake up user space program. It turns out that it takes too much time from interrupt to user space.

Is there any better way?

Thanks!


回答1:


There is a similar question asked here:

Notify gpio interrupt to user space from a kernel module

Please check above question. However, i can provide my approach which i suggested there as well.

You can send a signal to user space thread from kernel API, which can help u run non-blocking:

send_sig(int sig, struct task_struct *p, int priv);

You need to be aware of pid of user thread in Kernel. You can over come this by writing pid of user process via /proc and then kernel reading the pid. With this arrangement, when there is an interrupt, kernel can send signal to user thread. In case your process restarts or gets killed, you will have to update the pid via proc. Just for status notification you can use this method; however if you like to transfer data along with status than Netlink or char driver mechanism is good way.



来源:https://stackoverflow.com/questions/12899055/how-kernel-notify-a-user-space-program-an-interrupt-occurrs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!