2

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

agent.smith
  • 9,134
  • 9
  • 37
  • 49

2 Answers2

6

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.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • Currently, I am sleeping in the thread and implementing a signal. If I do "poll select" then will the thread wake up in the same timer tick of linux? In windows I can schedule a dpc and do event notification in that thread. I am not sure if signal/select is equally efficient as that. – agent.smith Jun 01 '12 at 21:33
1

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.

Saurabh
  • 1,059
  • 10
  • 20