lkml.org 
[lkml]   [1999]   [Nov]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: spinlock
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/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.041 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site