Re: Why can't we sleep in an ISR?



I agree that the reason an interrupt can not sleep is because an
interrupt is not associated with any context. But I do not agree that
it is specifically because the scheduler can not *resume* the context.

In early version, the ISR always borrow the stack of the currently
running process, so if the kernel design had allowed ISR sleep, it
would automatically be able to implement the context switch naturally.
But ISR sleep has been forbidden from the very beginning.

The reason why kernel design does not allow ISR sleep is because a
process should not be forced to wait for a event that irrelative to
itself. When an exception handler sleep, the event it sleeps on is
always in some sense related to the process incurring that exception.
But if an ISR was allowed to sleep, the event it sleeps on would have
nothing to do with the process being interrupted.

So my understanding is, the forbidden of ISR sleep is not because of
the difficulty to resume context, but because a process should not
wait for irrelative event.


2007/5/14, Bahadir Balban <bahadir.balban@xxxxxxxxx>:
On 5/14/07, Learning Linux <learninglinux4@xxxxxxxxx> wrote:
> Ok, but how about an ISR, that does not take any locks? Why can't we
> sleep in SUCH an ISR?
> LL
> -

The killer reason why you can't sleep in an interrupt is because an
interrupt is not associated with any context in the first place. What
is a context, then? It is the state information for a process. This
includes the kernel and userspace stack pointers, the register set,
and the page tables for that process. The scheduler has access to all
this information, to preempt one process and run another. Contrary to
this, an interrupt, depending on the version of your kernel and arch,
uses a separate irq stack or the kernel stack of the interrupted
process. An irq is not a context but merely a temporary execution to
be concluded asap.

Hope this helps,
Bahadir

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: Kernel crypto lib problem
    ... In the interrupt code you wake up the ... thread may then go to sleep if it needs to. ... The reasons you cannot sleep in an interrupt context is ... This is just one reason for wanting crypto code outside ...
    (comp.os.linux.development.system)
  • Re: Kernel crypto lib problem
    ... > that could potentially sleep. ... > interrupt context, the kernel would panic. ... > Do you understand why the crypto functions could potentially ...
    (comp.os.linux.development.system)
  • Re: 8ms Timer for serial port access
    ... sleep has a grainularity of 10ms. ... and that's at the next 10ms interrupt. ... -scheduler runs as soon as the driver tasklett completes. ... Disable the FIFO on your UART so you get an interrupt for every byte. ...
    (comp.os.linux.development.apps)
  • Re: Conversing with a tcl application...
    ... If the interrupt count for the keyboard, touchpad, ... will awake the computer from the sleep state. ...
    (comp.lang.tcl)
  • Re: newbie delay/sleep question
    ... microseconds and then do some other task. ... another interrupt within that 100 microseconds and the sleep I've been ... receive the interrupt and queue them up on a tasklet or work/wait queue ...
    (comp.os.linux.development.system)