1 #define WRITER_PROGRESS
3 // Poison value for freed memory
5 // Memory with correct data
9 #define read_poison (data_read_first[0] == POISON)
11 #define RCU_GP_CTR_BIT (1 << 7)
12 #define RCU_GP_CTR_NEST_MASK (RCU_GP_CTR_BIT - 1)
15 #define REMOTE_BARRIERS
19 //#define ARCH_POWERPC
21 * mem.spin: Promela code to validate memory barriers with OOO memory
22 * and out-of-order instruction scheduling.
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * Copyright (c) 2009 Mathieu Desnoyers
41 /* Promela validation variables. */
43 /* specific defines "included" here */
44 /* DEFINES file "included" here */
51 #define get_pid() (_pid)
53 #define get_readerid() (get_pid())
56 * Produced process control and data flow. Updated after each instruction to
57 * show which variables are ready. Using one-hot bit encoding per variable to
58 * save state space. Used as triggers to execute the instructions having those
59 * variables as input. Leaving bits active to inhibit instruction execution.
60 * Scheme used to make instruction disabling and automatic dependency fall-back
64 #define CONSUME_TOKENS(state, bits, notbits) \
65 ((!(state & (notbits))) && (state & (bits)) == (bits))
67 #define PRODUCE_TOKENS(state, bits) \
68 state = state | (bits);
70 #define CLEAR_TOKENS(state, bits) \
71 state = state & ~(bits)
74 * Types of dependency :
78 * - True dependency, Read-after-Write (RAW)
80 * This type of dependency happens when a statement depends on the result of a
81 * previous statement. This applies to any statement which needs to read a
82 * variable written by a preceding statement.
84 * - False dependency, Write-after-Read (WAR)
86 * Typically, variable renaming can ensure that this dependency goes away.
87 * However, if the statements must read and then write from/to the same variable
88 * in the OOO memory model, renaming may be impossible, and therefore this
89 * causes a WAR dependency.
91 * - Output dependency, Write-after-Write (WAW)
93 * Two writes to the same variable in subsequent statements. Variable renaming
94 * can ensure this is not needed, but can be required when writing multiple
95 * times to the same OOO mem model variable.
99 * Execution of a given instruction depends on a previous instruction evaluating
100 * in a way that allows its execution. E.g. : branches.
102 * Useful considerations for joining dependencies after branch
106 * "We say box i dominates box j if every path (leading from input to output
107 * through the diagram) which passes through box j must also pass through box
108 * i. Thus box i dominates box j if box j is subordinate to box i in the
111 * http://www.hipersoft.rice.edu/grads/publications/dom14.pdf
112 * Other classic algorithm to calculate dominance : Lengauer-Tarjan (in gcc)
116 * Just as pre-dominance, but with arcs of the data flow inverted, and input vs
117 * output exchanged. Therefore, i post-dominating j ensures that every path
118 * passing by j will pass by i before reaching the output.
120 * Prefetch and speculative execution
122 * If an instruction depends on the result of a previous branch, but it does not
123 * have side-effects, it can be executed before the branch result is known.
124 * however, it must be restarted if a core-synchronizing instruction is issued.
125 * Note that instructions which depend on the speculative instruction result
126 * but that have side-effects must depend on the branch completion in addition
127 * to the speculatively executed instruction.
129 * Other considerations
131 * Note about "volatile" keyword dependency : The compiler will order volatile
132 * accesses so they appear in the right order on a given CPU. They can be
133 * reordered by the CPU instruction scheduling. This therefore cannot be
134 * considered as a depencency.
138 * Cooper, Keith D.; & Torczon, Linda. (2005). Engineering a Compiler. Morgan
139 * Kaufmann. ISBN 1-55860-698-X.
140 * Kennedy, Ken; & Allen, Randy. (2001). Optimizing Compilers for Modern
141 * Architectures: A Dependence-based Approach. Morgan Kaufmann. ISBN
143 * Muchnick, Steven S. (1997). Advanced Compiler Design and Implementation.
144 * Morgan Kaufmann. ISBN 1-55860-320-4.
148 * Note about loops and nested calls
150 * To keep this model simple, loops expressed in the framework will behave as if
151 * there was a core synchronizing instruction between loops. To see the effect
152 * of loop unrolling, manually unrolling loops is required. Note that if loops
153 * end or start with a core synchronizing instruction, the model is appropriate.
154 * Nested calls are not supported.
158 * Only Alpha has out-of-order cache bank loads. Other architectures (intel,
159 * powerpc, arm) ensure that dependent reads won't be reordered. c.f.
160 * http://www.linuxjournal.com/article/8212)
163 #define HAVE_OOO_CACHE_READ
167 * Each process have its own data in cache. Caches are randomly updated.
168 * smp_wmb and smp_rmb forces cache updates (write and read), smp_mb forces
172 typedef per_proc_byte {
176 typedef per_proc_bit {
180 /* Bitfield has a maximum of 8 procs */
181 typedef per_proc_bitfield {
185 #define DECLARE_CACHED_VAR(type, x) \
188 #define DECLARE_PROC_CACHED_VAR(type, x)\
192 #define INIT_CACHED_VAR(x, v) \
195 #define INIT_PROC_CACHED_VAR(x, v) \
196 cache_dirty_##x = 0; \
199 #define IS_CACHE_DIRTY(x, id) (cache_dirty_##x)
201 #define READ_CACHED_VAR(x) (cached_##x)
203 #define WRITE_CACHED_VAR(x, v) \
206 cache_dirty_##x = 1; \
209 #define CACHE_WRITE_TO_MEM(x, id) \
211 :: IS_CACHE_DIRTY(x, id) -> \
212 mem_##x = cached_##x; \
213 cache_dirty_##x = 0; \
218 #define CACHE_READ_FROM_MEM(x, id) \
220 :: !IS_CACHE_DIRTY(x, id) -> \
221 cached_##x = mem_##x; \
227 * May update other caches if cache is dirty, or not.
229 #define RANDOM_CACHE_WRITE_TO_MEM(x, id)\
231 :: 1 -> CACHE_WRITE_TO_MEM(x, id); \
235 #define RANDOM_CACHE_READ_FROM_MEM(x, id)\
237 :: 1 -> CACHE_READ_FROM_MEM(x, id); \
241 /* Must consume all prior read tokens. All subsequent reads depend on it. */
245 CACHE_READ_FROM_MEM(urcu_gp_ctr, get_pid());
249 CACHE_READ_FROM_MEM(urcu_active_readers[i], get_pid());
251 :: i >= NR_READERS -> break
253 CACHE_READ_FROM_MEM(rcu_ptr, get_pid());
257 CACHE_READ_FROM_MEM(rcu_data[i], get_pid());
259 :: i >= SLAB_SIZE -> break
264 /* Must consume all prior write tokens. All subsequent writes depend on it. */
268 CACHE_WRITE_TO_MEM(urcu_gp_ctr, get_pid());
272 CACHE_WRITE_TO_MEM(urcu_active_readers[i], get_pid());
274 :: i >= NR_READERS -> break
276 CACHE_WRITE_TO_MEM(rcu_ptr, get_pid());
280 CACHE_WRITE_TO_MEM(rcu_data[i], get_pid());
282 :: i >= SLAB_SIZE -> break
287 /* Synchronization point. Must consume all prior read and write tokens. All
288 * subsequent reads and writes depend on it. */
297 #ifdef REMOTE_BARRIERS
299 bit reader_barrier[NR_READERS];
302 * We cannot leave the barriers dependencies in place in REMOTE_BARRIERS mode
303 * because they would add unexisting core synchronization and would therefore
304 * create an incomplete model.
305 * Therefore, we model the read-side memory barriers by completely disabling the
306 * memory barriers and their dependencies from the read-side. One at a time
307 * (different verification runs), we make a different instruction listen for
311 #define smp_mb_reader(i, j)
314 * Service 0, 1 or many barrier requests.
316 inline smp_mb_recv(i, j)
319 :: (reader_barrier[get_readerid()] == 1) ->
321 * We choose to ignore cycles caused by writer busy-looping,
322 * waiting for the reader, sending barrier requests, and the
323 * reader always services them without continuing execution.
325 progress_ignoring_mb1:
327 reader_barrier[get_readerid()] = 0;
330 * We choose to ignore writer's non-progress caused by the
331 * reader ignoring the writer's mb() requests.
333 progress_ignoring_mb2:
338 #define PROGRESS_LABEL(progressid) progress_writer_progid_##progressid:
340 #define smp_mb_send(i, j, progressid) \
345 :: i < NR_READERS -> \
346 reader_barrier[i] = 1; \
348 * Busy-looping waiting for reader barrier handling is of little\
349 * interest, given the reader has the ability to totally ignore \
350 * barrier requests. \
353 :: (reader_barrier[i] == 1) -> \
354 PROGRESS_LABEL(progressid) \
356 :: (reader_barrier[i] == 0) -> break; \
359 :: i >= NR_READERS -> \
367 #define smp_mb_send(i, j, progressid) smp_mb(i)
368 #define smp_mb_reader(i, j) smp_mb(i)
369 #define smp_mb_recv(i, j)
373 /* Keep in sync manually with smp_rmb, smp_wmb, ooo_mem and init() */
374 DECLARE_CACHED_VAR(byte, urcu_gp_ctr);
375 /* Note ! currently only one reader */
376 DECLARE_CACHED_VAR(byte, urcu_active_readers[NR_READERS]);
378 DECLARE_CACHED_VAR(bit, rcu_data[SLAB_SIZE]);
382 DECLARE_CACHED_VAR(bit, rcu_ptr);
383 bit ptr_read_first[NR_READERS];
385 DECLARE_CACHED_VAR(byte, rcu_ptr);
386 byte ptr_read_first[NR_READERS];
389 bit data_read_first[NR_READERS];
393 inline wait_init_done()
396 :: init_done == 0 -> skip;
404 RANDOM_CACHE_WRITE_TO_MEM(urcu_gp_ctr, get_pid());
408 RANDOM_CACHE_WRITE_TO_MEM(urcu_active_readers[i],
411 :: i >= NR_READERS -> break
413 RANDOM_CACHE_WRITE_TO_MEM(rcu_ptr, get_pid());
417 RANDOM_CACHE_WRITE_TO_MEM(rcu_data[i], get_pid());
419 :: i >= SLAB_SIZE -> break
421 #ifdef HAVE_OOO_CACHE_READ
422 RANDOM_CACHE_READ_FROM_MEM(urcu_gp_ctr, get_pid());
426 RANDOM_CACHE_READ_FROM_MEM(urcu_active_readers[i],
429 :: i >= NR_READERS -> break
431 RANDOM_CACHE_READ_FROM_MEM(rcu_ptr, get_pid());
435 RANDOM_CACHE_READ_FROM_MEM(rcu_data[i], get_pid());
437 :: i >= SLAB_SIZE -> break
441 #endif /* HAVE_OOO_CACHE_READ */
446 * Bit encoding, urcu_reader :
449 int _proc_urcu_reader;
450 #define proc_urcu_reader _proc_urcu_reader
452 /* Body of PROCEDURE_READ_LOCK */
453 #define READ_PROD_A_READ (1 << 0)
454 #define READ_PROD_B_IF_TRUE (1 << 1)
455 #define READ_PROD_B_IF_FALSE (1 << 2)
456 #define READ_PROD_C_IF_TRUE_READ (1 << 3)
458 #define PROCEDURE_READ_LOCK(base, consumetoken, consumetoken2, producetoken) \
459 :: CONSUME_TOKENS(proc_urcu_reader, (consumetoken | consumetoken2), READ_PROD_A_READ << base) -> \
461 tmp = READ_CACHED_VAR(urcu_active_readers[get_readerid()]); \
462 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_A_READ << base); \
463 :: CONSUME_TOKENS(proc_urcu_reader, \
464 READ_PROD_A_READ << base, /* RAW, pre-dominant */ \
465 (READ_PROD_B_IF_TRUE | READ_PROD_B_IF_FALSE) << base) -> \
467 :: (!(tmp & RCU_GP_CTR_NEST_MASK)) -> \
468 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_B_IF_TRUE << base); \
470 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_B_IF_FALSE << base); \
473 :: CONSUME_TOKENS(proc_urcu_reader, consumetoken, /* prefetch */ \
474 READ_PROD_C_IF_TRUE_READ << base) -> \
476 tmp2 = READ_CACHED_VAR(urcu_gp_ctr); \
477 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_C_IF_TRUE_READ << base); \
478 :: CONSUME_TOKENS(proc_urcu_reader, \
479 (READ_PROD_B_IF_TRUE \
480 | READ_PROD_C_IF_TRUE_READ /* pre-dominant */ \
481 | READ_PROD_A_READ) << base, /* WAR */ \
484 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp2); \
485 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
486 /* IF_MERGE implies \
487 * post-dominance */ \
489 :: CONSUME_TOKENS(proc_urcu_reader, \
490 (READ_PROD_B_IF_FALSE /* pre-dominant */ \
491 | READ_PROD_A_READ) << base, /* WAR */ \
494 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], \
496 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
497 /* IF_MERGE implies \
498 * post-dominance */ \
502 /* Body of PROCEDURE_READ_LOCK */
503 #define READ_PROC_READ_UNLOCK (1 << 0)
505 #define PROCEDURE_READ_UNLOCK(base, consumetoken, producetoken) \
506 :: CONSUME_TOKENS(proc_urcu_reader, \
508 READ_PROC_READ_UNLOCK << base) -> \
510 tmp = READ_CACHED_VAR(urcu_active_readers[get_readerid()]); \
511 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_READ_UNLOCK << base); \
512 :: CONSUME_TOKENS(proc_urcu_reader, \
514 | (READ_PROC_READ_UNLOCK << base), /* WAR */ \
517 WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp - 1); \
518 PRODUCE_TOKENS(proc_urcu_reader, producetoken); \
522 #define READ_PROD_NONE (1 << 0)
524 /* PROCEDURE_READ_LOCK base = << 1 : 1 to 5 */
525 #define READ_LOCK_BASE 1
526 #define READ_LOCK_OUT (1 << 5)
528 #define READ_PROC_FIRST_MB (1 << 6)
530 #define READ_PROC_READ_GEN (1 << 12)
531 #define READ_PROC_ACCESS_GEN (1 << 13)
533 #define READ_PROC_SECOND_MB (1 << 16)
535 /* PROCEDURE_READ_UNLOCK base = << 17 : 17 to 18 */
536 #define READ_UNLOCK_BASE 17
537 #define READ_UNLOCK_OUT (1 << 18)
539 /* Should not include branches */
540 #define READ_PROC_ALL_TOKENS (READ_PROD_NONE \
542 | READ_PROC_FIRST_MB \
543 | READ_PROC_READ_GEN \
544 | READ_PROC_ACCESS_GEN \
545 | READ_PROC_SECOND_MB \
548 /* Must clear all tokens, including branches */
549 #define READ_PROC_ALL_TOKENS_CLEAR ((1 << 30) - 1)
551 inline urcu_one_read(i, j, nest_i, tmp, tmp2)
553 PRODUCE_TOKENS(proc_urcu_reader, READ_PROD_NONE);
556 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
557 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
560 #ifdef REMOTE_BARRIERS
561 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
562 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
568 #ifdef REMOTE_BARRIERS
570 * Signal-based memory barrier will only execute when the
571 * execution order appears in program order.
577 :: CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE,
579 | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN
581 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE
583 READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN
585 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE
587 | READ_PROC_READ_GEN, READ_PROC_ACCESS_GEN
589 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE
591 | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN,
593 || CONSUME_TOKENS(proc_urcu_reader, READ_PROD_NONE
595 | READ_PROC_READ_GEN | READ_PROC_ACCESS_GEN
596 | READ_UNLOCK_OUT, 0) ->
604 goto non_atomic3_skip;
607 goto non_atomic3_end;
610 #endif /* REMOTE_BARRIERS */
614 PROCEDURE_READ_LOCK(READ_LOCK_BASE, READ_PROD_NONE, 0, READ_LOCK_OUT);
616 :: CONSUME_TOKENS(proc_urcu_reader,
617 READ_LOCK_OUT, /* post-dominant */
618 READ_PROC_FIRST_MB) ->
620 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_FIRST_MB);
622 :: CONSUME_TOKENS(proc_urcu_reader,
623 READ_PROC_FIRST_MB, /* mb() orders reads */
624 READ_PROC_READ_GEN) ->
626 ptr_read_first[get_readerid()] = READ_CACHED_VAR(rcu_ptr);
627 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_READ_GEN);
629 :: CONSUME_TOKENS(proc_urcu_reader,
630 READ_PROC_FIRST_MB /* mb() orders reads */
631 | READ_PROC_READ_GEN,
632 READ_PROC_ACCESS_GEN) ->
633 /* smp_read_barrier_depends */
636 data_read_first[get_readerid()] =
637 READ_CACHED_VAR(rcu_data[ptr_read_first[get_readerid()]]);
638 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_ACCESS_GEN);
641 :: CONSUME_TOKENS(proc_urcu_reader,
642 READ_PROC_ACCESS_GEN /* mb() orders reads */
643 | READ_PROC_READ_GEN /* mb() orders reads */
644 | READ_PROC_FIRST_MB /* mb() ordered */
645 | READ_LOCK_OUT, /* post-dominant */
646 READ_PROC_SECOND_MB) ->
648 PRODUCE_TOKENS(proc_urcu_reader, READ_PROC_SECOND_MB);
650 PROCEDURE_READ_UNLOCK(READ_UNLOCK_BASE,
651 READ_PROC_SECOND_MB /* mb() orders reads */
652 | READ_PROC_FIRST_MB /* mb() orders reads */
653 | READ_LOCK_OUT, /* RAW */
656 :: CONSUME_TOKENS(proc_urcu_reader, READ_PROC_ALL_TOKENS, 0) ->
657 CLEAR_TOKENS(proc_urcu_reader, READ_PROC_ALL_TOKENS_CLEAR);
663 * Dependency between consecutive loops :
665 * WRITE_CACHED_VAR(urcu_active_readers[get_readerid()], tmp2 - 1)
666 * tmp = READ_CACHED_VAR(urcu_active_readers[get_readerid()]);
668 * _WHEN THE MB()s are in place_, they add full ordering of the
669 * generation pointer read wrt active reader count read, which ensures
670 * execution will not spill across loop execution.
671 * However, in the event mb()s are removed (execution using signal
672 * handler to promote barrier()() -> smp_mb()), nothing prevents one loop
673 * to spill its execution on other loop's execution.
689 active proctype urcu_reader()
694 /* Keep in sync manually with smp_rmb, smp_wmb, ooo_mem and init() */
695 DECLARE_PROC_CACHED_VAR(byte, urcu_gp_ctr);
696 /* Note ! currently only one reader */
697 DECLARE_PROC_CACHED_VAR(byte, urcu_active_readers[NR_READERS]);
699 DECLARE_PROC_CACHED_VAR(bit, rcu_data[SLAB_SIZE]);
703 DECLARE_PROC_CACHED_VAR(bit, rcu_ptr);
705 DECLARE_PROC_CACHED_VAR(byte, rcu_ptr);
709 INIT_PROC_CACHED_VAR(urcu_gp_ctr, 1);
710 INIT_PROC_CACHED_VAR(rcu_ptr, 0);
715 INIT_PROC_CACHED_VAR(urcu_active_readers[i], 0);
717 :: i >= NR_READERS -> break
719 INIT_PROC_CACHED_VAR(rcu_data[0], WINE);
723 INIT_PROC_CACHED_VAR(rcu_data[i], POISON);
725 :: i >= SLAB_SIZE -> break
731 assert(get_pid() < NR_PROCS);
737 * We do not test reader's progress here, because we are mainly
738 * interested in writer's progress. The reader never blocks
739 * anyway. We have to test for reader/writer's progress
740 * separately, otherwise we could think the writer is doing
741 * progress when it's blocked by an always progressing reader.
743 #ifdef READER_PROGRESS
746 urcu_one_read(i, j, nest_i, tmp, tmp2);
750 /* no name clash please */
751 #undef proc_urcu_reader
754 /* Model the RCU update process. */
757 * Bit encoding, urcu_writer :
758 * Currently only supports one reader.
761 int _proc_urcu_writer;
762 #define proc_urcu_writer _proc_urcu_writer
764 #define WRITE_PROD_NONE (1 << 0)
766 #define WRITE_DATA (1 << 1)
767 #define WRITE_PROC_WMB (1 << 2)
768 #define WRITE_XCHG_PTR (1 << 3)
770 #define WRITE_PROC_FIRST_MB (1 << 4)
773 #define WRITE_PROC_FIRST_READ_GP (1 << 5)
774 #define WRITE_PROC_FIRST_WRITE_GP (1 << 6)
775 #define WRITE_PROC_FIRST_WAIT (1 << 7)
776 #define WRITE_PROC_FIRST_WAIT_LOOP (1 << 8)
779 #define WRITE_PROC_SECOND_READ_GP (1 << 9)
780 #define WRITE_PROC_SECOND_WRITE_GP (1 << 10)
781 #define WRITE_PROC_SECOND_WAIT (1 << 11)
782 #define WRITE_PROC_SECOND_WAIT_LOOP (1 << 12)
784 #define WRITE_PROC_SECOND_MB (1 << 13)
786 #define WRITE_FREE (1 << 14)
788 #define WRITE_PROC_ALL_TOKENS (WRITE_PROD_NONE \
792 | WRITE_PROC_FIRST_MB \
793 | WRITE_PROC_FIRST_READ_GP \
794 | WRITE_PROC_FIRST_WRITE_GP \
795 | WRITE_PROC_FIRST_WAIT \
796 | WRITE_PROC_SECOND_READ_GP \
797 | WRITE_PROC_SECOND_WRITE_GP \
798 | WRITE_PROC_SECOND_WAIT \
799 | WRITE_PROC_SECOND_MB \
802 #define WRITE_PROC_ALL_TOKENS_CLEAR ((1 << 15) - 1)
805 * Mutexes are implied around writer execution. A single writer at a time.
807 active proctype urcu_writer()
810 byte tmp, tmp2, tmpa;
811 byte cur_data = 0, old_data, loop_nr = 0;
812 byte cur_gp_val = 0; /*
813 * Keep a local trace of the current parity so
814 * we don't add non-existing dependencies on the global
815 * GP update. Needed to test single flip case.
818 /* Keep in sync manually with smp_rmb, smp_wmb, ooo_mem and init() */
819 DECLARE_PROC_CACHED_VAR(byte, urcu_gp_ctr);
820 /* Note ! currently only one reader */
821 DECLARE_PROC_CACHED_VAR(byte, urcu_active_readers[NR_READERS]);
823 DECLARE_PROC_CACHED_VAR(bit, rcu_data[SLAB_SIZE]);
827 DECLARE_PROC_CACHED_VAR(bit, rcu_ptr);
829 DECLARE_PROC_CACHED_VAR(byte, rcu_ptr);
833 INIT_PROC_CACHED_VAR(urcu_gp_ctr, 1);
834 INIT_PROC_CACHED_VAR(rcu_ptr, 0);
839 INIT_PROC_CACHED_VAR(urcu_active_readers[i], 0);
841 :: i >= NR_READERS -> break
843 INIT_PROC_CACHED_VAR(rcu_data[0], WINE);
847 INIT_PROC_CACHED_VAR(rcu_data[i], POISON);
849 :: i >= SLAB_SIZE -> break
856 assert(get_pid() < NR_PROCS);
860 #ifdef WRITER_PROGRESS
863 loop_nr = loop_nr + 1;
865 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROD_NONE);
868 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_WMB);
872 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_MB);
873 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_MB);
877 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_READ_GP);
878 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WRITE_GP);
879 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT);
880 /* For single flip, we need to know the current parity */
881 cur_gp_val = cur_gp_val ^ RCU_GP_CTR_BIT;
888 :: CONSUME_TOKENS(proc_urcu_writer,
892 cur_data = (cur_data + 1) % SLAB_SIZE;
893 WRITE_CACHED_VAR(rcu_data[cur_data], WINE);
894 PRODUCE_TOKENS(proc_urcu_writer, WRITE_DATA);
897 :: CONSUME_TOKENS(proc_urcu_writer,
901 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_WMB);
903 :: CONSUME_TOKENS(proc_urcu_writer,
906 /* rcu_xchg_pointer() */
908 old_data = READ_CACHED_VAR(rcu_ptr);
909 WRITE_CACHED_VAR(rcu_ptr, cur_data);
911 PRODUCE_TOKENS(proc_urcu_writer, WRITE_XCHG_PTR);
913 :: CONSUME_TOKENS(proc_urcu_writer,
914 WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR,
915 WRITE_PROC_FIRST_MB) ->
918 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_MB);
921 :: CONSUME_TOKENS(proc_urcu_writer,
923 WRITE_PROC_FIRST_READ_GP) ->
924 tmpa = READ_CACHED_VAR(urcu_gp_ctr);
925 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_READ_GP);
926 :: CONSUME_TOKENS(proc_urcu_writer,
927 WRITE_PROC_FIRST_MB | WRITE_PROC_WMB
928 | WRITE_PROC_FIRST_READ_GP,
929 WRITE_PROC_FIRST_WRITE_GP) ->
931 WRITE_CACHED_VAR(urcu_gp_ctr, tmpa ^ RCU_GP_CTR_BIT);
932 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WRITE_GP);
934 :: CONSUME_TOKENS(proc_urcu_writer,
935 //WRITE_PROC_FIRST_WRITE_GP | /* TEST ADDING SYNC CORE */
936 WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
937 WRITE_PROC_FIRST_WAIT | WRITE_PROC_FIRST_WAIT_LOOP) ->
939 //smp_mb(i); /* TEST */
940 /* ONLY WAITING FOR READER 0 */
941 tmp2 = READ_CACHED_VAR(urcu_active_readers[0]);
943 /* In normal execution, we are always starting by
944 * waiting for the even parity.
946 cur_gp_val = RCU_GP_CTR_BIT;
949 :: (tmp2 & RCU_GP_CTR_NEST_MASK)
950 && ((tmp2 ^ cur_gp_val) & RCU_GP_CTR_BIT) ->
951 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT_LOOP);
953 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT);
956 :: CONSUME_TOKENS(proc_urcu_writer,
957 //WRITE_PROC_FIRST_WRITE_GP /* TEST ADDING SYNC CORE */
958 WRITE_PROC_FIRST_WRITE_GP
959 | WRITE_PROC_FIRST_READ_GP
960 | WRITE_PROC_FIRST_WAIT_LOOP
961 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
962 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
964 #ifndef GEN_ERROR_WRITER_PROGRESS
967 /* The memory barrier will invalidate the
968 * second read done as prefetching. Note that all
969 * instructions with side-effects depending on
970 * WRITE_PROC_SECOND_READ_GP should also depend on
971 * completion of this busy-waiting loop. */
972 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_READ_GP);
976 /* This instruction loops to WRITE_PROC_FIRST_WAIT */
977 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_FIRST_WAIT_LOOP | WRITE_PROC_FIRST_WAIT);
980 :: CONSUME_TOKENS(proc_urcu_writer,
981 //WRITE_PROC_FIRST_WAIT | //test /* no dependency. Could pre-fetch, no side-effect. */
982 WRITE_PROC_FIRST_WRITE_GP
983 | WRITE_PROC_FIRST_READ_GP
984 | WRITE_PROC_FIRST_MB,
985 WRITE_PROC_SECOND_READ_GP) ->
987 //smp_mb(i); /* TEST */
988 tmpa = READ_CACHED_VAR(urcu_gp_ctr);
989 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_READ_GP);
990 :: CONSUME_TOKENS(proc_urcu_writer,
991 WRITE_PROC_FIRST_WAIT /* dependency on first wait, because this
992 * instruction has globally observable
995 | WRITE_PROC_FIRST_MB
997 | WRITE_PROC_FIRST_READ_GP
998 | WRITE_PROC_FIRST_WRITE_GP
999 | WRITE_PROC_SECOND_READ_GP,
1000 WRITE_PROC_SECOND_WRITE_GP) ->
1002 WRITE_CACHED_VAR(urcu_gp_ctr, tmpa ^ RCU_GP_CTR_BIT);
1003 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WRITE_GP);
1005 :: CONSUME_TOKENS(proc_urcu_writer,
1006 //WRITE_PROC_FIRST_WRITE_GP | /* TEST ADDING SYNC CORE */
1007 WRITE_PROC_FIRST_WAIT
1008 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1009 WRITE_PROC_SECOND_WAIT | WRITE_PROC_SECOND_WAIT_LOOP) ->
1011 //smp_mb(i); /* TEST */
1012 /* ONLY WAITING FOR READER 0 */
1013 tmp2 = READ_CACHED_VAR(urcu_active_readers[0]);
1015 :: (tmp2 & RCU_GP_CTR_NEST_MASK)
1016 && ((tmp2 ^ 0) & RCU_GP_CTR_BIT) ->
1017 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT_LOOP);
1019 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT);
1022 :: CONSUME_TOKENS(proc_urcu_writer,
1023 //WRITE_PROC_FIRST_WRITE_GP | /* TEST ADDING SYNC CORE */
1024 WRITE_PROC_SECOND_WRITE_GP
1025 | WRITE_PROC_FIRST_WRITE_GP
1026 | WRITE_PROC_SECOND_READ_GP
1027 | WRITE_PROC_FIRST_READ_GP
1028 | WRITE_PROC_SECOND_WAIT_LOOP
1029 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
1030 | WRITE_PROC_FIRST_MB, /* can be reordered before/after flips */
1032 #ifndef GEN_ERROR_WRITER_PROGRESS
1038 /* This instruction loops to WRITE_PROC_SECOND_WAIT */
1039 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_WAIT_LOOP | WRITE_PROC_SECOND_WAIT);
1042 :: CONSUME_TOKENS(proc_urcu_writer,
1043 WRITE_PROC_FIRST_WAIT
1044 | WRITE_PROC_SECOND_WAIT
1045 | WRITE_PROC_FIRST_READ_GP
1046 | WRITE_PROC_SECOND_READ_GP
1047 | WRITE_PROC_FIRST_WRITE_GP
1048 | WRITE_PROC_SECOND_WRITE_GP
1049 | WRITE_DATA | WRITE_PROC_WMB | WRITE_XCHG_PTR
1050 | WRITE_PROC_FIRST_MB,
1051 WRITE_PROC_SECOND_MB) ->
1054 PRODUCE_TOKENS(proc_urcu_writer, WRITE_PROC_SECOND_MB);
1056 :: CONSUME_TOKENS(proc_urcu_writer,
1058 | WRITE_PROC_FIRST_WAIT
1059 | WRITE_PROC_SECOND_WAIT
1060 | WRITE_PROC_WMB /* No dependency on
1061 * WRITE_DATA because we
1063 * different location. */
1064 | WRITE_PROC_SECOND_MB
1065 | WRITE_PROC_FIRST_MB,
1067 WRITE_CACHED_VAR(rcu_data[old_data], POISON);
1068 PRODUCE_TOKENS(proc_urcu_writer, WRITE_FREE);
1070 :: CONSUME_TOKENS(proc_urcu_writer, WRITE_PROC_ALL_TOKENS, 0) ->
1071 CLEAR_TOKENS(proc_urcu_writer, WRITE_PROC_ALL_TOKENS_CLEAR);
1077 * Note : Promela model adds implicit serialization of the
1078 * WRITE_FREE instruction. Normally, it would be permitted to
1079 * spill on the next loop execution. Given the validation we do
1080 * checks for the data entry read to be poisoned, it's ok if
1081 * we do not check "late arriving" memory poisoning.
1086 * Given the reader loops infinitely, let the writer also busy-loop
1087 * with progress here so, with weak fairness, we can test the
1088 * writer's progress.
1093 #ifdef WRITER_PROGRESS
1096 #ifdef READER_PROGRESS
1098 * Make sure we don't block the reader's progress.
1100 smp_mb_send(i, j, 5);
1105 /* Non-atomic parts of the loop */
1108 smp_mb_send(i, j, 1);
1109 goto smp_mb_send1_end;
1110 #ifndef GEN_ERROR_WRITER_PROGRESS
1112 smp_mb_send(i, j, 2);
1113 goto smp_mb_send2_end;
1115 smp_mb_send(i, j, 3);
1116 goto smp_mb_send3_end;
1119 smp_mb_send(i, j, 4);
1120 goto smp_mb_send4_end;
1125 /* no name clash please */
1126 #undef proc_urcu_writer
1129 /* Leave after the readers and writers so the pid count is ok. */
1134 INIT_CACHED_VAR(urcu_gp_ctr, 1);
1135 INIT_CACHED_VAR(rcu_ptr, 0);
1139 :: i < NR_READERS ->
1140 INIT_CACHED_VAR(urcu_active_readers[i], 0);
1141 ptr_read_first[i] = 1;
1142 data_read_first[i] = WINE;
1144 :: i >= NR_READERS -> break
1146 INIT_CACHED_VAR(rcu_data[0], WINE);
1150 INIT_CACHED_VAR(rcu_data[i], POISON);
1152 :: i >= SLAB_SIZE -> break