162306a36Sopenharmony_ci============ 262306a36Sopenharmony_ciLITMUS TESTS 362306a36Sopenharmony_ci============ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciCoRR+poonceonce+Once.litmus 662306a36Sopenharmony_ci Test of read-read coherence, that is, whether or not two 762306a36Sopenharmony_ci successive reads from the same variable are ordered. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciCoRW+poonceonce+Once.litmus 1062306a36Sopenharmony_ci Test of read-write coherence, that is, whether or not a read 1162306a36Sopenharmony_ci from a given variable followed by a write to that same variable 1262306a36Sopenharmony_ci are ordered. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciCoWR+poonceonce+Once.litmus 1562306a36Sopenharmony_ci Test of write-read coherence, that is, whether or not a write 1662306a36Sopenharmony_ci to a given variable followed by a read from that same variable 1762306a36Sopenharmony_ci are ordered. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciCoWW+poonceonce.litmus 2062306a36Sopenharmony_ci Test of write-write coherence, that is, whether or not two 2162306a36Sopenharmony_ci successive writes to the same variable are ordered. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciIRIW+fencembonceonces+OnceOnce.litmus 2462306a36Sopenharmony_ci Test of independent reads from independent writes with smp_mb() 2562306a36Sopenharmony_ci between each pairs of reads. In other words, is smp_mb() 2662306a36Sopenharmony_ci sufficient to cause two different reading processes to agree on 2762306a36Sopenharmony_ci the order of a pair of writes, where each write is to a different 2862306a36Sopenharmony_ci variable by a different process? This litmus test is forbidden 2962306a36Sopenharmony_ci by LKMM's propagation rule. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciIRIW+poonceonces+OnceOnce.litmus 3262306a36Sopenharmony_ci Test of independent reads from independent writes with nothing 3362306a36Sopenharmony_ci between each pairs of reads. In other words, is anything at all 3462306a36Sopenharmony_ci needed to cause two different reading processes to agree on the 3562306a36Sopenharmony_ci order of a pair of writes, where each write is to a different 3662306a36Sopenharmony_ci variable by a different process? 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciISA2+pooncelock+pooncelock+pombonce.litmus 3962306a36Sopenharmony_ci Tests whether the ordering provided by a lock-protected S 4062306a36Sopenharmony_ci litmus test is visible to an external process whose accesses are 4162306a36Sopenharmony_ci separated by smp_mb(). This addition of an external process to 4262306a36Sopenharmony_ci S is otherwise known as ISA2. 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciISA2+poonceonces.litmus 4562306a36Sopenharmony_ci As below, but with store-release replaced with WRITE_ONCE() 4662306a36Sopenharmony_ci and load-acquire replaced with READ_ONCE(). 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciISA2+pooncerelease+poacquirerelease+poacquireonce.litmus 4962306a36Sopenharmony_ci Can a release-acquire chain order a prior store against 5062306a36Sopenharmony_ci a later load? 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciLB+fencembonceonce+ctrlonceonce.litmus 5362306a36Sopenharmony_ci Does a control dependency and an smp_mb() suffice for the 5462306a36Sopenharmony_ci load-buffering litmus test, where each process reads from one 5562306a36Sopenharmony_ci of two variables then writes to the other? 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciLB+poacquireonce+pooncerelease.litmus 5862306a36Sopenharmony_ci Does a release-acquire pair suffice for the load-buffering 5962306a36Sopenharmony_ci litmus test, where each process reads from one of two variables then 6062306a36Sopenharmony_ci writes to the other? 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciLB+poonceonces.litmus 6362306a36Sopenharmony_ci As above, but with store-release replaced with WRITE_ONCE() 6462306a36Sopenharmony_ci and load-acquire replaced with READ_ONCE(). 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciLB+unlocklockonceonce+poacquireonce.litmus 6762306a36Sopenharmony_ci Does a unlock+lock pair provides ordering guarantee between a 6862306a36Sopenharmony_ci load and a store? 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciMP+onceassign+derefonce.litmus 7162306a36Sopenharmony_ci As below, but with rcu_assign_pointer() and an rcu_dereference(). 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciMP+polockmbonce+poacquiresilsil.litmus 7462306a36Sopenharmony_ci Protect the access with a lock and an smp_mb__after_spinlock() 7562306a36Sopenharmony_ci in one process, and use an acquire load followed by a pair of 7662306a36Sopenharmony_ci spin_is_locked() calls in the other process. 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciMP+polockonce+poacquiresilsil.litmus 7962306a36Sopenharmony_ci Protect the access with a lock in one process, and use an 8062306a36Sopenharmony_ci acquire load followed by a pair of spin_is_locked() calls 8162306a36Sopenharmony_ci in the other process. 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciMP+polocks.litmus 8462306a36Sopenharmony_ci As below, but with the second access of the writer process 8562306a36Sopenharmony_ci and the first access of reader process protected by a lock. 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciMP+poonceonces.litmus 8862306a36Sopenharmony_ci As below, but without the smp_rmb() and smp_wmb(). 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ciMP+pooncerelease+poacquireonce.litmus 9162306a36Sopenharmony_ci As below, but with a release-acquire chain. 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciMP+porevlocks.litmus 9462306a36Sopenharmony_ci As below, but with the first access of the writer process 9562306a36Sopenharmony_ci and the second access of reader process protected by a lock. 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciMP+unlocklockonceonce+fencermbonceonce.litmus 9862306a36Sopenharmony_ci Does a unlock+lock pair provides ordering guarantee between a 9962306a36Sopenharmony_ci store and another store? 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciMP+fencewmbonceonce+fencermbonceonce.litmus 10262306a36Sopenharmony_ci Does a smp_wmb() (between the stores) and an smp_rmb() (between 10362306a36Sopenharmony_ci the loads) suffice for the message-passing litmus test, where one 10462306a36Sopenharmony_ci process writes data and then a flag, and the other process reads 10562306a36Sopenharmony_ci the flag and then the data. (This is similar to the ISA2 tests, 10662306a36Sopenharmony_ci but with two processes instead of three.) 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciR+fencembonceonces.litmus 10962306a36Sopenharmony_ci This is the fully ordered (via smp_mb()) version of one of 11062306a36Sopenharmony_ci the classic counterintuitive litmus tests that illustrates the 11162306a36Sopenharmony_ci effects of store propagation delays. 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciR+poonceonces.litmus 11462306a36Sopenharmony_ci As above, but without the smp_mb() invocations. 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciSB+fencembonceonces.litmus 11762306a36Sopenharmony_ci This is the fully ordered (again, via smp_mb() version of store 11862306a36Sopenharmony_ci buffering, which forms the core of Dekker's mutual-exclusion 11962306a36Sopenharmony_ci algorithm. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciSB+poonceonces.litmus 12262306a36Sopenharmony_ci As above, but without the smp_mb() invocations. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciSB+rfionceonce-poonceonces.litmus 12562306a36Sopenharmony_ci This litmus test demonstrates that LKMM is not fully multicopy 12662306a36Sopenharmony_ci atomic. (Neither is it other multicopy atomic.) This litmus test 12762306a36Sopenharmony_ci also demonstrates the "locations" debugging aid, which designates 12862306a36Sopenharmony_ci additional registers and locations to be printed out in the dump 12962306a36Sopenharmony_ci of final states in the herd7 output. Without the "locations" 13062306a36Sopenharmony_ci statement, only those registers and locations mentioned in the 13162306a36Sopenharmony_ci "exists" clause will be printed. 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciS+poonceonces.litmus 13462306a36Sopenharmony_ci As below, but without the smp_wmb() and acquire load. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ciS+fencewmbonceonce+poacquireonce.litmus 13762306a36Sopenharmony_ci Can a smp_wmb(), instead of a release, and an acquire order 13862306a36Sopenharmony_ci a prior store against a subsequent store? 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ciWRC+poonceonces+Once.litmus 14162306a36Sopenharmony_ciWRC+pooncerelease+fencermbonceonce+Once.litmus 14262306a36Sopenharmony_ci These two are members of an extension of the MP litmus-test 14362306a36Sopenharmony_ci class in which the first write is moved to a separate process. 14462306a36Sopenharmony_ci The second is forbidden because smp_store_release() is 14562306a36Sopenharmony_ci A-cumulative in LKMM. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ciZ6.0+pooncelock+pooncelock+pombonce.litmus 14862306a36Sopenharmony_ci Is the ordering provided by a spin_unlock() and a subsequent 14962306a36Sopenharmony_ci spin_lock() sufficient to make ordering apparent to accesses 15062306a36Sopenharmony_ci by a process not holding the lock? 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ciZ6.0+pooncelock+poonceLock+pombonce.litmus 15362306a36Sopenharmony_ci As above, but with smp_mb__after_spinlock() immediately 15462306a36Sopenharmony_ci following the spin_lock(). 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ciZ6.0+pooncerelease+poacquirerelease+fencembonceonce.litmus 15762306a36Sopenharmony_ci Is the ordering provided by a release-acquire chain sufficient 15862306a36Sopenharmony_ci to make ordering apparent to accesses by a process that does 15962306a36Sopenharmony_ci not participate in that release-acquire chain? 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciA great many more litmus tests are available here: 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci https://github.com/paulmckrcu/litmus 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci================== 16662306a36Sopenharmony_ciLITMUS TEST NAMING 16762306a36Sopenharmony_ci================== 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciLitmus tests are usually named based on their contents, which means that 17062306a36Sopenharmony_cilooking at the name tells you what the litmus test does. The naming 17162306a36Sopenharmony_cischeme covers litmus tests having a single cycle that passes through 17262306a36Sopenharmony_cieach process exactly once, so litmus tests not fitting this description 17362306a36Sopenharmony_ciare named on an ad-hoc basis. 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ciThe structure of a litmus-test name is the litmus-test class, a plus 17662306a36Sopenharmony_cisign ("+"), and one string for each process, separated by plus signs. 17762306a36Sopenharmony_ciThe end of the name is ".litmus". 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciThe litmus-test classes may be found in the infamous test6.pdf: 18062306a36Sopenharmony_cihttps://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf 18162306a36Sopenharmony_ciEach class defines the pattern of accesses and of the variables accessed. 18262306a36Sopenharmony_ciFor example, if the one process writes to a pair of variables, and 18362306a36Sopenharmony_cithe other process reads from these same variables, the corresponding 18462306a36Sopenharmony_cilitmus-test class is "MP" (message passing), which may be found on the 18562306a36Sopenharmony_cileft-hand end of the second row of tests on page one of test6.pdf. 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciThe strings used to identify the actions carried out by each process are 18862306a36Sopenharmony_cicomplex due to a desire to have short(er) names. Thus, there is a tool to 18962306a36Sopenharmony_cigenerate these strings from a given litmus test's actions. For example, 19062306a36Sopenharmony_ciconsider the processes from SB+rfionceonce-poonceonces.litmus: 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci P0(int *x, int *y) 19362306a36Sopenharmony_ci { 19462306a36Sopenharmony_ci int r1; 19562306a36Sopenharmony_ci int r2; 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci WRITE_ONCE(*x, 1); 19862306a36Sopenharmony_ci r1 = READ_ONCE(*x); 19962306a36Sopenharmony_ci r2 = READ_ONCE(*y); 20062306a36Sopenharmony_ci } 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci P1(int *x, int *y) 20362306a36Sopenharmony_ci { 20462306a36Sopenharmony_ci int r3; 20562306a36Sopenharmony_ci int r4; 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci WRITE_ONCE(*y, 1); 20862306a36Sopenharmony_ci r3 = READ_ONCE(*y); 20962306a36Sopenharmony_ci r4 = READ_ONCE(*x); 21062306a36Sopenharmony_ci } 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ciThe next step is to construct a space-separated list of descriptors, 21362306a36Sopenharmony_ciinterleaving descriptions of the relation between a pair of consecutive 21462306a36Sopenharmony_ciaccesses with descriptions of the second access in the pair. 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ciP0()'s WRITE_ONCE() is read by its first READ_ONCE(), which is a 21762306a36Sopenharmony_cireads-from link (rf) and internal to the P0() process. This is 21862306a36Sopenharmony_ci"rfi", which is an abbreviation for "reads-from internal". Because 21962306a36Sopenharmony_cisome of the tools string these abbreviations together with space 22062306a36Sopenharmony_cicharacters separating processes, the first character is capitalized, 22162306a36Sopenharmony_ciresulting in "Rfi". 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciP0()'s second access is a READ_ONCE(), as opposed to (for example) 22462306a36Sopenharmony_cismp_load_acquire(), so next is "Once". Thus far, we have "Rfi Once". 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ciP0()'s third access is also a READ_ONCE(), but to y rather than x. 22762306a36Sopenharmony_ciThis is related to P0()'s second access by program order ("po"), 22862306a36Sopenharmony_cito a different variable ("d"), and both accesses are reads ("RR"). 22962306a36Sopenharmony_ciThe resulting descriptor is "PodRR". Because P0()'s third access is 23062306a36Sopenharmony_ciREAD_ONCE(), we add another "Once" descriptor. 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ciA from-read ("fre") relation links P0()'s third to P1()'s first 23362306a36Sopenharmony_ciaccess, and the resulting descriptor is "Fre". P1()'s first access is 23462306a36Sopenharmony_ciWRITE_ONCE(), which as before gives the descriptor "Once". The string 23562306a36Sopenharmony_cithus far is thus "Rfi Once PodRR Once Fre Once". 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ciThe remainder of P1() is similar to P0(), which means we add 23862306a36Sopenharmony_ci"Rfi Once PodRR Once". Another fre links P1()'s last access to 23962306a36Sopenharmony_ciP0()'s first access, which is WRITE_ONCE(), so we add "Fre Once". 24062306a36Sopenharmony_ciThe full string is thus: 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ciThis string can be given to the "norm7" and "classify7" tools to 24562306a36Sopenharmony_ciproduce the name: 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci $ norm7 -bell linux-kernel.bell \ 24862306a36Sopenharmony_ci Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once | \ 24962306a36Sopenharmony_ci sed -e 's/:.*//g' 25062306a36Sopenharmony_ci SB+rfionceonce-poonceonces 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ciAdding the ".litmus" suffix: SB+rfionceonce-poonceonces.litmus 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ciThe descriptors that describe connections between consecutive accesses 25562306a36Sopenharmony_ciwithin the cycle through a given litmus test can be provided by the herd7 25662306a36Sopenharmony_citool (Rfi, Po, Fre, and so on) or by the linux-kernel.bell file (Once, 25762306a36Sopenharmony_ciRelease, Acquire, and so on). 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ciTo see the full list of descriptors, execute the following command: 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci $ diyone7 -bell linux-kernel.bell -show edges 262