18c2ecf20Sopenharmony_ci============ 28c2ecf20Sopenharmony_ciLITMUS TESTS 38c2ecf20Sopenharmony_ci============ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciCoRR+poonceonce+Once.litmus 68c2ecf20Sopenharmony_ci Test of read-read coherence, that is, whether or not two 78c2ecf20Sopenharmony_ci successive reads from the same variable are ordered. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciCoRW+poonceonce+Once.litmus 108c2ecf20Sopenharmony_ci Test of read-write coherence, that is, whether or not a read 118c2ecf20Sopenharmony_ci from a given variable followed by a write to that same variable 128c2ecf20Sopenharmony_ci are ordered. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciCoWR+poonceonce+Once.litmus 158c2ecf20Sopenharmony_ci Test of write-read coherence, that is, whether or not a write 168c2ecf20Sopenharmony_ci to a given variable followed by a read from that same variable 178c2ecf20Sopenharmony_ci are ordered. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciCoWW+poonceonce.litmus 208c2ecf20Sopenharmony_ci Test of write-write coherence, that is, whether or not two 218c2ecf20Sopenharmony_ci successive writes to the same variable are ordered. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciIRIW+fencembonceonces+OnceOnce.litmus 248c2ecf20Sopenharmony_ci Test of independent reads from independent writes with smp_mb() 258c2ecf20Sopenharmony_ci between each pairs of reads. In other words, is smp_mb() 268c2ecf20Sopenharmony_ci sufficient to cause two different reading processes to agree on 278c2ecf20Sopenharmony_ci the order of a pair of writes, where each write is to a different 288c2ecf20Sopenharmony_ci variable by a different process? This litmus test is forbidden 298c2ecf20Sopenharmony_ci by LKMM's propagation rule. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciIRIW+poonceonces+OnceOnce.litmus 328c2ecf20Sopenharmony_ci Test of independent reads from independent writes with nothing 338c2ecf20Sopenharmony_ci between each pairs of reads. In other words, is anything at all 348c2ecf20Sopenharmony_ci needed to cause two different reading processes to agree on the 358c2ecf20Sopenharmony_ci order of a pair of writes, where each write is to a different 368c2ecf20Sopenharmony_ci variable by a different process? 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciISA2+pooncelock+pooncelock+pombonce.litmus 398c2ecf20Sopenharmony_ci Tests whether the ordering provided by a lock-protected S 408c2ecf20Sopenharmony_ci litmus test is visible to an external process whose accesses are 418c2ecf20Sopenharmony_ci separated by smp_mb(). This addition of an external process to 428c2ecf20Sopenharmony_ci S is otherwise known as ISA2. 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciISA2+poonceonces.litmus 458c2ecf20Sopenharmony_ci As below, but with store-release replaced with WRITE_ONCE() 468c2ecf20Sopenharmony_ci and load-acquire replaced with READ_ONCE(). 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciISA2+pooncerelease+poacquirerelease+poacquireonce.litmus 498c2ecf20Sopenharmony_ci Can a release-acquire chain order a prior store against 508c2ecf20Sopenharmony_ci a later load? 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciLB+fencembonceonce+ctrlonceonce.litmus 538c2ecf20Sopenharmony_ci Does a control dependency and an smp_mb() suffice for the 548c2ecf20Sopenharmony_ci load-buffering litmus test, where each process reads from one 558c2ecf20Sopenharmony_ci of two variables then writes to the other? 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciLB+poacquireonce+pooncerelease.litmus 588c2ecf20Sopenharmony_ci Does a release-acquire pair suffice for the load-buffering 598c2ecf20Sopenharmony_ci litmus test, where each process reads from one of two variables then 608c2ecf20Sopenharmony_ci writes to the other? 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciLB+poonceonces.litmus 638c2ecf20Sopenharmony_ci As above, but with store-release replaced with WRITE_ONCE() 648c2ecf20Sopenharmony_ci and load-acquire replaced with READ_ONCE(). 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciMP+onceassign+derefonce.litmus 678c2ecf20Sopenharmony_ci As below, but with rcu_assign_pointer() and an rcu_dereference(). 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciMP+polockmbonce+poacquiresilsil.litmus 708c2ecf20Sopenharmony_ci Protect the access with a lock and an smp_mb__after_spinlock() 718c2ecf20Sopenharmony_ci in one process, and use an acquire load followed by a pair of 728c2ecf20Sopenharmony_ci spin_is_locked() calls in the other process. 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciMP+polockonce+poacquiresilsil.litmus 758c2ecf20Sopenharmony_ci Protect the access with a lock in one process, and use an 768c2ecf20Sopenharmony_ci acquire load followed by a pair of spin_is_locked() calls 778c2ecf20Sopenharmony_ci in the other process. 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciMP+polocks.litmus 808c2ecf20Sopenharmony_ci As below, but with the second access of the writer process 818c2ecf20Sopenharmony_ci and the first access of reader process protected by a lock. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciMP+poonceonces.litmus 848c2ecf20Sopenharmony_ci As below, but without the smp_rmb() and smp_wmb(). 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciMP+pooncerelease+poacquireonce.litmus 878c2ecf20Sopenharmony_ci As below, but with a release-acquire chain. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciMP+porevlocks.litmus 908c2ecf20Sopenharmony_ci As below, but with the first access of the writer process 918c2ecf20Sopenharmony_ci and the second access of reader process protected by a lock. 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciMP+fencewmbonceonce+fencermbonceonce.litmus 948c2ecf20Sopenharmony_ci Does a smp_wmb() (between the stores) and an smp_rmb() (between 958c2ecf20Sopenharmony_ci the loads) suffice for the message-passing litmus test, where one 968c2ecf20Sopenharmony_ci process writes data and then a flag, and the other process reads 978c2ecf20Sopenharmony_ci the flag and then the data. (This is similar to the ISA2 tests, 988c2ecf20Sopenharmony_ci but with two processes instead of three.) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ciR+fencembonceonces.litmus 1018c2ecf20Sopenharmony_ci This is the fully ordered (via smp_mb()) version of one of 1028c2ecf20Sopenharmony_ci the classic counterintuitive litmus tests that illustrates the 1038c2ecf20Sopenharmony_ci effects of store propagation delays. 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciR+poonceonces.litmus 1068c2ecf20Sopenharmony_ci As above, but without the smp_mb() invocations. 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciSB+fencembonceonces.litmus 1098c2ecf20Sopenharmony_ci This is the fully ordered (again, via smp_mb() version of store 1108c2ecf20Sopenharmony_ci buffering, which forms the core of Dekker's mutual-exclusion 1118c2ecf20Sopenharmony_ci algorithm. 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciSB+poonceonces.litmus 1148c2ecf20Sopenharmony_ci As above, but without the smp_mb() invocations. 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ciSB+rfionceonce-poonceonces.litmus 1178c2ecf20Sopenharmony_ci This litmus test demonstrates that LKMM is not fully multicopy 1188c2ecf20Sopenharmony_ci atomic. (Neither is it other multicopy atomic.) This litmus test 1198c2ecf20Sopenharmony_ci also demonstrates the "locations" debugging aid, which designates 1208c2ecf20Sopenharmony_ci additional registers and locations to be printed out in the dump 1218c2ecf20Sopenharmony_ci of final states in the herd7 output. Without the "locations" 1228c2ecf20Sopenharmony_ci statement, only those registers and locations mentioned in the 1238c2ecf20Sopenharmony_ci "exists" clause will be printed. 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ciS+poonceonces.litmus 1268c2ecf20Sopenharmony_ci As below, but without the smp_wmb() and acquire load. 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ciS+fencewmbonceonce+poacquireonce.litmus 1298c2ecf20Sopenharmony_ci Can a smp_wmb(), instead of a release, and an acquire order 1308c2ecf20Sopenharmony_ci a prior store against a subsequent store? 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ciWRC+poonceonces+Once.litmus 1338c2ecf20Sopenharmony_ciWRC+pooncerelease+fencermbonceonce+Once.litmus 1348c2ecf20Sopenharmony_ci These two are members of an extension of the MP litmus-test 1358c2ecf20Sopenharmony_ci class in which the first write is moved to a separate process. 1368c2ecf20Sopenharmony_ci The second is forbidden because smp_store_release() is 1378c2ecf20Sopenharmony_ci A-cumulative in LKMM. 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciZ6.0+pooncelock+pooncelock+pombonce.litmus 1408c2ecf20Sopenharmony_ci Is the ordering provided by a spin_unlock() and a subsequent 1418c2ecf20Sopenharmony_ci spin_lock() sufficient to make ordering apparent to accesses 1428c2ecf20Sopenharmony_ci by a process not holding the lock? 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciZ6.0+pooncelock+poonceLock+pombonce.litmus 1458c2ecf20Sopenharmony_ci As above, but with smp_mb__after_spinlock() immediately 1468c2ecf20Sopenharmony_ci following the spin_lock(). 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ciZ6.0+pooncerelease+poacquirerelease+fencembonceonce.litmus 1498c2ecf20Sopenharmony_ci Is the ordering provided by a release-acquire chain sufficient 1508c2ecf20Sopenharmony_ci to make ordering apparent to accesses by a process that does 1518c2ecf20Sopenharmony_ci not participate in that release-acquire chain? 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ciA great many more litmus tests are available here: 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci https://github.com/paulmckrcu/litmus 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci================== 1588c2ecf20Sopenharmony_ciLITMUS TEST NAMING 1598c2ecf20Sopenharmony_ci================== 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciLitmus tests are usually named based on their contents, which means that 1628c2ecf20Sopenharmony_cilooking at the name tells you what the litmus test does. The naming 1638c2ecf20Sopenharmony_cischeme covers litmus tests having a single cycle that passes through 1648c2ecf20Sopenharmony_cieach process exactly once, so litmus tests not fitting this description 1658c2ecf20Sopenharmony_ciare named on an ad-hoc basis. 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ciThe structure of a litmus-test name is the litmus-test class, a plus 1688c2ecf20Sopenharmony_cisign ("+"), and one string for each process, separated by plus signs. 1698c2ecf20Sopenharmony_ciThe end of the name is ".litmus". 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ciThe litmus-test classes may be found in the infamous test6.pdf: 1728c2ecf20Sopenharmony_cihttps://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf 1738c2ecf20Sopenharmony_ciEach class defines the pattern of accesses and of the variables accessed. 1748c2ecf20Sopenharmony_ciFor example, if the one process writes to a pair of variables, and 1758c2ecf20Sopenharmony_cithe other process reads from these same variables, the corresponding 1768c2ecf20Sopenharmony_cilitmus-test class is "MP" (message passing), which may be found on the 1778c2ecf20Sopenharmony_cileft-hand end of the second row of tests on page one of test6.pdf. 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ciThe strings used to identify the actions carried out by each process are 1808c2ecf20Sopenharmony_cicomplex due to a desire to have short(er) names. Thus, there is a tool to 1818c2ecf20Sopenharmony_cigenerate these strings from a given litmus test's actions. For example, 1828c2ecf20Sopenharmony_ciconsider the processes from SB+rfionceonce-poonceonces.litmus: 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci P0(int *x, int *y) 1858c2ecf20Sopenharmony_ci { 1868c2ecf20Sopenharmony_ci int r1; 1878c2ecf20Sopenharmony_ci int r2; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci WRITE_ONCE(*x, 1); 1908c2ecf20Sopenharmony_ci r1 = READ_ONCE(*x); 1918c2ecf20Sopenharmony_ci r2 = READ_ONCE(*y); 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci P1(int *x, int *y) 1958c2ecf20Sopenharmony_ci { 1968c2ecf20Sopenharmony_ci int r3; 1978c2ecf20Sopenharmony_ci int r4; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci WRITE_ONCE(*y, 1); 2008c2ecf20Sopenharmony_ci r3 = READ_ONCE(*y); 2018c2ecf20Sopenharmony_ci r4 = READ_ONCE(*x); 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ciThe next step is to construct a space-separated list of descriptors, 2058c2ecf20Sopenharmony_ciinterleaving descriptions of the relation between a pair of consecutive 2068c2ecf20Sopenharmony_ciaccesses with descriptions of the second access in the pair. 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ciP0()'s WRITE_ONCE() is read by its first READ_ONCE(), which is a 2098c2ecf20Sopenharmony_cireads-from link (rf) and internal to the P0() process. This is 2108c2ecf20Sopenharmony_ci"rfi", which is an abbreviation for "reads-from internal". Because 2118c2ecf20Sopenharmony_cisome of the tools string these abbreviations together with space 2128c2ecf20Sopenharmony_cicharacters separating processes, the first character is capitalized, 2138c2ecf20Sopenharmony_ciresulting in "Rfi". 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ciP0()'s second access is a READ_ONCE(), as opposed to (for example) 2168c2ecf20Sopenharmony_cismp_load_acquire(), so next is "Once". Thus far, we have "Rfi Once". 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ciP0()'s third access is also a READ_ONCE(), but to y rather than x. 2198c2ecf20Sopenharmony_ciThis is related to P0()'s second access by program order ("po"), 2208c2ecf20Sopenharmony_cito a different variable ("d"), and both accesses are reads ("RR"). 2218c2ecf20Sopenharmony_ciThe resulting descriptor is "PodRR". Because P0()'s third access is 2228c2ecf20Sopenharmony_ciREAD_ONCE(), we add another "Once" descriptor. 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ciA from-read ("fre") relation links P0()'s third to P1()'s first 2258c2ecf20Sopenharmony_ciaccess, and the resulting descriptor is "Fre". P1()'s first access is 2268c2ecf20Sopenharmony_ciWRITE_ONCE(), which as before gives the descriptor "Once". The string 2278c2ecf20Sopenharmony_cithus far is thus "Rfi Once PodRR Once Fre Once". 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ciThe remainder of P1() is similar to P0(), which means we add 2308c2ecf20Sopenharmony_ci"Rfi Once PodRR Once". Another fre links P1()'s last access to 2318c2ecf20Sopenharmony_ciP0()'s first access, which is WRITE_ONCE(), so we add "Fre Once". 2328c2ecf20Sopenharmony_ciThe full string is thus: 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ciThis string can be given to the "norm7" and "classify7" tools to 2378c2ecf20Sopenharmony_ciproduce the name: 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci $ norm7 -bell linux-kernel.bell \ 2408c2ecf20Sopenharmony_ci Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once | \ 2418c2ecf20Sopenharmony_ci sed -e 's/:.*//g' 2428c2ecf20Sopenharmony_ci SB+rfionceonce-poonceonces 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ciAdding the ".litmus" suffix: SB+rfionceonce-poonceonces.litmus 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ciThe descriptors that describe connections between consecutive accesses 2478c2ecf20Sopenharmony_ciwithin the cycle through a given litmus test can be provided by the herd7 2488c2ecf20Sopenharmony_citool (Rfi, Po, Fre, and so on) or by the linux-kernel.bell file (Once, 2498c2ecf20Sopenharmony_ciRelease, Acquire, and so on). 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ciTo see the full list of descriptors, execute the following command: 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci $ diyone7 -bell linux-kernel.bell -show edges 254