Re: [patch] spinlocks: remove 'volatile'
From: Linus Torvalds
Date: Sat Jul 08 2006 - 14:22:26 EST
On Fri, 7 Jul 2006, trajce nedev wrote:
>
> Incorrect. I haven't been following this thread very closely [...]
Right. And maybe you should have followed it a bit more closely.
We're not talking about "asm volatile", which is a totally different use
of the same word.
We're not talking about pointers to volatile as arguments, which can be
required for a generic function to not complain about it's argument types.
We're not even talking about code like
#define writel(data, offset) \
*(volatile int *)(offset) = (data)
which is perfectly fine on some architectures (but realize that on other
archtiectures, you may need a _lot_ more than a single memory access to do
an IO write, so if you don't abstract it like the above, you're broken by
design.
In short, we're not talking about "volatile" in _code_. That's usually
fine. We're talkign about "volatile" on data. IT'S WRONG.
Btw, your spinlock (that uses "volatile") is _totally_ and _utterly_
broken, exactly because it doesn't take things like memory ordering into
account. In other words, your spinlock WON'T WORK. It won't actually
protect the data accesses you have inside the spinlock.
Which proves my point: people who think that "volatile" is good are
usually ignorant about the real needs of the code. To do a spinlock on
_any_ modern CPU, you need inline assembly. End of story. You need it to
make sure that you have told the CPU the right ordering constraints,
something that "volatile" simply does not (and _can_not) do.
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/