1*4882a593Smuzhiyun============ 2*4882a593SmuzhiyunLITMUS TESTS 3*4882a593Smuzhiyun============ 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunCoRR+poonceonce+Once.litmus 6*4882a593Smuzhiyun Test of read-read coherence, that is, whether or not two 7*4882a593Smuzhiyun successive reads from the same variable are ordered. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunCoRW+poonceonce+Once.litmus 10*4882a593Smuzhiyun Test of read-write coherence, that is, whether or not a read 11*4882a593Smuzhiyun from a given variable followed by a write to that same variable 12*4882a593Smuzhiyun are ordered. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunCoWR+poonceonce+Once.litmus 15*4882a593Smuzhiyun Test of write-read coherence, that is, whether or not a write 16*4882a593Smuzhiyun to a given variable followed by a read from that same variable 17*4882a593Smuzhiyun are ordered. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunCoWW+poonceonce.litmus 20*4882a593Smuzhiyun Test of write-write coherence, that is, whether or not two 21*4882a593Smuzhiyun successive writes to the same variable are ordered. 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunIRIW+fencembonceonces+OnceOnce.litmus 24*4882a593Smuzhiyun Test of independent reads from independent writes with smp_mb() 25*4882a593Smuzhiyun between each pairs of reads. In other words, is smp_mb() 26*4882a593Smuzhiyun sufficient to cause two different reading processes to agree on 27*4882a593Smuzhiyun the order of a pair of writes, where each write is to a different 28*4882a593Smuzhiyun variable by a different process? This litmus test is forbidden 29*4882a593Smuzhiyun by LKMM's propagation rule. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunIRIW+poonceonces+OnceOnce.litmus 32*4882a593Smuzhiyun Test of independent reads from independent writes with nothing 33*4882a593Smuzhiyun between each pairs of reads. In other words, is anything at all 34*4882a593Smuzhiyun needed to cause two different reading processes to agree on the 35*4882a593Smuzhiyun order of a pair of writes, where each write is to a different 36*4882a593Smuzhiyun variable by a different process? 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunISA2+pooncelock+pooncelock+pombonce.litmus 39*4882a593Smuzhiyun Tests whether the ordering provided by a lock-protected S 40*4882a593Smuzhiyun litmus test is visible to an external process whose accesses are 41*4882a593Smuzhiyun separated by smp_mb(). This addition of an external process to 42*4882a593Smuzhiyun S is otherwise known as ISA2. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunISA2+poonceonces.litmus 45*4882a593Smuzhiyun As below, but with store-release replaced with WRITE_ONCE() 46*4882a593Smuzhiyun and load-acquire replaced with READ_ONCE(). 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunISA2+pooncerelease+poacquirerelease+poacquireonce.litmus 49*4882a593Smuzhiyun Can a release-acquire chain order a prior store against 50*4882a593Smuzhiyun a later load? 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunLB+fencembonceonce+ctrlonceonce.litmus 53*4882a593Smuzhiyun Does a control dependency and an smp_mb() suffice for the 54*4882a593Smuzhiyun load-buffering litmus test, where each process reads from one 55*4882a593Smuzhiyun of two variables then writes to the other? 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunLB+poacquireonce+pooncerelease.litmus 58*4882a593Smuzhiyun Does a release-acquire pair suffice for the load-buffering 59*4882a593Smuzhiyun litmus test, where each process reads from one of two variables then 60*4882a593Smuzhiyun writes to the other? 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunLB+poonceonces.litmus 63*4882a593Smuzhiyun As above, but with store-release replaced with WRITE_ONCE() 64*4882a593Smuzhiyun and load-acquire replaced with READ_ONCE(). 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunMP+onceassign+derefonce.litmus 67*4882a593Smuzhiyun As below, but with rcu_assign_pointer() and an rcu_dereference(). 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunMP+polockmbonce+poacquiresilsil.litmus 70*4882a593Smuzhiyun Protect the access with a lock and an smp_mb__after_spinlock() 71*4882a593Smuzhiyun in one process, and use an acquire load followed by a pair of 72*4882a593Smuzhiyun spin_is_locked() calls in the other process. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunMP+polockonce+poacquiresilsil.litmus 75*4882a593Smuzhiyun Protect the access with a lock in one process, and use an 76*4882a593Smuzhiyun acquire load followed by a pair of spin_is_locked() calls 77*4882a593Smuzhiyun in the other process. 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunMP+polocks.litmus 80*4882a593Smuzhiyun As below, but with the second access of the writer process 81*4882a593Smuzhiyun and the first access of reader process protected by a lock. 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunMP+poonceonces.litmus 84*4882a593Smuzhiyun As below, but without the smp_rmb() and smp_wmb(). 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunMP+pooncerelease+poacquireonce.litmus 87*4882a593Smuzhiyun As below, but with a release-acquire chain. 88*4882a593Smuzhiyun 89*4882a593SmuzhiyunMP+porevlocks.litmus 90*4882a593Smuzhiyun As below, but with the first access of the writer process 91*4882a593Smuzhiyun and the second access of reader process protected by a lock. 92*4882a593Smuzhiyun 93*4882a593SmuzhiyunMP+fencewmbonceonce+fencermbonceonce.litmus 94*4882a593Smuzhiyun Does a smp_wmb() (between the stores) and an smp_rmb() (between 95*4882a593Smuzhiyun the loads) suffice for the message-passing litmus test, where one 96*4882a593Smuzhiyun process writes data and then a flag, and the other process reads 97*4882a593Smuzhiyun the flag and then the data. (This is similar to the ISA2 tests, 98*4882a593Smuzhiyun but with two processes instead of three.) 99*4882a593Smuzhiyun 100*4882a593SmuzhiyunR+fencembonceonces.litmus 101*4882a593Smuzhiyun This is the fully ordered (via smp_mb()) version of one of 102*4882a593Smuzhiyun the classic counterintuitive litmus tests that illustrates the 103*4882a593Smuzhiyun effects of store propagation delays. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunR+poonceonces.litmus 106*4882a593Smuzhiyun As above, but without the smp_mb() invocations. 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunSB+fencembonceonces.litmus 109*4882a593Smuzhiyun This is the fully ordered (again, via smp_mb() version of store 110*4882a593Smuzhiyun buffering, which forms the core of Dekker's mutual-exclusion 111*4882a593Smuzhiyun algorithm. 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunSB+poonceonces.litmus 114*4882a593Smuzhiyun As above, but without the smp_mb() invocations. 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunSB+rfionceonce-poonceonces.litmus 117*4882a593Smuzhiyun This litmus test demonstrates that LKMM is not fully multicopy 118*4882a593Smuzhiyun atomic. (Neither is it other multicopy atomic.) This litmus test 119*4882a593Smuzhiyun also demonstrates the "locations" debugging aid, which designates 120*4882a593Smuzhiyun additional registers and locations to be printed out in the dump 121*4882a593Smuzhiyun of final states in the herd7 output. Without the "locations" 122*4882a593Smuzhiyun statement, only those registers and locations mentioned in the 123*4882a593Smuzhiyun "exists" clause will be printed. 124*4882a593Smuzhiyun 125*4882a593SmuzhiyunS+poonceonces.litmus 126*4882a593Smuzhiyun As below, but without the smp_wmb() and acquire load. 127*4882a593Smuzhiyun 128*4882a593SmuzhiyunS+fencewmbonceonce+poacquireonce.litmus 129*4882a593Smuzhiyun Can a smp_wmb(), instead of a release, and an acquire order 130*4882a593Smuzhiyun a prior store against a subsequent store? 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunWRC+poonceonces+Once.litmus 133*4882a593SmuzhiyunWRC+pooncerelease+fencermbonceonce+Once.litmus 134*4882a593Smuzhiyun These two are members of an extension of the MP litmus-test 135*4882a593Smuzhiyun class in which the first write is moved to a separate process. 136*4882a593Smuzhiyun The second is forbidden because smp_store_release() is 137*4882a593Smuzhiyun A-cumulative in LKMM. 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunZ6.0+pooncelock+pooncelock+pombonce.litmus 140*4882a593Smuzhiyun Is the ordering provided by a spin_unlock() and a subsequent 141*4882a593Smuzhiyun spin_lock() sufficient to make ordering apparent to accesses 142*4882a593Smuzhiyun by a process not holding the lock? 143*4882a593Smuzhiyun 144*4882a593SmuzhiyunZ6.0+pooncelock+poonceLock+pombonce.litmus 145*4882a593Smuzhiyun As above, but with smp_mb__after_spinlock() immediately 146*4882a593Smuzhiyun following the spin_lock(). 147*4882a593Smuzhiyun 148*4882a593SmuzhiyunZ6.0+pooncerelease+poacquirerelease+fencembonceonce.litmus 149*4882a593Smuzhiyun Is the ordering provided by a release-acquire chain sufficient 150*4882a593Smuzhiyun to make ordering apparent to accesses by a process that does 151*4882a593Smuzhiyun not participate in that release-acquire chain? 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunA great many more litmus tests are available here: 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun https://github.com/paulmckrcu/litmus 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun================== 158*4882a593SmuzhiyunLITMUS TEST NAMING 159*4882a593Smuzhiyun================== 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunLitmus tests are usually named based on their contents, which means that 162*4882a593Smuzhiyunlooking at the name tells you what the litmus test does. The naming 163*4882a593Smuzhiyunscheme covers litmus tests having a single cycle that passes through 164*4882a593Smuzhiyuneach process exactly once, so litmus tests not fitting this description 165*4882a593Smuzhiyunare named on an ad-hoc basis. 166*4882a593Smuzhiyun 167*4882a593SmuzhiyunThe structure of a litmus-test name is the litmus-test class, a plus 168*4882a593Smuzhiyunsign ("+"), and one string for each process, separated by plus signs. 169*4882a593SmuzhiyunThe end of the name is ".litmus". 170*4882a593Smuzhiyun 171*4882a593SmuzhiyunThe litmus-test classes may be found in the infamous test6.pdf: 172*4882a593Smuzhiyunhttps://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf 173*4882a593SmuzhiyunEach class defines the pattern of accesses and of the variables accessed. 174*4882a593SmuzhiyunFor example, if the one process writes to a pair of variables, and 175*4882a593Smuzhiyunthe other process reads from these same variables, the corresponding 176*4882a593Smuzhiyunlitmus-test class is "MP" (message passing), which may be found on the 177*4882a593Smuzhiyunleft-hand end of the second row of tests on page one of test6.pdf. 178*4882a593Smuzhiyun 179*4882a593SmuzhiyunThe strings used to identify the actions carried out by each process are 180*4882a593Smuzhiyuncomplex due to a desire to have short(er) names. Thus, there is a tool to 181*4882a593Smuzhiyungenerate these strings from a given litmus test's actions. For example, 182*4882a593Smuzhiyunconsider the processes from SB+rfionceonce-poonceonces.litmus: 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun P0(int *x, int *y) 185*4882a593Smuzhiyun { 186*4882a593Smuzhiyun int r1; 187*4882a593Smuzhiyun int r2; 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun WRITE_ONCE(*x, 1); 190*4882a593Smuzhiyun r1 = READ_ONCE(*x); 191*4882a593Smuzhiyun r2 = READ_ONCE(*y); 192*4882a593Smuzhiyun } 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun P1(int *x, int *y) 195*4882a593Smuzhiyun { 196*4882a593Smuzhiyun int r3; 197*4882a593Smuzhiyun int r4; 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun WRITE_ONCE(*y, 1); 200*4882a593Smuzhiyun r3 = READ_ONCE(*y); 201*4882a593Smuzhiyun r4 = READ_ONCE(*x); 202*4882a593Smuzhiyun } 203*4882a593Smuzhiyun 204*4882a593SmuzhiyunThe next step is to construct a space-separated list of descriptors, 205*4882a593Smuzhiyuninterleaving descriptions of the relation between a pair of consecutive 206*4882a593Smuzhiyunaccesses with descriptions of the second access in the pair. 207*4882a593Smuzhiyun 208*4882a593SmuzhiyunP0()'s WRITE_ONCE() is read by its first READ_ONCE(), which is a 209*4882a593Smuzhiyunreads-from link (rf) and internal to the P0() process. This is 210*4882a593Smuzhiyun"rfi", which is an abbreviation for "reads-from internal". Because 211*4882a593Smuzhiyunsome of the tools string these abbreviations together with space 212*4882a593Smuzhiyuncharacters separating processes, the first character is capitalized, 213*4882a593Smuzhiyunresulting in "Rfi". 214*4882a593Smuzhiyun 215*4882a593SmuzhiyunP0()'s second access is a READ_ONCE(), as opposed to (for example) 216*4882a593Smuzhiyunsmp_load_acquire(), so next is "Once". Thus far, we have "Rfi Once". 217*4882a593Smuzhiyun 218*4882a593SmuzhiyunP0()'s third access is also a READ_ONCE(), but to y rather than x. 219*4882a593SmuzhiyunThis is related to P0()'s second access by program order ("po"), 220*4882a593Smuzhiyunto a different variable ("d"), and both accesses are reads ("RR"). 221*4882a593SmuzhiyunThe resulting descriptor is "PodRR". Because P0()'s third access is 222*4882a593SmuzhiyunREAD_ONCE(), we add another "Once" descriptor. 223*4882a593Smuzhiyun 224*4882a593SmuzhiyunA from-read ("fre") relation links P0()'s third to P1()'s first 225*4882a593Smuzhiyunaccess, and the resulting descriptor is "Fre". P1()'s first access is 226*4882a593SmuzhiyunWRITE_ONCE(), which as before gives the descriptor "Once". The string 227*4882a593Smuzhiyunthus far is thus "Rfi Once PodRR Once Fre Once". 228*4882a593Smuzhiyun 229*4882a593SmuzhiyunThe remainder of P1() is similar to P0(), which means we add 230*4882a593Smuzhiyun"Rfi Once PodRR Once". Another fre links P1()'s last access to 231*4882a593SmuzhiyunP0()'s first access, which is WRITE_ONCE(), so we add "Fre Once". 232*4882a593SmuzhiyunThe full string is thus: 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once 235*4882a593Smuzhiyun 236*4882a593SmuzhiyunThis string can be given to the "norm7" and "classify7" tools to 237*4882a593Smuzhiyunproduce the name: 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun $ norm7 -bell linux-kernel.bell \ 240*4882a593Smuzhiyun Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once | \ 241*4882a593Smuzhiyun sed -e 's/:.*//g' 242*4882a593Smuzhiyun SB+rfionceonce-poonceonces 243*4882a593Smuzhiyun 244*4882a593SmuzhiyunAdding the ".litmus" suffix: SB+rfionceonce-poonceonces.litmus 245*4882a593Smuzhiyun 246*4882a593SmuzhiyunThe descriptors that describe connections between consecutive accesses 247*4882a593Smuzhiyunwithin the cycle through a given litmus test can be provided by the herd7 248*4882a593Smuzhiyuntool (Rfi, Po, Fre, and so on) or by the linux-kernel.bell file (Once, 249*4882a593SmuzhiyunRelease, Acquire, and so on). 250*4882a593Smuzhiyun 251*4882a593SmuzhiyunTo see the full list of descriptors, execute the following command: 252*4882a593Smuzhiyun 253*4882a593Smuzhiyun $ diyone7 -bell linux-kernel.bell -show edges 254