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