diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2018-05-14 19:33:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-05-15 02:11:18 -0400 |
commit | fd0359dbac3df00d1c6c22769e7d647b16b920cc (patch) | |
tree | a688328193303f16e0ba8d17178e5e84258e03d2 | |
parent | 8559183ccaec97454b2515ac426f113967256cf9 (diff) |
tools/memory-model: Improve comments in lock.cat
This patch improves the comments in tools/memory-model/lock.cat. In
addition to making the text more uniform and removing redundant
comments, it adds a description of all the possible locking events
that herd can generate.
Tested-by: Andrea Parri <andrea.parri@amarulasolutions.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Akira Yokosawa <akiyks@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Jade Alglave <j.alglave@ucl.ac.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luc Maranget <luc.maranget@inria.fr>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-arch@vger.kernel.org
Cc: parri.andrea@gmail.com
Link: http://lkml.kernel.org/r/1526340837-12222-13-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | tools/memory-model/lock.cat | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/tools/memory-model/lock.cat b/tools/memory-model/lock.cat index 1f6d67e79065..df74de2148f6 100644 --- a/tools/memory-model/lock.cat +++ b/tools/memory-model/lock.cat | |||
@@ -4,15 +4,35 @@ | |||
4 | * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu> | 4 | * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu> |
5 | *) | 5 | *) |
6 | 6 | ||
7 | (* Generate coherence orders and handle lock operations *) | ||
8 | (* | 7 | (* |
9 | * Warning, crashes with herd7 versions strictly before 7.48. | 8 | * Generate coherence orders and handle lock operations |
10 | * spin_islocked is functional from version 7.49. | ||
11 | * | 9 | * |
10 | * Warning: spin_is_locked() crashes herd7 versions strictly before 7.48. | ||
11 | * spin_is_locked() is functional from herd7 version 7.49. | ||
12 | *) | 12 | *) |
13 | |||
13 | include "cross.cat" | 14 | include "cross.cat" |
14 | 15 | ||
15 | (* From lock reads to their partner lock writes *) | 16 | (* |
17 | * The lock-related events generated by herd are as follows: | ||
18 | * | ||
19 | * LKR Lock-Read: the read part of a spin_lock() or successful | ||
20 | * spin_trylock() read-modify-write event pair | ||
21 | * LKW Lock-Write: the write part of a spin_lock() or successful | ||
22 | * spin_trylock() RMW event pair | ||
23 | * UL Unlock: a spin_unlock() event | ||
24 | * LF Lock-Fail: a failed spin_trylock() event | ||
25 | * RL Read-Locked: a spin_is_locked() event which returns True | ||
26 | * RU Read-Unlocked: a spin_is_locked() event which returns False | ||
27 | * | ||
28 | * LKR and LKW events always come paired, like all RMW event sequences. | ||
29 | * | ||
30 | * LKR, LF, RL, and RU are read events; LKR has Acquire ordering. | ||
31 | * LKW and UL are write events; UL has Release ordering. | ||
32 | * LKW, LF, RL, and RU have no ordering properties. | ||
33 | *) | ||
34 | |||
35 | (* Link Lock-Reads to their RMW-partner Lock-Writes *) | ||
16 | let lk-rmw = ([LKR] ; po-loc ; [LKW]) \ (po ; po) | 36 | let lk-rmw = ([LKR] ; po-loc ; [LKW]) \ (po ; po) |
17 | let rmw = rmw | lk-rmw | 37 | let rmw = rmw | lk-rmw |
18 | 38 | ||
@@ -29,18 +49,16 @@ flag ~empty LKW \ range(lk-rmw) as unpaired-LKW | |||
29 | (* This will be allowed if we implement spin_is_locked() *) | 49 | (* This will be allowed if we implement spin_is_locked() *) |
30 | flag ~empty LKR \ domain(lk-rmw) as unpaired-LKR | 50 | flag ~empty LKR \ domain(lk-rmw) as unpaired-LKR |
31 | 51 | ||
32 | (* There should be no R or W accesses to spinlocks *) | 52 | (* There should be no ordinary R or W accesses to spinlocks *) |
33 | let ALL-LOCKS = LKR | LKW | UL | LF | 53 | let ALL-LOCKS = LKR | LKW | UL | LF |
34 | flag ~empty [M \ IW] ; loc ; [ALL-LOCKS] as mixed-lock-accesses | 54 | flag ~empty [M \ IW] ; loc ; [ALL-LOCKS] as mixed-lock-accesses |
35 | 55 | ||
36 | (* The final value of a spinlock should not be tested *) | 56 | (* The final value of a spinlock should not be tested *) |
37 | flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final | 57 | flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final |
38 | 58 | ||
39 | (* | 59 | (* Backward compatibility *) |
40 | * Backward compatibility | 60 | let RL = try RL with emptyset |
41 | *) | 61 | let RU = try RU with emptyset |
42 | let RL = try RL with emptyset (* defined herd7 >= 7.49 *) | ||
43 | let RU = try RU with emptyset (* defined herd7 >= 7.49 *) | ||
44 | 62 | ||
45 | (* Treat RL as a kind of LF: a read with no ordering properties *) | 63 | (* Treat RL as a kind of LF: a read with no ordering properties *) |
46 | let LF = LF | RL | 64 | let LF = LF | RL |
@@ -55,7 +73,6 @@ let W = W | LKW | |||
55 | let Release = Release | UL | 73 | let Release = Release | UL |
56 | let Acquire = Acquire | LKR | 74 | let Acquire = Acquire | LKR |
57 | 75 | ||
58 | |||
59 | (* Match LKW events to their corresponding UL events *) | 76 | (* Match LKW events to their corresponding UL events *) |
60 | let critical = ([LKW] ; po-loc ; [UL]) \ (po-loc ; [LKW | UL] ; po-loc) | 77 | let critical = ([LKW] ; po-loc ; [UL]) \ (po-loc ; [LKW | UL] ; po-loc) |
61 | 78 | ||
@@ -65,7 +82,6 @@ flag ~empty UL \ range(critical) as unmatched-unlock | |||
65 | let UNMATCHED-LKW = LKW \ domain(critical) | 82 | let UNMATCHED-LKW = LKW \ domain(critical) |
66 | empty ([UNMATCHED-LKW] ; loc ; [UNMATCHED-LKW]) \ id as unmatched-locks | 83 | empty ([UNMATCHED-LKW] ; loc ; [UNMATCHED-LKW]) \ id as unmatched-locks |
67 | 84 | ||
68 | |||
69 | (* rfi for LF events: link each LKW to the LF events in its critical section *) | 85 | (* rfi for LF events: link each LKW to the LF events in its critical section *) |
70 | let rfi-lf = ([LKW] ; po-loc ; [LF]) \ ([LKW] ; po-loc ; [UL] ; po-loc) | 86 | let rfi-lf = ([LKW] ; po-loc ; [LF]) \ ([LKW] ; po-loc ; [UL] ; po-loc) |
71 | 87 | ||
@@ -86,18 +102,23 @@ let all-possible-rfe-lf = | |||
86 | with rfe-lf from cross(all-possible-rfe-lf) | 102 | with rfe-lf from cross(all-possible-rfe-lf) |
87 | let rf-lf = rfe-lf | rfi-lf | 103 | let rf-lf = rfe-lf | rfi-lf |
88 | 104 | ||
89 | (* Read from unlock, ie islocked returning false, slightly different *) | 105 | (* |
106 | * RU, i.e., spin_is_locked() returning False, is slightly different. | ||
107 | * We rely on the memory model to rule out cases where spin_is_locked() | ||
108 | * within one of the lock's critical sections returns False. | ||
109 | *) | ||
90 | 110 | ||
91 | (* islocked returning false can read from the last po-previous unlock *) | 111 | (* rfi for RU events: an RU may read from the last po-previous UL *) |
92 | let rfi-ru = ([UL] ; po-loc ; [RU]) \ ([UL] ; po-loc ; [LKW] ; po-loc) | 112 | let rfi-ru = ([UL] ; po-loc ; [RU]) \ ([UL] ; po-loc ; [LKW] ; po-loc) |
93 | 113 | ||
94 | (* any islocked returning false can read from any external unlock *) | 114 | (* rfe for RU events: an RU may read from an external UL or the initial write *) |
95 | let all-possible-rfe-ru = | 115 | let all-possible-rfe-ru = |
96 | let possible-rfe-ru r = | 116 | let possible-rfe-ru r = |
97 | let pair-to-relation p = p ++ 0 | 117 | let pair-to-relation p = p ++ 0 |
98 | in map pair-to-relation (((UL|IW) * {r}) & loc & ext) | 118 | in map pair-to-relation (((UL|IW) * {r}) & loc & ext) |
99 | in map possible-rfe-ru RU | 119 | in map possible-rfe-ru RU |
100 | 120 | ||
121 | (* Generate all rf relations for RU events *) | ||
101 | with rfe-ru from cross(all-possible-rfe-ru) | 122 | with rfe-ru from cross(all-possible-rfe-ru) |
102 | let rf-ru = rfe-ru | rfi-ru | 123 | let rf-ru = rfe-ru | rfi-ru |
103 | 124 | ||