tools/memory-model/lock.cat

Source file repositories/reference/linux-study-clean/tools/memory-model/lock.cat

File Facts

System
Linux kernel
Corpus path
tools/memory-model/lock.cat
Extension
.cat
Size
5206 bytes
Lines
158
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
(*
 * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria
 * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>
 *)

(*
 * Generate coherence orders and handle lock operations
 *)

include "cross.cat"

(*
 * The lock-related events generated by herd7 are as follows:
 *
 * LKR		Lock-Read: the read part of a spin_lock() or successful
 *			spin_trylock() read-modify-write event pair
 * LKW		Lock-Write: the write part of a spin_lock() or successful
 *			spin_trylock() RMW event pair
 * UL		Unlock: a spin_unlock() event
 * LF		Lock-Fail: a failed spin_trylock() event
 * RL		Read-Locked: a spin_is_locked() event which returns True
 * RU		Read-Unlocked: a spin_is_locked() event which returns False
 *
 * LKR and LKW events always come paired, like all RMW event sequences.
 *
 * LKR, LF, RL, and RU are read events; LKR has Acquire ordering.
 * LKW and UL are write events; UL has Release ordering.
 * LKW, LF, RL, and RU have no ordering properties.
 *)

(* Backward compatibility *)
let RL = try RL with emptyset
let RU = try RU with emptyset

(* Treat RL as a kind of LF: a read with no ordering properties *)
let LF = LF | RL

(* There should be no ordinary R or W accesses to spinlocks or SRCU structs *)
let ALL-LOCKS = LKR | LKW | UL | LF | RU | Srcu-lock | Srcu-unlock | Sync-srcu
flag ~empty [M \ IW \ ALL-LOCKS] ; loc ; [ALL-LOCKS] as mixed-lock-accesses

(* Link Lock-Reads to their RMW-partner Lock-Writes *)
let lk-rmw = ([LKR] ; po-loc ; [LKW]) \ (po ; po)
let rmw = rmw | lk-rmw

(* The litmus test is invalid if an LKR/LKW event is not part of an RMW pair *)
flag ~empty LKW \ range(lk-rmw) as unpaired-LKW
flag ~empty LKR \ domain(lk-rmw) as unpaired-LKR

(*
 * An LKR must always see an unlocked value; spin_lock() calls nested
 * inside a critical section (for the same lock) always deadlock.
 *)
empty ([LKW] ; po-loc ; [LKR]) \ (po-loc ; [UL] ; po-loc) as lock-nest

(*
 * In the same way, spin_is_locked() inside a critical section must always
 * return True (no RU events can be in a critical section for the same lock).
 *)
empty ([LKW] ; po-loc ; [RU]) \ (po-loc ; [UL] ; po-loc) as nested-is-locked

(* The final value of a spinlock should not be tested *)
flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final

(*
 * Put lock operations in their appropriate classes, but leave UL out of W
 * until after the co relation has been generated.
 *)
let R = R | LKR | LF | RU

Annotation

Implementation Notes