linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* wake_up from interrupt handler
@ 2002-10-07 12:41 Amol Lad
  2002-10-07 13:04 ` Arjan van de Ven
  2002-10-07 22:52 ` Rui Sousa
  0 siblings, 2 replies; 6+ messages in thread
From: Amol Lad @ 2002-10-07 12:41 UTC (permalink / raw)
  To: linux-kernel

Hi,
 I have a kernel thread which did add_to_wait_queue()
to wait for an event. 
The event for which above thread is waiting occurs in
an interrupt handler that calls wake_up() to wake the
above thread. 
Now I am faced with a 'lost wakeup' problem, in which
the    
kernel thread checks whether event occured, he finds
it to be 'not-occured' but before calling
add_to_wait_queue(), interrupt handler detects that
the event has occured and calls wake_up().
My thread sleeps forever.

I know some new APIs are provided in recent 2.5
kernel, but how to avoid this in 2.4.18

please CC me 

Thanks
Amol


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: wake_up from interrupt handler
  2002-10-07 12:41 wake_up from interrupt handler Amol Lad
@ 2002-10-07 13:04 ` Arjan van de Ven
  2002-10-07 14:25   ` Amol Lad
  2002-10-07 22:52 ` Rui Sousa
  1 sibling, 1 reply; 6+ messages in thread
From: Arjan van de Ven @ 2002-10-07 13:04 UTC (permalink / raw)
  To: Amol Lad; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 764 bytes --]

On Mon, 2002-10-07 at 14:41, Amol Lad wrote:
> Hi,
>  I have a kernel thread which did add_to_wait_queue()
> to wait for an event. 
> The event for which above thread is waiting occurs in
> an interrupt handler that calls wake_up() to wake the
> above thread. 
> Now I am faced with a 'lost wakeup' problem, in which
> the    
> kernel thread checks whether event occured, he finds
> it to be 'not-occured' but before calling
> add_to_wait_queue(), interrupt handler detects that
> the event has occured and calls wake_up().
> My thread sleeps forever.

set_current_state(TASK_INTERRUPTIBLE);
add_to_wait_queue(...);
if (even_occured) { ...} 
  else
     schedule();
 
remove_from_wait_queue(..);
set_current_state(TASK_RUNNABLE);


> 


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: wake_up from interrupt handler
  2002-10-07 13:04 ` Arjan van de Ven
@ 2002-10-07 14:25   ` Amol Lad
  2002-10-07 15:36     ` Arjan van de Ven
  2002-10-07 17:44     ` Mike Galbraith
  0 siblings, 2 replies; 6+ messages in thread
From: Amol Lad @ 2002-10-07 14:25 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel

In this code too.. lost-wakeup problem is not solved

if (event_occured)
  else 
    schedule();

what if in check ' if(event_occured) ' goes to 'else'
and before calling schedule() my ISR interrupted this
thread and set the event..

Also Mike told to disable the interrupt before
checking for event... So When to enable interrupts
then ??
 
--- Arjan van de Ven <arjanv@redhat.com> wrote:
> On Mon, 2002-10-07 at 14:41, Amol Lad wrote:
> > Hi,
> >  I have a kernel thread which did
> add_to_wait_queue()
> > to wait for an event. 
> > The event for which above thread is waiting occurs
> in
> > an interrupt handler that calls wake_up() to wake
> the
> > above thread. 
> > Now I am faced with a 'lost wakeup' problem, in
> which
> > the    
> > kernel thread checks whether event occured, he
> finds
> > it to be 'not-occured' but before calling
> > add_to_wait_queue(), interrupt handler detects
> that
> > the event has occured and calls wake_up().
> > My thread sleeps forever.
> 
> set_current_state(TASK_INTERRUPTIBLE);
> add_to_wait_queue(...);
> if (even_occured) { ...} 
>   else
>      schedule();
>  
> remove_from_wait_queue(..);
> set_current_state(TASK_RUNNABLE);
> 
> 
> > 
> 
> 

> ATTACHMENT part 2 application/pgp-signature
name=signature.asc



__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: wake_up from interrupt handler
  2002-10-07 14:25   ` Amol Lad
@ 2002-10-07 15:36     ` Arjan van de Ven
  2002-10-07 17:44     ` Mike Galbraith
  1 sibling, 0 replies; 6+ messages in thread
From: Arjan van de Ven @ 2002-10-07 15:36 UTC (permalink / raw)
  To: Amol Lad; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

On Mon, 2002-10-07 at 16:25, Amol Lad wrote:
> In this code too.. lost-wakeup problem is not solved
> 
> if (event_occured)
>   else 
>     schedule();
> 
> what if in check ' if(event_occured) ' goes to 'else'
> and before calling schedule() my ISR interrupted this
> thread and set the event..

that's fine; the wake_up() will mark your process as TASK_RUNNING at
which point the schedule() is effectively a NOP, at which point your
event loop just loops immediatly again ->  no problem

always keep interrupts enabled during this, no need to block them ;)

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: wake_up from interrupt handler
  2002-10-07 14:25   ` Amol Lad
  2002-10-07 15:36     ` Arjan van de Ven
@ 2002-10-07 17:44     ` Mike Galbraith
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Galbraith @ 2002-10-07 17:44 UTC (permalink / raw)
  To: Amol Lad, Arjan van de Ven; +Cc: linux-kernel

At 07:25 AM 10/7/2002 -0700, Amol Lad wrote:
>In this code too.. lost-wakeup problem is not solved
>
>if (event_occured)
>   else
>     schedule();
>
>what if in check ' if(event_occured) ' goes to 'else'
>and before calling schedule() my ISR interrupted this
>thread and set the event..

(yes, this is what I was thinking about)

>Also Mike told to disable the interrupt before
>checking for event... So When to enable interrupts
>then ??

(this mike)

Well, disabling interrupts as a solution aside :), why are you checking for 
event in the kthread?  It seems to me that receipt of wakeup has to be the 
sole knowledge that the event happened, else a race is a done deal. (no?)

         -Mike

>
>--- Arjan van de Ven <arjanv@redhat.com> wrote:
> > On Mon, 2002-10-07 at 14:41, Amol Lad wrote:
> > > Hi,
> > >  I have a kernel thread which did
> > add_to_wait_queue()
> > > to wait for an event.
> > > The event for which above thread is waiting occurs
> > in
> > > an interrupt handler that calls wake_up() to wake
> > the
> > > above thread.
> > > Now I am faced with a 'lost wakeup' problem, in
> > which
> > > the
> > > kernel thread checks whether event occured, he
> > finds
> > > it to be 'not-occured' but before calling
> > > add_to_wait_queue(), interrupt handler detects
> > that
> > > the event has occured and calls wake_up().
> > > My thread sleeps forever.
> >
> > set_current_state(TASK_INTERRUPTIBLE);
> > add_to_wait_queue(...);
> > if (even_occured) { ...}
> >   else
> >      schedule();
> >
> > remove_from_wait_queue(..);
> > set_current_state(TASK_RUNNABLE);
> >
> >
> > >
> >
> >
>
> > ATTACHMENT part 2 application/pgp-signature
>name=signature.asc
>
>
>
>__________________________________________________
>Do you Yahoo!?
>Faith Hill - Exclusive Performances, Videos & More
>http://faith.yahoo.com
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: wake_up from interrupt handler
  2002-10-07 12:41 wake_up from interrupt handler Amol Lad
  2002-10-07 13:04 ` Arjan van de Ven
@ 2002-10-07 22:52 ` Rui Sousa
  1 sibling, 0 replies; 6+ messages in thread
From: Rui Sousa @ 2002-10-07 22:52 UTC (permalink / raw)
  To: Amol Lad; +Cc: linux-kernel

On Mon, 7 Oct 2002, Amol Lad wrote:

> Hi,
>  I have a kernel thread which did add_to_wait_queue()
> to wait for an event. 
> The event for which above thread is waiting occurs in
> an interrupt handler that calls wake_up() to wake the
> above thread. 
> Now I am faced with a 'lost wakeup' problem, in which
> the    
> kernel thread checks whether event occured, he finds
> it to be 'not-occured' but before calling
> add_to_wait_queue(), interrupt handler detects that
> the event has occured and calls wake_up().
> My thread sleeps forever.

I believe the solution is to simply add_to_wait_queue()
_before_ checking the condition. If the signal arrives between
checking the condition and going to sleep your task will be
immediately awoken.

Rui Sousa

> I know some new APIs are provided in recent 2.5
> kernel, but how to avoid this in 2.4.18
>
> please CC me 
> 
> Thanks
> Amol
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Faith Hill - Exclusive Performances, Videos & More
> http://faith.yahoo.com
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-10-07 22:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-07 12:41 wake_up from interrupt handler Amol Lad
2002-10-07 13:04 ` Arjan van de Ven
2002-10-07 14:25   ` Amol Lad
2002-10-07 15:36     ` Arjan van de Ven
2002-10-07 17:44     ` Mike Galbraith
2002-10-07 22:52 ` Rui Sousa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).