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 reader stores

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
a591890c be4a3797

+48
+11
Documentation/litmus-tests/README
··· 1 + ============ 2 + LITMUS TESTS 3 + ============ 4 + 5 + RCU (/rcu directory) 6 + -------------------- 7 + 8 + RCU+sync+read.litmus 9 + RCU+sync+free.litmus 10 + Both the above litmus tests demonstrate the RCU grace period guarantee 11 + that an RCU read-side critical section can never span a grace period.
+37
Documentation/litmus-tests/rcu/RCU+sync+read.litmus
··· 1 + C RCU+sync+read 2 + 3 + (* 4 + * Result: Never 5 + * 6 + * This litmus test demonstrates that after a grace period, an RCU updater always 7 + * sees all stores done in prior RCU read-side critical sections. Such 8 + * read-side critical sections would have ended before the grace period ended. 9 + * 10 + * This is one implication of the RCU grace-period guarantee, which says (among 11 + * other things) that an RCU read-side critical section cannot span a grace period. 12 + *) 13 + 14 + { 15 + int x = 0; 16 + int y = 0; 17 + } 18 + 19 + P0(int *x, int *y) 20 + { 21 + rcu_read_lock(); 22 + WRITE_ONCE(*x, 1); 23 + WRITE_ONCE(*y, 1); 24 + rcu_read_unlock(); 25 + } 26 + 27 + P1(int *x, int *y) 28 + { 29 + int r0; 30 + int r1; 31 + 32 + r0 = READ_ONCE(*x); 33 + synchronize_rcu(); 34 + r1 = READ_ONCE(*y); 35 + } 36 + 37 + exists (1:r0=1 /\ 1:r1=0)