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
66*c438b7d8SBoqun FengLB+unlocklockonceonce+poacquireonce.litmus
67*c438b7d8SBoqun Feng	Does a unlock+lock pair provides ordering guarantee between a
68*c438b7d8SBoqun Feng	load and a store?
69*c438b7d8SBoqun Feng
701c27b644SPaul E. McKenneyMP+onceassign+derefonce.litmus
711c27b644SPaul E. McKenney	As below, but with rcu_assign_pointer() and an rcu_dereference().
721c27b644SPaul E. McKenney
7315553dcbSLuc MarangetMP+polockmbonce+poacquiresilsil.litmus
7415553dcbSLuc Maranget	Protect the access with a lock and an smp_mb__after_spinlock()
7515553dcbSLuc Maranget	in one process, and use an acquire load followed by a pair of
7615553dcbSLuc Maranget	spin_is_locked() calls in the other process.
7715553dcbSLuc Maranget
7815553dcbSLuc MarangetMP+polockonce+poacquiresilsil.litmus
7915553dcbSLuc Maranget	Protect the access with a lock in one process, and use an
8015553dcbSLuc Maranget	acquire load followed by a pair of spin_is_locked() calls
8115553dcbSLuc Maranget	in the other process.
8215553dcbSLuc Maranget
831c27b644SPaul E. McKenneyMP+polocks.litmus
841c27b644SPaul E. McKenney	As below, but with the second access of the writer process
851c27b644SPaul E. McKenney	and the first access of reader process protected by a lock.
861c27b644SPaul E. McKenney
871c27b644SPaul E. McKenneyMP+poonceonces.litmus
881c27b644SPaul E. McKenney	As below, but without the smp_rmb() and smp_wmb().
891c27b644SPaul E. McKenney
901c27b644SPaul E. McKenneyMP+pooncerelease+poacquireonce.litmus
911c27b644SPaul E. McKenney	As below, but with a release-acquire chain.
921c27b644SPaul E. McKenney
931c27b644SPaul E. McKenneyMP+porevlocks.litmus
941c27b644SPaul E. McKenney	As below, but with the first access of the writer process
951c27b644SPaul E. McKenney	and the second access of reader process protected by a lock.
961c27b644SPaul E. McKenney
97*c438b7d8SBoqun FengMP+unlocklockonceonce+fencermbonceonce.litmus
98*c438b7d8SBoqun Feng	Does a unlock+lock pair provides ordering guarantee between a
99*c438b7d8SBoqun Feng	store and another store?
100*c438b7d8SBoqun Feng
10171b7ff5eSAndrea ParriMP+fencewmbonceonce+fencermbonceonce.litmus
1021c27b644SPaul E. McKenney	Does a smp_wmb() (between the stores) and an smp_rmb() (between
1031c27b644SPaul E. McKenney	the loads) suffice for the message-passing litmus test, where one
1041c27b644SPaul E. McKenney	process writes data and then a flag, and the other process reads
1051c27b644SPaul E. McKenney	the flag and then the data.  (This is similar to the ISA2 tests,
1061c27b644SPaul E. McKenney	but with two processes instead of three.)
1071c27b644SPaul E. McKenney
10871b7ff5eSAndrea ParriR+fencembonceonces.litmus
1091c27b644SPaul E. McKenney	This is the fully ordered (via smp_mb()) version of one of
1101c27b644SPaul E. McKenney	the classic counterintuitive litmus tests that illustrates the
1111c27b644SPaul E. McKenney	effects of store propagation delays.
1121c27b644SPaul E. McKenney
1131c27b644SPaul E. McKenneyR+poonceonces.litmus
1141c27b644SPaul E. McKenney	As above, but without the smp_mb() invocations.
1151c27b644SPaul E. McKenney
11671b7ff5eSAndrea ParriSB+fencembonceonces.litmus
1171c27b644SPaul E. McKenney	This is the fully ordered (again, via smp_mb() version of store
1181c27b644SPaul E. McKenney	buffering, which forms the core of Dekker's mutual-exclusion
1191c27b644SPaul E. McKenney	algorithm.
1201c27b644SPaul E. McKenney
1211c27b644SPaul E. McKenneySB+poonceonces.litmus
1221c27b644SPaul E. McKenney	As above, but without the smp_mb() invocations.
1231c27b644SPaul E. McKenney
124b4648189SPaul E. McKenneySB+rfionceonce-poonceonces.litmus
125b4648189SPaul E. McKenney	This litmus test demonstrates that LKMM is not fully multicopy
126b4648189SPaul E. McKenney	atomic.  (Neither is it other multicopy atomic.)  This litmus test
127b4648189SPaul E. McKenney	also demonstrates the "locations" debugging aid, which designates
128b4648189SPaul E. McKenney	additional registers and locations to be printed out in the dump
129b4648189SPaul E. McKenney	of final states in the herd7 output.  Without the "locations"
130b4648189SPaul E. McKenney	statement, only those registers and locations mentioned in the
131b4648189SPaul E. McKenney	"exists" clause will be printed.
132b4648189SPaul E. McKenney
1331c27b644SPaul E. McKenneyS+poonceonces.litmus
1341c27b644SPaul E. McKenney	As below, but without the smp_wmb() and acquire load.
1351c27b644SPaul E. McKenney
13671b7ff5eSAndrea ParriS+fencewmbonceonce+poacquireonce.litmus
1371c27b644SPaul E. McKenney	Can a smp_wmb(), instead of a release, and an acquire order
1381c27b644SPaul E. McKenney	a prior store against a subsequent store?
1391c27b644SPaul E. McKenney
1401c27b644SPaul E. McKenneyWRC+poonceonces+Once.litmus
14171b7ff5eSAndrea ParriWRC+pooncerelease+fencermbonceonce+Once.litmus
1421bd37420SPaul E. McKenney	These two are members of an extension of the MP litmus-test
1431bd37420SPaul E. McKenney	class in which the first write is moved to a separate process.
1441bd37420SPaul E. McKenney	The second is forbidden because smp_store_release() is
1451bd37420SPaul E. McKenney	A-cumulative in LKMM.
1461c27b644SPaul E. McKenney
1471c27b644SPaul E. McKenneyZ6.0+pooncelock+pooncelock+pombonce.litmus
1481c27b644SPaul E. McKenney	Is the ordering provided by a spin_unlock() and a subsequent
1491c27b644SPaul E. McKenney	spin_lock() sufficient to make ordering apparent to accesses
1501c27b644SPaul E. McKenney	by a process not holding the lock?
1511c27b644SPaul E. McKenney
1521c27b644SPaul E. McKenneyZ6.0+pooncelock+poonceLock+pombonce.litmus
1531c27b644SPaul E. McKenney	As above, but with smp_mb__after_spinlock() immediately
1541c27b644SPaul E. McKenney	following the spin_lock().
1551c27b644SPaul E. McKenney
15671b7ff5eSAndrea ParriZ6.0+pooncerelease+poacquirerelease+fencembonceonce.litmus
1571c27b644SPaul E. McKenney	Is the ordering provided by a release-acquire chain sufficient
1581c27b644SPaul E. McKenney	to make ordering apparent to accesses by a process that does
1591c27b644SPaul E. McKenney	not participate in that release-acquire chain?
1601c27b644SPaul E. McKenney
1611c27b644SPaul E. McKenneyA great many more litmus tests are available here:
1621c27b644SPaul E. McKenney
1631c27b644SPaul E. McKenney	https://github.com/paulmckrcu/litmus
164c4f790f2SPaul E. McKenney
165c4f790f2SPaul E. McKenney==================
166c4f790f2SPaul E. McKenneyLITMUS TEST NAMING
167c4f790f2SPaul E. McKenney==================
168c4f790f2SPaul E. McKenney
169c4f790f2SPaul E. McKenneyLitmus tests are usually named based on their contents, which means that
170c4f790f2SPaul E. McKenneylooking at the name tells you what the litmus test does.  The naming
171c4f790f2SPaul E. McKenneyscheme covers litmus tests having a single cycle that passes through
172c4f790f2SPaul E. McKenneyeach process exactly once, so litmus tests not fitting this description
173c4f790f2SPaul E. McKenneyare named on an ad-hoc basis.
174c4f790f2SPaul E. McKenney
175c4f790f2SPaul E. McKenneyThe structure of a litmus-test name is the litmus-test class, a plus
176c4f790f2SPaul E. McKenneysign ("+"), and one string for each process, separated by plus signs.
177c4f790f2SPaul E. McKenneyThe end of the name is ".litmus".
178c4f790f2SPaul E. McKenney
179c4f790f2SPaul E. McKenneyThe litmus-test classes may be found in the infamous test6.pdf:
180c4f790f2SPaul E. McKenneyhttps://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf
181c4f790f2SPaul E. McKenneyEach class defines the pattern of accesses and of the variables accessed.
182c4f790f2SPaul E. McKenneyFor example, if the one process writes to a pair of variables, and
183c4f790f2SPaul E. McKenneythe other process reads from these same variables, the corresponding
184c4f790f2SPaul E. McKenneylitmus-test class is "MP" (message passing), which may be found on the
185c4f790f2SPaul E. McKenneyleft-hand end of the second row of tests on page one of test6.pdf.
186c4f790f2SPaul E. McKenney
187c4f790f2SPaul E. McKenneyThe strings used to identify the actions carried out by each process are
188c4f790f2SPaul E. McKenneycomplex due to a desire to have short(er) names.  Thus, there is a tool to
189c4f790f2SPaul E. McKenneygenerate these strings from a given litmus test's actions.  For example,
190c4f790f2SPaul E. McKenneyconsider the processes from SB+rfionceonce-poonceonces.litmus:
191c4f790f2SPaul E. McKenney
192c4f790f2SPaul E. McKenney	P0(int *x, int *y)
193c4f790f2SPaul E. McKenney	{
194c4f790f2SPaul E. McKenney		int r1;
195c4f790f2SPaul E. McKenney		int r2;
196c4f790f2SPaul E. McKenney
197c4f790f2SPaul E. McKenney		WRITE_ONCE(*x, 1);
198c4f790f2SPaul E. McKenney		r1 = READ_ONCE(*x);
199c4f790f2SPaul E. McKenney		r2 = READ_ONCE(*y);
200c4f790f2SPaul E. McKenney	}
201c4f790f2SPaul E. McKenney
202c4f790f2SPaul E. McKenney	P1(int *x, int *y)
203c4f790f2SPaul E. McKenney	{
204c4f790f2SPaul E. McKenney		int r3;
205c4f790f2SPaul E. McKenney		int r4;
206c4f790f2SPaul E. McKenney
207c4f790f2SPaul E. McKenney		WRITE_ONCE(*y, 1);
208c4f790f2SPaul E. McKenney		r3 = READ_ONCE(*y);
209c4f790f2SPaul E. McKenney		r4 = READ_ONCE(*x);
210c4f790f2SPaul E. McKenney	}
211c4f790f2SPaul E. McKenney
212c4f790f2SPaul E. McKenneyThe next step is to construct a space-separated list of descriptors,
213c4f790f2SPaul E. McKenneyinterleaving descriptions of the relation between a pair of consecutive
214c4f790f2SPaul E. McKenneyaccesses with descriptions of the second access in the pair.
215c4f790f2SPaul E. McKenney
216c4f790f2SPaul E. McKenneyP0()'s WRITE_ONCE() is read by its first READ_ONCE(), which is a
217c4f790f2SPaul E. McKenneyreads-from link (rf) and internal to the P0() process.  This is
218c4f790f2SPaul E. McKenney"rfi", which is an abbreviation for "reads-from internal".  Because
219c4f790f2SPaul E. McKenneysome of the tools string these abbreviations together with space
220c4f790f2SPaul E. McKenneycharacters separating processes, the first character is capitalized,
221c4f790f2SPaul E. McKenneyresulting in "Rfi".
222c4f790f2SPaul E. McKenney
223c4f790f2SPaul E. McKenneyP0()'s second access is a READ_ONCE(), as opposed to (for example)
224c4f790f2SPaul E. McKenneysmp_load_acquire(), so next is "Once".  Thus far, we have "Rfi Once".
225c4f790f2SPaul E. McKenney
226c4f790f2SPaul E. McKenneyP0()'s third access is also a READ_ONCE(), but to y rather than x.
227c4f790f2SPaul E. McKenneyThis is related to P0()'s second access by program order ("po"),
228c4f790f2SPaul E. McKenneyto a different variable ("d"), and both accesses are reads ("RR").
229c4f790f2SPaul E. McKenneyThe resulting descriptor is "PodRR".  Because P0()'s third access is
230c4f790f2SPaul E. McKenneyREAD_ONCE(), we add another "Once" descriptor.
231c4f790f2SPaul E. McKenney
232c4f790f2SPaul E. McKenneyA from-read ("fre") relation links P0()'s third to P1()'s first
233c4f790f2SPaul E. McKenneyaccess, and the resulting descriptor is "Fre".  P1()'s first access is
234c4f790f2SPaul E. McKenneyWRITE_ONCE(), which as before gives the descriptor "Once".  The string
235c4f790f2SPaul E. McKenneythus far is thus "Rfi Once PodRR Once Fre Once".
236c4f790f2SPaul E. McKenney
237c4f790f2SPaul E. McKenneyThe remainder of P1() is similar to P0(), which means we add
238c4f790f2SPaul E. McKenney"Rfi Once PodRR Once".  Another fre links P1()'s last access to
239c4f790f2SPaul E. McKenneyP0()'s first access, which is WRITE_ONCE(), so we add "Fre Once".
240c4f790f2SPaul E. McKenneyThe full string is thus:
241c4f790f2SPaul E. McKenney
242c4f790f2SPaul E. McKenney	Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once
243c4f790f2SPaul E. McKenney
244c4f790f2SPaul E. McKenneyThis string can be given to the "norm7" and "classify7" tools to
245c4f790f2SPaul E. McKenneyproduce the name:
246c4f790f2SPaul E. McKenney
247c4f790f2SPaul E. McKenney	$ norm7 -bell linux-kernel.bell \
248c4f790f2SPaul E. McKenney		Rfi Once PodRR Once Fre Once Rfi Once PodRR Once Fre Once | \
249c4f790f2SPaul E. McKenney	  sed -e 's/:.*//g'
250c4f790f2SPaul E. McKenney	SB+rfionceonce-poonceonces
251c4f790f2SPaul E. McKenney
252c4f790f2SPaul E. McKenneyAdding the ".litmus" suffix: SB+rfionceonce-poonceonces.litmus
253c4f790f2SPaul E. McKenney
254c4f790f2SPaul E. McKenneyThe descriptors that describe connections between consecutive accesses
25537c600a3SAndrea Parriwithin the cycle through a given litmus test can be provided by the herd7
256c4f790f2SPaul E. McKenneytool (Rfi, Po, Fre, and so on) or by the linux-kernel.bell file (Once,
257c4f790f2SPaul E. McKenneyRelease, Acquire, and so on).
258c4f790f2SPaul E. McKenney
259c4f790f2SPaul E. McKenneyTo see the full list of descriptors, execute the following command:
260c4f790f2SPaul E. McKenney
261c4f790f2SPaul E. McKenney	$ diyone7 -bell linux-kernel.bell -show edges
262