membarrier.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef _UAPI_LINUX_MEMBARRIER_H
  2. #define _UAPI_LINUX_MEMBARRIER_H
  3. /*
  4. * linux/membarrier.h
  5. *
  6. * membarrier system call API
  7. *
  8. * Copyright (c) 2010, 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. */
  28. /**
  29. * enum membarrier_cmd - membarrier system call command
  30. * @MEMBARRIER_CMD_QUERY: Query the set of supported commands. It returns
  31. * a bitmask of valid commands.
  32. * @MEMBARRIER_CMD_GLOBAL: Execute a memory barrier on all running threads.
  33. * Upon return from system call, the caller thread
  34. * is ensured that all running threads have passed
  35. * through a state where all memory accesses to
  36. * user-space addresses match program order between
  37. * entry to and return from the system call
  38. * (non-running threads are de facto in such a
  39. * state). This covers threads from all processes
  40. * running on the system. This command returns 0.
  41. * @MEMBARRIER_CMD_GLOBAL_EXPEDITED:
  42. * Execute a memory barrier on all running threads
  43. * of all processes which previously registered
  44. * with MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED.
  45. * Upon return from system call, the caller thread
  46. * is ensured that all running threads have passed
  47. * through a state where all memory accesses to
  48. * user-space addresses match program order between
  49. * entry to and return from the system call
  50. * (non-running threads are de facto in such a
  51. * state). This only covers threads from processes
  52. * which registered with
  53. * MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED.
  54. * This command returns 0. Given that
  55. * registration is about the intent to receive
  56. * the barriers, it is valid to invoke
  57. * MEMBARRIER_CMD_GLOBAL_EXPEDITED from a
  58. * non-registered process.
  59. * @MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED:
  60. * Register the process intent to receive
  61. * MEMBARRIER_CMD_GLOBAL_EXPEDITED memory
  62. * barriers. Always returns 0.
  63. * @MEMBARRIER_CMD_PRIVATE_EXPEDITED:
  64. * Execute a memory barrier on each running
  65. * thread belonging to the same process as the current
  66. * thread. Upon return from system call, the
  67. * caller thread is ensured that all its running
  68. * threads siblings have passed through a state
  69. * where all memory accesses to user-space
  70. * addresses match program order between entry
  71. * to and return from the system call
  72. * (non-running threads are de facto in such a
  73. * state). This only covers threads from the
  74. * same process as the caller thread. This
  75. * command returns 0 on success. The
  76. * "expedited" commands complete faster than
  77. * the non-expedited ones, they never block,
  78. * but have the downside of causing extra
  79. * overhead. A process needs to register its
  80. * intent to use the private expedited command
  81. * prior to using it, otherwise this command
  82. * returns -EPERM.
  83. * @MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED:
  84. * Register the process intent to use
  85. * MEMBARRIER_CMD_PRIVATE_EXPEDITED. Always
  86. * returns 0.
  87. * @MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE:
  88. * In addition to provide memory ordering
  89. * guarantees described in
  90. * MEMBARRIER_CMD_PRIVATE_EXPEDITED, ensure
  91. * the caller thread, upon return from system
  92. * call, that all its running threads siblings
  93. * have executed a core serializing
  94. * instruction. (architectures are required to
  95. * guarantee that non-running threads issue
  96. * core serializing instructions before they
  97. * resume user-space execution). This only
  98. * covers threads from the same process as the
  99. * caller thread. This command returns 0 on
  100. * success. The "expedited" commands complete
  101. * faster than the non-expedited ones, they
  102. * never block, but have the downside of
  103. * causing extra overhead. If this command is
  104. * not implemented by an architecture, -EINVAL
  105. * is returned. A process needs to register its
  106. * intent to use the private expedited sync
  107. * core command prior to using it, otherwise
  108. * this command returns -EPERM.
  109. * @MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE:
  110. * Register the process intent to use
  111. * MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE.
  112. * If this command is not implemented by an
  113. * architecture, -EINVAL is returned.
  114. * Returns 0 on success.
  115. * @MEMBARRIER_CMD_SHARED:
  116. * Alias to MEMBARRIER_CMD_GLOBAL. Provided for
  117. * header backward compatibility.
  118. *
  119. * Command to be passed to the membarrier system call. The commands need to
  120. * be a single bit each, except for MEMBARRIER_CMD_QUERY which is assigned to
  121. * the value 0.
  122. */
  123. enum membarrier_cmd {
  124. MEMBARRIER_CMD_QUERY = 0,
  125. MEMBARRIER_CMD_GLOBAL = (1 << 0),
  126. MEMBARRIER_CMD_GLOBAL_EXPEDITED = (1 << 1),
  127. MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED = (1 << 2),
  128. MEMBARRIER_CMD_PRIVATE_EXPEDITED = (1 << 3),
  129. MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4),
  130. MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 5),
  131. MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6),
  132. /* Alias for header backward compatibility. */
  133. MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL,
  134. };
  135. #endif /* _UAPI_LINUX_MEMBARRIER_H */