From: "Luong Ngo" <luong.ngo@gmail.com>
To: "Robert Hancock" <hancockr@shaw.ca>
Cc: linux-kernel <linux-kernel@vger.kernel.org>, tglx@linutronix.de
Subject: Re: Sleeping thread not receive signal until it wakes up
Date: Thu, 8 Mar 2007 19:24:10 -0800 [thread overview]
Message-ID: <1b2aacd80703081924w44652c71yb8a16e005247a55a@mail.gmail.com> (raw)
In-Reply-To: <45F0B40F.7070301@shaw.ca>
On 3/8/07, Robert Hancock <hancockr@shaw.ca> wrote:
> Luong Ngo wrote:
> > Hi Thomas and Dick,
> > I appreciate all the responses. They are very good information to me.
> > Actually, it wasn't me working on the driver but it's been there long
> > time. I thought I just need to add the signal and signal handling
> > part, not expecting it would lead me to the driver space.
> > Here is what I have in the driver. Maybe racing condition could happen
> > in scenario that the ioctl realease the lock but befor going to sleep,
> > the ISR is invoked and call waking up on the queue, hence the ioctl
> > will not be waken up since the wak up cal already executed. But I
> > believe in our system, this could be tolerant since the hardware would
> > keep raising interrupt if the abnormal condition still exists (Due to
> > the ioctl being blocked so user app nevers get a chance to service the
> > device). But is this the reason why my signal handler not get executed
> > at all? Theoretically, according to the Richard Stevens book, I think
> > the process should be waken up and received the signal even if it gets
> > blocked in the IOCTL call, am i right?
>
> ..
>
> > static int ats89_ioctl(struct inode *inode, struct file *file, u_int
> > cmd, u_long arg)
> > {
> >
> > switch(cmd){
> > case GET_IRQ_CMD: {
> > u32 regMask32;
> >
> > spin_lock_irq(dev->lock);
> > while ((dev->irqMask & dev->irqEvent) == 0) {
> > // Sleep until board interrupt happens
> > spin_unlock_irq(dev->lock);
> > interruptible_sleep_on(&(dev->boardIRQWaitQueue));
> > if (uncond_wakeup) {
> > /* don't go back to loop */
> > break;
> > }
> > spin_lock_irq(dev->lock);
> > }
>
> Kernel code does not get pre-empted by signals. If the code needs to be
> interruptible by signals this has to be handled explicitly.
> interruptible_sleep on will stop waiting if your task gets a signal, but
> your code doesn't check the signal_pending flag to know whether it
> should exit the loop. If signal_pending(current) is set after the sleep
> you should likely be returning -ERESTARTSYS to allow the task to handle
> the signal. Then after the signal handler from the task returns, the
> ioctl will get called again.
>
> Also, as was pointed out, you should not use the sleep_on family of
> functions, use the wait_event functions intead. sleep_on is racy, if the
> interrupt happened just before you do the sleep, you'll sit there
> waiting for something that already occurred.
>
> --
> Robert Hancock Saskatoon, SK, Canada
> To email, remove "nospam" from hancockr@nospamshaw.ca
> Home Page: http://www.roberthancock.com/
>
>
Robert, thanks a lot for your suggestion
But I have added the signal_pending(current) check and signal handler
is not invoked
spin_lock_irq(dev->lock);
while ((dev->irqMask & dev->irqEvent) == 0) {
// Sleep until board interrupt happens
spin_unlock_irq(dev->lock);
interruptible_sleep_on(&(dev->boardIRQWaitQueue));
if(signal_pending(current) {
return -ERESTARTSYS;
}
if (uncond_wakeup) {
/* don't go back to loop */
break;
}
spin_lock_irq(dev->lock);
}
Still no luck yet.
LNgo
next prev parent reply other threads:[~2007-03-09 3:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fa.kb3wuhac4W+1DqK61+sKe9uZwto@ifi.uio.no>
[not found] ` <fa.cyXmbtXvYymKHdI0rEXZCxyk+KE@ifi.uio.no>
[not found] ` <fa.zPDT1vfJF5MjVXXQH/l+YSaLl84@ifi.uio.no>
[not found] ` <fa.HmQN7RhZNBRsiJYADMOsY8DL67k@ifi.uio.no>
[not found] ` <fa.PDmHwxZ3arhmED5SLuEONyxUlz4@ifi.uio.no>
[not found] ` <fa.ygLhZcCLgDxnwAYYVse/Xshr9IE@ifi.uio.no>
2007-03-09 1:10 ` Robert Hancock
2007-03-09 3:24 ` Luong Ngo [this message]
2007-03-09 3:45 ` Parav K Pandit
2007-03-10 0:10 ` Luong Ngo
2007-03-10 8:22 ` Sergey Vlasov
2007-03-10 10:54 ` Luong Ngo
2007-03-07 5:31 Luong Ngo
2007-03-07 13:19 ` linux-os (Dick Johnson)
2007-03-07 19:28 ` Luong Ngo
2007-03-07 20:08 ` linux-os (Dick Johnson)
2007-03-07 21:03 ` Lee Revell
2007-03-08 0:40 ` Luong Ngo
2007-03-08 0:28 ` Luong Ngo
2007-03-08 13:01 ` linux-os (Dick Johnson)
2007-03-08 13:53 ` Thomas Gleixner
2007-03-08 22:52 ` Luong Ngo
2007-03-09 14:58 ` Sergey Vlasov
2007-03-09 19:50 ` Luong Ngo
2007-03-07 20:20 ` Jan Engelhardt
2007-03-07 18:09 ` Sergey Vlasov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1b2aacd80703081924w44652c71yb8a16e005247a55a@mail.gmail.com \
--to=luong.ngo@gmail.com \
--cc=hancockr@shaw.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®