I have a code which detects GPIO interrupt in a kernel module. Now,I am looking for a mechanism to notify user space upon detecting gpio interrupt from kernel module. Any example / code snippet with certain advantages/disadvantages over different options? I would appreciate your response.
我有一个代码,可以检测内核模块中的GPIO中断。现在,我正在寻找一种机制,在检测到来自内核模块的gpio中断时通知用户空间。任何与不同选项有某些优点/缺点的示例/代码片段?谢谢你的回复。
3 个解决方案
#1
1
Take a look at the GPIO keyboard driver (drivers/input/keyboard/gpio_keys.c
). It is a good starting point for your problem.
看一下GPIO键盘驱动程序(drivers / input / keyboard / gpio_keys.c)。这是你的问题的一个很好的起点。
In the userspace you then listen (some blocking read for example, or just tail
to test) to /dev/input/yourevent
for events.
然后在用户空间中,您可以监听(例如,某些阻塞读取,或者只是尾部测试)到/ dev / input / yourevent for events。
#2
1
You can send a signal to user space thread from kernel API, which can help u run non-blocking:
您可以从内核API向用户空间线程发送信号,这可以帮助您运行非阻塞:
send_sig(int sig, struct task_struct *p, int priv)
But there is a limitation: u 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.
但是有一个限制:你需要知道内核中用户线程的pid。您可以通过/ proc编写用户进程的pid然后读取pid的内核来实现此目的。通过这种安排,当存在中断时,内核可以向用户线程发送信号。如果您的进程重新启动或被杀死,您将不得不通过proc更新pid。
If i were you, i would have preferred to do this unless i dont want to transfer data from kernel to user. For data transfer requirement, i would have used Netlink or some other mechanism.
如果我是你,我宁愿这样做,除非我不想将数据从内核传输到用户。对于数据传输要求,我会使用Netlink或其他一些机制。
#3
1
You can: (1) Send a signal to the user application, or (2) implement file_operations->poll method, use poll_wait and wait queue to wake user application when interrupt occur.
您可以:(1)向用户应用程序发送信号,或者(2)实现file_operations-> poll方法,使用poll_wait和等待队列在发生中断时唤醒用户应用程序。
#1
1
Take a look at the GPIO keyboard driver (drivers/input/keyboard/gpio_keys.c
). It is a good starting point for your problem.
看一下GPIO键盘驱动程序(drivers / input / keyboard / gpio_keys.c)。这是你的问题的一个很好的起点。
In the userspace you then listen (some blocking read for example, or just tail
to test) to /dev/input/yourevent
for events.
然后在用户空间中,您可以监听(例如,某些阻塞读取,或者只是尾部测试)到/ dev / input / yourevent for events。
#2
1
You can send a signal to user space thread from kernel API, which can help u run non-blocking:
您可以从内核API向用户空间线程发送信号,这可以帮助您运行非阻塞:
send_sig(int sig, struct task_struct *p, int priv)
But there is a limitation: u 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.
但是有一个限制:你需要知道内核中用户线程的pid。您可以通过/ proc编写用户进程的pid然后读取pid的内核来实现此目的。通过这种安排,当存在中断时,内核可以向用户线程发送信号。如果您的进程重新启动或被杀死,您将不得不通过proc更新pid。
If i were you, i would have preferred to do this unless i dont want to transfer data from kernel to user. For data transfer requirement, i would have used Netlink or some other mechanism.
如果我是你,我宁愿这样做,除非我不想将数据从内核传输到用户。对于数据传输要求,我会使用Netlink或其他一些机制。
#3
1
You can: (1) Send a signal to the user application, or (2) implement file_operations->poll method, use poll_wait and wait queue to wake user application when interrupt occur.
您可以:(1)向用户应用程序发送信号,或者(2)实现file_operations-> poll方法,使用poll_wait和等待队列在发生中断时唤醒用户应用程序。