All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Ornati <ornati@fastwebnet.it>
To: "Sorin Manolache" <sorinm@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: newbie questions about while (1) in kernel mode and spinlocks
Date: Thu, 21 Dec 2006 11:05:51 +0100	[thread overview]
Message-ID: <20061221110551.104ca3e1@localhost> (raw)
In-Reply-To: <20170a030612210141y6578602eo525e6df5f324747d@mail.gmail.com>

On Thu, 21 Dec 2006 10:41:44 +0100
"Sorin Manolache" <sorinm@gmail.com> wrote:

> The Linux Device Drivers book says that a spin_lock should not be
> shared between a process and an interrupt handler. The explanation is
> that the process may hold the lock, an interrupt occurs, the interrupt
> handler spins on the lock held by the process and the system freezes.
> Why should it freeze? Isn't it possible for the interrupt handler to
> re-enable interrupts as its first thing, then to spin at the lock, the
> timer interrupt to preempt the interrupt handler and to relinquish
> control to the process which in turn will finish its critical section
> and release the lock, making way for the interrupt handler to
> continue.

Iterrupt handlers are executend in the process context (on top of the
process that they interrupted).

So, if you have a proccess A that does:

	Usual Kernel Code		Interrupt Handler

	...
	spin_lock(my_lock);
	...
		-------interrupt----->	...
					spin_lock(my_lock); // deadlock!
					...
		<------ back --------- 
	----
	spin_unlock(my_lock);


See?

If the interrupt comes in when process A is running and holding the
lock PREEMPTION can't do anything.

-- 
	Paolo Ornati
	Linux 2.6.20-rc1-g99f5e971 on x86_64

  reply	other threads:[~2006-12-21 10:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21  9:41 newbie questions about while (1) in kernel mode and spinlocks Sorin Manolache
2006-12-21 10:05 ` Paolo Ornati [this message]
2006-12-21 10:20 ` Paolo Ornati
2006-12-21 10:40 ` Paolo Ornati
2006-12-21 23:54 ` Steven Rostedt
     [not found] <fa.D8ff1OmLNpVeVOoaJAP7ENpm+Wk@ifi.uio.no>
2006-12-21 14:31 ` Robert Hancock
  -- strict thread matches above, loose matches on Subject: below --
2006-12-21 18:14 SR, Krishna

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=20061221110551.104ca3e1@localhost \
    --to=ornati@fastwebnet.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sorinm@gmail.com \
    /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.