lkml.org 
[lkml]   [2000]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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