4 * Userspace RCU library - test program
6 * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
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.
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.
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.
28 #include <sys/types.h>
40 #define DEFAULT_HASH_SIZE 32
41 #define DEFAULT_MIN_ALLOC_SIZE 1
42 #define DEFAULT_RAND_POOL 1000000
44 #define TEST_HASH_SEED 0x42UL
46 /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */
47 #define CACHE_LINE_SIZE 4096
49 /* hardcoded number of CPUs */
53 #define poison_free(ptr) \
55 memset(ptr, 0x42, sizeof(*(ptr))); \
59 #define poison_free(ptr) free(ptr)
64 #if defined(_syscall0)
65 _syscall0(pid_t
, gettid
)
66 #elif defined(__NR_gettid)
67 static inline pid_t
gettid(void)
69 return syscall(__NR_gettid
);
72 #warning "use pid as tid"
73 static inline pid_t
gettid(void)
79 #ifndef DYNAMIC_LINK_TEST
82 #define debug_yield_read()
84 #include <urcu-qsbr.h>
85 #include <urcu/rculfhash.h>
86 #include <urcu-call-rcu.h>
89 unsigned long update_ops
;
91 unsigned long add_exist
;
95 static unsigned int __thread rand_lookup
;
96 static unsigned long __thread nr_add
;
97 static unsigned long __thread nr_addexist
;
98 static unsigned long __thread nr_del
;
99 static unsigned long __thread nr_delnoent
;
100 static unsigned long __thread lookup_fail
;
101 static unsigned long __thread lookup_ok
;
103 static struct cds_lfht
*test_ht
;
110 struct lfht_test_node
{
111 struct cds_lfht_node node
;
113 unsigned int key_len
;
114 /* cache-cold for iteration */
115 struct rcu_head head
;
118 static inline struct lfht_test_node
*
119 to_test_node(struct cds_lfht_node
*node
)
121 return caa_container_of(node
, struct lfht_test_node
, node
);
125 void lfht_test_node_init(struct lfht_test_node
*node
, void *key
,
128 cds_lfht_node_init(&node
->node
);
130 node
->key_len
= key_len
;
133 static inline struct lfht_test_node
*
134 cds_lfht_iter_get_test_node(struct cds_lfht_iter
*iter
)
136 return to_test_node(cds_lfht_iter_get_node(iter
));
139 static volatile int test_go
, test_stop
;
141 static unsigned long wdelay
;
143 static unsigned long duration
;
145 /* read-side C.S. duration, in loops */
146 static unsigned long rduration
;
148 static unsigned long init_hash_size
= DEFAULT_HASH_SIZE
;
149 static unsigned long min_hash_alloc_size
= DEFAULT_MIN_ALLOC_SIZE
;
150 static unsigned long max_hash_buckets_size
= (1UL << 20);
151 static unsigned long init_populate
;
152 static int opt_auto_resize
;
153 static int add_only
, add_unique
, add_replace
;
155 static unsigned long init_pool_offset
, lookup_pool_offset
, write_pool_offset
;
156 static unsigned long init_pool_size
= DEFAULT_RAND_POOL
,
157 lookup_pool_size
= DEFAULT_RAND_POOL
,
158 write_pool_size
= DEFAULT_RAND_POOL
;
159 static int validate_lookup
;
161 static int count_pipe
[2];
163 static inline void loop_sleep(unsigned long l
)
169 static int verbose_mode
;
171 #define printf_verbose(fmt, args...) \
174 printf(fmt, ## args); \
177 static unsigned int cpu_affinities
[NR_CPUS
];
178 static unsigned int next_aff
= 0;
179 static int use_affinity
= 0;
181 pthread_mutex_t affinity_mutex
= PTHREAD_MUTEX_INITIALIZER
;
183 static void set_affinity(void)
192 ret
= pthread_mutex_lock(&affinity_mutex
);
194 perror("Error in pthread mutex lock");
197 cpu
= cpu_affinities
[next_aff
++];
198 ret
= pthread_mutex_unlock(&affinity_mutex
);
200 perror("Error in pthread mutex unlock");
205 sched_setaffinity(0, sizeof(mask
), &mask
);
212 } addremove
; /* 1: add, -1 remove, 0: random */
215 void sigusr1_handler(int signo
)
219 printf("Add/Remove: random.\n");
220 addremove
= AR_RANDOM
;
223 printf("Add/Remove: remove only.\n");
224 addremove
= AR_REMOVE
;
227 printf("Add/Remove: add only.\n");
234 void sigusr2_handler(int signo
)
236 char msg
[1] = { 0x42 };
240 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
241 } while (ret
== -1L && errno
== EINTR
);
245 * returns 0 if test should end.
247 static int test_duration_write(void)
252 static int test_duration_read(void)
257 static unsigned long long __thread nr_writes
;
258 static unsigned long long __thread nr_reads
;
260 static unsigned int nr_readers
;
261 static unsigned int nr_writers
;
263 pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
265 void rcu_copy_mutex_lock(void)
268 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
270 perror("Error in pthread mutex lock");
275 void rcu_copy_mutex_unlock(void)
279 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
281 perror("Error in pthread mutex unlock");
288 * Source: http://burtleburtle.net/bob/c/lookup3.c
289 * Originally Public Domain
292 #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
294 #define mix(a, b, c) \
296 a -= c; a ^= rot(c, 4); c += b; \
297 b -= a; b ^= rot(a, 6); a += c; \
298 c -= b; c ^= rot(b, 8); b += a; \
299 a -= c; a ^= rot(c, 16); c += b; \
300 b -= a; b ^= rot(a, 19); a += c; \
301 c -= b; c ^= rot(b, 4); b += a; \
304 #define final(a, b, c) \
306 c ^= b; c -= rot(b, 14); \
307 a ^= c; a -= rot(c, 11); \
308 b ^= a; b -= rot(a, 25); \
309 c ^= b; c -= rot(b, 16); \
310 a ^= c; a -= rot(c, 4);\
311 b ^= a; b -= rot(a, 14); \
312 c ^= b; c -= rot(b, 24); \
315 static __attribute__((unused
))
317 const uint32_t *k
, /* the key, an array of uint32_t values */
318 size_t length
, /* the length of the key, in uint32_ts */
319 uint32_t initval
) /* the previous hash, or an arbitrary value */
323 /* Set up the internal state */
324 a
= b
= c
= 0xdeadbeef + (((uint32_t) length
) << 2) + initval
;
326 /*----------------------------------------- handle most of the key */
336 /*----------------------------------- handle the last 3 uint32_t's */
337 switch (length
) { /* all the case statements fall through */
342 case 0: /* case 0: nothing left to add */
345 /*---------------------------------------------- report the result */
351 const uint32_t *k
, /* the key, an array of uint32_t values */
352 size_t length
, /* the length of the key, in uint32_ts */
353 uint32_t *pc
, /* IN: seed OUT: primary hash value */
354 uint32_t *pb
) /* IN: more seed OUT: secondary hash value */
358 /* Set up the internal state */
359 a
= b
= c
= 0xdeadbeef + ((uint32_t) (length
<< 2)) + *pc
;
362 /*----------------------------------------- handle most of the key */
372 /*----------------------------------- handle the last 3 uint32_t's */
373 switch (length
) { /* all the case statements fall through */
378 case 0: /* case 0: nothing left to add */
381 /*---------------------------------------------- report the result */
386 #if (CAA_BITS_PER_LONG == 32)
388 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
390 unsigned int key
= (unsigned int) _key
;
392 assert(length
== sizeof(unsigned int));
393 return hash_u32(&key
, 1, seed
);
397 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
408 assert(length
== sizeof(unsigned long));
409 v
.v64
= (uint64_t) seed
;
410 key
.v64
= (uint64_t) _key
;
411 hashword2(key
.v32
, 2, &v
.v32
[0], &v
.v32
[1]);
417 unsigned long test_compare(const void *key1
, size_t key1_len
,
418 const void *key2
, size_t key2_len
)
420 if (caa_unlikely(key1_len
!= key2_len
))
422 assert(key1_len
== sizeof(unsigned long));
430 int test_match(struct cds_lfht_node
*node
, const void *key
)
432 struct lfht_test_node
*test_node
= to_test_node(node
);
434 return !test_compare(test_node
->key
, test_node
->key_len
,
435 key
, sizeof(unsigned long));
439 void cds_lfht_test_lookup(struct cds_lfht
*ht
, void *key
, size_t key_len
,
440 struct cds_lfht_iter
*iter
)
442 assert(key_len
== sizeof(unsigned long));
444 cds_lfht_lookup(ht
, test_hash(key
, key_len
, TEST_HASH_SEED
),
445 test_match
, key
, iter
);
448 void *thr_count(void *arg
)
450 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
451 "counter", pthread_self(), (unsigned long)gettid());
453 rcu_register_thread();
456 unsigned long count
, removed
;
457 long approx_before
, approx_after
;
461 rcu_thread_offline();
462 len
= read(count_pipe
[0], buf
, 1);
464 if (caa_unlikely(!test_duration_read()))
469 printf("Counting nodes... ");
472 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &removed
,
476 printf("Approximation before node accounting: %ld nodes.\n",
478 printf("Accounting of nodes in the hash table: "
479 "%lu nodes + %lu logically removed.\n",
481 printf("Approximation after node accounting: %ld nodes.\n",
484 rcu_unregister_thread();
488 void *thr_reader(void *_count
)
490 unsigned long long *count
= _count
;
491 struct lfht_test_node
*node
;
492 struct cds_lfht_iter iter
;
494 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
495 "reader", pthread_self(), (unsigned long)gettid());
499 rcu_register_thread();
508 cds_lfht_test_lookup(test_ht
,
509 (void *)(((unsigned long) rand_r(&rand_lookup
) % lookup_pool_size
) + lookup_pool_offset
),
510 sizeof(void *), &iter
);
511 node
= cds_lfht_iter_get_test_node(&iter
);
513 if (validate_lookup
) {
514 printf("[ERROR] Lookup cannot find initial node.\n");
522 if (caa_unlikely(rduration
))
523 loop_sleep(rduration
);
526 if (caa_unlikely(!test_duration_read()))
528 if (caa_unlikely((nr_reads
& ((1 << 10) - 1)) == 0))
529 rcu_quiescent_state();
532 rcu_unregister_thread();
535 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
536 "reader", pthread_self(), (unsigned long)gettid());
537 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
538 pthread_self(), lookup_fail
, lookup_ok
);
544 void free_node_cb(struct rcu_head
*head
)
546 struct lfht_test_node
*node
=
547 caa_container_of(head
, struct lfht_test_node
, head
);
551 void *thr_writer(void *_count
)
553 struct lfht_test_node
*node
;
554 struct cds_lfht_node
*ret_node
;
555 struct cds_lfht_iter iter
;
556 struct wr_count
*count
= _count
;
559 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
560 "writer", pthread_self(), (unsigned long)gettid());
564 rcu_register_thread();
572 if ((addremove
== AR_ADD
|| add_only
)
573 || (addremove
== AR_RANDOM
&& rand_r(&rand_lookup
) & 1)) {
574 node
= malloc(sizeof(struct lfht_test_node
));
575 lfht_test_node_init(node
,
576 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
580 ret_node
= cds_lfht_add_unique(test_ht
,
581 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
582 test_match
, node
->key
, &node
->node
);
585 ret_node
= cds_lfht_add_replace(test_ht
,
586 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
587 test_match
, node
->key
, &node
->node
);
589 cds_lfht_add(test_ht
,
590 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
594 if (add_unique
&& ret_node
!= &node
->node
) {
598 if (add_replace
&& ret_node
) {
599 call_rcu(&to_test_node(ret_node
)->head
,
609 cds_lfht_test_lookup(test_ht
,
610 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
611 sizeof(void *), &iter
);
612 ret
= cds_lfht_del(test_ht
, &iter
);
615 node
= cds_lfht_iter_get_test_node(&iter
);
616 call_rcu(&node
->head
, free_node_cb
);
622 //if (nr_writes % 100000 == 0) {
623 if (nr_writes
% 1000 == 0) {
625 if (rand_r(&rand_lookup
) & 1) {
626 ht_resize(test_ht
, 1);
628 ht_resize(test_ht
, -1);
634 if (caa_unlikely(!test_duration_write()))
636 if (caa_unlikely(wdelay
))
638 if (caa_unlikely((nr_writes
& ((1 << 10) - 1)) == 0))
639 rcu_quiescent_state();
642 rcu_unregister_thread();
644 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
645 "writer", pthread_self(), (unsigned long)gettid());
646 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
647 "nr_delnoent %lu\n", pthread_self(), nr_add
,
648 nr_addexist
, nr_del
, nr_delnoent
);
649 count
->update_ops
= nr_writes
;
651 count
->add_exist
= nr_addexist
;
652 count
->remove
= nr_del
;
656 static int populate_hash(void)
658 struct lfht_test_node
*node
;
659 struct cds_lfht_node
*ret_node
;
664 if ((add_unique
|| add_replace
) && init_populate
* 10 > init_pool_size
) {
665 printf("WARNING: required to populate %lu nodes (-k), but random "
666 "pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a "
667 "larger random pool (-p option). This may take a while...\n", init_populate
, init_pool_size
);
670 while (nr_add
< init_populate
) {
671 node
= malloc(sizeof(struct lfht_test_node
));
672 lfht_test_node_init(node
,
673 (void *)(((unsigned long) rand_r(&rand_lookup
) % init_pool_size
) + init_pool_offset
),
677 ret_node
= cds_lfht_add_unique(test_ht
,
678 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
679 test_match
, node
->key
, &node
->node
);
682 ret_node
= cds_lfht_add_replace(test_ht
,
683 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
684 test_match
, node
->key
, &node
->node
);
686 cds_lfht_add(test_ht
,
687 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
691 if (add_unique
&& ret_node
!= &node
->node
) {
695 if (add_replace
&& ret_node
) {
696 call_rcu(&to_test_node(ret_node
)->head
, free_node_cb
);
708 void test_delete_all_nodes(struct cds_lfht
*ht
)
710 struct cds_lfht_iter iter
;
711 struct lfht_test_node
*node
;
712 unsigned long count
= 0;
714 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
717 ret
= cds_lfht_del(test_ht
, &iter
);
719 call_rcu(&node
->head
, free_node_cb
);
722 printf("deleted %lu nodes.\n", count
);
725 void show_usage(int argc
, char **argv
)
727 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
729 printf(" [-r] [-w] (yield reader and/or writer)\n");
731 printf(" [-d delay] (writer period (us))\n");
732 printf(" [-c duration] (reader C.S. duration (in loops))\n");
733 printf(" [-v] (verbose output)\n");
734 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
735 printf(" [-h size] (initial number of buckets)\n");
736 printf(" [-m size] (minimum number of allocated buckets)\n");
737 printf(" [-n size] (maximum number of buckets)\n");
738 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
739 printf(" [-u] Uniquify add (no redundant keys).\n");
740 printf(" [-s] Replace (swap) entries.\n");
741 printf(" [-i] Add only (no removal).\n");
742 printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
743 printf(" [-A] Automatically resize hash table.\n");
744 printf(" [-R offset] Lookup pool offset.\n");
745 printf(" [-S offset] Write pool offset.\n");
746 printf(" [-T offset] Init pool offset.\n");
747 printf(" [-M size] Lookup pool size.\n");
748 printf(" [-N size] Write pool size.\n");
749 printf(" [-O size] Init pool size.\n");
750 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
754 int main(int argc
, char **argv
)
757 pthread_t
*tid_reader
, *tid_writer
;
760 unsigned long long *count_reader
;
761 struct wr_count
*count_writer
;
762 unsigned long long tot_reads
= 0, tot_writes
= 0,
763 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
764 unsigned long count
, removed
;
765 long approx_before
, approx_after
;
767 struct sigaction act
;
771 show_usage(argc
, argv
);
775 err
= sscanf(argv
[1], "%u", &nr_readers
);
777 show_usage(argc
, argv
);
781 err
= sscanf(argv
[2], "%u", &nr_writers
);
783 show_usage(argc
, argv
);
787 err
= sscanf(argv
[3], "%lu", &duration
);
789 show_usage(argc
, argv
);
793 for (i
= 4; i
< argc
; i
++) {
794 if (argv
[i
][0] != '-')
796 switch (argv
[i
][1]) {
799 yield_active
|= YIELD_READ
;
802 yield_active
|= YIELD_WRITE
;
807 show_usage(argc
, argv
);
811 cpu_affinities
[next_aff
++] = a
;
813 printf_verbose("Adding CPU %d affinity\n", a
);
817 show_usage(argc
, argv
);
820 rduration
= atol(argv
[++i
]);
824 show_usage(argc
, argv
);
827 wdelay
= atol(argv
[++i
]);
834 show_usage(argc
, argv
);
837 init_hash_size
= atol(argv
[++i
]);
841 show_usage(argc
, argv
);
844 min_hash_alloc_size
= atol(argv
[++i
]);
848 show_usage(argc
, argv
);
851 max_hash_buckets_size
= atol(argv
[++i
]);
855 printf("Please specify at most one of -s or -u.\n");
862 printf("Please specify at most one of -s or -u.\n");
871 init_populate
= atol(argv
[++i
]);
877 lookup_pool_offset
= atol(argv
[++i
]);
880 write_pool_offset
= atol(argv
[++i
]);
883 init_pool_offset
= atol(argv
[++i
]);
886 lookup_pool_size
= atol(argv
[++i
]);
889 write_pool_size
= atol(argv
[++i
]);
892 init_pool_size
= atol(argv
[++i
]);
901 /* Check if hash size is power of 2 */
902 if (init_hash_size
&& init_hash_size
& (init_hash_size
- 1)) {
903 printf("Error: Initial number of buckets (%lu) is not a power of 2.\n",
908 if (min_hash_alloc_size
&& min_hash_alloc_size
& (min_hash_alloc_size
- 1)) {
909 printf("Error: Minimum number of allocated buckets (%lu) is not a power of 2.\n",
910 min_hash_alloc_size
);
914 if (max_hash_buckets_size
&& max_hash_buckets_size
& (max_hash_buckets_size
- 1)) {
915 printf("Error: Maximum number of buckets (%lu) is not a power of 2.\n",
916 max_hash_buckets_size
);
920 memset(&act
, 0, sizeof(act
));
921 ret
= sigemptyset(&act
.sa_mask
);
923 perror("sigemptyset");
926 act
.sa_handler
= sigusr1_handler
;
927 act
.sa_flags
= SA_RESTART
;
928 ret
= sigaction(SIGUSR1
, &act
, NULL
);
934 ret
= pipe(count_pipe
);
940 /* spawn counter thread */
941 err
= pthread_create(&tid_count
, NULL
, thr_count
,
946 act
.sa_handler
= sigusr2_handler
;
947 act
.sa_flags
= SA_RESTART
;
948 ret
= sigaction(SIGUSR2
, &act
, NULL
);
954 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
955 duration
, nr_readers
, nr_writers
);
956 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
957 printf_verbose("Reader duration : %lu loops.\n", rduration
);
958 printf_verbose("Mode:%s%s.\n",
959 add_only
? " add only" : " add/remove",
960 add_unique
? " uniquify" : ( add_replace
? " replace" : " insert"));
961 printf_verbose("Initial number of buckets: %lu buckets.\n", init_hash_size
);
962 printf_verbose("Minimum number of allocated buckets: %lu buckets.\n", min_hash_alloc_size
);
963 printf_verbose("Maximum number of buckets: %lu buckets.\n", max_hash_buckets_size
);
964 printf_verbose("Init pool size offset %lu size %lu.\n",
965 init_pool_offset
, init_pool_size
);
966 printf_verbose("Lookup pool size offset %lu size %lu.\n",
967 lookup_pool_offset
, lookup_pool_size
);
968 printf_verbose("Update pool size offset %lu size %lu.\n",
969 write_pool_offset
, write_pool_size
);
970 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
971 "main", pthread_self(), (unsigned long)gettid());
973 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
974 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
975 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
976 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
978 err
= create_all_cpu_call_rcu_data(0);
982 * Hash creation and population needs to be seen as a RCU reader
983 * thread from the point of view of resize.
985 rcu_register_thread();
986 test_ht
= cds_lfht_new(init_hash_size
, min_hash_alloc_size
,
987 max_hash_buckets_size
,
988 (opt_auto_resize
? CDS_LFHT_AUTO_RESIZE
: 0) |
989 CDS_LFHT_ACCOUNTING
, NULL
);
990 ret
= populate_hash();
993 rcu_thread_offline();
997 for (i
= 0; i
< nr_readers
; i
++) {
998 err
= pthread_create(&tid_reader
[i
], NULL
, thr_reader
,
1003 for (i
= 0; i
< nr_writers
; i
++) {
1004 err
= pthread_create(&tid_writer
[i
], NULL
, thr_writer
,
1016 remain
= sleep(remain
);
1017 } while (remain
> 0);
1021 for (i
= 0; i
< nr_readers
; i
++) {
1022 err
= pthread_join(tid_reader
[i
], &tret
);
1025 tot_reads
+= count_reader
[i
];
1027 for (i
= 0; i
< nr_writers
; i
++) {
1028 err
= pthread_join(tid_writer
[i
], &tret
);
1031 tot_writes
+= count_writer
[i
].update_ops
;
1032 tot_add
+= count_writer
[i
].add
;
1033 tot_add_exist
+= count_writer
[i
].add_exist
;
1034 tot_remove
+= count_writer
[i
].remove
;
1037 /* teardown counter thread */
1038 act
.sa_handler
= SIG_IGN
;
1039 act
.sa_flags
= SA_RESTART
;
1040 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1042 perror("sigaction");
1046 char msg
[1] = { 0x42 };
1050 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1051 } while (ret
== -1L && errno
== EINTR
);
1053 err
= pthread_join(tid_count
, &tret
);
1058 rcu_thread_online();
1060 printf("Counting nodes... ");
1061 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &removed
,
1064 test_delete_all_nodes(test_ht
);
1066 rcu_thread_offline();
1067 if (count
|| removed
) {
1068 printf("Approximation before node accounting: %ld nodes.\n",
1070 printf("Nodes deleted from hash table before destroy: "
1071 "%lu nodes + %lu logically removed.\n",
1073 printf("Approximation after node accounting: %ld nodes.\n",
1076 ret
= cds_lfht_destroy(test_ht
, NULL
);
1078 printf_verbose("final delete aborted\n");
1080 printf_verbose("final delete success\n");
1081 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1083 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1085 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1086 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1087 argv
[0], duration
, nr_readers
, rduration
,
1088 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1089 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1090 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1091 rcu_unregister_thread();
1092 free_all_cpu_call_rcu_data();