Commit b6c7347f authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds

x86: optimise barriers

According to latest memory ordering specification documents from Intel
and AMD, both manufacturers are committed to in-order loads from
cacheable memory for the x86 architecture.  Hence, smp_rmb() may be a
simple barrier.

Also according to those documents, and according to existing practice in
Linux (eg.  spin_unlock doesn't enforce ordering), stores to cacheable
memory are visible in program order too.  Special string stores are safe
-- their constituent stores may be out of order, but they must complete
in order WRT surrounding stores.  Nontemporal stores to WB memory can go
out of order, and so they should be fenced explicitly to make them
appear in-order WRT other stores.  Hence, smp_wmb() may be a simple

In userspace microbenchmarks on a core2 system, fence instructions range
anywhere from around 15 cycles to 50, which may not be totally
insignificant in performance critical paths (code size will go down

However the primary motivation for this is to have the canonical barrier
implementation for x86 architecture.

smp_rmb on buggy pentium pros remains a locked op, which is apparently
Signed-off-by: default avatarNick Piggin <>
Signed-off-by: default avatarLinus Torvalds <>
parent 4071c718
......@@ -274,7 +274,11 @@ static inline unsigned long get_limit(unsigned long segment)
#define smp_mb() mb()
#define smp_rmb() rmb()
# define smp_rmb() rmb()
# define smp_rmb() barrier()
# define smp_wmb() wmb()
......@@ -141,8 +141,8 @@ static inline void write_cr8(unsigned long val)
#define smp_mb() mb()
#define smp_rmb() rmb()
#define smp_wmb() wmb()
#define smp_rmb() barrier()
#define smp_wmb() barrier()
#define smp_read_barrier_depends() do {} while(0)
#define smp_mb() barrier()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment