Re: spinlock

Pavel Machek (pavel@suse.cz)
Sat, 27 Nov 1999 22:10:10 +0100


Hi!

> > typedef struct {
> > volatile unsigned int lock ;
> > } spinlock ;
> >
> > why the spinlock structure should be converted to dummy_lock_t
> > in inline asm code:
> > typedef struct { unsigned long a[100] ; } dummy_lock_t ;
> > #define dummy_lock(lock) (*(dummy_lock_t*)(lock))
> >
> > I see many conversion like this in kernel source, can anyone help me!!!
>
> The asm statements you see in spin_lock and spin_unlock refer to the
> lock by implication from its value, rather than by its address. As long
> as GCC uses the actual memory location this is fine, and produces better
> code than using the address.
>
> The dummy_lock cast prevents GCC from "optimising" the lock by copying
> it into a register and using that in the asm. It works because GCC is not
> clever enough to optimise a 100-entry array in this way.

We should not do such tricks. gcc 2.95 may not be clever enough, but
gcc 3.05? egcs people are doing subtle tricks, and we should be very
carefull.

Pavel

-- 
I'm really pavel@ucw.cz. Look at http://195.113.31.123/~pavel.  Pavel
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/