18c2ecf20Sopenharmony_ci		=====================================
28c2ecf20Sopenharmony_ci		LINUX KERNEL MEMORY CONSISTENCY MODEL
38c2ecf20Sopenharmony_ci		=====================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci============
68c2ecf20Sopenharmony_ciINTRODUCTION
78c2ecf20Sopenharmony_ci============
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciThis directory contains the memory consistency model (memory model, for
108c2ecf20Sopenharmony_cishort) of the Linux kernel, written in the "cat" language and executable
118c2ecf20Sopenharmony_ciby the externally provided "herd7" simulator, which exhaustively explores
128c2ecf20Sopenharmony_cithe state space of small litmus tests.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciIn addition, the "klitmus7" tool (also externally provided) may be used
158c2ecf20Sopenharmony_cito convert a litmus test to a Linux kernel module, which in turn allows
168c2ecf20Sopenharmony_cithat litmus test to be exercised within the Linux kernel.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci============
208c2ecf20Sopenharmony_ciREQUIREMENTS
218c2ecf20Sopenharmony_ci============
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciVersion 7.52 or higher of the "herd7" and "klitmus7" tools must be
248c2ecf20Sopenharmony_cidownloaded separately:
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci  https://github.com/herd/herdtools7
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciSee "herdtools7/INSTALL.md" for installation instructions.
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciNote that although these tools usually provide backwards compatibility,
318c2ecf20Sopenharmony_cithis is not absolutely guaranteed.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciFor example, a future version of herd7 might not work with the model
348c2ecf20Sopenharmony_ciin this release.  A compatible model will likely be made available in
358c2ecf20Sopenharmony_cia later release of Linux kernel.
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciIf you absolutely need to run the model in this particular release,
388c2ecf20Sopenharmony_ciplease try using the exact version called out above.
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciklitmus7 is independent of the model provided here.  It has its own
418c2ecf20Sopenharmony_cidependency on a target kernel release where converted code is built
428c2ecf20Sopenharmony_ciand executed.  Any change in kernel APIs essential to klitmus7 will
438c2ecf20Sopenharmony_cinecessitate an upgrade of klitmus7.
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciIf you find any compatibility issues in klitmus7, please inform the
468c2ecf20Sopenharmony_cimemory model maintainers.
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciklitmus7 Compatibility Table
498c2ecf20Sopenharmony_ci----------------------------
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	============  ==========
528c2ecf20Sopenharmony_ci	target Linux  herdtools7
538c2ecf20Sopenharmony_ci	------------  ----------
548c2ecf20Sopenharmony_ci	     -- 4.18  7.48 --
558c2ecf20Sopenharmony_ci	4.15 -- 4.19  7.49 --
568c2ecf20Sopenharmony_ci	4.20 -- 5.5   7.54 --
578c2ecf20Sopenharmony_ci	5.6  --       7.56 --
588c2ecf20Sopenharmony_ci	============  ==========
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci==================
628c2ecf20Sopenharmony_ciBASIC USAGE: HERD7
638c2ecf20Sopenharmony_ci==================
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciThe memory model is used, in conjunction with "herd7", to exhaustively
668c2ecf20Sopenharmony_ciexplore the state space of small litmus tests.  Documentation describing
678c2ecf20Sopenharmony_cithe format, features, capabilities and limitations of these litmus
688c2ecf20Sopenharmony_citests is available in tools/memory-model/Documentation/litmus-tests.txt.
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciExample litmus tests may be found in the Linux-kernel source tree:
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	tools/memory-model/litmus-tests/
738c2ecf20Sopenharmony_ci	Documentation/litmus-tests/
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciSeveral thousand more example litmus tests are available here:
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	https://github.com/paulmckrcu/litmus
788c2ecf20Sopenharmony_ci	https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/herd
798c2ecf20Sopenharmony_ci	https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/litmus
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciDocumentation describing litmus tests and now to use them may be found
828c2ecf20Sopenharmony_cihere:
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	tools/memory-model/Documentation/litmus-tests.txt
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciThe remainder of this section uses the SB+fencembonceonces.litmus test
878c2ecf20Sopenharmony_cilocated in the tools/memory-model directory.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciTo run SB+fencembonceonces.litmus against the memory model:
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci  $ cd $LINUX_SOURCE_TREE/tools/memory-model
928c2ecf20Sopenharmony_ci  $ herd7 -conf linux-kernel.cfg litmus-tests/SB+fencembonceonces.litmus
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciHere is the corresponding output:
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci  Test SB+fencembonceonces Allowed
978c2ecf20Sopenharmony_ci  States 3
988c2ecf20Sopenharmony_ci  0:r0=0; 1:r0=1;
998c2ecf20Sopenharmony_ci  0:r0=1; 1:r0=0;
1008c2ecf20Sopenharmony_ci  0:r0=1; 1:r0=1;
1018c2ecf20Sopenharmony_ci  No
1028c2ecf20Sopenharmony_ci  Witnesses
1038c2ecf20Sopenharmony_ci  Positive: 0 Negative: 3
1048c2ecf20Sopenharmony_ci  Condition exists (0:r0=0 /\ 1:r0=0)
1058c2ecf20Sopenharmony_ci  Observation SB+fencembonceonces Never 0 3
1068c2ecf20Sopenharmony_ci  Time SB+fencembonceonces 0.01
1078c2ecf20Sopenharmony_ci  Hash=d66d99523e2cac6b06e66f4c995ebb48
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciThe "Positive: 0 Negative: 3" and the "Never 0 3" each indicate that
1108c2ecf20Sopenharmony_cithis litmus test's "exists" clause can not be satisfied.
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciSee "herd7 -help" or "herdtools7/doc/" for more information on running the
1138c2ecf20Sopenharmony_citool itself, but please be aware that this documentation is intended for
1148c2ecf20Sopenharmony_cipeople who work on the memory model itself, that is, people making changes
1158c2ecf20Sopenharmony_cito the tools/memory-model/linux-kernel.* files.  It is not intended for
1168c2ecf20Sopenharmony_cipeople focusing on writing, understanding, and running LKMM litmus tests.
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci=====================
1208c2ecf20Sopenharmony_ciBASIC USAGE: KLITMUS7
1218c2ecf20Sopenharmony_ci=====================
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciThe "klitmus7" tool converts a litmus test into a Linux kernel module,
1248c2ecf20Sopenharmony_ciwhich may then be loaded and run.
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciFor example, to run SB+fencembonceonces.litmus against hardware:
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci  $ mkdir mymodules
1298c2ecf20Sopenharmony_ci  $ klitmus7 -o mymodules litmus-tests/SB+fencembonceonces.litmus
1308c2ecf20Sopenharmony_ci  $ cd mymodules ; make
1318c2ecf20Sopenharmony_ci  $ sudo sh run.sh
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciThe corresponding output includes:
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci  Test SB+fencembonceonces Allowed
1368c2ecf20Sopenharmony_ci  Histogram (3 states)
1378c2ecf20Sopenharmony_ci  644580  :>0:r0=1; 1:r0=0;
1388c2ecf20Sopenharmony_ci  644328  :>0:r0=0; 1:r0=1;
1398c2ecf20Sopenharmony_ci  711092  :>0:r0=1; 1:r0=1;
1408c2ecf20Sopenharmony_ci  No
1418c2ecf20Sopenharmony_ci  Witnesses
1428c2ecf20Sopenharmony_ci  Positive: 0, Negative: 2000000
1438c2ecf20Sopenharmony_ci  Condition exists (0:r0=0 /\ 1:r0=0) is NOT validated
1448c2ecf20Sopenharmony_ci  Hash=d66d99523e2cac6b06e66f4c995ebb48
1458c2ecf20Sopenharmony_ci  Observation SB+fencembonceonces Never 0 2000000
1468c2ecf20Sopenharmony_ci  Time SB+fencembonceonces 0.16
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ciThe "Positive: 0 Negative: 2000000" and the "Never 0 2000000" indicate
1498c2ecf20Sopenharmony_cithat during two million trials, the state specified in this litmus
1508c2ecf20Sopenharmony_citest's "exists" clause was not reached.
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciAnd, as with "herd7", please see "klitmus7 -help" or "herdtools7/doc/"
1538c2ecf20Sopenharmony_cifor more information.  And again, please be aware that this documentation
1548c2ecf20Sopenharmony_ciis intended for people who work on the memory model itself, that is,
1558c2ecf20Sopenharmony_cipeople making changes to the tools/memory-model/linux-kernel.* files.
1568c2ecf20Sopenharmony_ciIt is not intended for people focusing on writing, understanding, and
1578c2ecf20Sopenharmony_cirunning LKMM litmus tests.
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci====================
1618c2ecf20Sopenharmony_ciDESCRIPTION OF FILES
1628c2ecf20Sopenharmony_ci====================
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciDocumentation/cheatsheet.txt
1658c2ecf20Sopenharmony_ci	Quick-reference guide to the Linux-kernel memory model.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciDocumentation/explanation.txt
1688c2ecf20Sopenharmony_ci	Describes the memory model in detail.
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciDocumentation/litmus-tests.txt
1718c2ecf20Sopenharmony_ci	Describes the format, features, capabilities, and limitations
1728c2ecf20Sopenharmony_ci	of the litmus tests that LKMM can evaluate.
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciDocumentation/recipes.txt
1758c2ecf20Sopenharmony_ci	Lists common memory-ordering patterns.
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ciDocumentation/references.txt
1788c2ecf20Sopenharmony_ci	Provides background reading.
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ciDocumentation/simple.txt
1818c2ecf20Sopenharmony_ci	Starting point for someone new to Linux-kernel concurrency.
1828c2ecf20Sopenharmony_ci	And also for those needing a reminder of the simpler approaches
1838c2ecf20Sopenharmony_ci	to concurrency!
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cilinux-kernel.bell
1868c2ecf20Sopenharmony_ci	Categorizes the relevant instructions, including memory
1878c2ecf20Sopenharmony_ci	references, memory barriers, atomic read-modify-write operations,
1888c2ecf20Sopenharmony_ci	lock acquisition/release, and RCU operations.
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	More formally, this file (1) lists the subtypes of the various
1918c2ecf20Sopenharmony_ci	event types used by the memory model and (2) performs RCU
1928c2ecf20Sopenharmony_ci	read-side critical section nesting analysis.
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cilinux-kernel.cat
1958c2ecf20Sopenharmony_ci	Specifies what reorderings are forbidden by memory references,
1968c2ecf20Sopenharmony_ci	memory barriers, atomic read-modify-write operations, and RCU.
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	More formally, this file specifies what executions are forbidden
1998c2ecf20Sopenharmony_ci	by the memory model.  Allowed executions are those which
2008c2ecf20Sopenharmony_ci	satisfy the model's "coherence", "atomic", "happens-before",
2018c2ecf20Sopenharmony_ci	"propagation", and "rcu" axioms, which are defined in the file.
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cilinux-kernel.cfg
2048c2ecf20Sopenharmony_ci	Convenience file that gathers the common-case herd7 command-line
2058c2ecf20Sopenharmony_ci	arguments.
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cilinux-kernel.def
2088c2ecf20Sopenharmony_ci	Maps from C-like syntax to herd7's internal litmus-test
2098c2ecf20Sopenharmony_ci	instruction-set architecture.
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cilitmus-tests
2128c2ecf20Sopenharmony_ci	Directory containing a few representative litmus tests, which
2138c2ecf20Sopenharmony_ci	are listed in litmus-tests/README.  A great deal more litmus
2148c2ecf20Sopenharmony_ci	tests are available at https://github.com/paulmckrcu/litmus.
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cilock.cat
2178c2ecf20Sopenharmony_ci	Provides a front-end analysis of lock acquisition and release,
2188c2ecf20Sopenharmony_ci	for example, associating a lock acquisition with the preceding
2198c2ecf20Sopenharmony_ci	and following releases and checking for self-deadlock.
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	More formally, this file defines a performance-enhanced scheme
2228c2ecf20Sopenharmony_ci	for generation of the possible reads-from and coherence order
2238c2ecf20Sopenharmony_ci	relations on the locking primitives.
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ciREADME
2268c2ecf20Sopenharmony_ci	This file.
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ciscripts	Various scripts, see scripts/README.
229