Skip to content

Commit a3f600d

Browse files
AlanSternPaul E. McKenney
authored andcommitted
tools/memory-model: Add SRCU support
Add support for SRCU. Herd creates srcu events and linux-kernel.def associates them with three possible annotations (srcu-lock, srcu-unlock, and sync-srcu) corresponding to the API routines srcu_read_lock(), srcu_read_unlock(), and synchronize_srcu(). The linux-kernel.bell file now declares the annotations and determines matching lock/unlock pairs delimiting SRCU read-side critical sections, and it also checks for synchronize_srcu() calls inside an RCU critical section (which would generate a "sleeping in atomic context" error in real kernel code). The linux-kernel.cat file now adds SRCU-induced ordering, analogous to the existing RCU-induced ordering, to the gp and rcu-fence relations. Curiously enough, these small changes to the model's .cat code are all that is needed to describe SRCU. Portions of this patch (linux-kernel.def and the first hunk in linux-kernel.bell) were written by Luc Maranget. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: Luc Maranget <luc.maranget@inria.fr> Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com> Tested-by: Andrea Parri <andrea.parri@amarulasolutions.com>
1 parent 284749b commit a3f600d

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎tools/memory-model/linux-kernel.bell‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ enum Barriers = 'wmb (*smp_wmb*) ||
3333
'after-unlock-lock (*smp_mb__after_unlock_lock*)
3434
instructions F[Barriers]
3535

36+
(* SRCU *)
37+
enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu
38+
instructions SRCU[SRCU]
39+
(* All srcu events *)
40+
let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu
41+
3642
(* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)
3743
let rcu-rscs = let rec
3844
unmatched-locks = Rcu-lock \ domain(matched)
@@ -48,3 +54,22 @@ let rcu-rscs = let rec
4854
(* Validate nesting *)
4955
flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking
5056
flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking
57+
58+
(* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)
59+
let srcu-rscs = let rec
60+
unmatched-locks = Srcu-lock \ domain(matched)
61+
and unmatched-unlocks = Srcu-unlock \ range(matched)
62+
and unmatched = unmatched-locks | unmatched-unlocks
63+
and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc
64+
and unmatched-locks-to-unlocks =
65+
([unmatched-locks] ; po ; [unmatched-unlocks]) & loc
66+
and matched = matched | (unmatched-locks-to-unlocks \
67+
(unmatched-po ; unmatched-po))
68+
in matched
69+
70+
(* Validate nesting *)
71+
flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking
72+
flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking
73+
74+
(* Check for use of synchronize_srcu() inside an RCU critical section *)
75+
flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep

‎tools/memory-model/linux-kernel.cat‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let mb = ([M] ; fencerel(Mb) ; [M]) |
3333
([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M]) |
3434
([M] ; po ; [UL] ; (co | po) ; [LKW] ;
3535
fencerel(After-unlock-lock) ; [M])
36-
let gp = po ; [Sync-rcu] ; po?
36+
let gp = po ; [Sync-rcu | Sync-srcu] ; po?
3737

3838
let strong-fence = mb | gp
3939

@@ -92,15 +92,18 @@ acyclic pb as propagation
9292

9393
(*
9494
* Effects of read-side critical sections proceed from the rcu_read_unlock()
95-
* backwards on the one hand, and from the rcu_read_lock() forwards on the
96-
* other hand.
95+
* or srcu_read_unlock() backwards on the one hand, and from the
96+
* rcu_read_lock() or srcu_read_lock() forwards on the other hand.
9797
*
9898
* In the definition of rcu-fence below, the po term at the left-hand side
9999
* of each disjunct and the po? term at the right-hand end have been factored
100100
* out. They have been moved into the definitions of rcu-link and rb.
101+
* This was necessary in order to apply the "& loc" tests correctly.
101102
*)
102103
let rcu-gp = [Sync-rcu] (* Compare with gp *)
104+
let srcu-gp = [Sync-srcu]
103105
let rcu-rscsi = rcu-rscs^-1
106+
let srcu-rscsi = srcu-rscs^-1
104107

105108
(*
106109
* The synchronize_rcu() strong fence is special in that it can order not
@@ -112,12 +115,19 @@ let rcu-link = po? ; hb* ; pb* ; prop ; po
112115
(*
113116
* Any sequence containing at least as many grace periods as RCU read-side
114117
* critical sections (joined by rcu-link) acts as a generalized strong fence.
118+
* Likewise for SRCU grace periods and read-side critical sections, provided
119+
* the synchronize_srcu() and srcu_read_[un]lock() calls refer to the same
120+
* struct srcu_struct location.
115121
*)
116-
let rec rcu-fence = rcu-gp |
122+
let rec rcu-fence = rcu-gp | srcu-gp |
117123
(rcu-gp ; rcu-link ; rcu-rscsi) |
124+
((srcu-gp ; rcu-link ; srcu-rscsi) & loc) |
118125
(rcu-rscsi ; rcu-link ; rcu-gp) |
126+
((srcu-rscsi ; rcu-link ; srcu-gp) & loc) |
119127
(rcu-gp ; rcu-link ; rcu-fence ; rcu-link ; rcu-rscsi) |
128+
((srcu-gp ; rcu-link ; rcu-fence ; rcu-link ; srcu-rscsi) & loc) |
120129
(rcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; rcu-gp) |
130+
((srcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; srcu-gp) & loc) |
121131
(rcu-fence ; rcu-link ; rcu-fence)
122132

123133
(* rb orders instructions just as pb does *)

‎tools/memory-model/linux-kernel.def‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ rcu_read_unlock() { __fence{rcu-unlock}; }
4747
synchronize_rcu() { __fence{sync-rcu}; }
4848
synchronize_rcu_expedited() { __fence{sync-rcu}; }
4949

50+
// SRCU
51+
srcu_read_lock(X) __srcu{srcu-lock}(X)
52+
srcu_read_unlock(X,Y) { __srcu{srcu-unlock}(X); }
53+
synchronize_srcu(X) { __srcu{sync-srcu}(X); }
54+
5055
// Atomic
5156
atomic_read(X) READ_ONCE(*X)
5257
atomic_set(X,V) { WRITE_ONCE(*X,V); }

0 commit comments

Comments
 (0)