Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: LKMM: Add litmus test for RCU GP guarantee where updater frees object

This adds an example for the important RCU grace period guarantee, which
shows an RCU reader can never span a grace period.

Acked-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

authored by

Joel Fernandes (Google) and committed by
Paul E. McKenney
be4a3797 c1b14609

+42
+42
Documentation/litmus-tests/rcu/RCU+sync+free.litmus
··· 1 + C RCU+sync+free 2 + 3 + (* 4 + * Result: Never 5 + * 6 + * This litmus test demonstrates that an RCU reader can never see a write that 7 + * follows a grace period, if it did not see writes that precede that grace 8 + * period. 9 + * 10 + * This is a typical pattern of RCU usage, where the write before the grace 11 + * period assigns a pointer, and the writes following the grace period destroy 12 + * the object that the pointer used to point to. 13 + * 14 + * This is one implication of the RCU grace-period guarantee, which says (among 15 + * other things) that an RCU read-side critical section cannot span a grace period. 16 + *) 17 + 18 + { 19 + int x = 1; 20 + int *y = &x; 21 + int z = 1; 22 + } 23 + 24 + P0(int *x, int *z, int **y) 25 + { 26 + int *r0; 27 + int r1; 28 + 29 + rcu_read_lock(); 30 + r0 = rcu_dereference(*y); 31 + r1 = READ_ONCE(*r0); 32 + rcu_read_unlock(); 33 + } 34 + 35 + P1(int *x, int *z, int **y) 36 + { 37 + rcu_assign_pointer(*y, z); 38 + synchronize_rcu(); 39 + WRITE_ONCE(*x, 0); 40 + } 41 + 42 + exists (0:r0=x /\ 0:r1=0)