1c4f790f2SPaul E. McKenney============ 2c4f790f2SPaul E. McKenneyLITMUS TESTS 3c4f790f2SPaul E. McKenney============ 41c27b644SPaul E. McKenney 51c27b644SPaul E. McKenneyCoRR+poonceonce+Once.litmus 61c27b644SPaul E. McKenney Test of read-read coherence, that is, whether or not two 71c27b644SPaul E. McKenney successive reads from the same variable are ordered. 81c27b644SPaul E. McKenney 91c27b644SPaul E. McKenneyCoRW+poonceonce+Once.litmus 101c27b644SPaul E. McKenney Test of read-write coherence, that is, whether or not a read 111c27b644SPaul E. McKenney from a given variable followed by a write to that same variable 121c27b644SPaul E. McKenney are ordered. 131c27b644SPaul E. McKenney 141c27b644SPaul E. McKenneyCoWR+poonceonce+Once.litmus 151c27b644SPaul E. McKenney Test of write-read coherence, that is, whether or not a write 161c27b644SPaul E. McKenney to a given variable followed by a read from that same variable 171c27b644SPaul E. McKenney are ordered. 181c27b644SPaul E. McKenney 191c27b644SPaul E. McKenneyCoWW+poonceonce.litmus 201c27b644SPaul E. McKenney Test of write-write coherence, that is, whether or not two 211c27b644SPaul E. McKenney successive writes to the same variable are ordered. 221c27b644SPaul E. McKenney 2371b7ff5eSAndrea ParriIRIW+fencembonceonces+OnceOnce.litmus 241c27b644SPaul E. McKenney Test of independent reads from independent writes with smp_mb() 251c27b644SPaul E. McKenney between each pairs of reads. In other words, is smp_mb() 261c27b644SPaul E. McKenney sufficient to cause two different reading processes to agree on 271c27b644SPaul E. McKenney the order of a pair of writes, where each write is to a different 281bd37420SPaul E. McKenney variable by a different process? This litmus test is forbidden 291bd37420SPaul E. McKenney by LKMM's propagation rule. 301c27b644SPaul E. McKenney 311c27b644SPaul E. McKenneyIRIW+poonceonces+OnceOnce.litmus 321c27b644SPaul E. McKenney Test of independent reads from independent writes with nothing 331c27b644SPaul E. McKenney between each pairs of reads. In other words, is anything at all 341c27b644SPaul E. McKenney needed to cause two different reading processes to agree on the 351c27b644SPaul E. McKenney order of a pair of writes, where each write is to a different 3662155147SPaul E. McKenney variable by a different process? 371c27b644SPaul E. McKenney 38ff1fe5e0SPaul E. McKenneyISA2+pooncelock+pooncelock+pombonce.litmus 39ff1fe5e0SPaul E. McKenney Tests whether the ordering provided by a lock-protected S 40ff1fe5e0SPaul E. McKenney litmus test is visible to an external process whose accesses are 41ff1fe5e0SPaul E. McKenney separated by smp_mb(). This addition of an external process to 42ff1fe5e0SPaul E. McKenney S is otherwise known as ISA2. 43ff1fe5e0SPaul E. McKenney 441c27b644SPaul E. McKenneyISA2+poonceonces.litmus 451c27b644SPaul E. McKenney As below, but with store-release replaced with WRITE_ONCE() 461c27b644SPaul E. McKenney and load-acquire replaced with READ_ONCE(). 471c27b644SPaul E. McKenney 481c27b644SPaul E. McKenneyISA2+pooncerelease+poacquirerelease+poacquireonce.litmus 491c27b644SPaul E. McKenney Can a release-acquire chain order a prior store against 501c27b644SPaul E. McKenney a later load? 511c27b644SPaul E. McKenney 5271b7ff5eSAndrea ParriLB+fencembonceonce+ctrlonceonce.litmus 531c27b644SPaul E. McKenney Does a control dependency and an smp_mb() suffice for the 541c27b644SPaul E. McKenney load-buffering litmus test, where each process reads from one 551c27b644SPaul E. McKenney of two variables then writes to the other? 561c27b644SPaul E. McKenney 571c27b644SPaul E. McKenneyLB+poacquireonce+pooncerelease.litmus 581c27b644SPaul E. McKenney Does a release-acquire pair suffice for the load-buffering 591c27b644SPaul E. McKenney litmus test, where each process reads from one of two variables then 601c27b644SPaul E. McKenney writes to the other? 611c27b644SPaul E. McKenney 621c27b644SPaul E. McKenneyLB+poonceonces.litmus 631c27b644SPaul E. McKenney As above, but with store-release replaced with WRITE_ONCE() 641c27b644SPaul E. McKenney and load-acquire replaced with READ_ONCE(). 651c27b644SPaul E. McKenney 661c27b644SPaul E. McKenneyMP+onceassign+derefonce.litmus 671c27b644SPaul E. McKenney As below, but with rcu_assign_pointer() and an rcu_dereference(). 681c27b644SPaul E. McKenney 6915553dcbSLuc MarangetMP+polockmbonce+poacquiresilsil.litmus 7015553dcbSLuc Maranget Protect the access with a lock and an smp_mb__after_spinlock() 7115553dcbSLuc Maranget in one process, and use an acquire load followed by a pair of 7215553dcbSLuc Maranget spin_is_locked() calls in the other process. 7315553dcbSLuc Maranget 7415553dcbSLuc MarangetMP+polockonce+poacquiresilsil.litmus 7515553dcbSLuc Maranget Protect the access with a lock in one process, and use an 7615553dcbSLuc Maranget acquire load followed by a pair of spin_is_locked() calls 7715553dcbSLuc Maranget in the other process. 7815553dcbSLuc Maranget 791c27b644SPaul E. McKenneyMP+polocks.litmus 801c27b644SPaul E. McKenney As below, but with the second access of the writer process 811c27b644SPaul E. McKenney and the first access of reader process protected by a lock. 821c27b644SPaul E. McKenney 831c27b644SPaul E. McKenneyMP+poonceonces.litmus 841c27b644SPaul E. McKenney As below, but without the smp_rmb() and smp_wmb(). 851c27b644SPaul E. McKenney 861c27b644SPaul E. McKenneyMP+pooncerelease+poacquireonce.litmus 871c27b644SPaul E. McKenney As below, but with a release-acquire chain. 881c27b644SPaul E. McKenney 891c27b644SPaul E. McKenneyMP+porevlocks.litmus 901c27b644SPaul E. McKenney As below, but with the first access of the writer process 911c27b644SPaul E. McKenney and the second access of reader process protected by a lock. 921c27b644SPaul E. McKenney 9371b7ff5eSAndrea ParriMP+fencewmbonceonce+fencermbonceonce.litmus 941c27b644SPaul E. McKenney Does a smp_wmb() (between the stores) and an smp_rmb() (between 951c27b644SPaul E. McKenney the loads) suffice for the message-passing litmus test, where one 961c27b644SPaul E. McKenney process writes data and then a flag, and the other process reads 971c27b644SPaul E. McKenney the flag and then the data. (This is similar to the ISA2 tests, 981c27b644SPaul E. McKenney but with two processes instead of three.) 991c27b644SPaul E. McKenney 10071b7ff5eSAndrea ParriR+fencembonceonces.litmus 1011c27b644SPaul E. McKenney This is the fully ordered (via smp_mb()) version of one of 1021c27b644SPaul E. McKenney the classic counterintuitive litmus tests that illustrates the 1031c27b644SPaul E. McKenney effects of store propagation delays. 1041c27b644SPaul E. McKenney 1051c27b644SPaul E. McKenneyR+poonceonces.litmus 1061c27b644SPaul E. McKenney As above, but without the smp_mb() invocations. 1071c27b644SPaul E. McKenney 10871b7ff5eSAndrea ParriSB+fencembonceonces.litmus 1091c27b644SPaul E. McKenney This is the fully ordered (again, via smp_mb() version of store 1101c27b644SPaul E. McKenney buffering, which forms the core of Dekker's mutual-exclusion 1111c27b644SPaul E. McKenney algorithm. 1121c27b644SPaul E. McKenney 1131c27b644SPaul E. McKenneySB+poonceonces.litmus 1141c27b644SPaul E. McKenney As above, but without the smp_mb() invocations. 1151c27b644SPaul E. McKenney 116b4648189SPaul E. McKenneySB+rfionceonce-poonceonces.litmus 117b4648189SPaul E. McKenney This litmus test demonstrates that LKMM is not fully multicopy 118b4648189SPaul E. McKenney atomic. (Neither is it other multicopy atomic.) This litmus test 119b4648189SPaul E. McKenney also demonstrates the "locations" debugging aid, which designates 120b4648189SPaul E. McKenney additional registers and locations to be printed out in the dump 121b4648189SPaul E. McKenney of final states in the herd7 output. Without the "locations" 122b4648189SPaul E. McKenney statement, only those registers and locations mentioned in the 123b4648189SPaul E. McKenney "exists" clause will be printed. 124b4648189SPaul E. McKenney 1251c27b644SPaul E. McKenneyS+poonceonces.litmus 1261c27b644SPaul E. McKenney As below, but without the smp_wmb() and acquire load. 1271c27b644SPaul E. McKenney 12871b7ff5eSAndrea ParriS+fencewmbonceonce+poacquireonce.litmus 1291c27b644SPaul E. McKenney Can a smp_wmb(), instead of a release, and an acquire order 1301c27b644SPaul E. McKenney a prior store against a subsequent store? 1311c27b644SPaul E. McKenney 1321c27b644SPaul E. McKenneyWRC+poonceonces+Once.litmus 13371b7ff5eSAndrea ParriWRC+pooncerelease+fencermbonceonce+Once.litmus 1341bd37420SPaul E. McKenney These two are members of an extension of the MP litmus-test 1351bd37420SPaul E. McKenney class in which the first write is moved to a separate process. 1361bd37420SPaul E. McKenney The second is forbidden because smp_store_release() is 1371bd37420SPaul E. McKenney A-cumulative in LKMM. 1381c27b644SPaul E. McKenney 1391c27b644SPaul E. McKenneyZ6.0+pooncelock+pooncelock+pombonce.litmus 1401c27b644SPaul E. McKenney Is the ordering provided by a spin_unlock() and a subsequent 1411c27b644SPaul E. McKenney spin_lock() sufficient to make ordering apparent to accesses 1421c27b644SPaul E. McKenney by a process not holding the lock? 1431c27b644SPaul E. McKenney 1441c27b644SPaul E. McKenneyZ6.0+pooncelock+poonceLock+pombonce.litmus 1451c27b644SPaul E. McKenney As above, but with smp_mb__after_spinlock() immediately 1461c27b644SPaul E. McKenney following the spin_lock(). 1471c27b644SPaul E. McKenney 14871b7ff5eSAndrea ParriZ6.0+pooncerelease+poacquirerelease+fencembonceonce.litmus 1491c27b644SPaul E. McKenney Is the ordering provided by a release-acquire chain sufficient 1501c27b644SPaul E. McKenney to make ordering apparent to accesses by a process that does 1511c27b644SPaul E. McKenney not participate in that release-acquire chain? 1521c27b644SPaul E. McKenney 1531c27b644SPaul E. McKenneyA great many more litmus tests are available here: 1541c27b644SPaul E. McKenney 1551c27b644SPaul E. McKenney https://github.com/paulmckrcu/litmus 156c4f790f2SPaul E. McKenney 157c4f790f2SPaul E. McKenney================== 158c4f790f2SPaul E. McKenneyLITMUS TEST NAMING 159c4f790f2SPaul E. McKenney================== 160c4f790f2SPaul E. McKenney 161c4f790f2SPaul E. McKenneyLitmus tests are usually named based on their contents, which means that 162c4f790f2SPaul E. McKenneylooking at the name tells you what the litmus test does. The naming 163c4f790f2SPaul E. McKenneyscheme covers litmus tests having a single cycle that passes through 164c4f790f2SPaul E. McKenneyeach process exactly once, so litmus tests not fitting this description 165c4f790f2SPaul E. McKenneyare named on an ad-hoc basis. 166c4f790f2SPaul E. McKenney 167c4f790f2SPaul E. McKenneyThe structure of a litmus-test name is the litmus-test class, a plus 168c4f790f2SPaul E. McKenneysign ("+"), and one string for each process, separated by plus signs. 169c4f790f2SPaul E. McKenneyThe end of the name is ".litmus". 170c4f790f2SPaul E. McKenney 171c4f790f2SPaul E. McKenneyThe litmus-test classes may be found in the infamous test6.pdf: 172c4f790f2SPaul E. McKenneyhttps://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf 173c4f790f2SPaul E. McKenneyEach class defines the pattern of accesses and of the variables accessed. 174c4f790f2SPaul E. McKenneyFor example, if the one process writes to a pair of variables, and 175c4f790f2SPaul E. McKenneythe other process reads from these same variables, the corresponding 176c4f790f2SPaul E. McKenneylitmus-test class is "MP" (message passing), which may be found on the 177c4f790f2SPaul E. McKenneyleft-hand end of the second row of tests on page one of test6.pdf. 178c4f790f2SPaul E. McKenney 179c4f790f2SPaul E. McKenneyThe strings used to identify the actions carried out by each process are 180c4f790f2SPaul E. McKenneycomplex due to a desire to have short(er) names. Thus, there is a tool to 181c4f790f2SPaul E. McKenneygenerate these strings from a given litmus test's actions. For example, 182c4f790f2SPaul E. McKenneyconsider the processes from SB+rfionceonce-poonceonces.litmus: 183c4f790f2SPaul E. McKenney 184c4f790f2SPaul E. McKenney P0(int *x, int *y) 185c4f790f2SPaul E. McKenney { 186c4f790f2SPaul E. McKenney int r1; 187c4f790f2SPaul E. McKenney int r2; 188c4f790f2SPaul E. McKenney 189c4f790f2SPaul E. McKenney WRITE_ONCE(*x, 1); 190c4f790f2SPaul E. McKenney r1 = READ_ONCE(*x); 191c4f790f2SPaul E. McKenney r2 = READ_ONCE(*y); 192c4f790f2SPaul E. McKenney } 193c4f790f2SPaul E. McKenney 194c4f790f2SPaul E. McKenney P1(int *x, int *y) 195c4f790f2SPaul E. McKenney { 196c4f790f2SPaul E. McKenney int r3; 197c4f790f2SPaul E. McKenney int r4; 198c4f790f2SPaul E. McKenney 199c4f790f2SPaul E. McKenney WRITE_ONCE(*y, 1); 200c4f790f2SPaul E. McKenney r3 = READ_ONCE(*y); 201c4f790f2SPaul E. McKenney r4 = READ_ONCE(*x); 202c4f790f2SPaul E. McKenney } 203c4f790f2SPaul E. McKenney 204c4f790f2SPaul E. McKenneyThe next step is to construct a space-separated list of descriptors, 205c4f790f2SPaul E. McKenneyinterleaving descriptions of the relation between a pair of consecutive 206c4f790f2SPaul E. McKenneyaccesses with descriptions of the second access in the pair. 207c4f790f2SPaul E. McKenney 208c4f790f2SPaul E. McKenneyP0()'s WRITE_ONCE() is read by its first READ_ONCE(), which is a 209c4f790f2SPaul E. McKenneyreads-from link (rf) and internal to the P0() process. This is 210c4f790f2SPaul E. McKenney"rfi", which is an abbreviation for "reads-from internal". Because 211c4f790f2SPaul E. McKenneysome of the tools string these abbreviations together with space 212c4f790f2SPaul E. McKenneycharacters separating processes, the first character is capitalized, 213c4f790f2SPaul E. McKenneyresulting in "Rfi". 214c4f790f2SPaul E. McKenney 215c4f790f2SPaul E. McKenneyP0()'s second access is a READ_ONCE(), as opposed to (for example) 216c4f790f2SPaul E. McKenneysmp_load_acquire(), so next is "Once". Thus far, we have "Rfi Once". 217c4f790f2SPaul E. McKenney 218c4f790f2SPaul E. McKenneyP0()'s third access is also a READ_ONCE(), but to y rather than x. 219c4f790f2SPaul E. McKenneyThis is related to P0()'s second access by program order ("po"), 220c4f790f2SPaul E. McKenneyto a different variable ("d"), and both accesses are reads ("RR"). 221c4f790f2SPaul E. McKenneyThe resulting descriptor is "PodRR". Because P0()'s third access is 222c4f790f2SPaul E. McKenneyREAD_ONCE(), we add another "Once" descriptor. 223c4f790f2SPaul E. McKenney 224c4f790f2SPaul E. McKenneyA from-read ("fre") relation links P0()'s third to P1()'s first 225c4f790f2SPaul E. McKenneyaccess, and the resulting descriptor is "Fre". P1()'s first access is 226c4f790f2SPaul E. McKenneyWRITE_ONCE(), which as before gives the descriptor "Once". The string 227c4f790f2SPaul E. McKenneythus far is thus "Rfi Once PodRR Once Fre Once". 228c4f790f2SPaul E. McKenney 229c4f790f2SPaul E. McKenneyThe remainder of P1() is similar to P0(), which means we add 230c4f790f2SPaul E. McKenney"Rfi Once PodRR Once". Another fre links P1()'s last access to 231c4f790f2SPaul E. McKenneyP0()'s first access, which is WRITE_ONCE(), so we add "Fre Once". 232c4f790f2SPaul E. McKenneyThe full string is thus: 233c4f790f2SPaul E. McKenney 234c4f790f2SPaul E. McKenney Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once 235c4f790f2SPaul E. McKenney 236c4f790f2SPaul E. McKenneyThis string can be given to the "norm7" and "classify7" tools to 237c4f790f2SPaul E. McKenneyproduce the name: 238c4f790f2SPaul E. McKenney 239c4f790f2SPaul E. McKenney $ norm7 -bell linux-kernel.bell \ 240c4f790f2SPaul E. McKenney Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once | \ 241c4f790f2SPaul E. McKenney sed -e 's/:.*//g' 242c4f790f2SPaul E. McKenney SB+rfionceonce-poonceonces 243c4f790f2SPaul E. McKenney 244c4f790f2SPaul E. McKenneyAdding the ".litmus" suffix: SB+rfionceonce-poonceonces.litmus 245c4f790f2SPaul E. McKenney 246c4f790f2SPaul E. McKenneyThe descriptors that describe connections between consecutive accesses 247c4f790f2SPaul E. McKenneywithin the cycle through a given litmus test can be provided by the herd 248c4f790f2SPaul E. McKenneytool (Rfi, Po, Fre, and so on) or by the linux-kernel.bell file (Once, 249c4f790f2SPaul E. McKenneyRelease, Acquire, and so on). 250c4f790f2SPaul E. McKenney 251c4f790f2SPaul E. McKenneyTo see the full list of descriptors, execute the following command: 252c4f790f2SPaul E. McKenney 253c4f790f2SPaul E. McKenney $ diyone7 -bell linux-kernel.bell -show edges 254