All of lore.kernel.org
 help / color / mirror / Atom feed
From: Iain Fraser <iainkfraser@gmail.com>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Iain Fraser <iainkfraser@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: interrupt context
Date: Fri, 5 Oct 2012 15:03:53 +0100	[thread overview]
Message-ID: <CA+bLfK56qA4YrLS59ps9g8-hvpm3+_i2Ea2EQvedkwVymCmxuA@mail.gmail.com> (raw)
In-Reply-To: <20121005132714.GB21358@thunk.org>

Thanks for the response Ted. I've actual got that book, in fact it is
the source of this question :) .

I knew it wasn't a "nice" thing to do to the poor process. But your
explanation explains why
its also a dangerous thing so thanks.

Also another problem with async sleeping a process, is that you could
end up causing the idle
thread to sleep. And end up in a scenario where there are no runnable tasks.

Thanks for the help
Iain


On Fri, Oct 5, 2012 at 2:27 PM, Theodore Ts'o <tytso@mit.edu> wrote:
> On Fri, Oct 05, 2012 at 09:51:55AM +0100, Iain Fraser wrote:
>>
>> I understand the interrupts and softirq's run in interrupt context (
>> as opposed to process context ). But what I
>> don't understand is why you cannot sleep in interrupt context?
>
> Consider what happens with nested locks (and yes, we definitely need
> nested locks).  In order to prevent deadlocks, it is critical to have
> lock ordering; that is, you always take locks in a certain order.  If
> all processes take lock A, and then lock B, etc., then you won't have
> a problem where one process as lock A, and tries to get lock B, and
> another process has lock B, and tries to take lock A, and they wait
> for each other forever.
>
> If a process has a lock when it gets interrupted, the interrupt
> handler has no idea what locks may have already been taken.  So if a
> process has taken a mutex (or some other sleeping lock) B, and then
> the interrupt handler tries to take lock A, that's a perscription for
> deadlock.
>
> In addition, you must never sleep while holding a (non-sleeping)
> spinlock.  If the interrupt handler has interrupted a process which is
> holding a spinlock, then it simply may not sleep without triggering
> all sorts of other problems.
>
>> What I have read it states that it doesn't have a process to schedule
>> out. But interrupts use the interrupted processes
>> kernel stack just like a syscall. So surely it is possible to sleep
>> using that stack. Understandably It would be unfair on the process
>> that blocked through no fault of its own.
>>
>> Also if you are not allowed to sleep / schedule during interrupt
>> context. Then how does the system timer pre-empt processes by
>> calling schedule?
>
> The system timer sets the "need to reschedule" flag for that
> particular process.  Then as the system timer returns from the
> interrupt, there is a common code path which is checked on the way out
> of any interrupt handler or system call.  This code path checks to see
> if the "need to schedule" flag is set, and if so, at that point
> instead of returning to the original process, the kernel will simply
> return to some other process.
>
> I would suggest that you get a good introductory Linux book, such as
> "Linux Kernel Development" by Robert Love.  You might also check out
> the kernelnewbies.org website and mailing list, where you are more
> likely to get answers to basic introductory questions like this.
>
> Regards,
>
>                                                 - Ted

  reply	other threads:[~2012-10-05 14:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA+bLfK5FPqFvU2xy7xKdV4LkAvmY6GAPFrB-4UBzn-cOunQ6Xg@mail.gmail.com>
2012-10-05  8:51 ` interrupt context Iain Fraser
2012-10-05  9:32   ` Borislav Petkov
2012-10-05 10:20     ` Iain Fraser
2012-10-05 10:34       ` Borislav Petkov
2012-10-05 13:27   ` Theodore Ts'o
2012-10-05 14:03     ` Iain Fraser [this message]
2012-10-05 18:05     ` anish kumar
2012-10-05 18:15     ` Iain Fraser
2008-03-23 21:44 Interrupt context Codrin Alexandru Grajdeanu
2008-03-24 21:00 ` Christopher Li
2008-03-25  1:34   ` Octavian Purdila
2008-03-25  2:57     ` Christopher Li
2008-03-26 12:43       ` Octavian Purdila
2008-03-26 21:53         ` Christopher Li
  -- strict thread matches above, loose matches on Subject: below --
2003-04-14 18:51 interrupt context Jeremy Hall
2003-04-14 18:56 ` Robert Love
2003-04-14 19:32   ` Jeremy Hall
2003-04-14 19:35     ` Robert Love
2003-04-14 21:09   ` Jeremy Hall
2003-04-14 21:18     ` Robert Love
2003-04-14 21:48       ` Jeremy Hall
2003-04-14 22:57         ` Robert Love
2003-04-15  3:44           ` Jeremy Hall
2003-04-15  4:14             ` Jeremy Hall
2003-04-15 21:40             ` Robert Love
2003-04-15 23:02               ` Jeremy Hall
2003-04-16  3:41               ` Jeremy Hall

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=CA+bLfK56qA4YrLS59ps9g8-hvpm3+_i2Ea2EQvedkwVymCmxuA@mail.gmail.com \
    --to=iainkfraser@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.