Add phase 3 : scalability run
[urcu.git] / formal-model / results / urcu-controldataflow-no-ipi / urcu_free.spin.input
1
2 // Poison value for freed memory
3 #define POISON 1
4 // Memory with correct data
5 #define WINE 0
6 #define SLAB_SIZE 2
7
8 #define read_poison (data_read_first[0] == POISON || data_read_second[0] == POISON)
9
10 #define RCU_GP_CTR_BIT (1 << 7)
11 #define RCU_GP_CTR_NEST_MASK (RCU_GP_CTR_BIT - 1)
12
13 //disabled
14 //#define REMOTE_BARRIERS
15 /*
16 * mem.spin: Promela code to validate memory barriers with OOO memory
17 * and out-of-order instruction scheduling.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 *
33 * Copyright (c) 2009 Mathieu Desnoyers
34 */
35
36 /* Promela validation variables. */
37
38 /* specific defines "included" here */
39 /* DEFINES file "included" here */
40
41 #define NR_READERS 1
42 #define NR_WRITERS 1
43
44 #define NR_PROCS 2
45
46 #define get_pid() (_pid)
47
48 #define get_readerid() (get_pid())
49
50 /*
51 * Produced process control and data flow. Updated after each instruction to
52 * show which variables are ready. Using one-hot bit encoding per variable to
53 * save state space. Used as triggers to execute the instructions having those
54 * variables as input. Leaving bits active to inhibit instruction execution.
55 * Scheme used to make instruction disabling and automatic dependency fall-back
56 * automatic.
57 */
58
59 #define CONSUME_TOKENS(state, bits, notbits) \
60 ((!(state & (notbits))) && (state & (bits)) == (bits))
61
62 #define PRODUCE_TOKENS(state, bits) \
63 state = state | (bits);
64
65 #define CLEAR_TOKENS(state, bits) \
66 state = state & ~(bits)
67
68 /*
69 * Types of dependency :
70 *
71 * Data dependency
72 *
73 * - True dependency, Read-after-Write (RAW)
74 *
75 * This type of dependency happens when a statement depends on the result of a
76 * previous statement. This applies to any statement which needs to read a
77 * variable written by a preceding statement.
78 *
79 * - False dependency, Write-after-Read (WAR)
80 *
81 * Typically, variable renaming can ensure that this dependency goes away.
82 * However, if the statements must read and then write from/to the same variable
83 * in the OOO memory model, renaming may be impossible, and therefore this
84 * causes a WAR dependency.
85 *
86 * - Output dependency, Write-after-Write (WAW)
87 *
88 * Two writes to the same variable in subsequent statements. Variable renaming
89 * can ensure this is not needed, but can be required when writing multiple
90 * times to the same OOO mem model variable.
91 *
92 * Control dependency
93 *
94 * Execution of a given instruction depends on a previous instruction evaluating
95 * in a way that allows its execution. E.g. : branches.
96 *
97 * Useful considerations for joining dependencies after branch
98 *
99 * - Pre-dominance
100 *
101 * "We say box i dominates box j if every path (leading from input to output
102 * through the diagram) which passes through box j must also pass through box
103 * i. Thus box i dominates box j if box j is subordinate to box i in the
104 * program."
105 *
106 * http://www.hipersoft.rice.edu/grads/publications/dom14.pdf
107 * Other classic algorithm to calculate dominance : Lengauer-Tarjan (in gcc)
108 *
109 * - Post-dominance
110 *
111 * Just as pre-dominance, but with arcs of the data flow inverted, and input vs
112 * output exchanged. Therefore, i post-dominating j ensures that every path
113 * passing by j will pass by i before reaching the output.
114 *
115 * Other considerations
116 *
117 * Note about "volatile" keyword dependency : The compiler will order volatile
118 * accesses so they appear in the right order on a given CPU. They can be
119 * reordered by the CPU instruction scheduling. This therefore cannot be
120 * considered as a depencency.
121 *
122 * References :
123 *
124 * Cooper, Keith D.; & Torczon, Linda. (2005). Engineering a Compiler. Morgan
125 * Kaufmann. ISBN 1-55860-698-X.
126 * Kennedy, Ken; & Allen, Randy. (2001). Optimizing Compilers for Modern
127 * Architectures: A Dependence-based Approach. Morgan Kaufmann. ISBN
128 * 1-55860-286-0.
129 * Muchnick, Steven S. (1997). Advanced Compiler Design and Implementation.
130 * Morgan Kaufmann. ISBN 1-55860-320-4.
131 */
132
133 /*
134 * Note about loops and nested calls
135 *
136 * To keep this model simple, loops expressed in the framework will behave as if
137 * there was a core synchronizing instruction between loops. To see the effect
138 * of loop unrolling, manually unrolling loops is required. Note that if loops
139 * end or start with a core synchronizing instruction, the model is appropriate.
140 * Nested calls are not supported.
141 */
142
143 /*
144 * Each process have its own data in cache. Caches are randomly updated.
145 * smp_wmb and smp_rmb forces cache updates (write and read), smp_mb forces
146 * both.
147 */
148
149 typedef per_proc_byte {
150 byte val[NR_PROCS];
151 };
152
153 typedef per_proc_bit {
154 bit val[NR_PROCS];
155 };
156
157 /* Bitfield has a maximum of 8 procs */
158 typedef per_proc_bitfield {
159 byte bitfield;
160 };
161
162 #define DECLARE_CACHED_VAR(type, x) \
163 type mem_##x; \
164 per_proc_##type cached_##x; \
165 per_proc_bitfield cache_dirty_##x;
166
167 #define INIT_CACHED_VAR(x, v, j) \
168 mem_##x = v; \
169 cache_dirty_##x.bitfield = 0; \
170 j = 0; \
171 do \
172 :: j < NR_PROCS -> \
173 cached_##x.val[j] = v; \
174 j++ \
175 :: j >= NR_PROCS -> break \
176 od;
177
178 #define IS_CACHE_DIRTY(x, id) (cache_dirty_##x.bitfield & (1 << id))
179
180 #define READ_CACHED_VAR(x) (cached_##x.val[get_pid()])
181
182 #define WRITE_CACHED_VAR(x, v) \
183 atomic { \
184 cached_##x.val[get_pid()] = v; \
185 cache_dirty_##x.bitfield = \
186 cache_dirty_##x.bitfield | (1 << get_pid()); \
187 }
188
189 #define CACHE_WRITE_TO_MEM(x, id) \
190 if \
191 :: IS_CACHE_DIRTY(x, id) -> \
192 mem_##x = cached_##x.val[id]; \
193 cache_dirty_##x.bitfield = \
194 cache_dirty_##x.bitfield & (~(1 << id)); \
195 :: else -> \
196 skip \
197 fi;
198
199 #define CACHE_READ_FROM_MEM(x, id) \
200 if \
201 :: !IS_CACHE_DIRTY(x, id) -> \
202 cached_##x.val[id] = mem_##x;\
203 :: else -> \
204 skip \
205 fi;
206
207 /*
208 * May update other caches if cache is dirty, or not.
209 */
210 #define RANDOM_CACHE_WRITE_TO_MEM(x, id)\
211 if \
212 :: 1 -> CACHE_WRITE_TO_MEM(x, id); \
213 :: 1 -> skip \
214 fi;
215
216 #define RANDOM_CACHE_READ_FROM_MEM(x, id)\
217 if \
218 :: 1 -> CACHE_READ_FROM_MEM(x, id); \
219 :: 1 -> skip \
220 fi;
221
222 /* Must consume all prior read tokens. All subsequent reads depend on it. */
223 inline smp_rmb(i, j)
224 {
225 atomic {
226 CACHE_READ_FROM_MEM(urcu_gp_ctr, get_pid());
227 i = 0;
228 do
229 :: i < NR_READERS ->
230 CACHE_READ_FROM_MEM(urcu_active_readers[i], get_pid());
231 i++
232 :: i >= NR_READERS -> break
233 od;
234 CACHE_READ_FROM_MEM(rcu_ptr, get_pid());
235 i = 0;
236 do
237 :: i < SLAB_SIZE ->
238 CACHE_READ_FROM_MEM(rcu_data[i], get_pid());
239 i++
240 :: i >= SLAB_SIZE -> break
241 od;
242 }
243 }
244
245 /* Must consume all prior write tokens. All subsequent writes depend on it. */
246 inline smp_wmb(i, j)
247 {
248 atomic {
249 CACHE_WRITE_TO_MEM(urcu_gp_ctr, get_pid());
250 i = 0;
251 do
252 :: i < NR_READERS ->
253 CACHE_WRITE_TO_MEM(urcu_active_readers[i], get_pid());
254 i++
255 :: i >= NR_READERS -> break
256 od;
257 CACHE_WRITE_TO_MEM(rcu_ptr, get_pid());
258 i = 0;
259 do
260 :: i < SLAB_SIZE ->
261 CACHE_WRITE_TO_MEM(rcu_data[i], get_pid());
262 i++
263 :: i >= SLAB_SIZE -> break
264 od;
265 }
266 }
267
268 /* Synchronization point. Must consume all prior read and write tokens. All
269 * subsequent reads and writes depend on it. */
270 inline smp_mb(i, j)
271 {
272 atomic {
273 smp_wmb(i, j);
274 smp_rmb(i, j);
275 }
276 }
277
278 #ifdef REMOTE_BARRIERS
279
280 bit reader_barrier[NR_READERS];
281
282 /*
283 * We cannot leave the barriers dependencies in place in REMOTE_BARRIERS mode
284 * because they would add unexisting core synchronization and would therefore
285 * create an incomplete model.
286 * Therefore, we model the read-side memory barriers by completely disabling the
287 * memory barriers and their dependencies from the read-side. One at a time
288 * (different verification runs), we make a different instruction listen for
289 * signals.
290 */
291
292 #define smp_mb_reader(i, j)
293
294 /*
295 * Service 0, 1 or many barrier requests.
296 */
297 inline smp_mb_recv(i, j)
298 {
299 do
300 :: (reader_barrier[get_readerid()] == 1) ->
301 /*
302 * We choose to ignore cycles caused by writer busy-looping,
303 * waiting for the reader, sending barrier requests, and the
304 * reader always services them without continuing execution.
305 */
306 progress_ignoring_mb1:
307 smp_mb(i, j);
308 reader_barrier[get_readerid()] = 0;
309 :: 1 ->
310 /*
311 * We choose to ignore writer's non-progress caused by the
312 * reader ignoring the writer's mb() requests.
313 */
314 progress_ignoring_mb2:
315 break;
316 od;
317 }
318
319 //#ifdef WRITER_PROGRESS
320 //#define PROGRESS_LABEL(progressid)
321 //#else
322 //#define PROGRESS_LABEL(progressid)
323 //#endif
324
325 #define PROGRESS_LABEL(progressid) progress_writer_progid_##progressid:
326
327 #define smp_mb_send(i, j, progressid) \
328 { \
329 smp_mb(i, j); \
330 i = 0; \
331 do \
332 :: i < NR_READERS -> \
333 reader_barrier[i] = 1; \
334 /* \
335 * Busy-looping waiting for reader barrier handling is of little\
336 * interest, given the reader has the ability to totally ignore \
337 * barrier requests. \
338 */ \
339 do \
340 :: (reader_barrier[i] == 1) -> \
341 PROGRESS_LABEL(progressid) \
342 skip; \
343 :: (reader_barrier[i] == 0) -> break; \
344 od; \
345 i++; \
346 :: i >= NR_READERS -> \
347 break \
348 od; \
349 smp_mb(i, j); \
350 }
351
352 #else
353
354 #define smp_mb_send(i, j, progressid) smp_mb(i, j)
355 #define smp_mb_reader smp_mb
356 #define smp_mb_recv(i, j)
357
358 #endif
359
360 /* Keep in sync manually with smp_rmb, smp_wmb, ooo_mem and init() */
361 DECLARE_CACHED_VAR(byte, urcu_gp_ctr);
362 /* Note ! currently only one reader */
363 DECLARE_CACHED_VAR(byte, urcu_active_readers[NR_READERS]);
364 /* RCU data */
365 DECLARE_CACHED_VAR(bit, rcu_data[SLAB_SIZE]);
366
367 /* RCU pointer */
368 #if (SLAB_SIZE == 2)
369 DECLARE_CACHED_VAR(bit, rcu_ptr);
370 bit ptr_read_first[NR_READERS];
371 bit ptr_read_second[NR_READERS];
372 #else
373 DECLARE_CACHED_VAR(byte, rcu_ptr);
374 byte ptr_read_first[NR_READERS];
375 byte ptr_read_second[NR_READERS];
376 #endif
377
378 bit data_read_first[NR_READERS];
379 bit data_read_second[NR_READERS];
380
381 bit init_done = 0;
382
383 inline wait_init_done()
384 {
385 do
386 :: init_done == 0 -> skip;
387 :: else -> break;
388 od;
389 }
390
391 inline ooo_mem(i)
392 {
393 atomic {
394 RANDOM_CACHE_WRITE_TO_MEM(urcu_gp_ctr, get_pid());
395 i = 0;
396 do
397 :: i < NR_READERS ->
398 RANDOM_CACHE_WRITE_TO_MEM(urcu_active_readers[i],
399 get_pid());
400 i++
401 :: i >= NR_READERS -> break
402 od;
403 RANDOM_CACHE_WRITE_TO_MEM(rcu_ptr, get_pid());
404 i = 0;
405 do
406 :: i < SLAB_SIZE ->
407 RANDOM_CACHE_WRITE_TO_MEM(rcu_data[i], get_pid());
408 i++
409 :: i >= SLAB_SIZE -> break
410 od;
411 RANDOM_CACHE_READ_FROM_MEM(urcu_gp_ctr, get_pid());
412 i = 0;
413 do
414 :: i < NR_READERS ->
415 RANDOM_CACHE_READ_FROM_MEM(urcu_active_readers[i],
416 get_pid());
417 i++
418 :: i >= NR_READERS -> break
419 od;
420 RANDOM_CACHE_READ_FROM_MEM(rcu_ptr, get_pid());
421 i = 0;
422 do
423 :: i < SLAB_SIZE ->
424 RANDOM_CACHE_READ_FROM_MEM(rcu_data[i], get_pid());
425 i++
426 :: i >= SLAB_SIZE -> break
427 od;
428 }
429 }
430
431 /*
432 * Bit encoding, urcu_reader :
433 */
434
435 int _proc_urcu_reader;
436 #define proc_urcu_reader _proc_urcu_reader
437
438 /* Body of PROCEDURE_READ_LOCK */
439 #define READ_PROD_A_READ (1 << 0)
440 #define READ_PROD_B_IF_TRUE (1 << 1)
441 #define READ_PROD_B_IF_FALSE (1 << 2)
442 #define READ_PROD_C_IF_TRUE_READ (1 << 3)
443
444 #define PROCEDURE_READ_LOCK(base, consumetoken, producetoken) \
445 :: CONSUME_TOKENS(proc_urcu_reader, consumetoken, READ_PROD_A_READ << base) -> \
446 ooo_mem(i); \
447 tmp = READ_CACHED_VAR(urcu_active_readers[get_readerid()]); \
448 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_A_READ << base); \
449 :: CONSUME_TOKENS(proc_urcu_reader, \
450 READ_PROD_A_READ << base, /* RAW, pre-dominant */ \
451 (READ_PROD_B_IF_TRUE | READ_PROD_B_IF_FALSE) << base) -> \
452 if \
453 :: (!(tmp & RCU_GP_CTR_NEST_MASK)) -> \
454 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_B_IF_TRUE << base); \
455 :: else -> \
456 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_B_IF_FALSE << base); \
457 fi; \
458 /* IF TRUE */ \
459 :: CONSUME_TOKENS(proc_urcu_reader, READ_PROD_B_IF_TRUE << base, \
460 READ_PROD_C_IF_TRUE_READ << base) -> \
461 ooo_mem(i); \
462 tmp2 = READ_CACHED_VAR(urcu_gp_ctr); \
463 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_C_IF_TRUE_READ << base); \
464 :: CONSUME_TOKENS(proc_urcu_reader, \
465 (READ_PROD_C_IF_TRUE_READ /* pre-dominant */ \
466 | READ_PROD_A_READ) << base, /* WAR */ \
467 producetoken) -> \
468 ooo_mem(i); \
469 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp2); \
470 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
471 /* IF_MERGE implies \
472 * post-dominance */ \
473 /* ELSE */ \
474 :: CONSUME_TOKENS(proc_urcu_reader, \
475 (READ_PROD_B_IF_FALSE /* pre-dominant */ \
476 | READ_PROD_A_READ) << base, /* WAR */ \
477 producetoken) -> \
478 ooo_mem(i); \
479 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], \
480 tmp + 1); \
481 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
482 /* IF_MERGE implies \
483 * post-dominance */ \
484 /* ENDIF */ \
485 skip
486
487 /* Body of PROCEDURE_READ_LOCK */
488 #define READ_PROC_READ_UNLOCK (1 << 0)
489
490 #define PROCEDURE_READ_UNLOCK(base, consumetoken, producetoken) \
491 :: CONSUME_TOKENS(proc_urcu_reader, \
492 consumetoken, \
493 READ_PROC_READ_UNLOCK << base) -> \
494 ooo_mem(i); \
495 tmp2 = READ_CACHED_VAR(urcu_active_readers[get_readerid()]); \
496 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_READ_UNLOCK << base); \
497 :: CONSUME_TOKENS(proc_urcu_reader, \
498 consumetoken \
499 | (READ_PROC_READ_UNLOCK << base), /* WAR */ \
500 producetoken) -> \
501 ooo_mem(i); \
502 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp2 - 1); \
503 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
504 skip
505
506
507 #define READ_PROD_NONE (1 << 0)
508
509 /* PROCEDURE_READ_LOCK base = << 1 : 1 to 5 */
510 #define READ_LOCK_BASE 1
511 #define READ_LOCK_OUT (1 << 5)
512
513 #define READ_PROC_FIRST_MB (1 << 6)
514
515 /* PROCEDURE_READ_LOCK (NESTED) base : << 7 : 7 to 11 */
516 #define READ_LOCK_NESTED_BASE 7
517 #define READ_LOCK_NESTED_OUT (1 << 11)
518
519 #define READ_PROC_READ_GEN (1 << 12)
520 #define READ_PROC_ACCESS_GEN (1 << 13)
521
522 /* PROCEDURE_READ_UNLOCK (NESTED) base = << 14 : 14 to 15 */
523 #define READ_UNLOCK_NESTED_BASE 14
524 #define READ_UNLOCK_NESTED_OUT (1 << 15)
525
526 #define READ_PROC_SECOND_MB (1 << 16)
527
528 /* PROCEDURE_READ_UNLOCK base = << 17 : 17 to 18 */
529 #define READ_UNLOCK_BASE 17
530 #define READ_UNLOCK_OUT (1 << 18)
531
532 /* PROCEDURE_READ_LOCK_UNROLL base = << 19 : 19 to 23 */
533 #define READ_LOCK_UNROLL_BASE 19
534 #define READ_LOCK_OUT_UNROLL (1 << 23)
535
536 #define READ_PROC_THIRD_MB (1 << 24)
537
538 #define READ_PROC_READ_GEN_UNROLL (1 << 25)
539 #define READ_PROC_ACCESS_GEN_UNROLL (1 << 26)
540
541 #define READ_PROC_FOURTH_MB (1 << 27)
542
543 /* PROCEDURE_READ_UNLOCK_UNROLL base = << 28 : 28 to 29 */
544 #define READ_UNLOCK_UNROLL_BASE 28
545 #define READ_UNLOCK_OUT_UNROLL (1 << 29)
546
547
548 /* Should not include branches */
549 #define READ_PROC_ALL_TOKENS (READ_PROD_NONE \
550 | READ_LOCK_OUT \
551 | READ_PROC_FIRST_MB \
552 | READ_LOCK_NESTED_OUT \
553 | READ_PROC_READ_GEN \
554 | READ_PROC_ACCESS_GEN \
555 | READ_UNLOCK_NESTED_OUT \
556 | READ_PROC_SECOND_MB \
557 | READ_UNLOCK_OUT \
558 | READ_LOCK_OUT_UNROLL \
559 | READ_PROC_THIRD_MB \
560 | READ_PROC_READ_GEN_UNROLL \
561 | READ_PROC_ACCESS_GEN_UNROLL \
562 | READ_PROC_FOURTH_MB \
563 | READ_UNLOCK_OUT_UNROLL)
564
565 /* Must clear all tokens, including branches */
566 #define READ_PROC_ALL_TOKENS_CLEAR ((1 << 30) - 1)
567
568 inline urcu_one_read(i, j, nest_i, tmp, tmp2)
569 {
570 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_NONE);
571
572 #ifdef NO_MB
573 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
574 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
575 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_THIRD_MB);
576 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FOURTH_MB);
577 #endif
578
579 #ifdef REMOTE_BARRIERS
580 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
581 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
582 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_THIRD_MB);
583 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FOURTH_MB);
584 #endif
585
586 do
587 :: 1 ->
588
589 #ifdef REMOTE_BARRIERS
590 /*
591 * Signal-based memory barrier will only execute when the
592 * execution order appears in program order.
593 */
594 if
595 :: 1 ->
596 atomic {
597 if
598 :: CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE,
599 READ_LOCK_OUT | READ_LOCK_NESTED_OUT
600 | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
601 | READ_UNLOCK_OUT
602 | READ_LOCK_OUT_UNROLL
603 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
604 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT,
605 READ_LOCK_NESTED_OUT
606 | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
607 | READ_UNLOCK_OUT
608 | READ_LOCK_OUT_UNROLL
609 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
610 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT | READ_LOCK_NESTED_OUT,
611 READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
612 | READ_UNLOCK_OUT
613 | READ_LOCK_OUT_UNROLL
614 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
615 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
616 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN,
617 READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
618 | READ_UNLOCK_OUT
619 | READ_LOCK_OUT_UNROLL
620 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
621 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
622 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN,
623 READ_UNLOCK_NESTED_OUT
624 | READ_UNLOCK_OUT
625 | READ_LOCK_OUT_UNROLL
626 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
627 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
628 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN
629 | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT,
630 READ_UNLOCK_OUT
631 | READ_LOCK_OUT_UNROLL
632 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
633 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
634 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN
635 | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
636 | READ_UNLOCK_OUT,
637 READ_LOCK_OUT_UNROLL
638 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
639 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
640 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN
641 | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
642 | READ_UNLOCK_OUT | READ_LOCK_OUT_UNROLL,
643 READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
644 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
645 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN
646 | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
647 | READ_UNLOCK_OUT | READ_LOCK_OUT_UNROLL
648 | READ_PROC_READ_GEN_UNROLL,
649 READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL)
650 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
651 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN
652 | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
653 | READ_UNLOCK_OUT | READ_LOCK_OUT_UNROLL
654 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL,
655 READ_UNLOCK_OUT_UNROLL)
656 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE | READ_LOCK_OUT
657 | READ_LOCK_NESTED_OUT | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN | READ_UNLOCK_NESTED_OUT
658 | READ_UNLOCK_OUT | READ_LOCK_OUT_UNROLL
659 | READ_PROC_READ_GEN_UNROLL | READ_PROC_ACCESS_GEN_UNROLL | READ_UNLOCK_OUT_UNROLL,
660 0) ->
661 goto non_atomic3;
662 non_atomic3_end:
663 skip;
664 fi;
665 }
666 fi;
667
668 goto non_atomic3_skip;
669 non_atomic3:
670 smp_mb_recv(i, j);
671 goto non_atomic3_end;
672 non_atomic3_skip:
673
674 #endif /* REMOTE_BARRIERS */
675
676 atomic {
677 if
678 PROCEDURE_READ_LOCK(READ_LOCK_BASE, READ_PROD_NONE, READ_LOCK_OUT);
679
680 :: CONSUME_TOKENS(proc_urcu_reader,
681 READ_LOCK_OUT, /* post-dominant */
682 READ_PROC_FIRST_MB) ->
683 smp_mb_reader(i, j);
684 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
685
686 PROCEDURE_READ_LOCK(READ_LOCK_NESTED_BASE, READ_PROC_FIRST_MB | READ_LOCK_OUT,
687 READ_LOCK_NESTED_OUT);
688
689 :: CONSUME_TOKENS(proc_urcu_reader,
690 READ_PROC_FIRST_MB, /* mb() orders reads */
691 READ_PROC_READ_GEN) ->
692 ooo_mem(i);
693 ptr_read_first[get_readerid()] = READ_CACHED_VAR(rcu_ptr);
694 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_READ_GEN);
695
696 :: CONSUME_TOKENS(proc_urcu_reader,
697 READ_PROC_FIRST_MB /* mb() orders reads */
698 | READ_PROC_READ_GEN,
699 READ_PROC_ACCESS_GEN) ->
700 /* smp_read_barrier_depends */
701 goto rmb1;
702 rmb1_end:
703 data_read_first[get_readerid()] =
704 READ_CACHED_VAR(rcu_data[ptr_read_first[get_readerid()]]);
705 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_ACCESS_GEN);
706
707
708 /* Note : we remove the nested memory barrier from the read unlock
709 * model, given it is not usually needed. The implementation has the barrier
710 * because the performance impact added by a branch in the common case does not
711 * justify it.
712 */
713
714 PROCEDURE_READ_UNLOCK(READ_UNLOCK_NESTED_BASE,
715 READ_PROC_FIRST_MB
716 | READ_LOCK_OUT
717 | READ_LOCK_NESTED_OUT,
718 READ_UNLOCK_NESTED_OUT);
719
720
721 :: CONSUME_TOKENS(proc_urcu_reader,
722 READ_PROC_ACCESS_GEN /* mb() orders reads */
723 | READ_PROC_READ_GEN /* mb() orders reads */
724 | READ_PROC_FIRST_MB /* mb() ordered */
725 | READ_LOCK_OUT /* post-dominant */
726 | READ_LOCK_NESTED_OUT /* post-dominant */
727 | READ_UNLOCK_NESTED_OUT,
728 READ_PROC_SECOND_MB) ->
729 smp_mb_reader(i, j);
730 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
731
732 PROCEDURE_READ_UNLOCK(READ_UNLOCK_BASE,
733 READ_PROC_SECOND_MB /* mb() orders reads */
734 | READ_PROC_FIRST_MB /* mb() orders reads */
735 | READ_LOCK_NESTED_OUT /* RAW */
736 | READ_LOCK_OUT /* RAW */
737 | READ_UNLOCK_NESTED_OUT, /* RAW */
738 READ_UNLOCK_OUT);
739
740 /* Unrolling loop : second consecutive lock */
741 /* reading urcu_active_readers, which have been written by
742 * READ_UNLOCK_OUT : RAW */
743 PROCEDURE_READ_LOCK(READ_LOCK_UNROLL_BASE,
744 READ_UNLOCK_OUT /* RAW */
745 | READ_PROC_SECOND_MB /* mb() orders reads */
746 | READ_PROC_FIRST_MB /* mb() orders reads */
747 | READ_LOCK_NESTED_OUT /* RAW */
748 | READ_LOCK_OUT /* RAW */
749 | READ_UNLOCK_NESTED_OUT, /* RAW */
750 READ_LOCK_OUT_UNROLL);
751
752
753 :: CONSUME_TOKENS(proc_urcu_reader,
754 READ_PROC_FIRST_MB /* mb() ordered */
755 | READ_PROC_SECOND_MB /* mb() ordered */
756 | READ_LOCK_OUT_UNROLL /* post-dominant */
757 | READ_LOCK_NESTED_OUT
758 | READ_LOCK_OUT
759 | READ_UNLOCK_NESTED_OUT
760 | READ_UNLOCK_OUT,
761 READ_PROC_THIRD_MB) ->
762 smp_mb_reader(i, j);
763 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_THIRD_MB);
764
765 :: CONSUME_TOKENS(proc_urcu_reader,
766 READ_PROC_FIRST_MB /* mb() orders reads */
767 | READ_PROC_SECOND_MB /* mb() orders reads */
768 | READ_PROC_THIRD_MB, /* mb() orders reads */
769 READ_PROC_READ_GEN_UNROLL) ->
770 ooo_mem(i);
771 ptr_read_second[get_readerid()] = READ_CACHED_VAR(rcu_ptr);
772 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_READ_GEN_UNROLL);
773
774 :: CONSUME_TOKENS(proc_urcu_reader,
775 READ_PROC_READ_GEN_UNROLL
776 | READ_PROC_FIRST_MB /* mb() orders reads */
777 | READ_PROC_SECOND_MB /* mb() orders reads */
778 | READ_PROC_THIRD_MB, /* mb() orders reads */
779 READ_PROC_ACCESS_GEN_UNROLL) ->
780 /* smp_read_barrier_depends */
781 goto rmb2;
782 rmb2_end:
783 data_read_second[get_readerid()] =
784 READ_CACHED_VAR(rcu_data[ptr_read_second[get_readerid()]]);
785 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_ACCESS_GEN_UNROLL);
786
787 :: CONSUME_TOKENS(proc_urcu_reader,
788 READ_PROC_READ_GEN_UNROLL /* mb() orders reads */
789 | READ_PROC_ACCESS_GEN_UNROLL /* mb() orders reads */
790 | READ_PROC_FIRST_MB /* mb() ordered */
791 | READ_PROC_SECOND_MB /* mb() ordered */
792 | READ_PROC_THIRD_MB /* mb() ordered */
793 | READ_LOCK_OUT_UNROLL /* post-dominant */
794 | READ_LOCK_NESTED_OUT
795 | READ_LOCK_OUT
796 | READ_UNLOCK_NESTED_OUT
797 | READ_UNLOCK_OUT,
798 READ_PROC_FOURTH_MB) ->
799 smp_mb_reader(i, j);
800 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FOURTH_MB);
801
802 PROCEDURE_READ_UNLOCK(READ_UNLOCK_UNROLL_BASE,
803 READ_PROC_FOURTH_MB /* mb() orders reads */
804 | READ_PROC_THIRD_MB /* mb() orders reads */
805 | READ_LOCK_OUT_UNROLL /* RAW */
806 | READ_PROC_SECOND_MB /* mb() orders reads */
807 | READ_PROC_FIRST_MB /* mb() orders reads */
808 | READ_LOCK_NESTED_OUT /* RAW */
809 | READ_LOCK_OUT /* RAW */
810 | READ_UNLOCK_NESTED_OUT, /* RAW */
811 READ_UNLOCK_OUT_UNROLL);
812 :: CONSUME_TOKENS(proc_urcu_reader, READ_PROC_ALL_TOKENS, 0) ->
813 CLEAR_TOKENS(proc_urcu_reader, READ_PROC_ALL_TOKENS_CLEAR);
814 break;
815 fi;
816 }
817 od;
818 /*
819 * Dependency between consecutive loops :
820 * RAW dependency on
821 * WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp2 - 1)
822 * tmp = READ_CACHED_VAR(urcu_active_readers[get_readerid()]);
823 * between loops.
824 * _WHEN THE MB()s are in place_, they add full ordering of the
825 * generation pointer read wrt active reader count read, which ensures
826 * execution will not spill across loop execution.
827 * However, in the event mb()s are removed (execution using signal
828 * handler to promote barrier()() -> smp_mb()), nothing prevents one loop
829 * to spill its execution on other loop's execution.
830 */
831 goto end;
832 rmb1:
833 #ifndef NO_RMB
834 smp_rmb(i, j);
835 #else
836 ooo_mem(i);
837 #endif
838 goto rmb1_end;
839 rmb2:
840 #ifndef NO_RMB
841 smp_rmb(i, j);
842 #else
843 ooo_mem(i);
844 #endif
845 goto rmb2_end;
846 end:
847 skip;
848 }
849
850
851
852 active proctype urcu_reader()
853 {
854 byte i, j, nest_i;
855 byte tmp, tmp2;
856
857 wait_init_done();
858
859 assert(get_pid() < NR_PROCS);
860
861 end_reader:
862 do
863 :: 1 ->
864 /*
865 * We do not test reader's progress here, because we are mainly
866 * interested in writer's progress. The reader never blocks
867 * anyway. We have to test for reader/writer's progress
868 * separately, otherwise we could think the writer is doing
869 * progress when it's blocked by an always progressing reader.
870 */
871 #ifdef READER_PROGRESS
872 progress_reader:
873 #endif
874 urcu_one_read(i, j, nest_i, tmp, tmp2);
875 od;
876 }
877
878 /* no name clash please */
879 #undef proc_urcu_reader
880
881
882 /* Model the RCU update process. */
883
884 /*
885 * Bit encoding, urcu_writer :
886 * Currently only supports one reader.
887 */
888
889 int _proc_urcu_writer;
890 #define proc_urcu_writer _proc_urcu_writer
891
892 #define WRITE_PROD_NONE (1 << 0)
893
894 #define WRITE_DATA (1 << 1)
895 #define WRITE_PROC_WMB (1 << 2)
896 #define WRITE_XCHG_PTR (1 << 3)
897
898 #define WRITE_PROC_FIRST_MB (1 << 4)
899
900 /* first flip */
901 #define WRITE_PROC_FIRST_READ_GP (1 << 5)
902 #define WRITE_PROC_FIRST_WRITE_GP (1 << 6)
903 #define WRITE_PROC_FIRST_WAIT (1 << 7)
904 #define WRITE_PROC_FIRST_WAIT_LOOP (1 << 8)
905
906 /* second flip */
907 #define WRITE_PROC_SECOND_READ_GP (1 << 9)
908 #define WRITE_PROC_SECOND_WRITE_GP (1 << 10)
909 #define WRITE_PROC_SECOND_WAIT (1 << 11)
910 #define WRITE_PROC_SECOND_WAIT_LOOP (1 << 12)
911
912 #define WRITE_PROC_SECOND_MB (1 << 13)
913
914 #define WRITE_FREE (1 << 14)
915
916 #define WRITE_PROC_ALL_TOKENS (WRITE_PROD_NONE \
917 | WRITE_DATA \
918 | WRITE_PROC_WMB \
919 | WRITE_XCHG_PTR \
920 | WRITE_PROC_FIRST_MB \
921 | WRITE_PROC_FIRST_READ_GP \
922 | WRITE_PROC_FIRST_WRITE_GP \
923 | WRITE_PROC_FIRST_WAIT \
924 | WRITE_PROC_SECOND_READ_GP \
925 | WRITE_PROC_SECOND_WRITE_GP \
926 | WRITE_PROC_SECOND_WAIT \
927 | WRITE_PROC_SECOND_MB \
928 | WRITE_FREE)
929
930 #define WRITE_PROC_ALL_TOKENS_CLEAR ((1 << 15) - 1)
931
932 /*
933 * Mutexes are implied around writer execution. A single writer at a time.
934 */
935 active proctype urcu_writer()
936 {
937 byte i, j;
938 byte tmp, tmp2, tmpa;
939 byte cur_data = 0, old_data, loop_nr = 0;
940 byte cur_gp_val = 0; /*
941 * Keep a local trace of the current parity so
942 * we don't add non-existing dependencies on the global
943 * GP update. Needed to test single flip case.
944 */
945
946 wait_init_done();
947
948 assert(get_pid() < NR_PROCS);
949
950 do
951 :: (loop_nr < 3) ->
952 #ifdef WRITER_PROGRESS
953 progress_writer1:
954 #endif
955 loop_nr = loop_nr + 1;
956
957 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROD_NONE);
958
959 #ifdef NO_WMB
960 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_WMB);
961 #endif
962
963 #ifdef NO_MB
964 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_MB);
965 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_MB);
966 #endif
967
968 #ifdef SINGLE_FLIP
969 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_READ_GP);
970 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WRITE_GP);
971 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT);
972 /* For single flip, we need to know the current parity */
973 cur_gp_val = cur_gp_val ^ RCU_GP_CTR_BIT;
974 #endif
975
976 do :: 1 ->
977 atomic {
978 if
979
980 :: CONSUME_TOKENS(proc_urcu_writer,
981 WRITE_PROD_NONE,
982 WRITE_DATA) ->
983 ooo_mem(i);
984 cur_data = (cur_data + 1) % SLAB_SIZE;
985 WRITE_CACHED_VAR(rcu_data[cur_data], WINE);
986 PRODUCE_TOKENS(proc_urcu_writer, WRITE_DATA);
987
988
989 :: CONSUME_TOKENS(proc_urcu_writer,
990 WRITE_DATA,
991 WRITE_PROC_WMB) ->
992 smp_wmb(i, j);
993 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_WMB);
994
995 :: CONSUME_TOKENS(proc_urcu_writer,
996 WRITE_PROC_WMB,
997 WRITE_XCHG_PTR) ->
998 /* rcu_xchg_pointer() */
999 atomic {
1000 old_data = READ_CACHED_VAR(rcu_ptr);
1001 WRITE_CACHED_VAR(rcu_ptr, cur_data);
1002 }
1003 PRODUCE_TOKENS(proc_urcu_writer, WRITE_XCHG_PTR);
1004
1005 :: CONSUME_TOKENS(proc_urcu_writer,
1006 WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR,
1007 WRITE_PROC_FIRST_MB) ->
1008 goto smp_mb_send1;
1009 smp_mb_send1_end:
1010 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_MB);
1011
1012 /* first flip */
1013 :: CONSUME_TOKENS(proc_urcu_writer,
1014 WRITE_PROC_FIRST_MB,
1015 WRITE_PROC_FIRST_READ_GP) ->
1016 tmpa = READ_CACHED_VAR(urcu_gp_ctr);
1017 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_READ_GP);
1018 :: CONSUME_TOKENS(proc_urcu_writer,
1019 WRITE_PROC_FIRST_MB | WRITE_PROC_WMB
1020 | WRITE_PROC_FIRST_READ_GP,
1021 WRITE_PROC_FIRST_WRITE_GP) ->
1022 ooo_mem(i);
1023 WRITE_CACHED_VAR(urcu_gp_ctr, tmpa ^ RCU_GP_CTR_BIT);
1024 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WRITE_GP);
1025
1026 :: CONSUME_TOKENS(proc_urcu_writer,
1027 //WRITE_PROC_FIRST_WRITE_GP /* TEST ADDING SYNC CORE */
1028 WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1029 WRITE_PROC_FIRST_WAIT | WRITE_PROC_FIRST_WAIT_LOOP) ->
1030 ooo_mem(i);
1031 /* ONLY WAITING FOR READER 0 */
1032 tmp2 = READ_CACHED_VAR(urcu_active_readers[0]);
1033 #ifndef SINGLE_FLIP
1034 /* In normal execution, we are always starting by
1035 * waiting for the even parity.
1036 */
1037 cur_gp_val = RCU_GP_CTR_BIT;
1038 #endif
1039 if
1040 :: (tmp2 & RCU_GP_CTR_NEST_MASK)
1041 && ((tmp2 ^ cur_gp_val) & RCU_GP_CTR_BIT) ->
1042 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT_LOOP);
1043 :: else ->
1044 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT);
1045 fi;
1046
1047 :: CONSUME_TOKENS(proc_urcu_writer,
1048 //WRITE_PROC_FIRST_WRITE_GP /* TEST ADDING SYNC CORE */
1049 WRITE_PROC_FIRST_WRITE_GP
1050 | WRITE_PROC_FIRST_READ_GP
1051 | WRITE_PROC_FIRST_WAIT_LOOP
1052 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
1053 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1054 0) ->
1055 #ifndef GEN_ERROR_WRITER_PROGRESS
1056 goto smp_mb_send2;
1057 smp_mb_send2_end:
1058 #else
1059 ooo_mem(i);
1060 #endif
1061 /* This instruction loops to WRITE_PROC_FIRST_WAIT */
1062 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT_LOOP | WRITE_PROC_FIRST_WAIT);
1063
1064 /* second flip */
1065 :: CONSUME_TOKENS(proc_urcu_writer,
1066 WRITE_PROC_FIRST_WAIT /* Control dependency : need to branch out of
1067 * the loop to execute the next flip (CHECK) */
1068 | WRITE_PROC_FIRST_WRITE_GP
1069 | WRITE_PROC_FIRST_READ_GP
1070 | WRITE_PROC_FIRST_MB,
1071 WRITE_PROC_SECOND_READ_GP) ->
1072 ooo_mem(i);
1073 tmpa = READ_CACHED_VAR(urcu_gp_ctr);
1074 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_READ_GP);
1075 :: CONSUME_TOKENS(proc_urcu_writer,
1076 WRITE_PROC_FIRST_MB
1077 | WRITE_PROC_WMB
1078 | WRITE_PROC_FIRST_READ_GP
1079 | WRITE_PROC_FIRST_WRITE_GP
1080 | WRITE_PROC_SECOND_READ_GP,
1081 WRITE_PROC_SECOND_WRITE_GP) ->
1082 ooo_mem(i);
1083 WRITE_CACHED_VAR(urcu_gp_ctr, tmpa ^ RCU_GP_CTR_BIT);
1084 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WRITE_GP);
1085
1086 :: CONSUME_TOKENS(proc_urcu_writer,
1087 //WRITE_PROC_FIRST_WRITE_GP /* TEST ADDING SYNC CORE */
1088 WRITE_PROC_FIRST_WAIT
1089 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1090 WRITE_PROC_SECOND_WAIT | WRITE_PROC_SECOND_WAIT_LOOP) ->
1091 ooo_mem(i);
1092 /* ONLY WAITING FOR READER 0 */
1093 tmp2 = READ_CACHED_VAR(urcu_active_readers[0]);
1094 if
1095 :: (tmp2 & RCU_GP_CTR_NEST_MASK)
1096 && ((tmp2 ^ 0) & RCU_GP_CTR_BIT) ->
1097 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT_LOOP);
1098 :: else ->
1099 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT);
1100 fi;
1101
1102 :: CONSUME_TOKENS(proc_urcu_writer,
1103 //WRITE_PROC_FIRST_WRITE_GP /* TEST ADDING SYNC CORE */
1104 WRITE_PROC_SECOND_WRITE_GP
1105 | WRITE_PROC_FIRST_WRITE_GP
1106 | WRITE_PROC_SECOND_READ_GP
1107 | WRITE_PROC_FIRST_READ_GP
1108 | WRITE_PROC_SECOND_WAIT_LOOP
1109 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
1110 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1111 0) ->
1112 #ifndef GEN_ERROR_WRITER_PROGRESS
1113 goto smp_mb_send3;
1114 smp_mb_send3_end:
1115 #else
1116 ooo_mem(i);
1117 #endif
1118 /* This instruction loops to WRITE_PROC_SECOND_WAIT */
1119 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT_LOOP | WRITE_PROC_SECOND_WAIT);
1120
1121
1122 :: CONSUME_TOKENS(proc_urcu_writer,
1123 WRITE_PROC_FIRST_WAIT
1124 | WRITE_PROC_SECOND_WAIT
1125 | WRITE_PROC_FIRST_READ_GP
1126 | WRITE_PROC_SECOND_READ_GP
1127 | WRITE_PROC_FIRST_WRITE_GP
1128 | WRITE_PROC_SECOND_WRITE_GP
1129 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
1130 | WRITE_PROC_FIRST_MB,
1131 WRITE_PROC_SECOND_MB) ->
1132 goto smp_mb_send4;
1133 smp_mb_send4_end:
1134 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_MB);
1135
1136 :: CONSUME_TOKENS(proc_urcu_writer,
1137 WRITE_XCHG_PTR
1138 | WRITE_PROC_FIRST_WAIT
1139 | WRITE_PROC_SECOND_WAIT
1140 | WRITE_PROC_WMB /* No dependency on
1141 * WRITE_DATA because we
1142 * write to a
1143 * different location. */
1144 | WRITE_PROC_SECOND_MB
1145 | WRITE_PROC_FIRST_MB,
1146 WRITE_FREE) ->
1147 WRITE_CACHED_VAR(rcu_data[old_data], POISON);
1148 PRODUCE_TOKENS(proc_urcu_writer, WRITE_FREE);
1149
1150 :: CONSUME_TOKENS(proc_urcu_writer, WRITE_PROC_ALL_TOKENS, 0) ->
1151 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_ALL_TOKENS_CLEAR);
1152 break;
1153 fi;
1154 }
1155 od;
1156 /*
1157 * Note : Promela model adds implicit serialization of the
1158 * WRITE_FREE instruction. Normally, it would be permitted to
1159 * spill on the next loop execution. Given the validation we do
1160 * checks for the data entry read to be poisoned, it's ok if
1161 * we do not check "late arriving" memory poisoning.
1162 */
1163 :: else -> break;
1164 od;
1165 /*
1166 * Given the reader loops infinitely, let the writer also busy-loop
1167 * with progress here so, with weak fairness, we can test the
1168 * writer's progress.
1169 */
1170 end_writer:
1171 do
1172 :: 1 ->
1173 #ifdef WRITER_PROGRESS
1174 progress_writer2:
1175 #endif
1176 #ifdef READER_PROGRESS
1177 /*
1178 * Make sure we don't block the reader's progress.
1179 */
1180 smp_mb_send(i, j, 5);
1181 #endif
1182 skip;
1183 od;
1184
1185 /* Non-atomic parts of the loop */
1186 goto end;
1187 smp_mb_send1:
1188 smp_mb_send(i, j, 1);
1189 goto smp_mb_send1_end;
1190 #ifndef GEN_ERROR_WRITER_PROGRESS
1191 smp_mb_send2:
1192 smp_mb_send(i, j, 2);
1193 goto smp_mb_send2_end;
1194 smp_mb_send3:
1195 smp_mb_send(i, j, 3);
1196 goto smp_mb_send3_end;
1197 #endif
1198 smp_mb_send4:
1199 smp_mb_send(i, j, 4);
1200 goto smp_mb_send4_end;
1201 end:
1202 skip;
1203 }
1204
1205 /* no name clash please */
1206 #undef proc_urcu_writer
1207
1208
1209 /* Leave after the readers and writers so the pid count is ok. */
1210 init {
1211 byte i, j;
1212
1213 atomic {
1214 INIT_CACHED_VAR(urcu_gp_ctr, 1, j);
1215 INIT_CACHED_VAR(rcu_ptr, 0, j);
1216
1217 i = 0;
1218 do
1219 :: i < NR_READERS ->
1220 INIT_CACHED_VAR(urcu_active_readers[i], 0, j);
1221 ptr_read_first[i] = 1;
1222 ptr_read_second[i] = 1;
1223 data_read_first[i] = WINE;
1224 data_read_second[i] = WINE;
1225 i++;
1226 :: i >= NR_READERS -> break
1227 od;
1228 INIT_CACHED_VAR(rcu_data[0], WINE, j);
1229 i = 1;
1230 do
1231 :: i < SLAB_SIZE ->
1232 INIT_CACHED_VAR(rcu_data[i], POISON, j);
1233 i++
1234 :: i >= SLAB_SIZE -> break
1235 od;
1236
1237 init_done = 1;
1238 }
1239 }
This page took 0.08145 seconds and 4 git commands to generate.