162306a36Sopenharmony_ci ===================================== 262306a36Sopenharmony_ci LINUX KERNEL MEMORY CONSISTENCY MODEL 362306a36Sopenharmony_ci ===================================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci============ 662306a36Sopenharmony_ciINTRODUCTION 762306a36Sopenharmony_ci============ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciThis directory contains the memory consistency model (memory model, for 1062306a36Sopenharmony_cishort) of the Linux kernel, written in the "cat" language and executable 1162306a36Sopenharmony_ciby the externally provided "herd7" simulator, which exhaustively explores 1262306a36Sopenharmony_cithe state space of small litmus tests. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciIn addition, the "klitmus7" tool (also externally provided) may be used 1562306a36Sopenharmony_cito convert a litmus test to a Linux kernel module, which in turn allows 1662306a36Sopenharmony_cithat litmus test to be exercised within the Linux kernel. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci============ 2062306a36Sopenharmony_ciREQUIREMENTS 2162306a36Sopenharmony_ci============ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciVersion 7.52 or higher of the "herd7" and "klitmus7" tools must be 2462306a36Sopenharmony_cidownloaded separately: 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci https://github.com/herd/herdtools7 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciSee "herdtools7/INSTALL.md" for installation instructions. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciNote that although these tools usually provide backwards compatibility, 3162306a36Sopenharmony_cithis is not absolutely guaranteed. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciFor example, a future version of herd7 might not work with the model 3462306a36Sopenharmony_ciin this release. A compatible model will likely be made available in 3562306a36Sopenharmony_cia later release of Linux kernel. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciIf you absolutely need to run the model in this particular release, 3862306a36Sopenharmony_ciplease try using the exact version called out above. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciklitmus7 is independent of the model provided here. It has its own 4162306a36Sopenharmony_cidependency on a target kernel release where converted code is built 4262306a36Sopenharmony_ciand executed. Any change in kernel APIs essential to klitmus7 will 4362306a36Sopenharmony_cinecessitate an upgrade of klitmus7. 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciIf you find any compatibility issues in klitmus7, please inform the 4662306a36Sopenharmony_cimemory model maintainers. 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciklitmus7 Compatibility Table 4962306a36Sopenharmony_ci---------------------------- 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci ============ ========== 5262306a36Sopenharmony_ci target Linux herdtools7 5362306a36Sopenharmony_ci ------------ ---------- 5462306a36Sopenharmony_ci -- 4.14 7.48 -- 5562306a36Sopenharmony_ci 4.15 -- 4.19 7.49 -- 5662306a36Sopenharmony_ci 4.20 -- 5.5 7.54 -- 5762306a36Sopenharmony_ci 5.6 -- 5.16 7.56 -- 5862306a36Sopenharmony_ci 5.17 -- 7.56.1 -- 5962306a36Sopenharmony_ci ============ ========== 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci================== 6362306a36Sopenharmony_ciBASIC USAGE: HERD7 6462306a36Sopenharmony_ci================== 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciThe memory model is used, in conjunction with "herd7", to exhaustively 6762306a36Sopenharmony_ciexplore the state space of small litmus tests. Documentation describing 6862306a36Sopenharmony_cithe format, features, capabilities and limitations of these litmus 6962306a36Sopenharmony_citests is available in tools/memory-model/Documentation/litmus-tests.txt. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciExample litmus tests may be found in the Linux-kernel source tree: 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci tools/memory-model/litmus-tests/ 7462306a36Sopenharmony_ci Documentation/litmus-tests/ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciSeveral thousand more example litmus tests are available here: 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci https://github.com/paulmckrcu/litmus 7962306a36Sopenharmony_ci https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/herd 8062306a36Sopenharmony_ci https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git/tree/CodeSamples/formal/litmus 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciDocumentation describing litmus tests and now to use them may be found 8362306a36Sopenharmony_cihere: 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci tools/memory-model/Documentation/litmus-tests.txt 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciThe remainder of this section uses the SB+fencembonceonces.litmus test 8862306a36Sopenharmony_cilocated in the tools/memory-model directory. 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ciTo run SB+fencembonceonces.litmus against the memory model: 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci $ cd $LINUX_SOURCE_TREE/tools/memory-model 9362306a36Sopenharmony_ci $ herd7 -conf linux-kernel.cfg litmus-tests/SB+fencembonceonces.litmus 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciHere is the corresponding output: 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci Test SB+fencembonceonces Allowed 9862306a36Sopenharmony_ci States 3 9962306a36Sopenharmony_ci 0:r0=0; 1:r0=1; 10062306a36Sopenharmony_ci 0:r0=1; 1:r0=0; 10162306a36Sopenharmony_ci 0:r0=1; 1:r0=1; 10262306a36Sopenharmony_ci No 10362306a36Sopenharmony_ci Witnesses 10462306a36Sopenharmony_ci Positive: 0 Negative: 3 10562306a36Sopenharmony_ci Condition exists (0:r0=0 /\ 1:r0=0) 10662306a36Sopenharmony_ci Observation SB+fencembonceonces Never 0 3 10762306a36Sopenharmony_ci Time SB+fencembonceonces 0.01 10862306a36Sopenharmony_ci Hash=d66d99523e2cac6b06e66f4c995ebb48 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciThe "Positive: 0 Negative: 3" and the "Never 0 3" each indicate that 11162306a36Sopenharmony_cithis litmus test's "exists" clause can not be satisfied. 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciSee "herd7 -help" or "herdtools7/doc/" for more information on running the 11462306a36Sopenharmony_citool itself, but please be aware that this documentation is intended for 11562306a36Sopenharmony_cipeople who work on the memory model itself, that is, people making changes 11662306a36Sopenharmony_cito the tools/memory-model/linux-kernel.* files. It is not intended for 11762306a36Sopenharmony_cipeople focusing on writing, understanding, and running LKMM litmus tests. 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci===================== 12162306a36Sopenharmony_ciBASIC USAGE: KLITMUS7 12262306a36Sopenharmony_ci===================== 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciThe "klitmus7" tool converts a litmus test into a Linux kernel module, 12562306a36Sopenharmony_ciwhich may then be loaded and run. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciFor example, to run SB+fencembonceonces.litmus against hardware: 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci $ mkdir mymodules 13062306a36Sopenharmony_ci $ klitmus7 -o mymodules litmus-tests/SB+fencembonceonces.litmus 13162306a36Sopenharmony_ci $ cd mymodules ; make 13262306a36Sopenharmony_ci $ sudo sh run.sh 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciThe corresponding output includes: 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci Test SB+fencembonceonces Allowed 13762306a36Sopenharmony_ci Histogram (3 states) 13862306a36Sopenharmony_ci 644580 :>0:r0=1; 1:r0=0; 13962306a36Sopenharmony_ci 644328 :>0:r0=0; 1:r0=1; 14062306a36Sopenharmony_ci 711092 :>0:r0=1; 1:r0=1; 14162306a36Sopenharmony_ci No 14262306a36Sopenharmony_ci Witnesses 14362306a36Sopenharmony_ci Positive: 0, Negative: 2000000 14462306a36Sopenharmony_ci Condition exists (0:r0=0 /\ 1:r0=0) is NOT validated 14562306a36Sopenharmony_ci Hash=d66d99523e2cac6b06e66f4c995ebb48 14662306a36Sopenharmony_ci Observation SB+fencembonceonces Never 0 2000000 14762306a36Sopenharmony_ci Time SB+fencembonceonces 0.16 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciThe "Positive: 0 Negative: 2000000" and the "Never 0 2000000" indicate 15062306a36Sopenharmony_cithat during two million trials, the state specified in this litmus 15162306a36Sopenharmony_citest's "exists" clause was not reached. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciAnd, as with "herd7", please see "klitmus7 -help" or "herdtools7/doc/" 15462306a36Sopenharmony_cifor more information. And again, please be aware that this documentation 15562306a36Sopenharmony_ciis intended for people who work on the memory model itself, that is, 15662306a36Sopenharmony_cipeople making changes to the tools/memory-model/linux-kernel.* files. 15762306a36Sopenharmony_ciIt is not intended for people focusing on writing, understanding, and 15862306a36Sopenharmony_cirunning LKMM litmus tests. 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci==================== 16262306a36Sopenharmony_ciDESCRIPTION OF FILES 16362306a36Sopenharmony_ci==================== 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ciDocumentation/README 16662306a36Sopenharmony_ci Guide to the other documents in the Documentation/ directory. 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cilinux-kernel.bell 16962306a36Sopenharmony_ci Categorizes the relevant instructions, including memory 17062306a36Sopenharmony_ci references, memory barriers, atomic read-modify-write operations, 17162306a36Sopenharmony_ci lock acquisition/release, and RCU operations. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci More formally, this file (1) lists the subtypes of the various 17462306a36Sopenharmony_ci event types used by the memory model and (2) performs RCU 17562306a36Sopenharmony_ci read-side critical section nesting analysis. 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cilinux-kernel.cat 17862306a36Sopenharmony_ci Specifies what reorderings are forbidden by memory references, 17962306a36Sopenharmony_ci memory barriers, atomic read-modify-write operations, and RCU. 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci More formally, this file specifies what executions are forbidden 18262306a36Sopenharmony_ci by the memory model. Allowed executions are those which 18362306a36Sopenharmony_ci satisfy the model's "coherence", "atomic", "happens-before", 18462306a36Sopenharmony_ci "propagation", and "rcu" axioms, which are defined in the file. 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cilinux-kernel.cfg 18762306a36Sopenharmony_ci Convenience file that gathers the common-case herd7 command-line 18862306a36Sopenharmony_ci arguments. 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_cilinux-kernel.def 19162306a36Sopenharmony_ci Maps from C-like syntax to herd7's internal litmus-test 19262306a36Sopenharmony_ci instruction-set architecture. 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cilitmus-tests 19562306a36Sopenharmony_ci Directory containing a few representative litmus tests, which 19662306a36Sopenharmony_ci are listed in litmus-tests/README. A great deal more litmus 19762306a36Sopenharmony_ci tests are available at https://github.com/paulmckrcu/litmus. 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci By "representative", it means the one in the litmus-tests 20062306a36Sopenharmony_ci directory is: 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci 1) simple, the number of threads should be relatively 20362306a36Sopenharmony_ci small and each thread function should be relatively 20462306a36Sopenharmony_ci simple. 20562306a36Sopenharmony_ci 2) orthogonal, there should be no two litmus tests 20662306a36Sopenharmony_ci describing the same aspect of the memory model. 20762306a36Sopenharmony_ci 3) textbook, developers can easily copy-paste-modify 20862306a36Sopenharmony_ci the litmus tests to use the patterns on their own 20962306a36Sopenharmony_ci code. 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_cilock.cat 21262306a36Sopenharmony_ci Provides a front-end analysis of lock acquisition and release, 21362306a36Sopenharmony_ci for example, associating a lock acquisition with the preceding 21462306a36Sopenharmony_ci and following releases and checking for self-deadlock. 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci More formally, this file defines a performance-enhanced scheme 21762306a36Sopenharmony_ci for generation of the possible reads-from and coherence order 21862306a36Sopenharmony_ci relations on the locking primitives. 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ciREADME 22162306a36Sopenharmony_ci This file. 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciscripts Various scripts, see scripts/README. 224