1// SPDX-License-Identifier: GPL-2.0+ 2(* 3 * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria 4 * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu> 5 *) 6 7(* Generate coherence orders and handle lock operations *) 8 9include "cross.cat" 10 11(* From lock reads to their partner lock writes *) 12let lk-rmw = ([LKR] ; po-loc ; [LKW]) \ (po ; po) 13let rmw = rmw | lk-rmw 14 15(* 16 * A paired LKR must always see an unlocked value; spin_lock() calls nested 17 * inside a critical section (for the same lock) always deadlock. 18 *) 19empty ([LKW] ; po-loc ; [domain(lk-rmw)]) \ (po-loc ; [UL] ; po-loc) 20 as lock-nest 21 22(* The litmus test is invalid if an LKW event is not part of an RMW pair *) 23flag ~empty LKW \ range(lk-rmw) as unpaired-LKW 24 25(* This will be allowed if we implement spin_is_locked() *) 26flag ~empty LKR \ domain(lk-rmw) as unpaired-LKR 27 28(* There should be no R or W accesses to spinlocks *) 29let ALL-LOCKS = LKR | LKW | UL | LF 30flag ~empty [M \ IW] ; loc ; [ALL-LOCKS] as mixed-lock-accesses 31 32(* The final value of a spinlock should not be tested *) 33flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final 34 35 36(* 37 * Put lock operations in their appropriate classes, but leave UL out of W 38 * until after the co relation has been generated. 39 *) 40let R = R | LKR | LF 41let W = W | LKW 42 43let Release = Release | UL 44let Acquire = Acquire | LKR 45 46 47(* Match LKW events to their corresponding UL events *) 48let critical = ([LKW] ; po-loc ; [UL]) \ (po-loc ; [LKW | UL] ; po-loc) 49 50flag ~empty UL \ range(critical) as unmatched-unlock 51 52(* Allow up to one unmatched LKW per location; more must deadlock *) 53let UNMATCHED-LKW = LKW \ domain(critical) 54empty ([UNMATCHED-LKW] ; loc ; [UNMATCHED-LKW]) \ id as unmatched-locks 55 56 57(* rfi for LF events: link each LKW to the LF events in its critical section *) 58let rfi-lf = ([LKW] ; po-loc ; [LF]) \ ([LKW] ; po-loc ; [UL] ; po-loc) 59 60(* rfe for LF events *) 61let all-possible-rfe-lf = 62 (* 63 * Given an LF event r, compute the possible rfe edges for that event 64 * (all those starting from LKW events in other threads), 65 * and then convert that relation to a set of single-edge relations. 66 *) 67 let possible-rfe-lf r = 68 let pair-to-relation p = p ++ 0 69 in map pair-to-relation ((LKW * {r}) & loc & ext) 70 (* Do this for each LF event r that isn't in rfi-lf *) 71 in map possible-rfe-lf (LF \ range(rfi-lf)) 72 73(* Generate all rf relations for LF events *) 74with rfe-lf from cross(all-possible-rfe-lf) 75let rf = rf | rfi-lf | rfe-lf 76 77 78(* Generate all co relations, including LKW events but not UL *) 79let co0 = co0 | ([IW] ; loc ; [LKW]) | 80 (([LKW] ; loc ; [UNMATCHED-LKW]) \ [UNMATCHED-LKW]) 81include "cos-opt.cat" 82let W = W | UL 83let M = R | W 84 85(* Merge UL events into co *) 86let co = (co | critical | (critical^-1 ; co))+ 87let coe = co & ext 88let coi = co & int 89 90(* Merge LKR events into rf *) 91let rf = rf | ([IW | UL] ; singlestep(co) ; lk-rmw^-1) 92let rfe = rf & ext 93let rfi = rf & int 94 95let fr = rf^-1 ; co 96let fre = fr & ext 97let fri = fr & int 98 99show co,rf,fr 100