1 Modification to the current specifications.
4 -- Sequential order (SO): Some total order that is consistent with the union of
5 happens-before and SC relation.
8 1. Global state: We allow users to specify a single global state so that when we
9 want to execute the sequential replay (execute the sequential order), the whole
10 process is similar to executing an sequential program. Such a global state is
11 similiar to the internal state of a sequential data structure. We also have this
12 in our old version (the rejection of PLDI'16). As an analogy to the cache-memory
13 model, the global state we define here is similar to the main memory in the
14 sense that there does not exist a real total order to all memory accesses, but
15 to some degree (with the non-deterministic specifications) we can have an
16 illution that there is some total order.
18 2. Local State: Beside of having one global state (the one that we have in the
19 old approach), we also allow each method call to have a local state. This local
20 state is the accumulative side effects of the subset of method calls that happen
21 before the current method call. As an analogy to the cache-memory model, the
22 local state we define here is similar to cache, a local state is local to the
23 sense that the current method call must have seen those effects. The main goal
24 of having this is to support tighter non-deterministic specifications.
26 To evaluate the local state of each method call, an obvious approach is to
27 execute the subset of methods that happen before the current method in the
28 sequential order from the initial state. A optimization we can make is that we
29 start to evaluate the state from the most recent deviding node which every other
30 node in that subset is either hb before or after. Also, since local states are
31 not required in specifications all the time, it is only evaluated when needed.
34 Our specification language supports using the following primitives to access
35 both global state and local state so that users can use those to write
36 specifications with different level of tightness.
38 To support tighter specifications, we introduce the concept of concurrent set of
39 method calls, meaning that for a specific method call, it can basically see the
40 effect of two different categories of method calls --- one that happens before
41 it, and one that concurrently execute with it. It is worth noting that when two
42 two method calls execute concurrently, in general there can be the following two
43 effects: 1) those concurrent methods can happen in either order, and the final
44 result remains the same. A concurrent FIFO is an example, in which concurrent
45 enqueue and dequeue methods can happen in a random order; and 2) the order of
46 those concurrent methods will affect the final result. The C/C++11 atomics is an
47 example, in which when concurrent stores to the same location execute in
48 different order, a later store will have different result.
50 1. CONCURRENT: This primitive extracts all the methods that executes
51 "concurrently" with the current method --- neither hb/SC before nor after the
52 current method --- and returns as a set. It is worth noting that the concurrent
53 method calls cannot be accessed for calculating local state but only for
56 2. PREV: This primitive extracts all the methods that execute right before the
57 current method in the execution graph --- most recent method calls that are
58 hb/SC before the current method call --- and returns as a set. For each method
59 in this set, the current method's specification can access their local state.
61 3. NEXT: This primitive extracts all the methods that execute right after the
62 current method in the execution graph, and returns as a set. For each method in
63 this set, the current method's specification cannot access their local state.
65 4. LOCAL: This primitive allows users to access the local state of a method
66 call. It is worth noting that in order to calculate the local state of a method
67 call, one can only access the set of method calls that happen before the current
70 Our specifications allow two ways of calculating the local states, a default way
71 and a user-customized way. The default approach is to execute the set of method
72 calls that happen before the current method call in the sequential order, and a
73 the user-customized approach supports users to calculate the local state by
74 using the PREV primitive to access the local state of previous method calls.
76 5. COPY: This is the function that users provide to deep-copy the state. We
77 require users to provide such a primitive function because each local state
78 should be have its own copy.
80 6. FINALLY: This is the function that allows users to specify some final check
81 on the state. Initially, this check will only access the global state. However,
82 for the concern of expressiveness, we allow users to access the initial state,
83 meaning that users can basically access the whole graph and the local state of
84 each method call. This will enable to users to use the graph model (the relaxed
85 atomics can be specified) although the complxity of using that can get quite
90 // Global specification
91 @DeclareState: // Declare the state structure
92 @InitState: // How do we initialize the state
93 @CopyState: // A function on how to copy an existing state
94 @Commutativity: Method1 <-> Method2 (Guard) // Guard can only access the return
95 // value and the arguments of the two method calls
97 // Interface specification
98 @Interface: InterfaceName // Required; a label to represent the interface
99 @LocalState: // Optional; to calculate the accumulative local state before this
100 // method call in a customized fashion. If not specified here, the
101 // local state would be default, which is the result of the
102 // execution on the subset of method calls in the sequential order
103 @PreCondition: // Optional; checking code
104 @LocalSideEffect: // Optional; to calculate the side effect this method call
105 // have on the local state in a customized fashion. If this
106 // field is not stated, it means we don't care about it.
107 @SideEffect: // Optional; to calculate the side effect on the global state. When
108 // the "@LocalSideEffect" specification is ommitted, we also impose the
109 // same side effect on the set of method calls that happen before this
110 // method call in the sequential order.
111 @PostCondition: // Optional; checking code
113 // Ordering point specification
114 @OPDefine: condition // If the specified condition satisfied, the atomic
115 // operation right before is an ordering point
117 @PotentialOP(Label): condition // If the specified condition satisfied, the
118 // atomic operation right before is a potential
119 // ordering point, and we label it with a tag
121 @OPCheck(Label): condition // If the specified condition satisfied, the
122 // potential ordering point defined earlier with the
123 // same tag becomes an ordering point
125 @OPClear: condition // If the specified condition satisfied, all the
126 // ordering points and potential ordering points will be
129 @OPClearDefine: condition // If the specified condition satisfied, all the
130 // ordering points and potential ordering points will
131 // be cleared, and the atomic operation right before
132 // becomes an ordering point. This is a syntax sugar
133 // as the combination of an "OPClear" and "OPDefine"
137 1. The register examples: Basically, we can think of registers as the cache on a
138 memory system. The effect of a load or store basically tells us what the current
139 value in the cache line is, and a load can read from values that can be
140 potentially in the cache --- either one of the concurrent store update the cache
141 or it inherites one of the the previous local state in the execution graph.
143 ---------- Interfae ----------
144 void init(atomic_int &loc, int initial);
145 int load(atomic_int &loc);
146 void store(atomic_int &loc, int val);
147 ---------- Interfae ----------
149 a. The SC atomics --- the classic linearizability approach
151 b. The RA (release/acquire) C/C++ atomics
152 // For RA atomics, a load must read its value from a store that happens before
154 ---------- Specification ----------
161 void store(int *loc, int val);
165 IntegerSet *prevSet = new IntegerSet;
167 prevSet->add(m.LOCAL.x);
169 return prevSet->contains(RET);
174 c. The C/C++ atomics (a slightly loose specification)
175 // Actually, any concurrent data structures that rely modification-order to be
176 // correct would not have a precicely tight specification under our model, and
177 // C/C++ relaxed atomics is an example. See the following read-read coherence
188 Our model cannot prevent such a case from happening. However, we can still have
189 a slightly loose specification which basically states that a load can read from
190 any store that either immediately happens before it or concurrently executes.
192 ---------- Specification ----------
199 void store(int *loc, int val);
201 // We define a struct called MethodCall to represent the data we would collect
202 // and communicate between the real execution and the checking process
203 typedef struct MethodCall {
204 string interfaceName; // The interface label name
205 void *value; // The pointer that points to the struct that have the return
206 // value and the arguments
207 void *localState; // The pointer that points to the struct that represents
209 vector<MethodCall*> *prev; // Method calls that are hb right before me
210 vector<MethodCall*> *next; // Method calls that are hb right after me
211 vector<MethodCall*> *concurrent; // Method calls that are concurrent with me
214 We will automatically generate two types of struct. One is the state struct, and
215 we will call it StateStruct. This state is shared by all the global and local
216 state. The other one is a per interface struct, and it wraps the return value
217 (RET) and the arguments as its field. We will name those struct with the
218 interface label name.
220 // Some very nice C/C++ macro definition to make specifications a lot easier
221 // 1. ForEach --> to iterate all
222 #define ForEach(item, list) \
223 for (iterator<MethodCall*> _mIter = list->begin(), \
224 MethodCall *item = *_mIter; _mIter != list->end(); item = (++iter != \
225 list->end()) ? *_mIter : NULL)
228 *********************************************
230 TODO:We want subset operation by the equality and inequality of the interface
231 name, a specific (or combined) state and a specific (or combined) of the value
234 // 1.1 Subset(set, name) --> to get a subset of method calls by name
235 inline vector<MethodCall*>* Subset(vector<MethodCall*> *set, string name) {
236 vector<MethodCall*> _subset = new vector<MethodCall*>;
237 for (int i = 0; i < set->size(); i++) {
238 MethodCall *_m = (*set)[i];
239 if (_m->interfaceName == name)
240 _subset->push_back(_m);
245 // 1.2 Size(set) --> to get the size of a method set
246 #define Size(set) set->size()
248 // 1.3 Belong(set, method) --> whether method belongs to set
249 #define Belong(set, method) std::find(set->begin(), set->end(), method) != set->end()
251 // 1.4 Intersect(set1, set2) --> the intersection of two method sets
252 inline MethodSet Intersect(MethodSet set1, MethodSet set2) {
253 MethodSet res = NewSet;
261 // 1.5 Union(set1, set2) --> the union of two method sets
262 inline MethodSet Union(MethodSet set1, MethodSet set2) {
263 MethodSet res = NewSet(set1);
265 if (!Belong(set1, m))
271 // 1.6 Insert(set, method) --> add a method to the set
272 inline bool Insert(MethodSet set, Method m) {
281 // 1.7 Subtract(set1, set2) --> subtract set2 from set1
282 inline MethodSet Subtract(MethodSet set1, MethodSet set2) {
283 MethodSet res = NewSet;
285 if (!Belong(set2, m))
291 // 1.8 MakeSet(count, ...) --> Make a set from the arguments
294 // 2. Local(method, field)
295 #define Local(method, field) ((StateStruct*) method->localState)->field
297 // 3. Value(method, type, field)
298 #define Value(method, type, field) ((type*) method->value)->field
301 #defien Lable(method) method->interfaceName
304 #define Prev(method) mehtod->prev
307 #define Next(method) mehtod->next
309 // 7. Concurrent(method)
310 #define Concurrent(method) mehtod->concurrent
314 // Auto generated code
315 // MethodCall *ME = ((SomeTypeConversion) info)->method;
317 IntegerSet prevSet, concurSet;
319 prevSet->insert(LOCAL(m, x));
321 ForEach (m, Subset(CONCURRENT, "STORE")) {
322 concurSet->insert(Value(m, STORE, val));
324 return prevSet->contains(RET) || concurSet->contains(RET);
329 d. The C/C++ normal memory accesses
330 - Use the admissibility requirement, then the classic linearizability approach
331 on the admissible executions
333 2. The FIFO queue example.
334 ---------- Specification ----------
335 // A FIFO queue should have the following properties held:
336 // 1. The enq() methods should conflict
337 // 2. The deq() methods that succeed should conflict
338 // 3. Corresponding enq() and deq() methods should conflict
339 // 4. An enqueued item can be dequeued by at most once
340 // 5. A dequeued item must have a corresponding enqueued item
341 // 6. When a queue is NOT "empty" (users can tightly or loosely define
342 // emptiness), and there comes a deq() method, the deq() method should succeed
345 @DeclareVar: vector<int> *q;
346 @InitVar: q = new voctor<int>;
347 @Copy: New.q = new vector<int>(Old.q);
349 @Commutativity: Deq <-> Deq (!_M1.RET || !_M2.RET)
350 // The dequeuer doesn't dequeue from that enqueuer
351 @Commutativity: Enq <-> Deq (!_M2.RET || (_M2.RET && Enq.val != *Deq.res))
356 void enq(queue_t *q, int val);
360 // Check whether the queue is really empty
361 // Either the local state is an empty queue, or for all those remaining
362 // elements in the local queue, there should be some concurrent dequeuers to
365 // Local state is empty
366 if (Local.q->size() == 0) return true;
367 // Otherwise check there must be other concurrent dequeuers
368 for (int i = 0; i < Local.q->size(); i++) {
369 int item = (*Local.q)[i];
370 // Check there's some concurrent dequeuer for this item
372 ForEach (m, Subset(CONCURRENT, "Deq")) {
373 if (Value(m, Deq, RET) && *Value(m, Deq, res) == item)
376 if (!flag) return false;
379 } else { // Check the global queue state
380 return q->back() == *res;
385 bool deq(queue_t *q, int *res);
389 A good example to simulate a queue data structure is as follows.
390 Suppose we have a special structure
396 , and we have two interface on Q, read() and write(), where the write and read
397 method calls are synchronized by themselves, and they have to read and write the
398 x and y fields in turn.
418 ----------------------------------------------------------------------------------------
419 We also need to think about the non-ordered queue.
422 Combiming Data Structures ---
423 For example, a queue, a -hb->c, b -hb-> e.
426 enq(1) -> {1} - {$} // a
427 enq(2) -> {1, 2} - {$} // b
430 deq(1) -> {$} - {1} // c
431 deq($) -> {$} - {1} // d
433 // State before this method
434 JOIN ({1, 2} - {$}, {$} - {1}) = {2} - {1}
435 deq(2) -> {$} - {1, 2}