barrier.h 946 B

1234567891011121314151617181920212223242526272829
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _TOOLS_LINUX_ASM_X86_BARRIER_H
  3. #define _TOOLS_LINUX_ASM_X86_BARRIER_H
  4. /*
  5. * Copied from the Linux kernel sources, and also moving code
  6. * out from tools/perf/perf-sys.h so as to make it be located
  7. * in a place similar as in the kernel sources.
  8. *
  9. * Force strict CPU ordering.
  10. * And yes, this is required on UP too when we're talking
  11. * to devices.
  12. */
  13. #if defined(__i386__)
  14. /*
  15. * Some non-Intel clones support out of order store. wmb() ceases to be a
  16. * nop for these.
  17. */
  18. #define mb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  19. #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  20. #define wmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  21. #elif defined(__x86_64__)
  22. #define mb() asm volatile("mfence":::"memory")
  23. #define rmb() asm volatile("lfence":::"memory")
  24. #define wmb() asm volatile("sfence" ::: "memory")
  25. #endif
  26. #endif /* _TOOLS_LINUX_ASM_X86_BARRIER_H */