4 * Userspace RCU library - test program
6 * Copyright 2009-2012 - 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.
24 #include "test_urcu_ja.h"
28 DEFINE_URCU_TLS(unsigned int, rand_lookup
);
29 DEFINE_URCU_TLS(unsigned long, nr_add
);
30 DEFINE_URCU_TLS(unsigned long, nr_addexist
);
31 DEFINE_URCU_TLS(unsigned long, nr_del
);
32 DEFINE_URCU_TLS(unsigned long, nr_delnoent
);
33 DEFINE_URCU_TLS(unsigned long, lookup_fail
);
34 DEFINE_URCU_TLS(unsigned long, lookup_ok
);
36 struct cds_ja
*test_ja
;
38 volatile int test_go
, test_stop
;
42 unsigned long duration
;
44 /* read-side C.S. duration, in loops */
45 unsigned long rduration
;
47 unsigned long init_populate
;
50 unsigned long init_pool_offset
, lookup_pool_offset
, write_pool_offset
;
51 unsigned long init_pool_size
= DEFAULT_RAND_POOL
,
52 lookup_pool_size
= DEFAULT_RAND_POOL
,
53 write_pool_size
= DEFAULT_RAND_POOL
;
56 unsigned int key_bits
= 32;
62 unsigned int cpu_affinities
[NR_CPUS
];
63 unsigned int next_aff
= 0;
66 pthread_mutex_t affinity_mutex
= PTHREAD_MUTEX_INITIALIZER
;
68 DEFINE_URCU_TLS(unsigned long long, nr_writes
);
69 DEFINE_URCU_TLS(unsigned long long, nr_reads
);
71 unsigned int nr_readers
;
72 unsigned int nr_writers
;
74 static unsigned int add_ratio
= 50;
76 static pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
78 void set_affinity(void)
87 #if HAVE_SCHED_SETAFFINITY
88 ret
= pthread_mutex_lock(&affinity_mutex
);
90 perror("Error in pthread mutex lock");
93 cpu
= cpu_affinities
[next_aff
++];
94 ret
= pthread_mutex_unlock(&affinity_mutex
);
96 perror("Error in pthread mutex unlock");
101 #if SCHED_SETAFFINITY_ARGS == 2
102 sched_setaffinity(0, &mask
);
104 sched_setaffinity(0, sizeof(mask
), &mask
);
106 #endif /* HAVE_SCHED_SETAFFINITY */
109 void rcu_copy_mutex_lock(void)
112 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
114 perror("Error in pthread mutex lock");
119 void rcu_copy_mutex_unlock(void)
123 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
125 perror("Error in pthread mutex unlock");
130 void free_node_cb(struct rcu_head
*head
)
132 struct ja_test_node
*node
=
133 caa_container_of(head
, struct ja_test_node
, node
.head
);
139 void test_delete_all_nodes(struct cds_lfht
*ht
)
141 struct cds_lfht_iter iter
;
142 struct lfht_test_node
*node
;
143 unsigned long count
= 0;
145 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
148 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
150 call_rcu(&node
->head
, free_node_cb
);
153 printf("deleted %lu nodes.\n", count
);
157 void show_usage(int argc
, char **argv
)
159 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
161 printf(" [-r] [-w] (yield reader and/or writer)\n");
163 printf(" [-d delay] (writer period (us))\n");
164 printf(" [-c duration] (reader C.S. duration (in loops))\n");
165 printf(" [-v] (verbose output)\n");
166 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
167 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
168 printf(" [-r] Add ratio (in %% of add+removal).\n");
169 printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
170 printf(" [-R offset] Lookup pool offset.\n");
171 printf(" [-S offset] Write pool offset.\n");
172 printf(" [-T offset] Init pool offset.\n");
173 printf(" [-M size] Lookup pool size.\n");
174 printf(" [-N size] Write pool size.\n");
175 printf(" [-O size] Init pool size.\n");
176 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
177 printf(" [-s] Do sanity test.\n");
178 printf(" [-B] Key bits for multithread test (default: 32).\n");
184 int test_8bit_key(void)
189 /* Test with 8-bit key */
190 test_ja
= cds_ja_new(8);
192 printf("Error allocating judy array.\n");
197 printf("Test #1: add keys (8-bit).\n");
198 for (key
= 0; key
< 200; key
++) {
199 struct ja_test_node
*node
=
200 calloc(sizeof(*node
), 1);
202 ja_test_node_init(node
, key
);
204 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
207 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
214 printf("Test #2: successful key lookup (8-bit).\n");
215 for (key
= 0; key
< 200; key
++) {
216 struct cds_hlist_head head
;
219 head
= cds_ja_lookup(test_ja
, key
);
220 if (cds_hlist_empty(&head
)) {
221 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
227 printf("Test #3: unsuccessful key lookup (8-bit).\n");
228 for (key
= 200; key
< 240; key
++) {
229 struct cds_hlist_head head
;
232 head
= cds_ja_lookup(test_ja
, key
);
233 if (!cds_hlist_empty(&head
)) {
235 "Error unexpected lookup node %" PRIu64
"\n",
242 printf("Test #4: remove keys (8-bit).\n");
243 for (key
= 0; key
< 200; key
++) {
244 struct cds_hlist_head head
;
245 struct ja_test_node
*node
;
248 head
= cds_ja_lookup(test_ja
, key
);
249 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
251 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
254 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
256 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
259 call_rcu(&node
->node
.head
, free_node_cb
);
260 head
= cds_ja_lookup(test_ja
, key
);
261 if (!cds_hlist_empty(&head
)) {
262 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
269 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
271 fprintf(stderr
, "Error destroying judy array\n");
278 int test_16bit_key(void)
283 /* Test with 16-bit key */
284 test_ja
= cds_ja_new(16);
286 printf("Error allocating judy array.\n");
291 printf("Test #1: add keys (16-bit).\n");
292 for (key
= 0; key
< 10000; key
++) {
293 //for (key = 0; key < 65536; key+=256) {
294 struct ja_test_node
*node
=
295 calloc(sizeof(*node
), 1);
297 ja_test_node_init(node
, key
);
299 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
302 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
309 printf("Test #2: successful key lookup (16-bit).\n");
310 for (key
= 0; key
< 10000; key
++) {
311 //for (key = 0; key < 65536; key+=256) {
312 struct cds_hlist_head head
;
315 head
= cds_ja_lookup(test_ja
, key
);
316 if (cds_hlist_empty(&head
)) {
317 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
323 printf("Test #3: unsuccessful key lookup (16-bit).\n");
324 for (key
= 11000; key
<= 11002; key
++) {
325 struct cds_hlist_head head
;
328 head
= cds_ja_lookup(test_ja
, key
);
329 if (!cds_hlist_empty(&head
)) {
331 "Error unexpected lookup node %" PRIu64
"\n",
338 printf("Test #4: remove keys (16-bit).\n");
339 for (key
= 0; key
< 10000; key
++) {
340 //for (key = 0; key < 65536; key+=256) {
341 struct cds_hlist_head head
;
342 struct ja_test_node
*node
;
345 head
= cds_ja_lookup(test_ja
, key
);
346 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
348 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
351 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
353 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
356 call_rcu(&node
->node
.head
, free_node_cb
);
357 head
= cds_ja_lookup(test_ja
, key
);
358 if (!cds_hlist_empty(&head
)) {
359 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
366 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
368 fprintf(stderr
, "Error destroying judy array\n");
375 * nr_dup is number of nodes per key.
378 int test_sparse_key(unsigned int bits
, int nr_dup
)
380 uint64_t key
, max_key
;
381 int zerocount
, i
, ret
;
384 max_key
= UINT64_MAX
;
386 max_key
= (1ULL << bits
) - 1;
388 printf("Sparse key test begins for %u-bit keys\n", bits
);
389 /* Test with 16-bit key */
390 test_ja
= cds_ja_new(bits
);
392 printf("Error allocating judy array.\n");
397 printf("Test #1: add keys (%u-bit).\n", bits
);
398 for (i
= 0; i
< nr_dup
; i
++) {
400 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
401 struct ja_test_node
*node
=
402 calloc(sizeof(*node
), 1);
404 ja_test_node_init(node
, key
);
406 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
409 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
419 printf("Test #2: successful key lookup (%u-bit).\n", bits
);
421 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
422 struct cds_hlist_head head
;
423 struct ja_test_node
*node
;
424 struct cds_hlist_node
*pos
;
428 head
= cds_ja_lookup(test_ja
, key
);
429 if (cds_hlist_empty(&head
)) {
430 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
433 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
436 if (count
!= nr_dup
) {
437 fprintf(stderr
, "Unexpected number of match for key %" PRIu64
", expected %d, got %d.\n", key
, nr_dup
, count
);
445 printf("Test #3: unsuccessful key lookup (%u-bit).\n", bits
);
447 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
448 struct cds_hlist_head head
;
451 head
= cds_ja_lookup(test_ja
, key
+ 42);
452 if (!cds_hlist_empty(&head
)) {
454 "Error unexpected lookup node %" PRIu64
"\n",
464 printf("Test #4: remove keys (16-bit).\n");
466 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
467 struct cds_hlist_head head
;
468 struct ja_test_node
*node
;
469 struct cds_hlist_node
*pos
;
473 head
= cds_ja_lookup(test_ja
, key
);
476 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
477 struct cds_hlist_head testhead
;
481 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
484 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
486 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
489 call_rcu(&node
->node
.head
, free_node_cb
);
490 testhead
= cds_ja_lookup(test_ja
, key
);
491 if (count
< nr_dup
&& cds_hlist_empty(&testhead
)) {
492 fprintf(stderr
, "Error: no node found after deletion of some nodes of a key\n");
496 head
= cds_ja_lookup(test_ja
, key
);
497 if (!cds_hlist_empty(&head
)) {
498 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
507 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
509 fprintf(stderr
, "Error destroying judy array\n");
512 printf("Test ends\n");
518 int do_sanity_test(void)
522 printf("Sanity test start.\n");
524 for (i
= 0; i
< 3; i
++) {
525 ret
= test_8bit_key();
529 rcu_quiescent_state();
531 ret
= test_16bit_key();
535 rcu_quiescent_state();
538 for (i
= 8; i
<= 64; i
*= 2) {
539 /* nr of nodes per key */
540 for (j
= 1; j
< 4; j
++) {
541 ret
= test_sparse_key(i
, j
);
545 rcu_quiescent_state();
548 printf("Sanity test end.\n");
553 enum urcu_ja_addremove
{
557 }; /* 1: add, -1 remove, 0: random */
559 static enum urcu_ja_addremove addremove
; /* 1: add, -1 remove, 0: random */
562 void test_ja_rw_sigusr1_handler(int signo
)
566 printf("Add/Remove: random.\n");
567 addremove
= AR_RANDOM
;
570 printf("Add/Remove: remove only.\n");
571 addremove
= AR_REMOVE
;
574 printf("Add/Remove: add only.\n");
581 void *test_ja_rw_thr_reader(void *_count
)
583 unsigned long long *count
= _count
;
584 struct cds_hlist_head head
;
587 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
588 "reader", pthread_self(), (unsigned long) gettid());
592 rcu_register_thread();
602 /* note: only looking up ulong keys */
603 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % lookup_pool_size
) + lookup_pool_offset
;
604 head
= cds_ja_lookup(test_ja
, key
);
605 if (cds_hlist_empty(&head
)) {
606 if (validate_lookup
) {
607 printf("[ERROR] Lookup cannot find initial node.\n");
610 URCU_TLS(lookup_fail
)++;
612 URCU_TLS(lookup_ok
)++;
614 rcu_debug_yield_read();
615 if (caa_unlikely(rduration
))
616 loop_sleep(rduration
);
618 URCU_TLS(nr_reads
)++;
619 if (caa_unlikely(!test_duration_read()))
621 if (caa_unlikely((URCU_TLS(nr_reads
) & ((1 << 10) - 1)) == 0))
622 rcu_quiescent_state();
625 rcu_unregister_thread();
627 *count
= URCU_TLS(nr_reads
);
628 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
629 "reader", pthread_self(), (unsigned long) gettid());
630 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
631 pthread_self(), URCU_TLS(lookup_fail
),
632 URCU_TLS(lookup_ok
));
639 return ((unsigned int) rand_r(&URCU_TLS(rand_lookup
)) % 100) < add_ratio
;
643 void *test_ja_rw_thr_writer(void *_count
)
645 struct wr_count
*count
= _count
;
646 struct cds_hlist_head head
;
650 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
651 "writer", pthread_self(), (unsigned long) gettid());
655 rcu_register_thread();
663 if ((addremove
== AR_ADD
)
664 || (addremove
== AR_RANDOM
&& is_add())) {
665 struct ja_test_node
*node
= malloc(sizeof(*node
));
667 /* note: only inserting ulong keys */
668 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
669 ja_test_node_init(node
, key
);
671 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
675 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
680 struct ja_test_node
*node
;
683 /* note: only deleting ulong keys */
684 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
688 head
= cds_ja_lookup(test_ja
, key
);
689 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
691 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
693 call_rcu(&node
->node
.head
, free_node_cb
);
696 URCU_TLS(nr_delnoent
)++;
699 URCU_TLS(nr_delnoent
)++;
704 URCU_TLS(nr_writes
)++;
705 if (caa_unlikely(!test_duration_write()))
707 if (caa_unlikely(wdelay
))
709 if (caa_unlikely((URCU_TLS(nr_writes
) & ((1 << 10) - 1)) == 0))
710 rcu_quiescent_state();
713 rcu_unregister_thread();
715 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
716 "writer", pthread_self(), (unsigned long) gettid());
717 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
718 "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add
),
719 URCU_TLS(nr_addexist
), URCU_TLS(nr_del
),
720 URCU_TLS(nr_delnoent
));
721 count
->update_ops
= URCU_TLS(nr_writes
);
722 count
->add
= URCU_TLS(nr_add
);
723 count
->add_exist
= URCU_TLS(nr_addexist
);
724 count
->remove
= URCU_TLS(nr_del
);
729 int do_mt_populate_ja(void)
731 struct cds_hlist_head head
;
738 printf("Starting rw test\n");
740 for (key
= init_pool_offset
; key
< init_pool_offset
+ init_pool_size
; key
++) {
741 struct ja_test_node
*node
= malloc(sizeof(*node
));
743 /* note: only inserting ulong keys */
744 key
= (unsigned long) key
;
745 ja_test_node_init(node
, key
);
747 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
749 URCU_TLS(nr_writes
)++;
752 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
763 pthread_t
*tid_reader
, *tid_writer
;
766 unsigned long long *count_reader
;
767 struct wr_count
*count_writer
;
768 unsigned long long tot_reads
= 0, tot_writes
= 0,
769 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
772 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
773 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
774 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
775 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
777 printf("Allocating Judy Array for %u-bit keys\n", key_bits
);
778 test_ja
= cds_ja_new(key_bits
);
780 printf("Error allocating judy array.\n");
789 for (i
= 0; i
< nr_readers
; i
++) {
790 err
= pthread_create(&tid_reader
[i
],
791 NULL
, test_ja_rw_thr_reader
,
796 for (i
= 0; i
< nr_writers
; i
++) {
797 err
= pthread_create(&tid_writer
[i
],
798 NULL
, test_ja_rw_thr_writer
,
808 rcu_thread_offline_qsbr();
812 remain
= sleep(remain
);
813 } while (remain
> 0);
817 for (i
= 0; i
< nr_readers
; i
++) {
818 err
= pthread_join(tid_reader
[i
], &tret
);
821 tot_reads
+= count_reader
[i
];
823 for (i
= 0; i
< nr_writers
; i
++) {
824 err
= pthread_join(tid_writer
[i
], &tret
);
827 tot_writes
+= count_writer
[i
].update_ops
;
828 tot_add
+= count_writer
[i
].add
;
829 tot_add_exist
+= count_writer
[i
].add_exist
;
830 tot_remove
+= count_writer
[i
].remove
;
833 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
835 fprintf(stderr
, "Error destroying judy array\n");
838 rcu_thread_online_qsbr();
849 int main(int argc
, char **argv
)
851 int i
, j
, a
, ret
, err
;
853 struct sigaction act
;
856 show_usage(argc
, argv
);
860 err
= sscanf(argv
[1], "%u", &nr_readers
);
862 show_usage(argc
, argv
);
866 err
= sscanf(argv
[2], "%u", &nr_writers
);
868 show_usage(argc
, argv
);
872 err
= sscanf(argv
[3], "%lu", &duration
);
874 show_usage(argc
, argv
);
878 for (i
= 4; i
< argc
; i
++) {
879 if (argv
[i
][0] != '-')
881 switch (argv
[i
][1]) {
884 yield_active
|= YIELD_READ
;
887 yield_active
|= YIELD_WRITE
;
892 show_usage(argc
, argv
);
896 cpu_affinities
[next_aff
++] = a
;
898 printf_verbose("Adding CPU %d affinity\n", a
);
902 show_usage(argc
, argv
);
905 rduration
= atol(argv
[++i
]);
909 show_usage(argc
, argv
);
912 wdelay
= atol(argv
[++i
]);
918 add_ratio
= atoi(argv
[++i
]);
921 init_populate
= atol(argv
[++i
]);
924 lookup_pool_offset
= atol(argv
[++i
]);
927 write_pool_offset
= atol(argv
[++i
]);
930 init_pool_offset
= atol(argv
[++i
]);
933 lookup_pool_size
= atol(argv
[++i
]);
936 write_pool_size
= atol(argv
[++i
]);
939 init_pool_size
= atol(argv
[++i
]);
948 key_bits
= atol(argv
[++i
]);
953 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
954 duration
, nr_readers
, nr_writers
);
955 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
956 printf_verbose("Reader duration : %lu loops.\n", rduration
);
957 printf_verbose("Add ratio: %u%%.\n", add_ratio
);
958 printf_verbose("Init pool size offset %lu size %lu.\n",
959 init_pool_offset
, init_pool_size
);
960 printf_verbose("Lookup pool size offset %lu size %lu.\n",
961 lookup_pool_offset
, lookup_pool_size
);
962 printf_verbose("Update pool size offset %lu size %lu.\n",
963 write_pool_offset
, write_pool_size
);
964 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
965 "main", pthread_self(), (unsigned long)gettid());
967 memset(&act
, 0, sizeof(act
));
968 ret
= sigemptyset(&act
.sa_mask
);
970 perror("sigemptyset");
973 act
.sa_handler
= test_ja_rw_sigusr1_handler
;
974 act
.sa_flags
= SA_RESTART
;
975 ret
= sigaction(SIGUSR1
, &act
, NULL
);
981 err
= create_all_cpu_call_rcu_data(0);
983 printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");
986 rcu_register_thread();
989 ret
= do_sanity_test();
991 fprintf(stderr
, "Error in sanity test\n");
997 rcu_unregister_thread();
998 free_all_cpu_call_rcu_data();
1003 * Hash Population needs to be seen as a RCU reader
1004 * thread from the point of view of resize.
1006 rcu_register_thread();
1007 ret
= (get_populate_hash_cb())();
1010 rcu_thread_offline();
1012 /* teardown counter thread */
1013 act
.sa_handler
= SIG_IGN
;
1014 act
.sa_flags
= SA_RESTART
;
1015 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1017 perror("sigaction");
1021 char msg
[1] = { 0x42 };
1025 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1026 } while (ret
== -1L && errno
== EINTR
);
1030 rcu_thread_online();
1032 printf("Counting nodes... ");
1033 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1035 test_delete_all_nodes(test_ht
);
1037 rcu_thread_offline();
1039 printf("Approximation before node accounting: %ld nodes.\n",
1041 printf("Nodes deleted from hash table before destroy: "
1044 printf("Approximation after node accounting: %ld nodes.\n",
1047 ret
= cds_lfht_destroy(test_ht
, NULL
);
1049 printf_verbose("final delete aborted\n");
1051 printf_verbose("final delete success\n");
1052 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1054 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1056 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1057 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1058 argv
[0], duration
, nr_readers
, rduration
,
1059 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1060 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1061 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1062 rcu_unregister_thread();