Running user thread in context of an interrupt in

2019-07-22 15:30发布

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

2条回答
beautiful°
2楼-- · 2019-07-22 15:51

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.

查看更多
Deceive 欺骗
3楼-- · 2019-07-22 16:03

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.

查看更多
登录 后发表回答