Use urcu/tls-compat.h
[urcu.git] / tests / test_urcu_hash.c
CommitLineData
ab7d5fc6 1/*
cd1ae16a 2 * test_urcu_hash.c
ab7d5fc6
MD
3 *
4 * Userspace RCU library - test program
5 *
18ca7a5b 6 * Copyright 2009-2012 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
ab7d5fc6
MD
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#define _GNU_SOURCE
18ca7a5b 24#include "test_urcu_hash.h"
ab7d5fc6 25
f52c1ef7
MD
26enum test_hash {
27 TEST_HASH_RW,
20adf780 28 TEST_HASH_UNIQUE,
f52c1ef7
MD
29};
30
31struct test_hash_cb {
32 void (*sigusr1)(int signo);
33 void (*sigusr2)(int signo);
34 void *(*thr_reader)(void *_count);
35 void *(*thr_writer)(void *_count);
36 int (*populate_hash)(void);
37};
38
39static
40struct test_hash_cb test_hash_cb[] = {
41 [TEST_HASH_RW] = {
42 test_hash_rw_sigusr1_handler,
43 test_hash_rw_sigusr2_handler,
44 test_hash_rw_thr_reader,
45 test_hash_rw_thr_writer,
46 test_hash_rw_populate_hash,
47 },
20adf780
MD
48 [TEST_HASH_UNIQUE] = {
49 test_hash_unique_sigusr1_handler,
50 test_hash_unique_sigusr2_handler,
51 test_hash_unique_thr_reader,
52 test_hash_unique_thr_writer,
53 test_hash_unique_populate_hash,
54 },
55
f52c1ef7
MD
56};
57
58static enum test_hash test_choice = TEST_HASH_RW;
59
60void (*get_sigusr1_cb(void))(int)
61{
62 return test_hash_cb[test_choice].sigusr1;
63}
64
65void (*get_sigusr2_cb(void))(int)
66{
67 return test_hash_cb[test_choice].sigusr2;
68}
69
70void *(*get_thr_reader_cb(void))(void *)
71{
72 return test_hash_cb[test_choice].thr_reader;
73}
74
75void *(*get_thr_writer_cb(void))(void *)
76{
77 return test_hash_cb[test_choice].thr_writer;
78}
79
80int (*get_populate_hash_cb(void))(void)
81{
82 return test_hash_cb[test_choice].populate_hash;
83}
84
bd252a04
MD
85DEFINE_URCU_TLS(unsigned int, rand_lookup);
86DEFINE_URCU_TLS(unsigned long, nr_add);
87DEFINE_URCU_TLS(unsigned long, nr_addexist);
88DEFINE_URCU_TLS(unsigned long, nr_del);
89DEFINE_URCU_TLS(unsigned long, nr_delnoent);
90DEFINE_URCU_TLS(unsigned long, lookup_fail);
91DEFINE_URCU_TLS(unsigned long, lookup_ok);
b8e1907c 92
18ca7a5b 93struct cds_lfht *test_ht;
5e28c532 94
18ca7a5b 95volatile int test_go, test_stop;
ab7d5fc6 96
18ca7a5b 97unsigned long wdelay;
ab7d5fc6 98
18ca7a5b 99unsigned long duration;
ab7d5fc6
MD
100
101/* read-side C.S. duration, in loops */
18ca7a5b
MD
102unsigned long rduration;
103
104unsigned long init_hash_size = DEFAULT_HASH_SIZE;
105unsigned long min_hash_alloc_size = DEFAULT_MIN_ALLOC_SIZE;
106unsigned long max_hash_buckets_size = (1UL << 20);
107unsigned long init_populate;
108int opt_auto_resize;
109int add_only, add_unique, add_replace;
110const struct cds_lfht_mm_type *memory_backend;
111
112unsigned long init_pool_offset, lookup_pool_offset, write_pool_offset;
113unsigned long init_pool_size = DEFAULT_RAND_POOL,
d837911d
MD
114 lookup_pool_size = DEFAULT_RAND_POOL,
115 write_pool_size = DEFAULT_RAND_POOL;
18ca7a5b 116int validate_lookup;
495913bf 117unsigned long nr_hash_chains; /* 0: normal table, other: number of hash chains */
8008a032 118
18ca7a5b 119int count_pipe[2];
7ed7682f 120
18ca7a5b 121int verbose_mode;
ab7d5fc6 122
18ca7a5b
MD
123unsigned int cpu_affinities[NR_CPUS];
124unsigned int next_aff = 0;
125int use_affinity = 0;
ab7d5fc6 126
18ca7a5b 127pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
ab7d5fc6 128
bd252a04
MD
129DEFINE_URCU_TLS(unsigned long long, nr_writes);
130DEFINE_URCU_TLS(unsigned long long, nr_reads);
ab7d5fc6 131
18ca7a5b
MD
132unsigned int nr_readers;
133unsigned int nr_writers;
ab7d5fc6 134
18ca7a5b 135static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
fb6d173d 136
18ca7a5b 137void set_affinity(void)
ab7d5fc6
MD
138{
139 cpu_set_t mask;
140 int cpu;
141 int ret;
142
143 if (!use_affinity)
144 return;
145
fb6d173d 146#if HAVE_SCHED_SETAFFINITY
ab7d5fc6
MD
147 ret = pthread_mutex_lock(&affinity_mutex);
148 if (ret) {
149 perror("Error in pthread mutex lock");
150 exit(-1);
151 }
152 cpu = cpu_affinities[next_aff++];
153 ret = pthread_mutex_unlock(&affinity_mutex);
154 if (ret) {
155 perror("Error in pthread mutex unlock");
156 exit(-1);
157 }
158 CPU_ZERO(&mask);
159 CPU_SET(cpu, &mask);
fb6d173d
MD
160#if SCHED_SETAFFINITY_ARGS == 2
161 sched_setaffinity(0, &mask);
162#else
163 sched_setaffinity(0, sizeof(mask), &mask);
164#endif
165#endif /* HAVE_SCHED_SETAFFINITY */
ab7d5fc6
MD
166}
167
ab7d5fc6
MD
168void rcu_copy_mutex_lock(void)
169{
170 int ret;
171 ret = pthread_mutex_lock(&rcu_copy_mutex);
172 if (ret) {
173 perror("Error in pthread mutex lock");
174 exit(-1);
175 }
176}
177
178void rcu_copy_mutex_unlock(void)
179{
180 int ret;
181
182 ret = pthread_mutex_unlock(&rcu_copy_mutex);
183 if (ret) {
184 perror("Error in pthread mutex unlock");
185 exit(-1);
186 }
187}
188
996ff57c
MD
189unsigned long test_compare(const void *key1, size_t key1_len,
190 const void *key2, size_t key2_len)
732ad076 191{
8ed51e04 192 if (caa_unlikely(key1_len != key2_len))
732ad076
MD
193 return -1;
194 assert(key1_len == sizeof(unsigned long));
195 if (key1 == key2)
196 return 0;
197 else
198 return 1;
abc490a1 199}
ab7d5fc6 200
7ed7682f
MD
201void *thr_count(void *arg)
202{
203 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
204 "counter", pthread_self(), (unsigned long)gettid());
205
206 rcu_register_thread();
207
208 for (;;) {
caf3653d 209 unsigned long count;
d933dd0e 210 long approx_before, approx_after;
7ed7682f
MD
211 ssize_t len;
212 char buf[1];
213
214 rcu_thread_offline();
215 len = read(count_pipe[0], buf, 1);
216 rcu_thread_online();
8ed51e04 217 if (caa_unlikely(!test_duration_read()))
7ed7682f
MD
218 break;
219 if (len != 1)
220 continue;
221 /* Accounting */
222 printf("Counting nodes... ");
223 fflush(stdout);
224 rcu_read_lock();
caf3653d 225 cds_lfht_count_nodes(test_ht, &approx_before, &count,
7ed7682f
MD
226 &approx_after);
227 rcu_read_unlock();
228 printf("done.\n");
d933dd0e 229 printf("Approximation before node accounting: %ld nodes.\n",
7ed7682f
MD
230 approx_before);
231 printf("Accounting of nodes in the hash table: "
caf3653d
MD
232 "%lu nodes.\n",
233 count);
d933dd0e 234 printf("Approximation after node accounting: %ld nodes.\n",
7ed7682f
MD
235 approx_after);
236 }
237 rcu_unregister_thread();
238 return NULL;
239}
240
abc490a1
MD
241void free_node_cb(struct rcu_head *head)
242{
3c692076 243 struct lfht_test_node *node =
81d91005 244 caa_container_of(head, struct lfht_test_node, head);
abc490a1
MD
245 free(node);
246}
247
175ec0eb
MD
248static
249void test_delete_all_nodes(struct cds_lfht *ht)
250{
251 struct cds_lfht_iter iter;
3c692076 252 struct lfht_test_node *node;
175ec0eb
MD
253 unsigned long count = 0;
254
6d320126 255 cds_lfht_for_each_entry(ht, &iter, node, node) {
175ec0eb
MD
256 int ret;
257
bc8c3c74 258 ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter));
175ec0eb 259 assert(!ret);
81d91005 260 call_rcu(&node->head, free_node_cb);
175ec0eb
MD
261 count++;
262 }
263 printf("deleted %lu nodes.\n", count);
264}
265
ab7d5fc6
MD
266void show_usage(int argc, char **argv)
267{
48ed1c18 268 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv[0]);
ab7d5fc6 269#ifdef DEBUG_YIELD
48ed1c18 270 printf(" [-r] [-w] (yield reader and/or writer)\n");
ab7d5fc6 271#endif
48ed1c18
MD
272 printf(" [-d delay] (writer period (us))\n");
273 printf(" [-c duration] (reader C.S. duration (in loops))\n");
274 printf(" [-v] (verbose output)\n");
275 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
b99436d7
LJ
276 printf(" [-h size] (initial number of buckets)\n");
277 printf(" [-m size] (minimum number of allocated buckets)\n");
278 printf(" [-n size] (maximum number of buckets)\n");
18ca7a5b 279printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
48ed1c18
MD
280 printf(" [-u] Uniquify add (no redundant keys).\n");
281 printf(" [-s] Replace (swap) entries.\n");
282 printf(" [-i] Add only (no removal).\n");
283 printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
284 printf(" [-A] Automatically resize hash table.\n");
c0b8a865 285 printf(" [-B order|chunk|mmap] Specify the memory backend.\n");
48ed1c18
MD
286 printf(" [-R offset] Lookup pool offset.\n");
287 printf(" [-S offset] Write pool offset.\n");
288 printf(" [-T offset] Init pool offset.\n");
289 printf(" [-M size] Lookup pool size.\n");
290 printf(" [-N size] Write pool size.\n");
291 printf(" [-O size] Init pool size.\n");
292 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
20adf780 293 printf(" [-U] Uniqueness test.\n");
495913bf 294 printf(" [-C] Number of hash chains.\n");
48ed1c18 295 printf("\n\n");
ab7d5fc6
MD
296}
297
298int main(int argc, char **argv)
299{
300 int err;
301 pthread_t *tid_reader, *tid_writer;
7ed7682f 302 pthread_t tid_count;
ab7d5fc6 303 void *tret;
b8e1907c
MD
304 unsigned long long *count_reader;
305 struct wr_count *count_writer;
306 unsigned long long tot_reads = 0, tot_writes = 0,
3c16bf4b 307 tot_add = 0, tot_add_exist = 0, tot_remove = 0;
caf3653d 308 unsigned long count;
d933dd0e 309 long approx_before, approx_after;
5e28c532 310 int i, a, ret;
3967a8a8
MD
311 struct sigaction act;
312 unsigned int remain;
ab7d5fc6
MD
313
314 if (argc < 4) {
315 show_usage(argc, argv);
316 return -1;
317 }
318
319 err = sscanf(argv[1], "%u", &nr_readers);
320 if (err != 1) {
321 show_usage(argc, argv);
322 return -1;
323 }
324
325 err = sscanf(argv[2], "%u", &nr_writers);
326 if (err != 1) {
327 show_usage(argc, argv);
328 return -1;
329 }
330
331 err = sscanf(argv[3], "%lu", &duration);
332 if (err != 1) {
333 show_usage(argc, argv);
334 return -1;
335 }
336
337 for (i = 4; i < argc; i++) {
338 if (argv[i][0] != '-')
339 continue;
340 switch (argv[i][1]) {
341#ifdef DEBUG_YIELD
342 case 'r':
343 yield_active |= YIELD_READ;
344 break;
345 case 'w':
346 yield_active |= YIELD_WRITE;
347 break;
348#endif
349 case 'a':
350 if (argc < i + 2) {
351 show_usage(argc, argv);
352 return -1;
353 }
354 a = atoi(argv[++i]);
355 cpu_affinities[next_aff++] = a;
356 use_affinity = 1;
357 printf_verbose("Adding CPU %d affinity\n", a);
358 break;
359 case 'c':
360 if (argc < i + 2) {
361 show_usage(argc, argv);
362 return -1;
363 }
364 rduration = atol(argv[++i]);
365 break;
366 case 'd':
367 if (argc < i + 2) {
368 show_usage(argc, argv);
369 return -1;
370 }
371 wdelay = atol(argv[++i]);
372 break;
373 case 'v':
374 verbose_mode = 1;
375 break;
6d5c0ca9
MD
376 case 'h':
377 if (argc < i + 2) {
378 show_usage(argc, argv);
379 return -1;
380 }
381 init_hash_size = atol(argv[++i]);
382 break;
32becef6
LJ
383 case 'm':
384 if (argc < i + 2) {
385 show_usage(argc, argv);
386 return -1;
387 }
388 min_hash_alloc_size = atol(argv[++i]);
389 break;
b99436d7
LJ
390 case 'n':
391 if (argc < i + 2) {
392 show_usage(argc, argv);
393 return -1;
394 }
395 max_hash_buckets_size = atol(argv[++i]);
396 break;
6d5c0ca9 397 case 'u':
48ed1c18
MD
398 if (add_replace) {
399 printf("Please specify at most one of -s or -u.\n");
400 exit(-1);
401 }
6d5c0ca9
MD
402 add_unique = 1;
403 break;
48ed1c18
MD
404 case 's':
405 if (add_unique) {
406 printf("Please specify at most one of -s or -u.\n");
407 exit(-1);
408 }
409 add_replace = 1;
410 break;
6d5c0ca9
MD
411 case 'i':
412 add_only = 1;
413 break;
cd1ae16a
MD
414 case 'k':
415 init_populate = atol(argv[++i]);
416 break;
151e7a93
MD
417 case 'A':
418 opt_auto_resize = 1;
419 break;
c0b8a865
LJ
420 case 'B':
421 if (argc < i + 2) {
422 show_usage(argc, argv);
423 return -1;
424 }
425 i++;
426 if (!strcmp("order", argv[i]))
427 memory_backend = &cds_lfht_mm_order;
428 else if (!strcmp("chunk", argv[i]))
429 memory_backend = &cds_lfht_mm_chunk;
430 else if (!strcmp("mmap", argv[i]))
431 memory_backend = &cds_lfht_mm_mmap;
432 else {
433 printf("Please specify memory backend with order|chunk|mmap.\n");
434 exit(-1);
435 }
436 break;
8008a032
MD
437 case 'R':
438 lookup_pool_offset = atol(argv[++i]);
439 break;
440 case 'S':
441 write_pool_offset = atol(argv[++i]);
442 break;
443 case 'T':
444 init_pool_offset = atol(argv[++i]);
445 break;
d837911d
MD
446 case 'M':
447 lookup_pool_size = atol(argv[++i]);
448 break;
449 case 'N':
450 write_pool_size = atol(argv[++i]);
451 break;
452 case 'O':
453 init_pool_size = atol(argv[++i]);
454 break;
59b10634
MD
455 case 'V':
456 validate_lookup = 1;
457 break;
20adf780
MD
458 case 'U':
459 test_choice = TEST_HASH_UNIQUE;
460 break;
495913bf
MD
461 case 'C':
462 nr_hash_chains = atol(argv[++i]);
463 break;
ab7d5fc6
MD
464 }
465 }
466
6d5c0ca9
MD
467 /* Check if hash size is power of 2 */
468 if (init_hash_size && init_hash_size & (init_hash_size - 1)) {
b99436d7 469 printf("Error: Initial number of buckets (%lu) is not a power of 2.\n",
6d5c0ca9
MD
470 init_hash_size);
471 return -1;
472 }
473
d0d8f9aa 474 if (min_hash_alloc_size && min_hash_alloc_size & (min_hash_alloc_size - 1)) {
b99436d7 475 printf("Error: Minimum number of allocated buckets (%lu) is not a power of 2.\n",
32becef6
LJ
476 min_hash_alloc_size);
477 return -1;
478 }
479
b99436d7
LJ
480 if (max_hash_buckets_size && max_hash_buckets_size & (max_hash_buckets_size - 1)) {
481 printf("Error: Maximum number of buckets (%lu) is not a power of 2.\n",
482 max_hash_buckets_size);
483 return -1;
484 }
485
3967a8a8
MD
486 memset(&act, 0, sizeof(act));
487 ret = sigemptyset(&act.sa_mask);
488 if (ret == -1) {
489 perror("sigemptyset");
490 return -1;
491 }
f52c1ef7 492 act.sa_handler = get_sigusr1_cb();
3967a8a8
MD
493 act.sa_flags = SA_RESTART;
494 ret = sigaction(SIGUSR1, &act, NULL);
495 if (ret == -1) {
496 perror("sigaction");
497 return -1;
498 }
7ed7682f
MD
499
500 ret = pipe(count_pipe);
501 if (ret == -1) {
502 perror("pipe");
503 return -1;
504 }
505
506 /* spawn counter thread */
507 err = pthread_create(&tid_count, NULL, thr_count,
508 NULL);
509 if (err != 0)
510 exit(1);
511
f52c1ef7 512 act.sa_handler = get_sigusr2_cb();
973e5e1b
MD
513 act.sa_flags = SA_RESTART;
514 ret = sigaction(SIGUSR2, &act, NULL);
515 if (ret == -1) {
516 perror("sigaction");
517 return -1;
518 }
3967a8a8 519
ab7d5fc6
MD
520 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
521 duration, nr_readers, nr_writers);
522 printf_verbose("Writer delay : %lu loops.\n", wdelay);
523 printf_verbose("Reader duration : %lu loops.\n", rduration);
6d5c0ca9
MD
524 printf_verbose("Mode:%s%s.\n",
525 add_only ? " add only" : " add/remove",
48ed1c18 526 add_unique ? " uniquify" : ( add_replace ? " replace" : " insert"));
b99436d7
LJ
527 printf_verbose("Initial number of buckets: %lu buckets.\n", init_hash_size);
528 printf_verbose("Minimum number of allocated buckets: %lu buckets.\n", min_hash_alloc_size);
529 printf_verbose("Maximum number of buckets: %lu buckets.\n", max_hash_buckets_size);
5dc00396
MD
530 printf_verbose("Init pool size offset %lu size %lu.\n",
531 init_pool_offset, init_pool_size);
532 printf_verbose("Lookup pool size offset %lu size %lu.\n",
533 lookup_pool_offset, lookup_pool_size);
534 printf_verbose("Update pool size offset %lu size %lu.\n",
535 write_pool_offset, write_pool_size);
495913bf
MD
536 printf_verbose("Number of hash chains: %lu.\n",
537 nr_hash_chains);
ab7d5fc6
MD
538 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
539 "main", pthread_self(), (unsigned long)gettid());
540
ab7d5fc6
MD
541 tid_reader = malloc(sizeof(*tid_reader) * nr_readers);
542 tid_writer = malloc(sizeof(*tid_writer) * nr_writers);
543 count_reader = malloc(sizeof(*count_reader) * nr_readers);
544 count_writer = malloc(sizeof(*count_writer) * nr_writers);
48ed1c18
MD
545
546 err = create_all_cpu_call_rcu_data(0);
8bcbd94a
MD
547 if (err) {
548 printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");
549 }
48ed1c18 550
c0b8a865
LJ
551 if (memory_backend) {
552 test_ht = _cds_lfht_new(init_hash_size, min_hash_alloc_size,
553 max_hash_buckets_size,
554 (opt_auto_resize ? CDS_LFHT_AUTO_RESIZE : 0) |
555 CDS_LFHT_ACCOUNTING, memory_backend,
556 &rcu_flavor, NULL);
557 } else {
558 test_ht = cds_lfht_new(init_hash_size, min_hash_alloc_size,
559 max_hash_buckets_size,
560 (opt_auto_resize ? CDS_LFHT_AUTO_RESIZE : 0) |
561 CDS_LFHT_ACCOUNTING, NULL);
562 }
0d02f4b5
MD
563 if (!test_ht) {
564 printf("Error allocating hash table.\n");
565 return -1;
566 }
c0b8a865 567
48ed1c18 568 /*
c0b8a865 569 * Hash Population needs to be seen as a RCU reader
48ed1c18
MD
570 * thread from the point of view of resize.
571 */
572 rcu_register_thread();
f52c1ef7 573 ret = (get_populate_hash_cb())();
5dc45f25 574 assert(!ret);
59e371e3
MD
575
576 rcu_thread_offline();
14756542 577
ab7d5fc6
MD
578 next_aff = 0;
579
580 for (i = 0; i < nr_readers; i++) {
18ca7a5b 581 err = pthread_create(&tid_reader[i],
f52c1ef7 582 NULL, get_thr_reader_cb(),
ab7d5fc6
MD
583 &count_reader[i]);
584 if (err != 0)
585 exit(1);
586 }
587 for (i = 0; i < nr_writers; i++) {
18ca7a5b 588 err = pthread_create(&tid_writer[i],
f52c1ef7 589 NULL, get_thr_writer_cb(),
ab7d5fc6
MD
590 &count_writer[i]);
591 if (err != 0)
592 exit(1);
593 }
594
abc490a1 595 cmm_smp_mb();
ab7d5fc6
MD
596
597 test_go = 1;
598
3967a8a8
MD
599 remain = duration;
600 do {
601 remain = sleep(remain);
602 } while (remain > 0);
ab7d5fc6
MD
603
604 test_stop = 1;
605
606 for (i = 0; i < nr_readers; i++) {
607 err = pthread_join(tid_reader[i], &tret);
608 if (err != 0)
609 exit(1);
610 tot_reads += count_reader[i];
611 }
612 for (i = 0; i < nr_writers; i++) {
613 err = pthread_join(tid_writer[i], &tret);
614 if (err != 0)
615 exit(1);
b8e1907c
MD
616 tot_writes += count_writer[i].update_ops;
617 tot_add += count_writer[i].add;
3c16bf4b 618 tot_add_exist += count_writer[i].add_exist;
b8e1907c 619 tot_remove += count_writer[i].remove;
ab7d5fc6 620 }
7ed7682f
MD
621
622 /* teardown counter thread */
623 act.sa_handler = SIG_IGN;
624 act.sa_flags = SA_RESTART;
625 ret = sigaction(SIGUSR2, &act, NULL);
626 if (ret == -1) {
627 perror("sigaction");
628 return -1;
629 }
630 {
631 char msg[1] = { 0x42 };
3fb1173c
MD
632 ssize_t ret;
633
634 do {
635 ret = write(count_pipe[1], msg, 1); /* wakeup thread */
636 } while (ret == -1L && errno == EINTR);
7ed7682f
MD
637 }
638 err = pthread_join(tid_count, &tret);
639 if (err != 0)
640 exit(1);
641
33c7c748 642 fflush(stdout);
59e371e3
MD
643 rcu_thread_online();
644 rcu_read_lock();
175ec0eb 645 printf("Counting nodes... ");
caf3653d 646 cds_lfht_count_nodes(test_ht, &approx_before, &count, &approx_after);
175ec0eb
MD
647 printf("done.\n");
648 test_delete_all_nodes(test_ht);
59e371e3
MD
649 rcu_read_unlock();
650 rcu_thread_offline();
caf3653d 651 if (count) {
d933dd0e 652 printf("Approximation before node accounting: %ld nodes.\n",
973e5e1b 653 approx_before);
175ec0eb 654 printf("Nodes deleted from hash table before destroy: "
caf3653d
MD
655 "%lu nodes.\n",
656 count);
d933dd0e 657 printf("Approximation after node accounting: %ld nodes.\n",
973e5e1b
MD
658 approx_after);
659 }
b7d619b0 660 ret = cds_lfht_destroy(test_ht, NULL);
33c7c748
MD
661 if (ret)
662 printf_verbose("final delete aborted\n");
663 else
664 printf_verbose("final delete success\n");
ab7d5fc6
MD
665 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,
666 tot_writes);
667 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
668 "nr_writers %3u "
d837911d 669 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
cd1ae16a 670 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
ab7d5fc6 671 argv[0], duration, nr_readers, rduration,
d837911d 672 nr_writers, wdelay, tot_reads, tot_writes,
3c16bf4b 673 tot_reads + tot_writes, tot_add, tot_add_exist, tot_remove,
cd1ae16a 674 (long long) tot_add + init_populate - tot_remove - count);
59e371e3 675 rcu_unregister_thread();
3a22f1dd 676 free_all_cpu_call_rcu_data();
ab7d5fc6
MD
677 free(tid_reader);
678 free(tid_writer);
679 free(count_reader);
680 free(count_writer);
681 return 0;
682}
This page took 0.061722 seconds and 4 git commands to generate.