mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Strangeness with spinlocks declared static
@ 2004-09-23  4:25 Robert Hancock
  0 siblings, 0 replies; only message in thread
From: Robert Hancock @ 2004-09-23  4:25 UTC (permalink / raw)
  To: linux-kernel

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..


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-09-23  4:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-23  4:25 Strangeness with spinlocks declared static Robert Hancock

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®