xref: /kvm-unit-tests/lib/x86/asm/barrier.h (revision 2c96b77ec9d3b1fcec7525174e23a6240ee05949)
1 #ifndef _ASMX86_BARRIER_H_
2 #define _ASMX86_BARRIER_H_
3 /*
4  * Copyright (C) 2016, Red Hat Inc, Alexander Gordeev <agordeev@redhat.com>
5  *
6  * This work is licensed under the terms of the GNU LGPL, version 2.
7  */
8 
9 #define mb()	asm volatile("mfence":::"memory")
10 #define rmb()	asm volatile("lfence":::"memory")
11 #define wmb()	asm volatile("sfence":::"memory")
12 
13 #define smp_rmb()	barrier()
14 #define smp_wmb()	barrier()
15 
16 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
17 static inline void rep_nop(void)
18 {
19 	asm volatile("rep; nop" ::: "memory");
20 }
21 
22 static inline void cpu_relax(void)
23 {
24 	rep_nop();
25 }
26 
27 #endif
28