From: kai@gnukai.com (Kai Meyer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Spinlocks and interrupts
Date: Thu, 10 Nov 2011 14:55:02 -0700 [thread overview]
Message-ID: <4EBC4836.5090007@gnukai.com> (raw)
In-Reply-To: <6F5DE7538AFCDA45A114F5E7510424A702CAA3B2@hq-exchange01.bytemobile.com>
Alright, to summarize, for my benefit mostly,
I'm writing a block device driver, which has 2 entry points into my code
that will reach this critical section. It's either the make request
function for the block device, or the resulting bio->bi_end_io function.
I do some waiting with msleep() (for now) from the make request function
entry point, so I'm confident that entry point is not in an atomic
context. I also only end up requesting the critical section to call
kmalloc from this context, which is why I never ran into the scheduling
while atomic issue before.
I'm fairly certain the critical section executes in thread context not
interrupt context from either entry point.
I'm certain that the spinlock_t is only ever used in one function (a I
posted a simplified version of the critical section earlier).
It seems that the critical section is often called in an atomic context.
The spin_lock function sounds like it will only cause a second call to
spin_lock to spin if it is called on a separate core.
But, since I'm certain the critical section is never called from
interrupt context, only thread context, the fact that pre-emption is
disabled on the core should provide the protection I need with out
having to disable IRQs. Disabling IRQs would prevent an interrupt from
occurring while the lock is acquired. I would like to avoid disabling
interrupts if I don't need to.
So it sounds like spin_lock/spin_unlock is the correct choice?
In addition, I'd like to be more confident in my assumptions above. Can
I test for atomic context? For instance, I know that you can call
irqs_disabled(), is there a similar is_atomic() function I can call? I
would like to put a few calls in different places to learn what sort of
context I'm.
-Kai Meyer
On 11/10/2011 12:19 PM, Jeff Haran wrote:
>> -----Original Message-----
>> From: kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org
>> [mailto:kernelnewbies-
>> bounces+jharan=bytemobile.com at kernelnewbies.org] On Behalf Of Dave
>> Hylands
>> Sent: Thursday, November 10, 2011 11:07 AM
>> To: Kai Meyer
>> Cc: kernelnewbies at kernelnewbies.org
>> Subject: Re: Spinlocks and interrupts
>>
>> Hi Kai,
>>
>> On Thu, Nov 10, 2011 at 10:14 AM, Kai Meyer<kai@gnukai.com> wrote:
>>> I think I get it. I'm hitting the scheduling while atomic because
> I'm
>>> calling my function from a struct bio's endio function, which is
>>> probably running with a lock held somewhere else, and then my mutex
>>> sleeps, while the spin_lock functions do not sleep.
>> Actually, just holding a lock doesn't create an atomic context.
> I believe on kernels with kernel pre-emption enabled the act of taking
> the lock disables pre-emption. If it didn't work this way you could end
> up taking the lock in one process context and while the lock was held
> get pre-empted. Then another process tries to take the lock and you dead
> lock.
>
> Jeff Haran
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2011-11-10 21:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-09 21:07 Spinlocks and interrupts Kai Meyer
2011-11-09 21:40 ` Dave Hylands
2011-11-09 23:12 ` Kai Meyer
2011-11-10 0:03 ` Jeff Haran
2011-11-10 3:38 ` Dave Hylands
2011-11-10 17:02 ` Kai Meyer
2011-11-10 18:02 ` Kai Meyer
2011-11-10 18:14 ` Kai Meyer
2011-11-10 19:07 ` Dave Hylands
2011-11-10 19:19 ` Jeff Haran
2011-11-10 21:55 ` Kai Meyer [this message]
2011-11-10 23:00 ` Jeff Haran
2011-11-10 23:20 ` Kai Meyer
2011-11-11 6:58 ` Rajat Sharma
2011-11-14 19:05 ` Kai Meyer
2011-11-10 4:47 ` rohan puri
2011-11-10 5:47 ` Rajat Sharma
2011-11-10 10:05 ` santhosh kumars
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=4EBC4836.5090007@gnukai.com \
--to=kai@gnukai.com \
--cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).