Running user thread in context of an interrupt in linux

徘徊边缘 提交于 2019-12-10 22:56:45

问题


I am writing some customized application and allowed to change interrupt handler code in the linux kernel.

I am having a user thread which is waiting for an interrupt to happen. If that interrupt happens then the first thing I want to do is to execute that user thread.

Is there any way to make it work.

Thanks


回答1:


Create a character device (that's what the kernel does, handles devices). Have the user thread read from that device. It will hang as there are no characters to read.

When the interrupt happens, output a character (or some meaningful message) to that device from your module. The thread will wake up, read the message and continue.

Give the handler thread some nice priority so that it wakes up early.

Alternatively, you may just have the thread waiting on select or sleep and send it a signal (kernel function kill_proc_info) and the thread will wake up. Make sure the thread handles the signal.




回答2:


Instead of doing an overkill with making a character driver, making a sysfs entry would have been sufficient. You can do any blocking call like, read / select / poll on that sysfs entry and feed to it from your interrupt handler.

Interesting problem to solve for you is

  1. what in case another interrupt happens while you were already running.
  2. What if interrupt happened twice but you got woken up once only.

etc.



来源:https://stackoverflow.com/questions/10856103/running-user-thread-in-context-of-an-interrupt-in-linux

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