LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-22-2009, 01:58 PM   #1
moo.mike.moo
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Rep: Reputation: 0
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
 
Old 07-23-2009, 01:53 AM   #2
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 228

Rep: Reputation: 54
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?
 
Old 07-23-2009, 12:56 PM   #3
moo.mike.moo
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cladisch View Post
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.
 
Old 07-24-2009, 03:34 AM   #4
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 228

Rep: Reputation: 54
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.
 
Old 07-24-2009, 09:16 AM   #5
moo.mike.moo
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cladisch View Post
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.
 
Old 07-24-2009, 09:19 AM   #6
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 228

Rep: Reputation: 54
Quote:
Does this work even if called from interrupt context?
Yes.
 
Old 07-25-2009, 01:34 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
Old 08-04-2009, 05:26 AM   #8
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
You can implement fasync file ops too
 
Old 08-09-2009, 12:12 PM   #9
moo.mike.moo
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks all, I got it working!
 
  


Reply

Tags
interrupt, kernel, signal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The mouse generates interrupt signal (Ctrl+c) at Terminal southflow Linux - Newbie 2 03-09-2009 02:41 AM
Interrupt/Signal on Memory Access Denes Programming 3 04-28-2008 06:15 PM
CMC interrupt signal smallbook Linux - Newbie 0 01-27-2008 08:05 PM
How to obtain a interrupt or signal to press the tray key of CDROM? freedomli Linux - Enterprise 0 12-04-2007 02:31 AM
Signal() sigaction() and IO interrupt Linuxprocess Programming 2 09-20-2006 09:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration