barrier.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __BARRIER_H
  2. #define __BARRIER_H
  3. #include <asm/compiler.h>
  4. #define mb() __asm__ __volatile__("mb": : :"memory")
  5. #define rmb() __asm__ __volatile__("mb": : :"memory")
  6. #define wmb() __asm__ __volatile__("wmb": : :"memory")
  7. /**
  8. * read_barrier_depends - Flush all pending reads that subsequents reads
  9. * depend on.
  10. *
  11. * No data-dependent reads from memory-like regions are ever reordered
  12. * over this barrier. All reads preceding this primitive are guaranteed
  13. * to access memory (but not necessarily other CPUs' caches) before any
  14. * reads following this primitive that depend on the data return by
  15. * any of the preceding reads. This primitive is much lighter weight than
  16. * rmb() on most CPUs, and is never heavier weight than is
  17. * rmb().
  18. *
  19. * These ordering constraints are respected by both the local CPU
  20. * and the compiler.
  21. *
  22. * Ordering is not guaranteed by anything other than these primitives,
  23. * not even by data dependencies. See the documentation for
  24. * memory_barrier() for examples and URLs to more information.
  25. *
  26. * For example, the following code would force ordering (the initial
  27. * value of "a" is zero, "b" is one, and "p" is "&a"):
  28. *
  29. * <programlisting>
  30. * CPU 0 CPU 1
  31. *
  32. * b = 2;
  33. * memory_barrier();
  34. * p = &b; q = p;
  35. * read_barrier_depends();
  36. * d = *q;
  37. * </programlisting>
  38. *
  39. * because the read of "*q" depends on the read of "p" and these
  40. * two reads are separated by a read_barrier_depends(). However,
  41. * the following code, with the same initial values for "a" and "b":
  42. *
  43. * <programlisting>
  44. * CPU 0 CPU 1
  45. *
  46. * a = 2;
  47. * memory_barrier();
  48. * b = 3; y = b;
  49. * read_barrier_depends();
  50. * x = a;
  51. * </programlisting>
  52. *
  53. * does not enforce ordering, since there is no data dependency between
  54. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  55. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  56. * in cases like this where there are no data dependencies.
  57. */
  58. #define read_barrier_depends() __asm__ __volatile__("mb": : :"memory")
  59. #ifdef CONFIG_SMP
  60. #define __ASM_SMP_MB "\tmb\n"
  61. #else
  62. #define __ASM_SMP_MB
  63. #endif
  64. #include <asm-generic/barrier.h>
  65. #endif /* __BARRIER_H */