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