Re: [patch] spinlocks: remove 'volatile'
From: Linus Torvalds
Date: Fri Jul 07 2006 - 16:27:08 EST
On Fri, 7 Jul 2006, linux-os (Dick Johnson) wrote:
>
> Now Linus declares that instead of declaring an object volatile
> so that it is actually accessed every time it is referenced, he wants
> to use a GNU-ism with assembly that tells the compiler to re-read
> __every__ variable existing im memory, instead of just one. Go figure!
Actually, it's not just me.
Read things like the Intel CPU documentation.
IT IS ACTIVELY WRONG to busy-loop on a variable. It will make the CPU
potentially over-heat, causing degreaded performance, and you're simply
not supposed to do it.
> Reference:
> /usr/src/linux-2.6.16.4/include/linux/compiler-gcc.h:
> #define barrier() __asm__ __volatile__("": : :"memory")
Actually, for your kind of stupid loop, you should use
- include/asm-i386/processor.h:
#define cpu_relax() rep_nop()
where rep_nop() is
/* REP NOP (PAUSE) is a a good thing to insert into busy-wait loops. */
static inline void rep_nop(void)
{
__asm__ __volatile__("rep;nop": : :"memory");
}
on x86, and can be other things on other CPU's. On ppc64 it is
#define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
where those HMT macros adjust thread priority.
In other words, you just don't know what you're talking about. "volatile"
is simply not useful, and the fact that you cannot seem to grasp that is
_your_ problem.
Repeat after me (or just shut up about things that you not only don't know
about, but are apparently not willing to even learn):
"'volatile' is useless. The things it did 30 years ago are much
more complex these days, and need to be tied to much more
detailed rules that depend on the actual particular problem,
rather than one keyword to the compiler that doesn't actually
give enough information for the compiler to do anything useful"
Comprende?
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/