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