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 * 81c27b644SPaul E. McKenney * An earlier version of this file appears 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, 111c27b644SPaul E. McKenney * which is to appear in ASPLOS 2018. 121c27b644SPaul E. McKenney *) 131c27b644SPaul E. McKenney 14*48d44d4eSAndrea 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 rb-dep = [R] ; fencerel(Rb_dep) ; [R] 291c27b644SPaul E. McKenneylet rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn] 301c27b644SPaul E. McKenneylet wmb = [W] ; fencerel(Wmb) ; [W] 311c27b644SPaul E. McKenneylet mb = ([M] ; fencerel(Mb) ; [M]) | 321c27b644SPaul E. McKenney ([M] ; fencerel(Before_atomic) ; [RMW] ; po? ; [M]) | 331c27b644SPaul E. McKenney ([M] ; po? ; [RMW] ; fencerel(After_atomic) ; [M]) | 341c27b644SPaul E. McKenney ([M] ; po? ; [LKW] ; fencerel(After_spinlock) ; [M]) 351c27b644SPaul E. McKenneylet gp = po ; [Sync-rcu] ; po? 361c27b644SPaul E. McKenney 371c27b644SPaul E. McKenneylet strong-fence = mb | gp 381c27b644SPaul E. McKenney 391c27b644SPaul E. McKenney(* Release Acquire *) 401c27b644SPaul E. McKenneylet acq-po = [Acquire] ; po ; [M] 411c27b644SPaul E. McKenneylet po-rel = [M] ; po ; [Release] 421c27b644SPaul E. McKenneylet rfi-rel-acq = [Release] ; rfi ; [Acquire] 431c27b644SPaul E. McKenney 441c27b644SPaul E. McKenney(**********************************) 451c27b644SPaul E. McKenney(* Fundamental coherence ordering *) 461c27b644SPaul E. McKenney(**********************************) 471c27b644SPaul E. McKenney 481c27b644SPaul E. McKenney(* Sequential Consistency Per Variable *) 491c27b644SPaul E. McKenneylet com = rf | co | fr 501c27b644SPaul E. McKenneyacyclic po-loc | com as coherence 511c27b644SPaul E. McKenney 521c27b644SPaul E. McKenney(* Atomic Read-Modify-Write *) 531c27b644SPaul E. McKenneyempty rmw & (fre ; coe) as atomic 541c27b644SPaul E. McKenney 551c27b644SPaul E. McKenney(**********************************) 561c27b644SPaul E. McKenney(* Instruction execution ordering *) 571c27b644SPaul E. McKenney(**********************************) 581c27b644SPaul E. McKenney 591c27b644SPaul E. McKenney(* Preserved Program Order *) 601c27b644SPaul E. McKenneylet dep = addr | data 611c27b644SPaul E. McKenneylet rwdep = (dep | ctrl) ; [W] 621c27b644SPaul E. McKenneylet overwrite = co | fr 631c27b644SPaul E. McKenneylet to-w = rwdep | (overwrite & int) 641c27b644SPaul E. McKenneylet rrdep = addr | (dep ; rfi) 651c27b644SPaul E. McKenneylet strong-rrdep = rrdep+ & rb-dep 661c27b644SPaul E. McKenneylet to-r = strong-rrdep | rfi-rel-acq 671c27b644SPaul E. McKenneylet fence = strong-fence | wmb | po-rel | rmb | acq-po 681c27b644SPaul E. McKenneylet ppo = rrdep* ; (to-r | to-w | fence) 691c27b644SPaul E. McKenney 701c27b644SPaul E. McKenney(* Propagation: Ordering from release operations and strong fences. *) 711c27b644SPaul E. McKenneylet A-cumul(r) = rfe? ; r 721c27b644SPaul E. McKenneylet cumul-fence = A-cumul(strong-fence | po-rel) | wmb 731c27b644SPaul E. McKenneylet prop = (overwrite & ext)? ; cumul-fence* ; rfe? 741c27b644SPaul E. McKenney 751c27b644SPaul E. McKenney(* 761c27b644SPaul E. McKenney * Happens Before: Ordering from the passage of time. 771c27b644SPaul E. McKenney * No fences needed here for prop because relation confined to one process. 781c27b644SPaul E. McKenney *) 791c27b644SPaul E. McKenneylet hb = ppo | rfe | ((prop \ id) & int) 801c27b644SPaul E. McKenneyacyclic hb as happens-before 811c27b644SPaul E. McKenney 821c27b644SPaul E. McKenney(****************************************) 831c27b644SPaul E. McKenney(* Write and fence propagation ordering *) 841c27b644SPaul E. McKenney(****************************************) 851c27b644SPaul E. McKenney 861c27b644SPaul E. McKenney(* Propagation: Each non-rf link needs a strong fence. *) 871c27b644SPaul E. McKenneylet pb = prop ; strong-fence ; hb* 881c27b644SPaul E. McKenneyacyclic pb as propagation 891c27b644SPaul E. McKenney 901c27b644SPaul E. McKenney(*******) 911c27b644SPaul E. McKenney(* RCU *) 921c27b644SPaul E. McKenney(*******) 931c27b644SPaul E. McKenney 941c27b644SPaul E. McKenney(* 951c27b644SPaul E. McKenney * Effect of read-side critical section proceeds from the rcu_read_lock() 961c27b644SPaul E. McKenney * onward on the one hand and from the rcu_read_unlock() backwards on the 971c27b644SPaul E. McKenney * other hand. 981c27b644SPaul E. McKenney *) 991c27b644SPaul E. McKenneylet rscs = po ; crit^-1 ; po? 1001c27b644SPaul E. McKenney 1011c27b644SPaul E. McKenney(* 1021c27b644SPaul E. McKenney * The synchronize_rcu() strong fence is special in that it can order not 1031c27b644SPaul E. McKenney * one but two non-rf relations, but only in conjunction with an RCU 1041c27b644SPaul E. McKenney * read-side critical section. 1051c27b644SPaul E. McKenney *) 1061c27b644SPaul E. McKenneylet link = hb* ; pb* ; prop 1071c27b644SPaul E. McKenney 1081c27b644SPaul E. McKenney(* Chains that affect the RCU grace-period guarantee *) 1091c27b644SPaul E. McKenneylet gp-link = gp ; link 1101c27b644SPaul E. McKenneylet rscs-link = rscs ; link 1111c27b644SPaul E. McKenney 1121c27b644SPaul E. McKenney(* 1131c27b644SPaul E. McKenney * A cycle containing at least as many grace periods as RCU read-side 1141c27b644SPaul E. McKenney * critical sections is forbidden. 1151c27b644SPaul E. McKenney *) 1161c27b644SPaul E. McKenneylet rec rcu-path = 1171c27b644SPaul E. McKenney gp-link | 1181c27b644SPaul E. McKenney (gp-link ; rscs-link) | 1191c27b644SPaul E. McKenney (rscs-link ; gp-link) | 1201c27b644SPaul E. McKenney (rcu-path ; rcu-path) | 1211c27b644SPaul E. McKenney (gp-link ; rcu-path ; rscs-link) | 1221c27b644SPaul E. McKenney (rscs-link ; rcu-path ; gp-link) 1231c27b644SPaul E. McKenney 1241c27b644SPaul E. McKenneyirreflexive rcu-path as rcu 125