From: Robert Hancock <hancockr@shaw.ca>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Strangeness with spinlocks declared static
Date: Wed, 22 Sep 2004 22:25:31 -0600 [thread overview]
Message-ID: <000801c4a125$5d0e80f0$6601a8c0@northbrook> (raw)
I was recently debugging a Linux driver for a PCI card that was developed
in-house at our company. I was having a problem whereby a function which did
a spin_lock_irqsave and spin_unlock_irqsave seemed to hang up sometimes,
especially when the function was called very rapidly. It appeared that
sometimes the spin_lock_irqsave was blocking, even though the spinlock
should not have been locked. (This was on an SMP system, dual Xeon
processors or 4 logical CPUs.)
The spinlock was declared like this (outside of any function):
static spinlock_t debug_spinlock;
and initialized with spin_lock_init.
Eventually I went and looked at the assembly that gcc was generating for the
spinlock operations, and noticed that the spin loop appeared to be
performing operations checking the %ebx register instead of the actual
memory location of the spinlock. That explains why it was behaving so
strangely, since clearly another CPU won't be able to see/affect the
register contents.
I then changed the declaration of the spinlock to do it more like most other
code I've seen:
spinlock_t debug_spinlock = SPIN_LOCK_UNLOCKED;
When I looked at the code for the operations then, it was operating on the
spinlock in memory as I expected, and the hang problem went away.
This was on Red Hat 9, kernel version 2.4.20-31.9, compiler version gcc
3.2.2.
I am curious whether this is a known/unknown gcc bug, or whether the
declaration as static causes it to legally assume that the spinlock counter
can be cached in a register? The latter seems rather insane to me,
considering that the lock variable inside the spinlock_t is declared as
volatile..
reply other threads:[~2004-09-23 4:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='000801c4a125$5d0e80f0$6601a8c0@northbrook' \
--to=hancockr@shaw.ca \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®