This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC proposal for "@" asm constraint
- To: Andrea Arcangeli <andrea at suse dot de>
- Subject: Re: GCC proposal for "@" asm constraint
- From: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- Date: Tue, 19 Sep 2000 10:40:04 +0200
- Cc: John Wehle <john at feith dot com>, gcc at gcc dot gnu dot org, kuznet at ms2 dot inr dot ac dot ru, linux-kernel at vger dot kernel dot org, torvalds at transmeta dot com
- References: <200009182353.TAA26001@jwlab.FEITH.COM> <20000919031831.E16004@athlon.random>
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