Skip to contentSkip to conversation

wake_up from interrupt handler

DISCUSSION Amol Lad 4 participants 6 messages Oct 7, 2002

lore
Share & tools
lore

Amol Lad

author
#0 lore raw

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

#1 lore raw
Quoted 5 lines · Amol Lad

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

Quoted 8 lines

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);

Quoted 1 line
author
#2 lore raw

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 ??

Quoted 35 lines · --- Arjan van de Ven
Quoted 2 lines · Amol Lad

Hi,
I have a kernel thread which did

add_to_wait_queue()

Quoted 2 lines

to wait for an event.
The event for which above thread is waiting occurs

in

Quoted 1 line

an interrupt handler that calls wake_up() to wake

the

Quoted 2 lines

above thread.
Now I am faced with a 'lost wakeup' problem, in

which

Quoted 2 lines

the
kernel thread checks whether event occured, he

finds

Quoted 2 lines

it to be 'not-occured' but before calling add_to_wait_queue(), interrupt handler detects

that

Quoted 2 lines

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);

Quoted 1 line
Quoted 1 line

ATTACHMENT part 2 application/pgp-signature

name=signature.asc

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

#3 lore raw
Quoted 9 lines · Amol Lad

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 ;)

#4 lore raw
In reply to Amol Lad
Quoted 9 lines · Amol Lad

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)

Quoted 3 lines

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

Quoted 51 lines
Quoted 35 lines · --- Arjan van de Ven
Quoted 2 lines · Amol Lad

Hi,
I have a kernel thread which did

add_to_wait_queue()

Quoted 2 lines

to wait for an event.
The event for which above thread is waiting occurs

in

Quoted 1 line

an interrupt handler that calls wake_up() to wake

the

Quoted 2 lines

above thread.
Now I am faced with a 'lost wakeup' problem, in

which

Quoted 2 lines

the
kernel thread checks whether event occured, he

finds

Quoted 2 lines

it to be 'not-occured' but before calling add_to_wait_queue(), interrupt handler detects

that

Quoted 2 lines

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);

Quoted 1 line
Quoted 1 line

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw
In reply to Amol Lad
Quoted 5 lines · Amol Lad

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

Quoted 8 lines

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

Quoted 19 lines

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/