public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: linux@horizon.com
To: learninglinux4@gmail.com
Cc: linux-kernel@vger.kernel.org, linux-newbie@vger.kernel.org
Subject: Re: Why can't we sleep in an ISR?
Date: 14 May 2007 11:22:18 -0400	[thread overview]
Message-ID: <20070514152218.19773.qmail@science.horizon.com> (raw)

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.

             reply	other threads:[~2007-05-14 15:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-14 15:22 linux [this message]
2007-05-14 15:55 ` Why can't we sleep in an ISR? Rik van Riel
  -- strict thread matches above, loose matches on Subject: below --
2007-05-15  9:34 rohit  hooda
2007-05-15  9:46 ` pradeep singh
2007-05-14  6:37 Learning Linux
2007-05-14  7:10 ` pradeep singh
2007-05-14  7:16   ` Learning Linux
2007-05-14 15:24     ` Bahadir Balban
2007-05-14 15:56       ` Dong Feng
2007-05-15  5:17       ` pradeep singh
2007-05-15  6:45         ` Dong Feng
2007-05-15  7:10           ` pradeep singh
2007-05-15  7:28             ` Dong Feng
2007-05-15  8:12               ` pradeep singh
2007-05-15  8:40               ` Learning Linux
2007-05-15  8:58                 ` Dong Feng
2007-05-15 16:57           ` Phillip Susi
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
2007-05-14 12:52   ` pradeep singh
2007-05-14 13:36     ` Dong Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070514152218.19773.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=learninglinux4@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox