blob: 882fc33274ac3ce1ca64695e736e7dd755ab7198 [file] [log] [blame]
Paul E. McKenney1c27b642018-01-18 19:58:55 -08001// SPDX-License-Identifier: GPL-2.0+
2(*
3 * Copyright (C) 2015 Jade Alglave <j.alglave@ucl.ac.uk>,
4 * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria
5 * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>,
6 * Andrea Parri <parri.andrea@gmail.com>
7 *
Andrea Parri1a00b4552018-05-14 16:33:56 -07008 * An earlier version of this file appeared in the companion webpage for
Paul E. McKenney1c27b642018-01-18 19:58:55 -08009 * "Frightening small children and disconcerting grown-ups: Concurrency
10 * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
Andrea Parri1a00b4552018-05-14 16:33:56 -070011 * which appeared in ASPLOS 2018.
Paul E. McKenney1c27b642018-01-18 19:58:55 -080012 *)
13
Andrea Parri48d44d42018-02-20 15:25:01 -080014"Linux-kernel memory consistency model"
Paul E. McKenney1c27b642018-01-18 19:58:55 -080015
16(*
17 * File "lock.cat" handles locks and is experimental.
18 * It can be replaced by include "cos.cat" for tests that do not use locks.
19 *)
20
21include "lock.cat"
22
23(*******************)
24(* Basic relations *)
25(*******************)
26
27(* Fences *)
Paul E. McKenney1c27b642018-01-18 19:58:55 -080028let rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn]
29let wmb = [W] ; fencerel(Wmb) ; [W]
30let mb = ([M] ; fencerel(Mb) ; [M]) |
Paul E. McKenneycac79a392018-02-20 15:25:11 -080031 ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
32 ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
33 ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M])
Paul E. McKenney1c27b642018-01-18 19:58:55 -080034let gp = po ; [Sync-rcu] ; po?
35
36let strong-fence = mb | gp
37
38(* Release Acquire *)
39let acq-po = [Acquire] ; po ; [M]
40let po-rel = [M] ; po ; [Release]
Alan Stern6e89e832018-09-26 11:29:17 -070041let po-unlock-rf-lock-po = po ; [UL] ; rf ; [LKR] ; po
Paul E. McKenney1c27b642018-01-18 19:58:55 -080042
43(**********************************)
44(* Fundamental coherence ordering *)
45(**********************************)
46
47(* Sequential Consistency Per Variable *)
48let com = rf | co | fr
49acyclic po-loc | com as coherence
50
51(* Atomic Read-Modify-Write *)
52empty rmw & (fre ; coe) as atomic
53
54(**********************************)
55(* Instruction execution ordering *)
56(**********************************)
57
58(* Preserved Program Order *)
59let dep = addr | data
60let rwdep = (dep | ctrl) ; [W]
61let overwrite = co | fr
62let to-w = rwdep | (overwrite & int)
Alan Stern6e89e832018-09-26 11:29:17 -070063let to-r = addr | (dep ; rfi)
Paul E. McKenney1c27b642018-01-18 19:58:55 -080064let fence = strong-fence | wmb | po-rel | rmb | acq-po
Alan Stern6e89e832018-09-26 11:29:17 -070065let ppo = to-r | to-w | fence | (po-unlock-rf-lock-po & int)
Paul E. McKenney1c27b642018-01-18 19:58:55 -080066
67(* Propagation: Ordering from release operations and strong fences. *)
68let A-cumul(r) = rfe? ; r
Alan Stern6e89e832018-09-26 11:29:17 -070069let cumul-fence = A-cumul(strong-fence | po-rel) | wmb | po-unlock-rf-lock-po
Paul E. McKenney1c27b642018-01-18 19:58:55 -080070let prop = (overwrite & ext)? ; cumul-fence* ; rfe?
71
72(*
73 * Happens Before: Ordering from the passage of time.
74 * No fences needed here for prop because relation confined to one process.
75 *)
76let hb = ppo | rfe | ((prop \ id) & int)
77acyclic hb as happens-before
78
79(****************************************)
80(* Write and fence propagation ordering *)
81(****************************************)
82
83(* Propagation: Each non-rf link needs a strong fence. *)
84let pb = prop ; strong-fence ; hb*
85acyclic pb as propagation
86
87(*******)
88(* RCU *)
89(*******)
90
91(*
92 * Effect of read-side critical section proceeds from the rcu_read_lock()
93 * onward on the one hand and from the rcu_read_unlock() backwards on the
94 * other hand.
95 *)
96let rscs = po ; crit^-1 ; po?
97
98(*
99 * The synchronize_rcu() strong fence is special in that it can order not
100 * one but two non-rf relations, but only in conjunction with an RCU
101 * read-side critical section.
102 *)
Alan Stern1ee2da52018-05-14 16:33:39 -0700103let rcu-link = hb* ; pb* ; prop
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800104
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800105(*
Alan Stern9d036882018-05-14 16:33:40 -0700106 * Any sequence containing at least as many grace periods as RCU read-side
107 * critical sections (joined by rcu-link) acts as a generalized strong fence.
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800108 *)
Alan Stern9d036882018-05-14 16:33:40 -0700109let rec rcu-fence = gp |
110 (gp ; rcu-link ; rscs) |
111 (rscs ; rcu-link ; gp) |
112 (gp ; rcu-link ; rcu-fence ; rcu-link ; rscs) |
113 (rscs ; rcu-link ; rcu-fence ; rcu-link ; gp) |
114 (rcu-fence ; rcu-link ; rcu-fence)
115
116(* rb orders instructions just as pb does *)
117let rb = prop ; rcu-fence ; hb* ; pb*
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800118
Alan Stern1ee2da52018-05-14 16:33:39 -0700119irreflexive rb as rcu
Alan Stern9d036882018-05-14 16:33:40 -0700120
121(*
122 * The happens-before, propagation, and rcu constraints are all
123 * expressions of temporal ordering. They could be replaced by
124 * a single constraint on an "executes-before" relation, xb:
125 *
126 * let xb = hb | pb | rb
127 * acyclic xb as executes-before
128 *)