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;
75 static uint64_t key_mul
= 1ULL;
77 static pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
79 void set_affinity(void)
88 #if HAVE_SCHED_SETAFFINITY
89 ret
= pthread_mutex_lock(&affinity_mutex
);
91 perror("Error in pthread mutex lock");
94 cpu
= cpu_affinities
[next_aff
++];
95 ret
= pthread_mutex_unlock(&affinity_mutex
);
97 perror("Error in pthread mutex unlock");
102 #if SCHED_SETAFFINITY_ARGS == 2
103 sched_setaffinity(0, &mask
);
105 sched_setaffinity(0, sizeof(mask
), &mask
);
107 #endif /* HAVE_SCHED_SETAFFINITY */
110 void rcu_copy_mutex_lock(void)
113 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
115 perror("Error in pthread mutex lock");
120 void rcu_copy_mutex_unlock(void)
124 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
126 perror("Error in pthread mutex unlock");
131 void free_node_cb(struct rcu_head
*head
)
133 struct ja_test_node
*node
=
134 caa_container_of(head
, struct ja_test_node
, node
.head
);
140 void test_delete_all_nodes(struct cds_lfht
*ht
)
142 struct cds_lfht_iter iter
;
143 struct lfht_test_node
*node
;
144 unsigned long count
= 0;
146 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
149 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
151 call_rcu(&node
->head
, free_node_cb
);
154 printf("deleted %lu nodes.\n", count
);
158 void show_usage(int argc
, char **argv
)
160 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
162 printf(" [-r] [-w] (yield reader and/or writer)\n");
164 printf(" [-d delay] (writer period (us))\n");
165 printf(" [-c duration] (reader C.S. duration (in loops))\n");
166 printf(" [-v] (verbose output)\n");
167 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
168 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
169 printf(" [-r ratio] Add ratio (in %% of add+removal).\n");
170 printf(" [-k] Populate init nodes.\n");
171 printf(" [-R offset] Lookup pool offset.\n");
172 printf(" [-S offset] Write pool offset.\n");
173 printf(" [-T offset] Init pool offset.\n");
174 printf(" [-M size] Lookup pool size.\n");
175 printf(" [-N size] Write pool size.\n");
176 printf(" [-O size] Init pool size.\n");
177 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
178 printf(" [-s] Do sanity test.\n");
179 printf(" [-B] Key bits for multithread test (default: 32).\n");
180 printf(" [-m factor] Key multiplication factor.\n");
186 int test_8bit_key(void)
191 /* Test with 8-bit key */
192 test_ja
= cds_ja_new(8);
194 printf("Error allocating judy array.\n");
199 printf("Test #1: add keys (8-bit).\n");
200 for (key
= 0; key
< 200; key
++) {
201 struct ja_test_node
*node
=
202 calloc(sizeof(*node
), 1);
204 ja_test_node_init(node
, key
);
206 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
209 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
216 printf("Test #2: successful key lookup (8-bit).\n");
217 for (key
= 0; key
< 200; key
++) {
218 struct cds_hlist_head head
;
221 head
= cds_ja_lookup(test_ja
, key
);
222 if (cds_hlist_empty(&head
)) {
223 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
229 printf("Test #3: unsuccessful key lookup (8-bit).\n");
230 for (key
= 200; key
< 240; key
++) {
231 struct cds_hlist_head head
;
234 head
= cds_ja_lookup(test_ja
, key
);
235 if (!cds_hlist_empty(&head
)) {
237 "Error unexpected lookup node %" PRIu64
"\n",
244 printf("Test #4: remove keys (8-bit).\n");
245 for (key
= 0; key
< 200; key
++) {
246 struct cds_hlist_head head
;
247 struct ja_test_node
*node
;
250 head
= cds_ja_lookup(test_ja
, key
);
251 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
253 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
256 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
258 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
261 call_rcu(&node
->node
.head
, free_node_cb
);
262 head
= cds_ja_lookup(test_ja
, key
);
263 if (!cds_hlist_empty(&head
)) {
264 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
271 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
273 fprintf(stderr
, "Error destroying judy array\n");
280 int test_16bit_key(void)
285 /* Test with 16-bit key */
286 test_ja
= cds_ja_new(16);
288 printf("Error allocating judy array.\n");
293 printf("Test #1: add keys (16-bit).\n");
294 for (key
= 0; key
< 10000; key
++) {
295 //for (key = 0; key < 65536; key+=256) {
296 struct ja_test_node
*node
=
297 calloc(sizeof(*node
), 1);
299 ja_test_node_init(node
, key
);
301 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
304 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
311 printf("Test #2: successful key lookup (16-bit).\n");
312 for (key
= 0; key
< 10000; key
++) {
313 //for (key = 0; key < 65536; key+=256) {
314 struct cds_hlist_head head
;
317 head
= cds_ja_lookup(test_ja
, key
);
318 if (cds_hlist_empty(&head
)) {
319 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
325 printf("Test #3: unsuccessful key lookup (16-bit).\n");
326 for (key
= 11000; key
<= 11002; key
++) {
327 struct cds_hlist_head head
;
330 head
= cds_ja_lookup(test_ja
, key
);
331 if (!cds_hlist_empty(&head
)) {
333 "Error unexpected lookup node %" PRIu64
"\n",
340 printf("Test #4: remove keys (16-bit).\n");
341 for (key
= 0; key
< 10000; key
++) {
342 //for (key = 0; key < 65536; key+=256) {
343 struct cds_hlist_head head
;
344 struct ja_test_node
*node
;
347 head
= cds_ja_lookup(test_ja
, key
);
348 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
350 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
353 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
355 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
358 call_rcu(&node
->node
.head
, free_node_cb
);
359 head
= cds_ja_lookup(test_ja
, key
);
360 if (!cds_hlist_empty(&head
)) {
361 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
368 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
370 fprintf(stderr
, "Error destroying judy array\n");
377 * nr_dup is number of nodes per key.
380 int test_sparse_key(unsigned int bits
, int nr_dup
)
382 uint64_t key
, max_key
;
383 int zerocount
, i
, ret
;
386 max_key
= UINT64_MAX
;
388 max_key
= (1ULL << bits
) - 1;
390 printf("Sparse key test begins for %u-bit keys\n", bits
);
391 /* Test with 16-bit key */
392 test_ja
= cds_ja_new(bits
);
394 printf("Error allocating judy array.\n");
399 printf("Test #1: add keys (%u-bit).\n", bits
);
400 for (i
= 0; i
< nr_dup
; i
++) {
402 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
403 struct ja_test_node
*node
=
404 calloc(sizeof(*node
), 1);
406 ja_test_node_init(node
, key
);
408 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
411 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
421 printf("Test #2: successful key lookup (%u-bit).\n", bits
);
423 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
424 struct cds_hlist_head head
;
425 struct ja_test_node
*node
;
426 struct cds_hlist_node
*pos
;
430 head
= cds_ja_lookup(test_ja
, key
);
431 if (cds_hlist_empty(&head
)) {
432 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
435 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
438 if (count
!= nr_dup
) {
439 fprintf(stderr
, "Unexpected number of match for key %" PRIu64
", expected %d, got %d.\n", key
, nr_dup
, count
);
447 printf("Test #3: unsuccessful key lookup (%u-bit).\n", bits
);
449 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
450 struct cds_hlist_head head
;
453 head
= cds_ja_lookup(test_ja
, key
+ 42);
454 if (!cds_hlist_empty(&head
)) {
456 "Error unexpected lookup node %" PRIu64
"\n",
466 printf("Test #4: remove keys (16-bit).\n");
468 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
469 struct cds_hlist_head head
;
470 struct ja_test_node
*node
;
471 struct cds_hlist_node
*pos
;
475 head
= cds_ja_lookup(test_ja
, key
);
478 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
479 struct cds_hlist_head testhead
;
483 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
486 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
488 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
491 call_rcu(&node
->node
.head
, free_node_cb
);
492 testhead
= cds_ja_lookup(test_ja
, key
);
493 if (count
< nr_dup
&& cds_hlist_empty(&testhead
)) {
494 fprintf(stderr
, "Error: no node found after deletion of some nodes of a key\n");
498 head
= cds_ja_lookup(test_ja
, key
);
499 if (!cds_hlist_empty(&head
)) {
500 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
509 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
511 fprintf(stderr
, "Error destroying judy array\n");
514 printf("Test ends\n");
520 int do_sanity_test(void)
524 printf("Sanity test start.\n");
526 for (i
= 0; i
< 3; i
++) {
527 ret
= test_8bit_key();
531 rcu_quiescent_state();
533 ret
= test_16bit_key();
537 rcu_quiescent_state();
540 for (i
= 8; i
<= 64; i
*= 2) {
541 /* nr of nodes per key */
542 for (j
= 1; j
< 4; j
++) {
543 ret
= test_sparse_key(i
, j
);
547 rcu_quiescent_state();
550 printf("Sanity test end.\n");
555 enum urcu_ja_addremove
{
559 }; /* 1: add, -1 remove, 0: random */
561 static enum urcu_ja_addremove addremove
; /* 1: add, -1 remove, 0: random */
564 void test_ja_rw_sigusr1_handler(int signo
)
568 printf("Add/Remove: random.\n");
569 addremove
= AR_RANDOM
;
572 printf("Add/Remove: remove only.\n");
573 addremove
= AR_REMOVE
;
576 printf("Add/Remove: add only.\n");
583 void *test_ja_rw_thr_reader(void *_count
)
585 unsigned long long *count
= _count
;
586 struct cds_hlist_head head
;
589 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
590 "reader", pthread_self(), (unsigned long) gettid());
594 rcu_register_thread();
604 /* note: only looking up ulong keys */
605 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % lookup_pool_size
) + lookup_pool_offset
;
607 head
= cds_ja_lookup(test_ja
, key
);
608 if (cds_hlist_empty(&head
)) {
609 if (validate_lookup
) {
610 printf("[ERROR] Lookup cannot find initial node.\n");
613 URCU_TLS(lookup_fail
)++;
615 URCU_TLS(lookup_ok
)++;
617 rcu_debug_yield_read();
618 if (caa_unlikely(rduration
))
619 loop_sleep(rduration
);
621 URCU_TLS(nr_reads
)++;
622 if (caa_unlikely(!test_duration_read()))
624 if (caa_unlikely((URCU_TLS(nr_reads
) & ((1 << 10) - 1)) == 0))
625 rcu_quiescent_state();
628 rcu_unregister_thread();
630 *count
= URCU_TLS(nr_reads
);
631 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
632 "reader", pthread_self(), (unsigned long) gettid());
633 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
634 pthread_self(), URCU_TLS(lookup_fail
),
635 URCU_TLS(lookup_ok
));
642 return ((unsigned int) rand_r(&URCU_TLS(rand_lookup
)) % 100) < add_ratio
;
646 void *test_ja_rw_thr_writer(void *_count
)
648 struct wr_count
*count
= _count
;
649 struct cds_hlist_head head
;
653 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
654 "writer", pthread_self(), (unsigned long) gettid());
658 rcu_register_thread();
666 if ((addremove
== AR_ADD
)
667 || (addremove
== AR_RANDOM
&& is_add())) {
668 struct ja_test_node
*node
= malloc(sizeof(*node
));
670 /* note: only inserting ulong keys */
671 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
673 ja_test_node_init(node
, key
);
675 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
679 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
684 struct ja_test_node
*node
;
687 /* note: only deleting ulong keys */
688 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
693 head
= cds_ja_lookup(test_ja
, key
);
694 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
696 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
698 call_rcu(&node
->node
.head
, free_node_cb
);
701 URCU_TLS(nr_delnoent
)++;
704 URCU_TLS(nr_delnoent
)++;
709 URCU_TLS(nr_writes
)++;
710 if (caa_unlikely(!test_duration_write()))
712 if (caa_unlikely(wdelay
))
714 if (caa_unlikely((URCU_TLS(nr_writes
) & ((1 << 10) - 1)) == 0))
715 rcu_quiescent_state();
718 rcu_unregister_thread();
720 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
721 "writer", pthread_self(), (unsigned long) gettid());
722 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
723 "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add
),
724 URCU_TLS(nr_addexist
), URCU_TLS(nr_del
),
725 URCU_TLS(nr_delnoent
));
726 count
->update_ops
= URCU_TLS(nr_writes
);
727 count
->add
= URCU_TLS(nr_add
);
728 count
->add_exist
= URCU_TLS(nr_addexist
);
729 count
->remove
= URCU_TLS(nr_del
);
734 int do_mt_populate_ja(void)
736 struct cds_hlist_head head
;
743 printf("Starting rw test\n");
745 for (iter
= init_pool_offset
; iter
< init_pool_offset
+ init_pool_size
; iter
++) {
746 struct ja_test_node
*node
= malloc(sizeof(*node
));
749 /* note: only inserting ulong keys */
750 key
= (unsigned long) iter
;
752 ja_test_node_init(node
, key
);
754 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
756 URCU_TLS(nr_writes
)++;
759 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
770 pthread_t
*tid_reader
, *tid_writer
;
773 unsigned long long *count_reader
;
774 struct wr_count
*count_writer
;
775 unsigned long long tot_reads
= 0, tot_writes
= 0,
776 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
779 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
780 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
781 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
782 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
784 printf("Allocating Judy Array for %u-bit keys\n", key_bits
);
785 test_ja
= cds_ja_new(key_bits
);
787 printf("Error allocating judy array.\n");
796 for (i
= 0; i
< nr_readers
; i
++) {
797 err
= pthread_create(&tid_reader
[i
],
798 NULL
, test_ja_rw_thr_reader
,
803 for (i
= 0; i
< nr_writers
; i
++) {
804 err
= pthread_create(&tid_writer
[i
],
805 NULL
, test_ja_rw_thr_writer
,
815 rcu_thread_offline_qsbr();
819 remain
= sleep(remain
);
820 } while (remain
> 0);
824 for (i
= 0; i
< nr_readers
; i
++) {
825 err
= pthread_join(tid_reader
[i
], &tret
);
828 tot_reads
+= count_reader
[i
];
830 for (i
= 0; i
< nr_writers
; i
++) {
831 err
= pthread_join(tid_writer
[i
], &tret
);
834 tot_writes
+= count_writer
[i
].update_ops
;
835 tot_add
+= count_writer
[i
].add
;
836 tot_add_exist
+= count_writer
[i
].add_exist
;
837 tot_remove
+= count_writer
[i
].remove
;
839 rcu_thread_online_qsbr();
841 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
843 fprintf(stderr
, "Error destroying judy array\n");
856 int main(int argc
, char **argv
)
858 int i
, j
, a
, ret
, err
;
860 struct sigaction act
;
863 show_usage(argc
, argv
);
867 err
= sscanf(argv
[1], "%u", &nr_readers
);
869 show_usage(argc
, argv
);
873 err
= sscanf(argv
[2], "%u", &nr_writers
);
875 show_usage(argc
, argv
);
879 err
= sscanf(argv
[3], "%lu", &duration
);
881 show_usage(argc
, argv
);
885 for (i
= 4; i
< argc
; i
++) {
886 if (argv
[i
][0] != '-')
888 switch (argv
[i
][1]) {
891 yield_active
|= YIELD_READ
;
894 yield_active
|= YIELD_WRITE
;
899 show_usage(argc
, argv
);
903 cpu_affinities
[next_aff
++] = a
;
905 printf_verbose("Adding CPU %d affinity\n", a
);
909 show_usage(argc
, argv
);
912 rduration
= atol(argv
[++i
]);
916 show_usage(argc
, argv
);
919 wdelay
= atol(argv
[++i
]);
925 add_ratio
= atoi(argv
[++i
]);
931 lookup_pool_offset
= atol(argv
[++i
]);
934 write_pool_offset
= atol(argv
[++i
]);
937 init_pool_offset
= atol(argv
[++i
]);
940 lookup_pool_size
= atol(argv
[++i
]);
943 write_pool_size
= atol(argv
[++i
]);
946 init_pool_size
= atol(argv
[++i
]);
955 key_bits
= atol(argv
[++i
]);
958 key_mul
= atoll(argv
[++i
]);
963 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
964 duration
, nr_readers
, nr_writers
);
965 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
966 printf_verbose("Reader duration : %lu loops.\n", rduration
);
967 printf_verbose("Add ratio: %u%%.\n", add_ratio
);
968 printf_verbose("Key multiplication factor: %" PRIu64
".\n", key_mul
);
969 printf_verbose("Init pool size offset %lu size %lu.\n",
970 init_pool_offset
, init_pool_size
);
971 printf_verbose("Lookup pool size offset %lu size %lu.\n",
972 lookup_pool_offset
, lookup_pool_size
);
973 printf_verbose("Update pool size offset %lu size %lu.\n",
974 write_pool_offset
, write_pool_size
);
975 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
976 "main", pthread_self(), (unsigned long)gettid());
978 memset(&act
, 0, sizeof(act
));
979 ret
= sigemptyset(&act
.sa_mask
);
981 perror("sigemptyset");
984 act
.sa_handler
= test_ja_rw_sigusr1_handler
;
985 act
.sa_flags
= SA_RESTART
;
986 ret
= sigaction(SIGUSR1
, &act
, NULL
);
992 err
= create_all_cpu_call_rcu_data(0);
994 printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");
997 rcu_register_thread();
1000 ret
= do_sanity_test();
1002 fprintf(stderr
, "Error in sanity test\n");
1008 rcu_unregister_thread();
1009 free_all_cpu_call_rcu_data();
1014 * Hash Population needs to be seen as a RCU reader
1015 * thread from the point of view of resize.
1017 rcu_register_thread();
1018 ret
= (get_populate_hash_cb())();
1021 rcu_thread_offline();
1023 /* teardown counter thread */
1024 act
.sa_handler
= SIG_IGN
;
1025 act
.sa_flags
= SA_RESTART
;
1026 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1028 perror("sigaction");
1032 char msg
[1] = { 0x42 };
1036 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1037 } while (ret
== -1L && errno
== EINTR
);
1041 rcu_thread_online();
1043 printf("Counting nodes... ");
1044 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1046 test_delete_all_nodes(test_ht
);
1048 rcu_thread_offline();
1050 printf("Approximation before node accounting: %ld nodes.\n",
1052 printf("Nodes deleted from hash table before destroy: "
1055 printf("Approximation after node accounting: %ld nodes.\n",
1058 ret
= cds_lfht_destroy(test_ht
, NULL
);
1060 printf_verbose("final delete aborted\n");
1062 printf_verbose("final delete success\n");
1063 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1065 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1067 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1068 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1069 argv
[0], duration
, nr_readers
, rduration
,
1070 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1071 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1072 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1073 rcu_unregister_thread();