xref: /openbmc/linux/tools/memory-model/README (revision ab8bcad6)
148d44d4eSAndrea Parri		=====================================
248d44d4eSAndrea Parri		LINUX KERNEL MEMORY CONSISTENCY MODEL
348d44d4eSAndrea Parri		=====================================
41c27b644SPaul E. McKenney
51c27b644SPaul E. McKenney============
61c27b644SPaul E. McKenneyINTRODUCTION
71c27b644SPaul E. McKenney============
81c27b644SPaul E. McKenney
948d44d4eSAndrea ParriThis directory contains the memory consistency model (memory model, for
1048d44d4eSAndrea Parrishort) of the Linux kernel, written in the "cat" language and executable
1148d44d4eSAndrea Parriby the externally provided "herd7" simulator, which exhaustively explores
1248d44d4eSAndrea Parrithe state space of small litmus tests.
131c27b644SPaul E. McKenney
141c27b644SPaul E. McKenneyIn addition, the "klitmus7" tool (also externally provided) may be used
151c27b644SPaul E. McKenneyto convert a litmus test to a Linux kernel module, which in turn allows
161c27b644SPaul E. McKenneythat litmus test to be exercised within the Linux kernel.
171c27b644SPaul E. McKenney
181c27b644SPaul E. McKenney
191c27b644SPaul E. McKenney============
201c27b644SPaul E. McKenneyREQUIREMENTS
211c27b644SPaul E. McKenney============
221c27b644SPaul E. McKenney
23034fb712SAndrea ParriVersion 7.52 or higher of the "herd7" and "klitmus7" tools must be
24034fb712SAndrea Parridownloaded separately:
251c27b644SPaul E. McKenney
261c27b644SPaul E. McKenney  https://github.com/herd/herdtools7
271c27b644SPaul E. McKenney
281c27b644SPaul E. McKenneySee "herdtools7/INSTALL.md" for installation instructions.
291c27b644SPaul E. McKenney
30034fb712SAndrea ParriNote that although these tools usually provide backwards compatibility,
31d075a78aSAkira Yokosawathis is not absolutely guaranteed.
32d075a78aSAkira Yokosawa
33d075a78aSAkira YokosawaFor example, a future version of herd7 might not work with the model
34d075a78aSAkira Yokosawain this release.  A compatible model will likely be made available in
35d075a78aSAkira Yokosawaa later release of Linux kernel.
36d075a78aSAkira Yokosawa
37d075a78aSAkira YokosawaIf you absolutely need to run the model in this particular release,
38d075a78aSAkira Yokosawaplease try using the exact version called out above.
39d075a78aSAkira Yokosawa
40d075a78aSAkira Yokosawaklitmus7 is independent of the model provided here.  It has its own
41d075a78aSAkira Yokosawadependency on a target kernel release where converted code is built
42d075a78aSAkira Yokosawaand executed.  Any change in kernel APIs essential to klitmus7 will
43d075a78aSAkira Yokosawanecessitate an upgrade of klitmus7.
44d075a78aSAkira Yokosawa
45d075a78aSAkira YokosawaIf you find any compatibility issues in klitmus7, please inform the
46d075a78aSAkira Yokosawamemory model maintainers.
47d075a78aSAkira Yokosawa
48d075a78aSAkira Yokosawaklitmus7 Compatibility Table
49d075a78aSAkira Yokosawa----------------------------
50d075a78aSAkira Yokosawa
51d075a78aSAkira Yokosawa	============  ==========
52d075a78aSAkira Yokosawa	target Linux  herdtools7
53d075a78aSAkira Yokosawa	------------  ----------
54d075a78aSAkira Yokosawa	     -- 4.18  7.48 --
55d075a78aSAkira Yokosawa	4.15 -- 4.19  7.49 --
56d075a78aSAkira Yokosawa	4.20 -- 5.5   7.54 --
572bfa5c62SAkira Yokosawa	5.6  --       7.56 --
58d075a78aSAkira Yokosawa	============  ==========
59034fb712SAndrea Parri
601c27b644SPaul E. McKenney
611c27b644SPaul E. McKenney==================
621c27b644SPaul E. McKenneyBASIC USAGE: HERD7
631c27b644SPaul E. McKenney==================
641c27b644SPaul E. McKenney
651c27b644SPaul E. McKenneyThe memory model is used, in conjunction with "herd7", to exhaustively
66984f272bSPaul E. McKenneyexplore the state space of small litmus tests.  Documentation describing
67984f272bSPaul E. McKenneythe format, features, capabilities and limitations of these litmus
68984f272bSPaul E. McKenneytests is available in tools/memory-model/Documentation/litmus-tests.txt.
691c27b644SPaul E. McKenney
70984f272bSPaul E. McKenneyExample litmus tests may be found in the Linux-kernel source tree:
711c27b644SPaul E. McKenney
72984f272bSPaul E. McKenney	tools/memory-model/litmus-tests/
73984f272bSPaul E. McKenney	Documentation/litmus-tests/
74984f272bSPaul E. McKenney
75984f272bSPaul E. McKenneySeveral thousand more example litmus tests are available here:
76984f272bSPaul E. McKenney
77984f272bSPaul E. McKenney	https://github.com/paulmckrcu/litmus
78984f272bSPaul E. McKenney	https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/herd
79984f272bSPaul E. McKenney	https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/litmus
80984f272bSPaul E. McKenney
81984f272bSPaul E. McKenneyDocumentation describing litmus tests and now to use them may be found
82984f272bSPaul E. McKenneyhere:
83984f272bSPaul E. McKenney
84984f272bSPaul E. McKenney	tools/memory-model/Documentation/litmus-tests.txt
85984f272bSPaul E. McKenney
86984f272bSPaul E. McKenneyThe remainder of this section uses the SB+fencembonceonces.litmus test
87984f272bSPaul E. McKenneylocated in the tools/memory-model directory.
88984f272bSPaul E. McKenney
89984f272bSPaul E. McKenneyTo run SB+fencembonceonces.litmus against the memory model:
90984f272bSPaul E. McKenney
91984f272bSPaul E. McKenney  $ cd $LINUX_SOURCE_TREE/tools/memory-model
9271b7ff5eSAndrea Parri  $ herd7 -conf linux-kernel.cfg litmus-tests/SB+fencembonceonces.litmus
931c27b644SPaul E. McKenney
941c27b644SPaul E. McKenneyHere is the corresponding output:
951c27b644SPaul E. McKenney
9671b7ff5eSAndrea Parri  Test SB+fencembonceonces Allowed
971c27b644SPaul E. McKenney  States 3
981c27b644SPaul E. McKenney  0:r0=0; 1:r0=1;
991c27b644SPaul E. McKenney  0:r0=1; 1:r0=0;
1001c27b644SPaul E. McKenney  0:r0=1; 1:r0=1;
1011c27b644SPaul E. McKenney  No
1021c27b644SPaul E. McKenney  Witnesses
1031c27b644SPaul E. McKenney  Positive: 0 Negative: 3
1041c27b644SPaul E. McKenney  Condition exists (0:r0=0 /\ 1:r0=0)
10571b7ff5eSAndrea Parri  Observation SB+fencembonceonces Never 0 3
10671b7ff5eSAndrea Parri  Time SB+fencembonceonces 0.01
1071c27b644SPaul E. McKenney  Hash=d66d99523e2cac6b06e66f4c995ebb48
1081c27b644SPaul E. McKenney
1091c27b644SPaul E. McKenneyThe "Positive: 0 Negative: 3" and the "Never 0 3" each indicate that
1101c27b644SPaul E. McKenneythis litmus test's "exists" clause can not be satisfied.
1111c27b644SPaul E. McKenney
112984f272bSPaul E. McKenneySee "herd7 -help" or "herdtools7/doc/" for more information on running the
113984f272bSPaul E. McKenneytool itself, but please be aware that this documentation is intended for
114984f272bSPaul E. McKenneypeople who work on the memory model itself, that is, people making changes
115984f272bSPaul E. McKenneyto the tools/memory-model/linux-kernel.* files.  It is not intended for
116984f272bSPaul E. McKenneypeople focusing on writing, understanding, and running LKMM litmus tests.
1171c27b644SPaul E. McKenney
1181c27b644SPaul E. McKenney
1191c27b644SPaul E. McKenney=====================
1201c27b644SPaul E. McKenneyBASIC USAGE: KLITMUS7
1211c27b644SPaul E. McKenney=====================
1221c27b644SPaul E. McKenney
1231c27b644SPaul E. McKenneyThe "klitmus7" tool converts a litmus test into a Linux kernel module,
1241c27b644SPaul E. McKenneywhich may then be loaded and run.
1251c27b644SPaul E. McKenney
12671b7ff5eSAndrea ParriFor example, to run SB+fencembonceonces.litmus against hardware:
1271c27b644SPaul E. McKenney
1281c27b644SPaul E. McKenney  $ mkdir mymodules
12971b7ff5eSAndrea Parri  $ klitmus7 -o mymodules litmus-tests/SB+fencembonceonces.litmus
1301c27b644SPaul E. McKenney  $ cd mymodules ; make
1311c27b644SPaul E. McKenney  $ sudo sh run.sh
1321c27b644SPaul E. McKenney
1331c27b644SPaul E. McKenneyThe corresponding output includes:
1341c27b644SPaul E. McKenney
13571b7ff5eSAndrea Parri  Test SB+fencembonceonces Allowed
1361c27b644SPaul E. McKenney  Histogram (3 states)
1371c27b644SPaul E. McKenney  644580  :>0:r0=1; 1:r0=0;
1381c27b644SPaul E. McKenney  644328  :>0:r0=0; 1:r0=1;
1391c27b644SPaul E. McKenney  711092  :>0:r0=1; 1:r0=1;
1401c27b644SPaul E. McKenney  No
1411c27b644SPaul E. McKenney  Witnesses
1421c27b644SPaul E. McKenney  Positive: 0, Negative: 2000000
1431c27b644SPaul E. McKenney  Condition exists (0:r0=0 /\ 1:r0=0) is NOT validated
1441c27b644SPaul E. McKenney  Hash=d66d99523e2cac6b06e66f4c995ebb48
14571b7ff5eSAndrea Parri  Observation SB+fencembonceonces Never 0 2000000
14671b7ff5eSAndrea Parri  Time SB+fencembonceonces 0.16
1471c27b644SPaul E. McKenney
1481c27b644SPaul E. McKenneyThe "Positive: 0 Negative: 2000000" and the "Never 0 2000000" indicate
1491c27b644SPaul E. McKenneythat during two million trials, the state specified in this litmus
1501c27b644SPaul E. McKenneytest's "exists" clause was not reached.
1511c27b644SPaul E. McKenney
1521c27b644SPaul E. McKenneyAnd, as with "herd7", please see "klitmus7 -help" or "herdtools7/doc/"
153984f272bSPaul E. McKenneyfor more information.  And again, please be aware that this documentation
154984f272bSPaul E. McKenneyis intended for people who work on the memory model itself, that is,
155984f272bSPaul E. McKenneypeople making changes to the tools/memory-model/linux-kernel.* files.
156984f272bSPaul E. McKenneyIt is not intended for people focusing on writing, understanding, and
157984f272bSPaul E. McKenneyrunning LKMM litmus tests.
1581c27b644SPaul E. McKenney
1591c27b644SPaul E. McKenney
1601c27b644SPaul E. McKenney====================
1611c27b644SPaul E. McKenneyDESCRIPTION OF FILES
1621c27b644SPaul E. McKenney====================
1631c27b644SPaul E. McKenney
164*ab8bcad6SPaul E. McKenneyDocumentation/README
165*ab8bcad6SPaul E. McKenney	Guide to the other documents in the Documentation/ directory.
1660b8c06b7SPaul E. McKenney
1671c27b644SPaul E. McKenneylinux-kernel.bell
1681c27b644SPaul E. McKenney	Categorizes the relevant instructions, including memory
1691c27b644SPaul E. McKenney	references, memory barriers, atomic read-modify-write operations,
1701c27b644SPaul E. McKenney	lock acquisition/release, and RCU operations.
1711c27b644SPaul E. McKenney
1721c27b644SPaul E. McKenney	More formally, this file (1) lists the subtypes of the various
1731c27b644SPaul E. McKenney	event types used by the memory model and (2) performs RCU
1741c27b644SPaul E. McKenney	read-side critical section nesting analysis.
1751c27b644SPaul E. McKenney
1761c27b644SPaul E. McKenneylinux-kernel.cat
1771c27b644SPaul E. McKenney	Specifies what reorderings are forbidden by memory references,
1781c27b644SPaul E. McKenney	memory barriers, atomic read-modify-write operations, and RCU.
1791c27b644SPaul E. McKenney
1801c27b644SPaul E. McKenney	More formally, this file specifies what executions are forbidden
1811c27b644SPaul E. McKenney	by the memory model.  Allowed executions are those which
1821c27b644SPaul E. McKenney	satisfy the model's "coherence", "atomic", "happens-before",
1831c27b644SPaul E. McKenney	"propagation", and "rcu" axioms, which are defined in the file.
1841c27b644SPaul E. McKenney
1851c27b644SPaul E. McKenneylinux-kernel.cfg
1861c27b644SPaul E. McKenney	Convenience file that gathers the common-case herd7 command-line
1871c27b644SPaul E. McKenney	arguments.
1881c27b644SPaul E. McKenney
1891c27b644SPaul E. McKenneylinux-kernel.def
1901c27b644SPaul E. McKenney	Maps from C-like syntax to herd7's internal litmus-test
1911c27b644SPaul E. McKenney	instruction-set architecture.
1921c27b644SPaul E. McKenney
1931c27b644SPaul E. McKenneylitmus-tests
1941c27b644SPaul E. McKenney	Directory containing a few representative litmus tests, which
1951c27b644SPaul E. McKenney	are listed in litmus-tests/README.  A great deal more litmus
1961c27b644SPaul E. McKenney	tests are available at https://github.com/paulmckrcu/litmus.
1971c27b644SPaul E. McKenney
1981c27b644SPaul E. McKenneylock.cat
1991c27b644SPaul E. McKenney	Provides a front-end analysis of lock acquisition and release,
2001c27b644SPaul E. McKenney	for example, associating a lock acquisition with the preceding
2011c27b644SPaul E. McKenney	and following releases and checking for self-deadlock.
2021c27b644SPaul E. McKenney
2031c27b644SPaul E. McKenney	More formally, this file defines a performance-enhanced scheme
2041c27b644SPaul E. McKenney	for generation of the possible reads-from and coherence order
2051c27b644SPaul E. McKenney	relations on the locking primitives.
2061c27b644SPaul E. McKenney
2071c27b644SPaul E. McKenneyREADME
2081c27b644SPaul E. McKenney	This file.
2091c27b644SPaul E. McKenney
210b02eb5b0SPaul E. McKenneyscripts	Various scripts, see scripts/README.
211