README 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. =====================================
  2. LINUX KERNEL MEMORY CONSISTENCY MODEL
  3. =====================================
  4. ============
  5. INTRODUCTION
  6. ============
  7. This directory contains the memory consistency model (memory model, for
  8. short) of the Linux kernel, written in the "cat" language and executable
  9. by the externally provided "herd7" simulator, which exhaustively explores
  10. the state space of small litmus tests.
  11. In addition, the "klitmus7" tool (also externally provided) may be used
  12. to convert a litmus test to a Linux kernel module, which in turn allows
  13. that litmus test to be exercised within the Linux kernel.
  14. ============
  15. REQUIREMENTS
  16. ============
  17. Version 7.52 or higher of the "herd7" and "klitmus7" tools must be
  18. downloaded separately:
  19. https://github.com/herd/herdtools7
  20. See "herdtools7/INSTALL.md" for installation instructions.
  21. Note that although these tools usually provide backwards compatibility,
  22. this is not absolutely guaranteed.
  23. For example, a future version of herd7 might not work with the model
  24. in this release. A compatible model will likely be made available in
  25. a later release of Linux kernel.
  26. If you absolutely need to run the model in this particular release,
  27. please try using the exact version called out above.
  28. klitmus7 is independent of the model provided here. It has its own
  29. dependency on a target kernel release where converted code is built
  30. and executed. Any change in kernel APIs essential to klitmus7 will
  31. necessitate an upgrade of klitmus7.
  32. If you find any compatibility issues in klitmus7, please inform the
  33. memory model maintainers.
  34. klitmus7 Compatibility Table
  35. ----------------------------
  36. ============ ==========
  37. target Linux herdtools7
  38. ------------ ----------
  39. -- 4.14 7.48 --
  40. 4.15 -- 4.19 7.49 --
  41. 4.20 -- 5.5 7.54 --
  42. 5.6 -- 5.16 7.56 --
  43. 5.17 -- 7.56.1 --
  44. ============ ==========
  45. ==================
  46. BASIC USAGE: HERD7
  47. ==================
  48. The memory model is used, in conjunction with "herd7", to exhaustively
  49. explore the state space of small litmus tests. Documentation describing
  50. the format, features, capabilities and limitations of these litmus
  51. tests is available in tools/memory-model/Documentation/litmus-tests.txt.
  52. Example litmus tests may be found in the Linux-kernel source tree:
  53. tools/memory-model/litmus-tests/
  54. Documentation/litmus-tests/
  55. Several thousand more example litmus tests are available here:
  56. https://github.com/paulmckrcu/litmus
  57. https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/herd
  58. https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/litmus
  59. Documentation describing litmus tests and now to use them may be found
  60. here:
  61. tools/memory-model/Documentation/litmus-tests.txt
  62. The remainder of this section uses the SB+fencembonceonces.litmus test
  63. located in the tools/memory-model directory.
  64. To run SB+fencembonceonces.litmus against the memory model:
  65. $ cd $LINUX_SOURCE_TREE/tools/memory-model
  66. $ herd7 -conf linux-kernel.cfg litmus-tests/SB+fencembonceonces.litmus
  67. Here is the corresponding output:
  68. Test SB+fencembonceonces Allowed
  69. States 3
  70. 0:r0=0; 1:r0=1;
  71. 0:r0=1; 1:r0=0;
  72. 0:r0=1; 1:r0=1;
  73. No
  74. Witnesses
  75. Positive: 0 Negative: 3
  76. Condition exists (0:r0=0 /\ 1:r0=0)
  77. Observation SB+fencembonceonces Never 0 3
  78. Time SB+fencembonceonces 0.01
  79. Hash=d66d99523e2cac6b06e66f4c995ebb48
  80. The "Positive: 0 Negative: 3" and the "Never 0 3" each indicate that
  81. this litmus test's "exists" clause can not be satisfied.
  82. See "herd7 -help" or "herdtools7/doc/" for more information on running the
  83. tool itself, but please be aware that this documentation is intended for
  84. people who work on the memory model itself, that is, people making changes
  85. to the tools/memory-model/linux-kernel.* files. It is not intended for
  86. people focusing on writing, understanding, and running LKMM litmus tests.
  87. =====================
  88. BASIC USAGE: KLITMUS7
  89. =====================
  90. The "klitmus7" tool converts a litmus test into a Linux kernel module,
  91. which may then be loaded and run.
  92. For example, to run SB+fencembonceonces.litmus against hardware:
  93. $ mkdir mymodules
  94. $ klitmus7 -o mymodules litmus-tests/SB+fencembonceonces.litmus
  95. $ cd mymodules ; make
  96. $ sudo sh run.sh
  97. The corresponding output includes:
  98. Test SB+fencembonceonces Allowed
  99. Histogram (3 states)
  100. 644580 :>0:r0=1; 1:r0=0;
  101. 644328 :>0:r0=0; 1:r0=1;
  102. 711092 :>0:r0=1; 1:r0=1;
  103. No
  104. Witnesses
  105. Positive: 0, Negative: 2000000
  106. Condition exists (0:r0=0 /\ 1:r0=0) is NOT validated
  107. Hash=d66d99523e2cac6b06e66f4c995ebb48
  108. Observation SB+fencembonceonces Never 0 2000000
  109. Time SB+fencembonceonces 0.16
  110. The "Positive: 0 Negative: 2000000" and the "Never 0 2000000" indicate
  111. that during two million trials, the state specified in this litmus
  112. test's "exists" clause was not reached.
  113. And, as with "herd7", please see "klitmus7 -help" or "herdtools7/doc/"
  114. for more information. And again, please be aware that this documentation
  115. is intended for people who work on the memory model itself, that is,
  116. people making changes to the tools/memory-model/linux-kernel.* files.
  117. It is not intended for people focusing on writing, understanding, and
  118. running LKMM litmus tests.
  119. ====================
  120. DESCRIPTION OF FILES
  121. ====================
  122. Documentation/README
  123. Guide to the other documents in the Documentation/ directory.
  124. linux-kernel.bell
  125. Categorizes the relevant instructions, including memory
  126. references, memory barriers, atomic read-modify-write operations,
  127. lock acquisition/release, and RCU operations.
  128. More formally, this file (1) lists the subtypes of the various
  129. event types used by the memory model and (2) performs RCU
  130. read-side critical section nesting analysis.
  131. linux-kernel.cat
  132. Specifies what reorderings are forbidden by memory references,
  133. memory barriers, atomic read-modify-write operations, and RCU.
  134. More formally, this file specifies what executions are forbidden
  135. by the memory model. Allowed executions are those which
  136. satisfy the model's "coherence", "atomic", "happens-before",
  137. "propagation", and "rcu" axioms, which are defined in the file.
  138. linux-kernel.cfg
  139. Convenience file that gathers the common-case herd7 command-line
  140. arguments.
  141. linux-kernel.def
  142. Maps from C-like syntax to herd7's internal litmus-test
  143. instruction-set architecture.
  144. litmus-tests
  145. Directory containing a few representative litmus tests, which
  146. are listed in litmus-tests/README. A great deal more litmus
  147. tests are available at https://github.com/paulmckrcu/litmus.
  148. By "representative", it means the one in the litmus-tests
  149. directory is:
  150. 1) simple, the number of threads should be relatively
  151. small and each thread function should be relatively
  152. simple.
  153. 2) orthogonal, there should be no two litmus tests
  154. describing the same aspect of the memory model.
  155. 3) textbook, developers can easily copy-paste-modify
  156. the litmus tests to use the patterns on their own
  157. code.
  158. lock.cat
  159. Provides a front-end analysis of lock acquisition and release,
  160. for example, associating a lock acquisition with the preceding
  161. and following releases and checking for self-deadlock.
  162. More formally, this file defines a performance-enhanced scheme
  163. for generation of the possible reads-from and coherence order
  164. relations on the locking primitives.
  165. README
  166. This file.
  167. scripts Various scripts, see scripts/README.