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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to