This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GCC proposal for "@" asm constraint


Andrea Arcangeli wrote:
> int * p;
> [...]
>         spin_lock(&lock);
>         a = *p;
>         spin_unlock(&lock);
> 
>         spin_lock(&lock);  
>         b = *p;
>         spin_unlock(&lock);

> [With "memory" clobber"] the [second] reload of the address of `p'
> isn't necessary and gcc is wrong in generating it.

Wrong, GCC is behaving correctly.

> p is a constant embedded into the .text section and set at link time,

p is a variable.  The _address_ of p is constant, but the reload is
not loading the address of p, it's loading the _value_.  That value can
be changed by other threads.

In fact, you have demonstrated why the "memory" clobber is necessary for
spinlocks.  A perfect test case!

In your first example, without the clobber, the asm code is incorrect.
A parallel thread can change the value of p between the first
spin_unlock and the second spin_lock, and the GCC-generated code does
not notice.

> The above reload are just wasted CPU cycles that we're little worried
> to waste.

Here, the saved cycle is a kernel bug.

-- Jamie

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]