Commit | Line | Data |
---|---|---|
a5eb5ffc MD |
1 | /* |
2 | * test_urcu_wfs.c | |
3 | * | |
4 | * Userspace RCU library - example RCU-based lock-free stack | |
5 | * | |
6 | * Copyright February 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * Copyright February 2010 - Paolo Bonzini <pbonzini@redhat.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 | */ | |
23 | ||
24 | #define _GNU_SOURCE | |
25 | #include "../config.h" | |
26 | #include <stdio.h> | |
27 | #include <pthread.h> | |
28 | #include <stdlib.h> | |
29 | #include <stdint.h> | |
30 | #include <stdbool.h> | |
31 | #include <string.h> | |
32 | #include <sys/types.h> | |
33 | #include <sys/wait.h> | |
34 | #include <unistd.h> | |
35 | #include <stdio.h> | |
36 | #include <assert.h> | |
a5eb5ffc MD |
37 | #include <errno.h> |
38 | ||
39 | #include <urcu/arch.h> | |
bd252a04 | 40 | #include <urcu/tls-compat.h> |
96a0c0cd | 41 | #include <urcu/uatomic.h> |
2953b501 | 42 | #include "cpuset.h" |
a5eb5ffc | 43 | |
65fcc7e9 MD |
44 | #ifdef __linux__ |
45 | #include <syscall.h> | |
46 | #endif | |
47 | ||
a5eb5ffc MD |
48 | /* hardcoded number of CPUs */ |
49 | #define NR_CPUS 16384 | |
50 | ||
51 | #if defined(_syscall0) | |
52 | _syscall0(pid_t, gettid) | |
53 | #elif defined(__NR_gettid) | |
54 | static inline pid_t gettid(void) | |
55 | { | |
56 | return syscall(__NR_gettid); | |
57 | } | |
58 | #else | |
59 | #warning "use pid as tid" | |
60 | static inline pid_t gettid(void) | |
61 | { | |
62 | return getpid(); | |
63 | } | |
64 | #endif | |
65 | ||
66 | #ifndef DYNAMIC_LINK_TEST | |
67 | #define _LGPL_SOURCE | |
68 | #endif | |
cb3f3d6b | 69 | #include <urcu/wfstack.h> |
a5eb5ffc | 70 | |
69328034 MD |
71 | /* |
72 | * External synchronization used. | |
73 | */ | |
74 | enum test_sync { | |
75 | TEST_SYNC_NONE = 0, | |
76 | TEST_SYNC_MUTEX, | |
77 | }; | |
78 | ||
79 | static enum test_sync test_sync; | |
80 | ||
0ee400bd MD |
81 | static int test_force_sync; |
82 | ||
d05e9936 | 83 | static volatile int test_go, test_stop_enqueue, test_stop_dequeue; |
a5eb5ffc MD |
84 | |
85 | static unsigned long rduration; | |
86 | ||
87 | static unsigned long duration; | |
88 | ||
89 | /* read-side C.S. duration, in loops */ | |
90 | static unsigned long wdelay; | |
91 | ||
ab0aacbe | 92 | static inline void loop_sleep(unsigned long loops) |
a5eb5ffc | 93 | { |
ab0aacbe | 94 | while (loops-- != 0) |
06f22bdb | 95 | caa_cpu_relax(); |
a5eb5ffc MD |
96 | } |
97 | ||
98 | static int verbose_mode; | |
99 | ||
d05e9936 MD |
100 | static int test_pop, test_pop_all, test_wait_empty; |
101 | static int test_enqueue_stopped; | |
69328034 | 102 | |
a5eb5ffc MD |
103 | #define printf_verbose(fmt, args...) \ |
104 | do { \ | |
105 | if (verbose_mode) \ | |
69328034 | 106 | printf(fmt, ## args); \ |
a5eb5ffc MD |
107 | } while (0) |
108 | ||
109 | static unsigned int cpu_affinities[NR_CPUS]; | |
110 | static unsigned int next_aff = 0; | |
111 | static int use_affinity = 0; | |
112 | ||
113 | pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; | |
114 | ||
a5eb5ffc MD |
115 | static void set_affinity(void) |
116 | { | |
95bc7fb9 | 117 | #if HAVE_SCHED_SETAFFINITY |
a5eb5ffc | 118 | cpu_set_t mask; |
95bc7fb9 MD |
119 | int cpu, ret; |
120 | #endif /* HAVE_SCHED_SETAFFINITY */ | |
a5eb5ffc MD |
121 | |
122 | if (!use_affinity) | |
123 | return; | |
124 | ||
125 | #if HAVE_SCHED_SETAFFINITY | |
126 | ret = pthread_mutex_lock(&affinity_mutex); | |
127 | if (ret) { | |
128 | perror("Error in pthread mutex lock"); | |
129 | exit(-1); | |
130 | } | |
131 | cpu = cpu_affinities[next_aff++]; | |
132 | ret = pthread_mutex_unlock(&affinity_mutex); | |
133 | if (ret) { | |
134 | perror("Error in pthread mutex unlock"); | |
135 | exit(-1); | |
136 | } | |
137 | ||
138 | CPU_ZERO(&mask); | |
139 | CPU_SET(cpu, &mask); | |
140 | #if SCHED_SETAFFINITY_ARGS == 2 | |
141 | sched_setaffinity(0, &mask); | |
142 | #else | |
143 | sched_setaffinity(0, sizeof(mask), &mask); | |
144 | #endif | |
145 | #endif /* HAVE_SCHED_SETAFFINITY */ | |
146 | } | |
147 | ||
148 | /* | |
149 | * returns 0 if test should end. | |
150 | */ | |
151 | static int test_duration_dequeue(void) | |
152 | { | |
d05e9936 | 153 | return !test_stop_dequeue; |
a5eb5ffc MD |
154 | } |
155 | ||
156 | static int test_duration_enqueue(void) | |
157 | { | |
d05e9936 | 158 | return !test_stop_enqueue; |
a5eb5ffc MD |
159 | } |
160 | ||
bd252a04 MD |
161 | static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); |
162 | static DEFINE_URCU_TLS(unsigned long long, nr_enqueues); | |
a5eb5ffc | 163 | |
bd252a04 MD |
164 | static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues); |
165 | static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues); | |
d05e9936 MD |
166 | static DEFINE_URCU_TLS(unsigned long long, nr_empty_dest_enqueues); |
167 | static DEFINE_URCU_TLS(unsigned long long, nr_pop_all); | |
d89f0c51 | 168 | static DEFINE_URCU_TLS(unsigned long long, nr_pop_last); |
a5eb5ffc MD |
169 | |
170 | static unsigned int nr_enqueuers; | |
171 | static unsigned int nr_dequeuers; | |
172 | ||
16aa9ee8 | 173 | static struct cds_wfs_stack s; |
a5eb5ffc | 174 | |
98fbc848 | 175 | static void *thr_enqueuer(void *_count) |
a5eb5ffc MD |
176 | { |
177 | unsigned long long *count = _count; | |
d05e9936 | 178 | bool was_nonempty; |
a5eb5ffc MD |
179 | |
180 | printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", | |
6ff854ac MD |
181 | "enqueuer", (unsigned long) pthread_self(), |
182 | (unsigned long) gettid()); | |
a5eb5ffc MD |
183 | |
184 | set_affinity(); | |
185 | ||
a5eb5ffc MD |
186 | while (!test_go) |
187 | { | |
188 | } | |
5481ddb3 | 189 | cmm_smp_mb(); |
a5eb5ffc MD |
190 | |
191 | for (;;) { | |
16aa9ee8 | 192 | struct cds_wfs_node *node = malloc(sizeof(*node)); |
a5eb5ffc MD |
193 | if (!node) |
194 | goto fail; | |
16aa9ee8 | 195 | cds_wfs_node_init(node); |
d05e9936 | 196 | was_nonempty = cds_wfs_push(&s, node); |
bd252a04 | 197 | URCU_TLS(nr_successful_enqueues)++; |
d05e9936 MD |
198 | if (!was_nonempty) |
199 | URCU_TLS(nr_empty_dest_enqueues)++; | |
a5eb5ffc | 200 | |
a0b7f7ea | 201 | if (caa_unlikely(wdelay)) |
a5eb5ffc MD |
202 | loop_sleep(wdelay); |
203 | fail: | |
bd252a04 | 204 | URCU_TLS(nr_enqueues)++; |
a0b7f7ea | 205 | if (caa_unlikely(!test_duration_enqueue())) |
a5eb5ffc MD |
206 | break; |
207 | } | |
208 | ||
d05e9936 | 209 | uatomic_inc(&test_enqueue_stopped); |
bd252a04 MD |
210 | count[0] = URCU_TLS(nr_enqueues); |
211 | count[1] = URCU_TLS(nr_successful_enqueues); | |
d05e9936 | 212 | count[2] = URCU_TLS(nr_empty_dest_enqueues); |
a5eb5ffc | 213 | printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, " |
d05e9936 MD |
214 | "enqueues %llu successful_enqueues %llu, " |
215 | "empty_dest_enqueues %llu\n", | |
6ff854ac MD |
216 | pthread_self(), |
217 | (unsigned long) gettid(), | |
d05e9936 MD |
218 | URCU_TLS(nr_enqueues), |
219 | URCU_TLS(nr_successful_enqueues), | |
220 | URCU_TLS(nr_empty_dest_enqueues)); | |
a5eb5ffc MD |
221 | return ((void*)1); |
222 | ||
223 | } | |
224 | ||
69328034 MD |
225 | static void do_test_pop(enum test_sync sync) |
226 | { | |
227 | struct cds_wfs_node *node; | |
d89f0c51 | 228 | int state; |
69328034 MD |
229 | |
230 | if (sync == TEST_SYNC_MUTEX) | |
231 | cds_wfs_pop_lock(&s); | |
d89f0c51 | 232 | node = __cds_wfs_pop_with_state_blocking(&s, &state); |
69328034 MD |
233 | if (sync == TEST_SYNC_MUTEX) |
234 | cds_wfs_pop_unlock(&s); | |
235 | ||
236 | if (node) { | |
d89f0c51 MD |
237 | if (state & CDS_WFS_STATE_LAST) |
238 | URCU_TLS(nr_pop_last)++; | |
69328034 MD |
239 | free(node); |
240 | URCU_TLS(nr_successful_dequeues)++; | |
241 | } | |
242 | URCU_TLS(nr_dequeues)++; | |
243 | } | |
244 | ||
245 | static void do_test_pop_all(enum test_sync sync) | |
246 | { | |
247 | struct cds_wfs_head *head; | |
248 | struct cds_wfs_node *node, *n; | |
249 | ||
250 | if (sync == TEST_SYNC_MUTEX) | |
251 | cds_wfs_pop_lock(&s); | |
252 | head = __cds_wfs_pop_all(&s); | |
253 | if (sync == TEST_SYNC_MUTEX) | |
254 | cds_wfs_pop_unlock(&s); | |
255 | ||
d05e9936 | 256 | /* Check if empty */ |
c7ba06ba | 257 | if (cds_wfs_first(head) == NULL) |
d05e9936 MD |
258 | return; |
259 | ||
260 | URCU_TLS(nr_pop_all)++; | |
d89f0c51 | 261 | URCU_TLS(nr_pop_last)++; |
d05e9936 | 262 | |
69328034 MD |
263 | cds_wfs_for_each_blocking_safe(head, node, n) { |
264 | free(node); | |
265 | URCU_TLS(nr_successful_dequeues)++; | |
266 | URCU_TLS(nr_dequeues)++; | |
267 | } | |
268 | } | |
269 | ||
98fbc848 | 270 | static void *thr_dequeuer(void *_count) |
a5eb5ffc MD |
271 | { |
272 | unsigned long long *count = _count; | |
69328034 | 273 | unsigned int counter; |
a5eb5ffc MD |
274 | |
275 | printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", | |
6ff854ac MD |
276 | "dequeuer", (unsigned long) pthread_self(), |
277 | (unsigned long) gettid()); | |
a5eb5ffc MD |
278 | |
279 | set_affinity(); | |
280 | ||
a5eb5ffc MD |
281 | while (!test_go) |
282 | { | |
283 | } | |
5481ddb3 | 284 | cmm_smp_mb(); |
a5eb5ffc | 285 | |
69328034 | 286 | assert(test_pop || test_pop_all); |
a5eb5ffc | 287 | |
69328034 MD |
288 | for (;;) { |
289 | if (test_pop && test_pop_all) { | |
290 | if (counter & 1) | |
291 | do_test_pop(test_sync); | |
292 | else | |
293 | do_test_pop_all(test_sync); | |
294 | counter++; | |
295 | } else { | |
296 | if (test_pop) | |
297 | do_test_pop(test_sync); | |
298 | else | |
299 | do_test_pop_all(test_sync); | |
a5eb5ffc MD |
300 | } |
301 | ||
a0b7f7ea | 302 | if (caa_unlikely(!test_duration_dequeue())) |
a5eb5ffc | 303 | break; |
a0b7f7ea | 304 | if (caa_unlikely(rduration)) |
a5eb5ffc MD |
305 | loop_sleep(rduration); |
306 | } | |
307 | ||
a5eb5ffc | 308 | printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " |
d05e9936 | 309 | "dequeues %llu, successful_dequeues %llu " |
d89f0c51 | 310 | "pop_all %llu pop_last %llu\n", |
6ff854ac MD |
311 | pthread_self(), |
312 | (unsigned long) gettid(), | |
d05e9936 | 313 | URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues), |
d89f0c51 MD |
314 | URCU_TLS(nr_pop_all), |
315 | URCU_TLS(nr_pop_last)); | |
bd252a04 MD |
316 | count[0] = URCU_TLS(nr_dequeues); |
317 | count[1] = URCU_TLS(nr_successful_dequeues); | |
d05e9936 | 318 | count[2] = URCU_TLS(nr_pop_all); |
d89f0c51 | 319 | count[3] = URCU_TLS(nr_pop_last); |
a5eb5ffc MD |
320 | return ((void*)2); |
321 | } | |
322 | ||
d89f0c51 MD |
323 | static void test_end(struct cds_wfs_stack *s, unsigned long long *nr_dequeues, |
324 | unsigned long long *nr_pop_last) | |
a5eb5ffc | 325 | { |
16aa9ee8 | 326 | struct cds_wfs_node *node; |
d89f0c51 | 327 | int state; |
a5eb5ffc MD |
328 | |
329 | do { | |
d89f0c51 | 330 | node = cds_wfs_pop_with_state_blocking(s, &state); |
a5eb5ffc | 331 | if (node) { |
d89f0c51 MD |
332 | if (state & CDS_WFS_STATE_LAST) |
333 | (*nr_pop_last)++; | |
a5eb5ffc MD |
334 | free(node); |
335 | (*nr_dequeues)++; | |
336 | } | |
337 | } while (node); | |
338 | } | |
339 | ||
98fbc848 | 340 | static void show_usage(int argc, char **argv) |
a5eb5ffc MD |
341 | { |
342 | printf("Usage : %s nr_dequeuers nr_enqueuers duration (s)", argv[0]); | |
343 | printf(" [-d delay] (enqueuer period (in loops))"); | |
344 | printf(" [-c duration] (dequeuer period (in loops))"); | |
345 | printf(" [-v] (verbose output)"); | |
346 | printf(" [-a cpu#] [-a cpu#]... (affinity)"); | |
69328034 MD |
347 | printf(" [-p] (test pop)"); |
348 | printf(" [-P] (test pop_all, enabled by default)"); | |
349 | printf(" [-M] (use mutex external synchronization)"); | |
350 | printf(" Note: default: no external synchronization used."); | |
0ee400bd | 351 | printf(" [-f] (force user-provided synchronization)"); |
d05e9936 | 352 | printf(" [-w] Wait for dequeuer to empty stack"); |
a5eb5ffc MD |
353 | printf("\n"); |
354 | } | |
355 | ||
356 | int main(int argc, char **argv) | |
357 | { | |
358 | int err; | |
359 | pthread_t *tid_enqueuer, *tid_dequeuer; | |
360 | void *tret; | |
361 | unsigned long long *count_enqueuer, *count_dequeuer; | |
362 | unsigned long long tot_enqueues = 0, tot_dequeues = 0; | |
363 | unsigned long long tot_successful_enqueues = 0, | |
d05e9936 MD |
364 | tot_successful_dequeues = 0, |
365 | tot_empty_dest_enqueues = 0, | |
d89f0c51 | 366 | tot_pop_all = 0, tot_pop_last = 0; |
a5eb5ffc | 367 | unsigned long long end_dequeues = 0; |
d05e9936 | 368 | int i, a, retval = 0; |
a5eb5ffc MD |
369 | |
370 | if (argc < 4) { | |
371 | show_usage(argc, argv); | |
372 | return -1; | |
373 | } | |
374 | ||
375 | err = sscanf(argv[1], "%u", &nr_dequeuers); | |
376 | if (err != 1) { | |
377 | show_usage(argc, argv); | |
378 | return -1; | |
379 | } | |
380 | ||
381 | err = sscanf(argv[2], "%u", &nr_enqueuers); | |
382 | if (err != 1) { | |
383 | show_usage(argc, argv); | |
384 | return -1; | |
385 | } | |
386 | ||
387 | err = sscanf(argv[3], "%lu", &duration); | |
388 | if (err != 1) { | |
389 | show_usage(argc, argv); | |
390 | return -1; | |
391 | } | |
392 | ||
393 | for (i = 4; i < argc; i++) { | |
394 | if (argv[i][0] != '-') | |
395 | continue; | |
396 | switch (argv[i][1]) { | |
397 | case 'a': | |
398 | if (argc < i + 2) { | |
399 | show_usage(argc, argv); | |
400 | return -1; | |
401 | } | |
402 | a = atoi(argv[++i]); | |
403 | cpu_affinities[next_aff++] = a; | |
404 | use_affinity = 1; | |
405 | printf_verbose("Adding CPU %d affinity\n", a); | |
406 | break; | |
407 | case 'c': | |
408 | if (argc < i + 2) { | |
409 | show_usage(argc, argv); | |
410 | return -1; | |
411 | } | |
412 | rduration = atol(argv[++i]); | |
413 | break; | |
414 | case 'd': | |
415 | if (argc < i + 2) { | |
416 | show_usage(argc, argv); | |
417 | return -1; | |
418 | } | |
419 | wdelay = atol(argv[++i]); | |
420 | break; | |
421 | case 'v': | |
422 | verbose_mode = 1; | |
423 | break; | |
69328034 MD |
424 | case 'p': |
425 | test_pop = 1; | |
426 | break; | |
427 | case 'P': | |
428 | test_pop_all = 1; | |
429 | break; | |
430 | case 'M': | |
431 | test_sync = TEST_SYNC_MUTEX; | |
432 | break; | |
d05e9936 MD |
433 | case 'w': |
434 | test_wait_empty = 1; | |
435 | break; | |
0ee400bd MD |
436 | case 'f': |
437 | test_force_sync = 1; | |
438 | break; | |
a5eb5ffc MD |
439 | } |
440 | } | |
441 | ||
69328034 MD |
442 | /* activate pop_all test by default */ |
443 | if (!test_pop && !test_pop_all) | |
444 | test_pop_all = 1; | |
445 | ||
0ee400bd MD |
446 | if (test_sync == TEST_SYNC_NONE && nr_dequeuers > 1 && test_pop) { |
447 | if (test_force_sync) { | |
448 | fprintf(stderr, "[WARNING] Using pop concurrently " | |
449 | "with other pop or pop_all without external " | |
450 | "synchronization. Expect run-time failure.\n"); | |
451 | } else { | |
452 | printf("Enforcing mutex synchronization\n"); | |
453 | test_sync = TEST_SYNC_MUTEX; | |
454 | } | |
455 | } | |
456 | ||
a5eb5ffc MD |
457 | printf_verbose("running test for %lu seconds, %u enqueuers, " |
458 | "%u dequeuers.\n", | |
459 | duration, nr_enqueuers, nr_dequeuers); | |
69328034 MD |
460 | if (test_pop) |
461 | printf_verbose("pop test activated.\n"); | |
462 | if (test_pop_all) | |
463 | printf_verbose("pop_all test activated.\n"); | |
98fbc848 MD |
464 | if (test_sync == TEST_SYNC_MUTEX) |
465 | printf_verbose("External sync: mutex.\n"); | |
466 | else | |
467 | printf_verbose("External sync: none.\n"); | |
d05e9936 MD |
468 | if (test_wait_empty) |
469 | printf_verbose("Wait for dequeuers to empty stack.\n"); | |
a5eb5ffc MD |
470 | printf_verbose("Writer delay : %lu loops.\n", rduration); |
471 | printf_verbose("Reader duration : %lu loops.\n", wdelay); | |
472 | printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", | |
6ff854ac MD |
473 | "main", (unsigned long) pthread_self(), |
474 | (unsigned long) gettid()); | |
a5eb5ffc MD |
475 | |
476 | tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); | |
477 | tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); | |
d05e9936 | 478 | count_enqueuer = malloc(3 * sizeof(*count_enqueuer) * nr_enqueuers); |
d89f0c51 | 479 | count_dequeuer = malloc(4 * sizeof(*count_dequeuer) * nr_dequeuers); |
16aa9ee8 | 480 | cds_wfs_init(&s); |
a5eb5ffc MD |
481 | |
482 | next_aff = 0; | |
483 | ||
484 | for (i = 0; i < nr_enqueuers; i++) { | |
485 | err = pthread_create(&tid_enqueuer[i], NULL, thr_enqueuer, | |
d05e9936 | 486 | &count_enqueuer[3 * i]); |
a5eb5ffc MD |
487 | if (err != 0) |
488 | exit(1); | |
489 | } | |
490 | for (i = 0; i < nr_dequeuers; i++) { | |
491 | err = pthread_create(&tid_dequeuer[i], NULL, thr_dequeuer, | |
d89f0c51 | 492 | &count_dequeuer[4 * i]); |
a5eb5ffc MD |
493 | if (err != 0) |
494 | exit(1); | |
495 | } | |
496 | ||
5481ddb3 | 497 | cmm_smp_mb(); |
a5eb5ffc MD |
498 | |
499 | test_go = 1; | |
500 | ||
501 | for (i = 0; i < duration; i++) { | |
502 | sleep(1); | |
503 | if (verbose_mode) | |
504 | write (1, ".", 1); | |
505 | } | |
506 | ||
d05e9936 MD |
507 | test_stop_enqueue = 1; |
508 | ||
509 | if (test_wait_empty) { | |
510 | while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) { | |
511 | sleep(1); | |
512 | } | |
513 | while (!cds_wfs_empty(&s)) { | |
514 | sleep(1); | |
515 | } | |
516 | } | |
517 | ||
518 | test_stop_dequeue = 1; | |
a5eb5ffc MD |
519 | |
520 | for (i = 0; i < nr_enqueuers; i++) { | |
521 | err = pthread_join(tid_enqueuer[i], &tret); | |
522 | if (err != 0) | |
523 | exit(1); | |
d05e9936 MD |
524 | tot_enqueues += count_enqueuer[3 * i]; |
525 | tot_successful_enqueues += count_enqueuer[3 * i + 1]; | |
526 | tot_empty_dest_enqueues += count_enqueuer[3 * i + 2]; | |
a5eb5ffc MD |
527 | } |
528 | for (i = 0; i < nr_dequeuers; i++) { | |
529 | err = pthread_join(tid_dequeuer[i], &tret); | |
530 | if (err != 0) | |
531 | exit(1); | |
d89f0c51 MD |
532 | tot_dequeues += count_dequeuer[4 * i]; |
533 | tot_successful_dequeues += count_dequeuer[4 * i + 1]; | |
534 | tot_pop_all += count_dequeuer[4 * i + 2]; | |
535 | tot_pop_last += count_dequeuer[4 * i + 3]; | |
a5eb5ffc MD |
536 | } |
537 | ||
d89f0c51 | 538 | test_end(&s, &end_dequeues, &tot_pop_last); |
a5eb5ffc MD |
539 | |
540 | printf_verbose("total number of enqueues : %llu, dequeues %llu\n", | |
541 | tot_enqueues, tot_dequeues); | |
542 | printf_verbose("total number of successful enqueues : %llu, " | |
d05e9936 MD |
543 | "enqueues to empty dest : %llu, " |
544 | "successful dequeues %llu, " | |
d89f0c51 | 545 | "pop_all : %llu, pop_last : %llu\n", |
d05e9936 MD |
546 | tot_successful_enqueues, |
547 | tot_empty_dest_enqueues, | |
548 | tot_successful_dequeues, | |
d89f0c51 | 549 | tot_pop_all, tot_pop_last); |
a5eb5ffc MD |
550 | printf("SUMMARY %-25s testdur %4lu nr_enqueuers %3u wdelay %6lu " |
551 | "nr_dequeuers %3u " | |
552 | "rdur %6lu nr_enqueues %12llu nr_dequeues %12llu " | |
d05e9936 MD |
553 | "successful enqueues %12llu enqueues to empty dest %12llu " |
554 | "successful dequeues %12llu pop_all %12llu " | |
d89f0c51 | 555 | "pop_last %llu end_dequeues %llu nr_ops %12llu\n", |
a5eb5ffc MD |
556 | argv[0], duration, nr_enqueuers, wdelay, |
557 | nr_dequeuers, rduration, tot_enqueues, tot_dequeues, | |
558 | tot_successful_enqueues, | |
d05e9936 | 559 | tot_empty_dest_enqueues, |
d89f0c51 MD |
560 | tot_successful_dequeues, tot_pop_all, tot_pop_last, |
561 | end_dequeues, | |
a5eb5ffc | 562 | tot_enqueues + tot_dequeues); |
d05e9936 | 563 | if (tot_successful_enqueues != tot_successful_dequeues + end_dequeues) { |
a5eb5ffc MD |
564 | printf("WARNING! Discrepancy between nr succ. enqueues %llu vs " |
565 | "succ. dequeues + end dequeues %llu.\n", | |
566 | tot_successful_enqueues, | |
567 | tot_successful_dequeues + end_dequeues); | |
d05e9936 MD |
568 | retval = 1; |
569 | } | |
570 | /* | |
d89f0c51 MD |
571 | * The enqueuer should see exactly as many empty queues than the |
572 | * number of non-empty stacks dequeued. | |
d05e9936 | 573 | */ |
d89f0c51 | 574 | if (tot_empty_dest_enqueues != tot_pop_last) { |
d05e9936 | 575 | printf("WARNING! Discrepancy between empty enqueue (%llu) and " |
d89f0c51 | 576 | "number of pop last (%llu)\n", |
d05e9936 | 577 | tot_empty_dest_enqueues, |
d89f0c51 | 578 | tot_pop_last); |
d05e9936 MD |
579 | retval = 1; |
580 | } | |
a5eb5ffc MD |
581 | free(count_enqueuer); |
582 | free(count_dequeuer); | |
583 | free(tid_enqueuer); | |
584 | free(tid_dequeuer); | |
d05e9936 | 585 | return retval; |
a5eb5ffc | 586 | } |