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