linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why can't we sleep in an ISR?
@ 2007-05-14  6:37 Learning Linux
       [not found] ` <366312910705140010m78b215a2t1753445e81120288@mail.gmail.com>
  2007-05-14 12:25 ` Helge Hafting
  0 siblings, 2 replies; 19+ messages in thread
From: Learning Linux @ 2007-05-14  6:37 UTC (permalink / raw)
  To: kernelnewbies, linux-newbie; +Cc: linux-kernel

I have a very basic doubt here ... what makes it impossible to sleep
in an ISR? I mean, I know that the kernel preemption is disabled and
the kernel will panic, but I could not understand why?

TIA,

LL

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: Why can't we sleep in an ISR?
@ 2007-05-14 15:22 linux
  2007-05-14 15:55 ` Rik van Riel
  0 siblings, 1 reply; 19+ messages in thread
From: linux @ 2007-05-14 15:22 UTC (permalink / raw)
  To: learninglinux4; +Cc: linux-kernel, linux-newbie

Sleeping in an ISR is not fundamentally impossible - I could design
a multitasker that permitted it - but has significant problems, and
most multitaskers, including Linux, forbid it.

The first problem is the scheduler.  "Sleeping" is actually a call
into the scheduler to choose another process to run.  There are times -
so-called critical sections - when the scheduler can't be called.

If an interrupt can call the scheduler, then every criticial section
has to disable interrupts.  Otherwise, an interrupt might arrive and
end up calling the scheduler.  This increases interrupt latency.

If interrupts are forbidden to sleep, then there's no need to
disable interrupts in critical sections, so interrupts can be responded
to faster.  Most multitaskers find this worth the price.

The second problem is shared interrupts.  You want to sleep until something
happens.  The processor hears about that event via an interrupt.  Inside
an ISR, interrupts are disabled.

You have to somehow enable the interrupt that will wake up the sleeping
ISR without enabling the interrupt that the ISR is in the middle of handling
(or the handler will start a second time and make a mess).

This is complicated and prone to error.  And, in the case of shared interrupts
(as allowed by PCI), it's possible that the the interrupt you need
to wait for is exactly the same interrupt as what you're in the middle
of handling.  So it might be impossible!

The third problem is that you're obviously increasing the latency of the
interrupt whose handler you're sleeping in.

Finally, if you're even *thinking* of wanting to sleep in an ISR,
you probably have a deadlock waiting to happen.

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

end of thread, other threads:[~2007-05-17 23:51 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-14  6:37 Why can't we sleep in an ISR? Learning Linux
     [not found] ` <366312910705140010m78b215a2t1753445e81120288@mail.gmail.com>
2007-05-14  7:16   ` Learning Linux
2007-05-14 15:24     ` Bahadir Balban
2007-05-14 15:56       ` Dong Feng
     [not found]       ` <366312910705142217geba69dbm98a6c0bf2aabb937@mail.gmail.com>
2007-05-15  6:45         ` Dong Feng
     [not found]           ` <366312910705150010p623f9732mc498f457245d23a1@mail.gmail.com>
2007-05-15  7:28             ` Dong Feng
2007-05-15  8:40               ` Learning Linux
2007-05-15  8:58                 ` Dong Feng
2007-05-15 16:57           ` Phillip Susi
2007-05-15 17:23             ` David Schwartz
2007-05-15 22:49             ` Dong Feng
2007-05-16 15:20               ` Phillip Susi
2007-05-16 23:17                 ` Dong Feng
2007-05-17 16:07                   ` Phillip Susi
2007-05-17 23:50                     ` Dong Feng
2007-05-14 12:25 ` Helge Hafting
     [not found]   ` <366312910705140552o6a507cbbl806f2ad0efc9d90c@mail.gmail.com>
2007-05-14 13:36     ` Dong Feng
  -- strict thread matches above, loose matches on Subject: below --
2007-05-14 15:22 linux
2007-05-14 15:55 ` Rik van Riel

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