__wait_event_interruptible question

From: Capstar (spam0_at_deleg.homeip.net)
Date: 02/16/04


Date: Mon, 16 Feb 2004 16:25:40 +0100

Hi NG,

I got the next macro from sched.h from kernel 2.4.23_pre5.

#define __wait_event_interruptible(wq, condition, ret) \
do { \
        wait_queue_t __wait; \
        init_waitqueue_entry(&__wait, current); \
                                                                \
        add_wait_queue(&wq, &__wait); \
        for (;;) { \
                set_current_state(TASK_INTERRUPTIBLE); \
                if (condition) \
                        break; \
                if (!signal_pending(current)) { \
                        schedule(); \
                        continue; \
                } \
                ret = -ERESTARTSYS; \
                break; \
        } \
        current->state = TASK_RUNNING; \
        remove_wait_queue(&wq, &__wait); \
} while (0)

This macro is internally used by wait_event_interruptible and is used to
wait for a condition to become true without polling it. SO what happens
is that the current process is added to a waitq specified in
wait_event_interruptible. After that it is set to TASK_INTERRUPTIBLE
and, if the condition is not yet met, the process is scheduled.

So what worries me a bit is that if the wake_up_interruptible is called
from an interrupt service routine, I think it is possible that the
process never get woken up.
Let me explain. If the interrupt occurs right between the add_wait_queue
ad the set_current_state, the state will be set to TASK_RUNNING by
wake_up_interruptible in the ISR. Then the isr returns, and the process
will be set to TASK_INTERRUPTIBLE. This will usually not be much of a
problem, because before schedule() is called, the condition will be
tested again. This condition is probably met because that's what caused
the interrupt anyway. But what if the process get scheduled by the timer
tick or some other interrupt before it could set it's state back to
TASK_RUNNING, we have a serious problem. In that case there is no source
that will wake up this process anymore.

Is this really an issue, or am I missing something,
Thanks,
   Mark

-- 
<<Remove the del for email>>


Relevant Pages

  • Re: How do I schedule a task to print a document
    ... to save the workbook or not after resetting the signature. ... it keeps on requiring interactive response about enabling macros ... could simply schedule a print-only task as from Explorer. ... Refinements to the print code can be made if you record a macro while making ...
    (microsoft.public.excel.misc)
  • Re: scheduler/SCHED_FIFO behaviour
    ... schedule() is being called once which implies my process ... > returning from the interrupt handler the schedulefunction must have been ... highest priority process than it does not need to call schedule. ... ISR calls wake_up_process (most likely on ksoftirqd) ...
    (Linux-Kernel)
  • Re: -rt more realtime scheduling issues
    ... are not delivered during __schedule processing. ... IPI' case where NEED_RESCHED is only set by the handler. ... where we 'reschedule' on a specific CPU the flag is set and IPI sent. ... schedule while coming back out of the interrupt handler as a preemption ...
    (Linux-Kernel)
  • Re: Compare Utility with External Tasks
    ... I did not create the schedule, ... The quantity of subprojects and total size of the master shouldn't be ... You mention you suspect corruption. ... previously I have a macro that will de-sensitize the file. ...
    (microsoft.public.project)
  • Re: -rt more realtime scheduling issues
    ... are not delivered during __schedule processing. ... doing the waking will set the NEED_RESCHED flag for that task. ... schedule while coming back out of the interrupt handler as a preemption ... with a prio of 2 and sets A's NEED_RESCHED flag. ...
    (Linux-Kernel)