1 #ifndef _ASM_X86_BARRIER_H
2 #define _ASM_X86_BARRIER_H
4 #include <asm/alternative.h>
8 * Force strict CPU ordering.
9 * And yes, this is required on UP too when we're talking
15 * Some non-Intel clones support out of order store. wmb() ceases to be a
18 #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
19 #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
20 #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
22 #define mb() asm volatile("mfence":::"memory")
23 #define rmb() asm volatile("lfence":::"memory")
24 #define wmb() asm volatile("sfence" ::: "memory")
28 * read_barrier_depends - Flush all pending reads that subsequents reads
31 * No data-dependent reads from memory-like regions are ever reordered
32 * over this barrier. All reads preceding this primitive are guaranteed
33 * to access memory (but not necessarily other CPUs' caches) before any
34 * reads following this primitive that depend on the data return by
35 * any of the preceding reads. This primitive is much lighter weight than
36 * rmb() on most CPUs, and is never heavier weight than is
39 * These ordering constraints are respected by both the local CPU
42 * Ordering is not guaranteed by anything other than these primitives,
43 * not even by data dependencies. See the documentation for
44 * memory_barrier() for examples and URLs to more information.
46 * For example, the following code would force ordering (the initial
47 * value of "a" is zero, "b" is one, and "p" is "&a"):
55 * read_barrier_depends();
59 * because the read of "*q" depends on the read of "p" and these
60 * two reads are separated by a read_barrier_depends(). However,
61 * the following code, with the same initial values for "a" and "b":
69 * read_barrier_depends();
73 * does not enforce ordering, since there is no data dependency between
74 * the read of "a" and the read of "b". Therefore, on some CPUs, such
75 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
76 * in cases like this where there are no data dependencies.
79 #define read_barrier_depends() do { } while (0)
83 #ifdef CONFIG_X86_PPRO_FENCE
84 # define smp_rmb() rmb()
86 # define smp_rmb() barrier()
88 #ifdef CONFIG_X86_OOSTORE
89 # define smp_wmb() wmb()
91 # define smp_wmb() barrier()
93 #define smp_read_barrier_depends() read_barrier_depends()
94 #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
96 #define smp_mb() barrier()
97 #define smp_rmb() barrier()
98 #define smp_wmb() barrier()
99 #define smp_read_barrier_depends() do { } while (0)
100 #define set_mb(var, value) do { var = value; barrier(); } while (0)
104 * Stop RDTSC speculation. This is needed when you need to use RDTSC
105 * (or get_cycles or vread that possibly accesses the TSC) in a defined
108 * (Could use an alternative three way for this if there was one.)
110 static __always_inline
void rdtsc_barrier(void)
112 alternative(ASM_NOP3
, "mfence", X86_FEATURE_MFENCE_RDTSC
);
113 alternative(ASM_NOP3
, "lfence", X86_FEATURE_LFENCE_RDTSC
);
116 #endif /* _ASM_X86_BARRIER_H */