LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Sending signal from interrupt (http://www.linuxquestions.org/questions/linux-kernel-70/sending-signal-from-interrupt-742028/)

moo.mike.moo 07-22-2009 02:58 PM

Sending signal from interrupt
 
Hi,

I need to write an interrupt handler that can:

1) Send a signal to the interrupted thread, and
2) Stop the execution of the interrupted thread (the thread must be descheduled after the interrupt returns)

Is this possible, and if so, how can it be done?

Thanks

cladisch 07-23-2009 02:53 AM

Quote:

I need to write an interrupt handler that can:

1) Send a signal to the interrupted thread,
What kind of signal?
And what should happen if there is no interrupted thread, or if you interrupted a kernel thread?

Quote:

2) Stop the execution of the interrupted thread (the thread must be descheduled after the interrupt returns)
That might be possible, but this isn't something that should be done outside the scheduler itself.

What are you trying to accomplish?

moo.mike.moo 07-23-2009 01:56 PM

Quote:

Originally Posted by cladisch (Post 3617368)
What kind of signal?
And what should happen if there is no interrupted thread, or if you interrupted a kernel thread?

A POSIX signal. There will be checks if the interrupted thread is not a target.


Quote:

That might be possible, but this isn't something that should be done outside the scheduler itself.

What are you trying to accomplish?
Actually, I was very unclear. The behavior that I want is that the interrupted thread (assume it's a target) should not continue normal execution before handling the signal. I believe that signal handlers are only called when the thread is about to be rescheduled? If it's an interrupt, I don't want the interrupt to return, then the thread executes without realizing it has received a signal, and have the signal be received after the thread is rescheduled, which may happen who-knows-when.

Basically, the next code that the thread executes has to be the signal handler, not the program code.

cladisch 07-24-2009 04:34 AM

Quote:

A POSIX signal.
send_sig_info(), kill_proc_info()

Quote:

The behavior that I want is that the interrupted thread (assume it's a target) should not continue normal execution before handling the signal.
As far as I know, this is the default behaviour, even if the target is running on another processor.

moo.mike.moo 07-24-2009 10:16 AM

Quote:

Originally Posted by cladisch (Post 3618599)
send_sig_info(), kill_proc_info()



As far as I know, this is the default behaviour, even if the target is running on another processor.

Does this work even if called from interrupt context?

A more general question would be, does the interrupt handler immediately return control to the interrupted thread as if nothing had happened, or does it invoke the scheduler first? It seems that this might not work if control was immediately returned to the interrupted thread.

cladisch 07-24-2009 10:19 AM

Quote:

Does this work even if called from interrupt context?
Yes.

sundialsvcs 07-25-2009 02:34 PM

My intuitive thought is that you capture the interrupt in the (by any other name) "top half" and then schedule the (call it what you like) "bottom half," in which you can post a signal to another process or thread... you're no longer in an interrupts-restricted context. The "bottom half" will be resolved before any user-land processes run again.

However, having said that, you must also consider the multi-CPU case. I can envision that, once in a blue moon, the target task might be running on a different CPU that, o'course, didn't get the interrupt. So you might have to be content with "the target process handles the signal 'very, very promptly.'" That's usually the way of such things.

jf.argentino 08-04-2009 06:26 AM

You can implement fasync file ops too

moo.mike.moo 08-09-2009 01:12 PM

Thanks all, I got it working!


All times are GMT -5. The time now is 11:46 AM.