11c27b644SPaul E. McKenney// SPDX-License-Identifier: GPL-2.0+ 21c27b644SPaul E. McKenney(* 31c27b644SPaul E. McKenney * Copyright (C) 2015 Jade Alglave <j.alglave@ucl.ac.uk>, 41c27b644SPaul E. McKenney * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria 51c27b644SPaul E. McKenney * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>, 61c27b644SPaul E. McKenney * Andrea Parri <parri.andrea@gmail.com> 71c27b644SPaul E. McKenney * 81a00b455SAndrea Parri * An earlier version of this file appeared in the companion webpage for 91c27b644SPaul E. McKenney * "Frightening small children and disconcerting grown-ups: Concurrency 101c27b644SPaul E. McKenney * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern, 111a00b455SAndrea Parri * which appeared in ASPLOS 2018. 121c27b644SPaul E. McKenney *) 131c27b644SPaul E. McKenney 1448d44d4eSAndrea Parri"Linux-kernel memory consistency model" 151c27b644SPaul E. McKenney 161c27b644SPaul E. McKenney(* 171c27b644SPaul E. McKenney * File "lock.cat" handles locks and is experimental. 181c27b644SPaul E. McKenney * It can be replaced by include "cos.cat" for tests that do not use locks. 191c27b644SPaul E. McKenney *) 201c27b644SPaul E. McKenney 211c27b644SPaul E. McKenneyinclude "lock.cat" 221c27b644SPaul E. McKenney 231c27b644SPaul E. McKenney(*******************) 241c27b644SPaul E. McKenney(* Basic relations *) 251c27b644SPaul E. McKenney(*******************) 261c27b644SPaul E. McKenney 271c27b644SPaul E. McKenney(* Fences *) 281c27b644SPaul E. McKenneylet rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn] 291c27b644SPaul E. McKenneylet wmb = [W] ; fencerel(Wmb) ; [W] 301c27b644SPaul E. McKenneylet mb = ([M] ; fencerel(Mb) ; [M]) | 31cac79a39SPaul E. McKenney ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) | 32cac79a39SPaul E. McKenney ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) | 335b735eb1SAndrea Parri ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M]) | 345b735eb1SAndrea Parri ([M] ; po ; [UL] ; (co | po) ; [LKW] ; 355b735eb1SAndrea Parri fencerel(After-unlock-lock) ; [M]) 36*a3f600d9SAlan Sternlet gp = po ; [Sync-rcu | Sync-srcu] ; po? 371c27b644SPaul E. McKenney 381c27b644SPaul E. McKenneylet strong-fence = mb | gp 391c27b644SPaul E. McKenney 401c27b644SPaul E. McKenney(* Release Acquire *) 411c27b644SPaul E. McKenneylet acq-po = [Acquire] ; po ; [M] 421c27b644SPaul E. McKenneylet po-rel = [M] ; po ; [Release] 436e89e831SAlan Sternlet po-unlock-rf-lock-po = po ; [UL] ; rf ; [LKR] ; po 441c27b644SPaul E. McKenney 451c27b644SPaul E. McKenney(**********************************) 461c27b644SPaul E. McKenney(* Fundamental coherence ordering *) 471c27b644SPaul E. McKenney(**********************************) 481c27b644SPaul E. McKenney 491c27b644SPaul E. McKenney(* Sequential Consistency Per Variable *) 501c27b644SPaul E. McKenneylet com = rf | co | fr 511c27b644SPaul E. McKenneyacyclic po-loc | com as coherence 521c27b644SPaul E. McKenney 531c27b644SPaul E. McKenney(* Atomic Read-Modify-Write *) 541c27b644SPaul E. McKenneyempty rmw & (fre ; coe) as atomic 551c27b644SPaul E. McKenney 561c27b644SPaul E. McKenney(**********************************) 571c27b644SPaul E. McKenney(* Instruction execution ordering *) 581c27b644SPaul E. McKenney(**********************************) 591c27b644SPaul E. McKenney 601c27b644SPaul E. McKenney(* Preserved Program Order *) 611c27b644SPaul E. McKenneylet dep = addr | data 621c27b644SPaul E. McKenneylet rwdep = (dep | ctrl) ; [W] 631c27b644SPaul E. McKenneylet overwrite = co | fr 641c27b644SPaul E. McKenneylet to-w = rwdep | (overwrite & int) 656e89e831SAlan Sternlet to-r = addr | (dep ; rfi) 661c27b644SPaul E. McKenneylet fence = strong-fence | wmb | po-rel | rmb | acq-po 676e89e831SAlan Sternlet ppo = to-r | to-w | fence | (po-unlock-rf-lock-po & int) 681c27b644SPaul E. McKenney 691c27b644SPaul E. McKenney(* Propagation: Ordering from release operations and strong fences. *) 701c27b644SPaul E. McKenneylet A-cumul(r) = rfe? ; r 716e89e831SAlan Sternlet cumul-fence = A-cumul(strong-fence | po-rel) | wmb | po-unlock-rf-lock-po 721c27b644SPaul E. McKenneylet prop = (overwrite & ext)? ; cumul-fence* ; rfe? 731c27b644SPaul E. McKenney 741c27b644SPaul E. McKenney(* 751c27b644SPaul E. McKenney * Happens Before: Ordering from the passage of time. 761c27b644SPaul E. McKenney * No fences needed here for prop because relation confined to one process. 771c27b644SPaul E. McKenney *) 781c27b644SPaul E. McKenneylet hb = ppo | rfe | ((prop \ id) & int) 791c27b644SPaul E. McKenneyacyclic hb as happens-before 801c27b644SPaul E. McKenney 811c27b644SPaul E. McKenney(****************************************) 821c27b644SPaul E. McKenney(* Write and fence propagation ordering *) 831c27b644SPaul E. McKenney(****************************************) 841c27b644SPaul E. McKenney 851c27b644SPaul E. McKenney(* Propagation: Each non-rf link needs a strong fence. *) 861c27b644SPaul E. McKenneylet pb = prop ; strong-fence ; hb* 871c27b644SPaul E. McKenneyacyclic pb as propagation 881c27b644SPaul E. McKenney 891c27b644SPaul E. McKenney(*******) 901c27b644SPaul E. McKenney(* RCU *) 911c27b644SPaul E. McKenney(*******) 921c27b644SPaul E. McKenney 931c27b644SPaul E. McKenney(* 94284749b0SAlan Stern * Effects of read-side critical sections proceed from the rcu_read_unlock() 95*a3f600d9SAlan Stern * or srcu_read_unlock() backwards on the one hand, and from the 96*a3f600d9SAlan Stern * rcu_read_lock() or srcu_read_lock() forwards on the other hand. 97284749b0SAlan Stern * 98284749b0SAlan Stern * In the definition of rcu-fence below, the po term at the left-hand side 99284749b0SAlan Stern * of each disjunct and the po? term at the right-hand end have been factored 100284749b0SAlan Stern * out. They have been moved into the definitions of rcu-link and rb. 101*a3f600d9SAlan Stern * This was necessary in order to apply the "& loc" tests correctly. 1021c27b644SPaul E. McKenney *) 103284749b0SAlan Sternlet rcu-gp = [Sync-rcu] (* Compare with gp *) 104*a3f600d9SAlan Sternlet srcu-gp = [Sync-srcu] 105284749b0SAlan Sternlet rcu-rscsi = rcu-rscs^-1 106*a3f600d9SAlan Sternlet srcu-rscsi = srcu-rscs^-1 1071c27b644SPaul E. McKenney 1081c27b644SPaul E. McKenney(* 1091c27b644SPaul E. McKenney * The synchronize_rcu() strong fence is special in that it can order not 1101c27b644SPaul E. McKenney * one but two non-rf relations, but only in conjunction with an RCU 1111c27b644SPaul E. McKenney * read-side critical section. 1121c27b644SPaul E. McKenney *) 113284749b0SAlan Sternlet rcu-link = po? ; hb* ; pb* ; prop ; po 1141c27b644SPaul E. McKenney 1151c27b644SPaul E. McKenney(* 1169d036883SAlan Stern * Any sequence containing at least as many grace periods as RCU read-side 1179d036883SAlan Stern * critical sections (joined by rcu-link) acts as a generalized strong fence. 118*a3f600d9SAlan Stern * Likewise for SRCU grace periods and read-side critical sections, provided 119*a3f600d9SAlan Stern * the synchronize_srcu() and srcu_read_[un]lock() calls refer to the same 120*a3f600d9SAlan Stern * struct srcu_struct location. 1211c27b644SPaul E. McKenney *) 122*a3f600d9SAlan Sternlet rec rcu-fence = rcu-gp | srcu-gp | 123284749b0SAlan Stern (rcu-gp ; rcu-link ; rcu-rscsi) | 124*a3f600d9SAlan Stern ((srcu-gp ; rcu-link ; srcu-rscsi) & loc) | 125284749b0SAlan Stern (rcu-rscsi ; rcu-link ; rcu-gp) | 126*a3f600d9SAlan Stern ((srcu-rscsi ; rcu-link ; srcu-gp) & loc) | 127284749b0SAlan Stern (rcu-gp ; rcu-link ; rcu-fence ; rcu-link ; rcu-rscsi) | 128*a3f600d9SAlan Stern ((srcu-gp ; rcu-link ; rcu-fence ; rcu-link ; srcu-rscsi) & loc) | 129284749b0SAlan Stern (rcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; rcu-gp) | 130*a3f600d9SAlan Stern ((srcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; srcu-gp) & loc) | 1319d036883SAlan Stern (rcu-fence ; rcu-link ; rcu-fence) 1329d036883SAlan Stern 1339d036883SAlan Stern(* rb orders instructions just as pb does *) 134284749b0SAlan Sternlet rb = prop ; po ; rcu-fence ; po? ; hb* ; pb* 1351c27b644SPaul E. McKenney 1361ee2da5fSAlan Sternirreflexive rb as rcu 1379d036883SAlan Stern 1389d036883SAlan Stern(* 1399d036883SAlan Stern * The happens-before, propagation, and rcu constraints are all 1409d036883SAlan Stern * expressions of temporal ordering. They could be replaced by 1419d036883SAlan Stern * a single constraint on an "executes-before" relation, xb: 1429d036883SAlan Stern * 1439d036883SAlan Stern * let xb = hb | pb | rb 1449d036883SAlan Stern * acyclic xb as executes-before 1459d036883SAlan Stern *) 146