Xen Test Framework
barrier.h
Go to the documentation of this file.
1#ifndef XTF_X86_BARRIER_H
2#define XTF_X86_BARRIER_H
3
4/*
5 * Memory barriers for x86 systems
6 *
7 * See Linux: Documentation/memory-barriers.txt for a very detailed
8 * description of the problems and their implications.
9 *
10 * Under Xen, we rely on the fact that only x86_64 cpus are supported, which
11 * guarantees that the {m,l,s}fence instructions are supported (SSE2 being a
12 * requirement of 64bit).
13 *
14 * x86 memory ordering requirements make the smp_???() variants easy. From
15 * the point of view of program order, reads may not be reordered with respect
16 * to other reads, and writes may not be reordered with respect to other
17 * writes, causing smp_rmb() and smp_wmb() to degrade to simple compiler
18 * barriers.
19 *
20 * smp_mb() however does need to provide real ordering, as reads are permitted
21 * to be reordered ahead of non-aliasing writes.
22 */
23
24#include <xtf/compiler.h>
25
26#define mb() __asm__ __volatile__ ("mfence" ::: "memory")
27#define rmb() __asm__ __volatile__ ("lfence" ::: "memory")
28#define wmb() __asm__ __volatile__ ("sfence" ::: "memory")
29
30#ifdef __i386__
31#define smp_mb() __asm__ __volatile__ ("lock addl $0, -4(%%esp)" ::: "memory");
32#else
33#define smp_mb() __asm__ __volatile__ ("lock addl $0, -4(%%rsp)" ::: "memory");
34#endif
35#define smp_rmb() barrier()
36#define smp_wmb() barrier()
37
38#endif /* XTF_X86_BARRIER_H */
39
40/*
41 * Local variables:
42 * mode: C
43 * c-file-style: "BSD"
44 * c-basic-offset: 4
45 * tab-width: 4
46 * indent-tabs-mode: nil
47 * End:
48 */