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 int add_unique
, add_replace
;
79 static pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
81 static int leak_detection
;
82 static unsigned long test_nodes_allocated
, test_nodes_freed
;
84 void set_affinity(void)
93 #if HAVE_SCHED_SETAFFINITY
94 ret
= pthread_mutex_lock(&affinity_mutex
);
96 perror("Error in pthread mutex lock");
99 cpu
= cpu_affinities
[next_aff
++];
100 ret
= pthread_mutex_unlock(&affinity_mutex
);
102 perror("Error in pthread mutex unlock");
107 #if SCHED_SETAFFINITY_ARGS == 2
108 sched_setaffinity(0, &mask
);
110 sched_setaffinity(0, sizeof(mask
), &mask
);
112 #endif /* HAVE_SCHED_SETAFFINITY */
115 void rcu_copy_mutex_lock(void)
118 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
120 perror("Error in pthread mutex lock");
125 void rcu_copy_mutex_unlock(void)
129 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
131 perror("Error in pthread mutex unlock");
137 struct ja_test_node
*node_alloc(void)
139 struct ja_test_node
*node
;
141 node
= calloc(sizeof(*node
), 1);
142 if (leak_detection
&& node
)
143 uatomic_inc(&test_nodes_allocated
);
148 void free_node_cb(struct rcu_head
*head
)
150 struct ja_test_node
*node
=
151 caa_container_of(head
, struct ja_test_node
, node
.head
);
154 uatomic_inc(&test_nodes_freed
);
159 void test_delete_all_nodes(struct cds_lfht
*ht
)
161 struct cds_lfht_iter iter
;
162 struct lfht_test_node
*node
;
163 unsigned long count
= 0;
165 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
168 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
170 call_rcu(&node
->head
, free_node_cb
);
173 printf("deleted %lu nodes.\n", count
);
177 void show_usage(int argc
, char **argv
)
179 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
181 printf(" [-r] [-w] (yield reader and/or writer)\n");
183 printf(" [-d delay] (writer period (us))\n");
184 printf(" [-c duration] (reader C.S. duration (in loops))\n");
185 printf(" [-v] (verbose output)\n");
186 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
187 printf(" [-u] Add unique keys.\n");
188 printf(" [-s] Replace existing keys.\n");
189 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
190 printf(" [-r ratio] Add ratio (in %% of add+removal).\n");
191 printf(" [-k] Populate init nodes.\n");
192 printf(" [-R offset] Lookup pool offset.\n");
193 printf(" [-S offset] Write pool offset.\n");
194 printf(" [-T offset] Init pool offset.\n");
195 printf(" [-M size] Lookup pool size.\n");
196 printf(" [-N size] Write pool size.\n");
197 printf(" [-O size] Init pool size.\n");
198 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
199 printf(" [-t] Do sanity test.\n");
200 printf(" [-B] Key bits for multithread test (default: 32).\n");
201 printf(" [-m factor] Key multiplication factor.\n");
202 printf(" [-l] Memory leak detection.\n");
208 int test_8bit_key(void)
213 /* Test with 8-bit key */
214 test_ja
= cds_ja_new(8);
216 printf("Error allocating judy array.\n");
221 printf("Test #1: add keys (8-bit).\n");
222 for (key
= 0; key
< 200; key
++) {
223 struct ja_test_node
*node
= node_alloc();
225 ja_test_node_init(node
, key
);
227 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
230 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
237 printf("Test #2: successful key lookup (8-bit).\n");
238 for (key
= 0; key
< 200; key
++) {
239 struct cds_hlist_head head
;
242 head
= cds_ja_lookup(test_ja
, key
);
243 if (cds_hlist_empty(&head
)) {
244 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
250 printf("Test #3: unsuccessful key lookup (8-bit).\n");
251 for (key
= 200; key
< 240; key
++) {
252 struct cds_hlist_head head
;
255 head
= cds_ja_lookup(test_ja
, key
);
256 if (!cds_hlist_empty(&head
)) {
258 "Error unexpected lookup node %" PRIu64
"\n",
265 printf("Test #4: remove keys (8-bit).\n");
266 for (key
= 0; key
< 200; key
++) {
267 struct cds_hlist_head head
;
268 struct ja_test_node
*node
;
271 head
= cds_ja_lookup(test_ja
, key
);
272 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
274 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
277 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
279 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
282 call_rcu(&node
->node
.head
, free_node_cb
);
283 head
= cds_ja_lookup(test_ja
, key
);
284 if (!cds_hlist_empty(&head
)) {
285 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
292 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
294 fprintf(stderr
, "Error destroying judy array\n");
301 int test_16bit_key(void)
306 /* Test with 16-bit key */
307 test_ja
= cds_ja_new(16);
309 printf("Error allocating judy array.\n");
314 printf("Test #1: add keys (16-bit).\n");
315 for (key
= 0; key
< 10000; key
++) {
316 //for (key = 0; key < 65536; key+=256) {
317 struct ja_test_node
*node
= node_alloc();
319 ja_test_node_init(node
, key
);
321 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
324 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
331 printf("Test #2: successful key lookup (16-bit).\n");
332 for (key
= 0; key
< 10000; key
++) {
333 //for (key = 0; key < 65536; key+=256) {
334 struct cds_hlist_head head
;
337 head
= cds_ja_lookup(test_ja
, key
);
338 if (cds_hlist_empty(&head
)) {
339 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
345 printf("Test #3: unsuccessful key lookup (16-bit).\n");
346 for (key
= 11000; key
<= 11002; key
++) {
347 struct cds_hlist_head head
;
350 head
= cds_ja_lookup(test_ja
, key
);
351 if (!cds_hlist_empty(&head
)) {
353 "Error unexpected lookup node %" PRIu64
"\n",
360 printf("Test #4: remove keys (16-bit).\n");
361 for (key
= 0; key
< 10000; key
++) {
362 //for (key = 0; key < 65536; key+=256) {
363 struct cds_hlist_head head
;
364 struct ja_test_node
*node
;
367 head
= cds_ja_lookup(test_ja
, key
);
368 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
370 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
373 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
375 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
378 call_rcu(&node
->node
.head
, free_node_cb
);
379 head
= cds_ja_lookup(test_ja
, key
);
380 if (!cds_hlist_empty(&head
)) {
381 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
388 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
390 fprintf(stderr
, "Error destroying judy array\n");
397 * nr_dup is number of nodes per key.
400 int test_sparse_key(unsigned int bits
, int nr_dup
)
402 uint64_t key
, max_key
;
403 int zerocount
, i
, ret
;
406 max_key
= UINT64_MAX
;
408 max_key
= (1ULL << bits
) - 1;
410 printf("Sparse key test begins for %u-bit keys\n", bits
);
411 /* Test with 16-bit key */
412 test_ja
= cds_ja_new(bits
);
414 printf("Error allocating judy array.\n");
419 printf("Test #1: add keys (%u-bit).\n", bits
);
420 for (i
= 0; i
< nr_dup
; i
++) {
422 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
423 struct ja_test_node
*node
= node_alloc();
425 ja_test_node_init(node
, key
);
427 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
430 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
440 printf("Test #2: successful key lookup (%u-bit).\n", bits
);
442 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
443 struct cds_hlist_head head
;
444 struct ja_test_node
*node
;
445 struct cds_hlist_node
*pos
;
449 head
= cds_ja_lookup(test_ja
, key
);
450 if (cds_hlist_empty(&head
)) {
451 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
454 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
457 if (count
!= nr_dup
) {
458 fprintf(stderr
, "Unexpected number of match for key %" PRIu64
", expected %d, got %d.\n", key
, nr_dup
, count
);
466 printf("Test #3: unsuccessful key lookup (%u-bit).\n", bits
);
468 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
469 struct cds_hlist_head head
;
472 head
= cds_ja_lookup(test_ja
, key
+ 42);
473 if (!cds_hlist_empty(&head
)) {
475 "Error unexpected lookup node %" PRIu64
"\n",
485 printf("Test #4: remove keys (16-bit).\n");
487 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
488 struct cds_hlist_head head
;
489 struct ja_test_node
*node
;
490 struct cds_hlist_node
*pos
;
494 head
= cds_ja_lookup(test_ja
, key
);
497 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
498 struct cds_hlist_head testhead
;
502 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
505 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
507 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
510 call_rcu(&node
->node
.head
, free_node_cb
);
511 testhead
= cds_ja_lookup(test_ja
, key
);
512 if (count
< nr_dup
&& cds_hlist_empty(&testhead
)) {
513 fprintf(stderr
, "Error: no node found after deletion of some nodes of a key\n");
517 head
= cds_ja_lookup(test_ja
, key
);
518 if (!cds_hlist_empty(&head
)) {
519 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
528 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
530 fprintf(stderr
, "Error destroying judy array\n");
533 printf("Test ends\n");
539 int do_sanity_test(void)
543 printf("Sanity test start.\n");
545 for (i
= 0; i
< 3; i
++) {
546 ret
= test_8bit_key();
550 rcu_quiescent_state();
552 ret
= test_16bit_key();
556 rcu_quiescent_state();
559 for (i
= 8; i
<= 64; i
*= 2) {
560 /* nr of nodes per key */
561 for (j
= 1; j
< 4; j
++) {
562 ret
= test_sparse_key(i
, j
);
566 rcu_quiescent_state();
569 printf("Sanity test end.\n");
574 enum urcu_ja_addremove
{
578 }; /* 1: add, -1 remove, 0: random */
580 static enum urcu_ja_addremove addremove
; /* 1: add, -1 remove, 0: random */
583 void test_ja_rw_sigusr1_handler(int signo
)
587 printf("Add/Remove: random.\n");
588 addremove
= AR_RANDOM
;
591 printf("Add/Remove: remove only.\n");
592 addremove
= AR_REMOVE
;
595 printf("Add/Remove: add only.\n");
602 void *test_ja_rw_thr_reader(void *_count
)
604 unsigned long long *count
= _count
;
605 struct cds_hlist_head head
;
608 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
609 "reader", pthread_self(), (unsigned long) gettid());
613 rcu_register_thread();
623 /* note: only looking up ulong keys */
624 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % lookup_pool_size
) + lookup_pool_offset
;
626 head
= cds_ja_lookup(test_ja
, key
);
627 if (cds_hlist_empty(&head
)) {
628 if (validate_lookup
) {
629 printf("[ERROR] Lookup cannot find initial node.\n");
632 URCU_TLS(lookup_fail
)++;
634 URCU_TLS(lookup_ok
)++;
636 rcu_debug_yield_read();
637 if (caa_unlikely(rduration
))
638 loop_sleep(rduration
);
640 URCU_TLS(nr_reads
)++;
641 if (caa_unlikely(!test_duration_read()))
643 if (caa_unlikely((URCU_TLS(nr_reads
) & ((1 << 10) - 1)) == 0))
644 rcu_quiescent_state();
647 rcu_unregister_thread();
649 *count
= URCU_TLS(nr_reads
);
650 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
651 "reader", pthread_self(), (unsigned long) gettid());
652 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
653 pthread_self(), URCU_TLS(lookup_fail
),
654 URCU_TLS(lookup_ok
));
661 return ((unsigned int) rand_r(&URCU_TLS(rand_lookup
)) % 100) < add_ratio
;
665 void *test_ja_rw_thr_writer(void *_count
)
667 struct wr_count
*count
= _count
;
668 struct cds_hlist_head head
;
672 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
673 "writer", pthread_self(), (unsigned long) gettid());
677 rcu_register_thread();
685 if ((addremove
== AR_ADD
)
686 || (addremove
== AR_RANDOM
&& is_add())) {
687 struct ja_test_node
*node
= node_alloc();
688 struct cds_ja_node
*ret_node
;
690 /* note: only inserting ulong keys */
691 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
693 ja_test_node_init(node
, key
);
696 ret_node
= cds_ja_add_unique(test_ja
, key
, &node
->node
);
697 if (ret_node
!= &node
->node
) {
699 URCU_TLS(nr_addexist
)++;
703 } else if (add_replace
) {
704 assert(0); /* not implemented yet. */
706 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
708 fprintf(stderr
, "Error in cds_ja_add: %d\n", ret
);
716 struct ja_test_node
*node
;
719 /* note: only deleting ulong keys */
720 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
725 head
= cds_ja_lookup(test_ja
, key
);
726 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
728 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
730 call_rcu(&node
->node
.head
, free_node_cb
);
733 URCU_TLS(nr_delnoent
)++;
736 URCU_TLS(nr_delnoent
)++;
741 URCU_TLS(nr_writes
)++;
742 if (caa_unlikely(!test_duration_write()))
744 if (caa_unlikely(wdelay
))
746 if (caa_unlikely((URCU_TLS(nr_writes
) & ((1 << 10) - 1)) == 0))
747 rcu_quiescent_state();
750 rcu_unregister_thread();
752 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
753 "writer", pthread_self(), (unsigned long) gettid());
754 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
755 "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add
),
756 URCU_TLS(nr_addexist
), URCU_TLS(nr_del
),
757 URCU_TLS(nr_delnoent
));
758 count
->update_ops
= URCU_TLS(nr_writes
);
759 count
->add
= URCU_TLS(nr_add
);
760 count
->add_exist
= URCU_TLS(nr_addexist
);
761 count
->remove
= URCU_TLS(nr_del
);
766 int do_mt_populate_ja(void)
768 struct cds_hlist_head head
;
775 printf("Starting rw test\n");
777 for (iter
= init_pool_offset
; iter
< init_pool_offset
+ init_pool_size
; iter
++) {
778 struct ja_test_node
*node
= node_alloc();
781 /* note: only inserting ulong keys */
782 key
= (unsigned long) iter
;
784 ja_test_node_init(node
, key
);
786 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
788 URCU_TLS(nr_writes
)++;
791 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
802 pthread_t
*tid_reader
, *tid_writer
;
805 unsigned long long *count_reader
;
806 struct wr_count
*count_writer
;
807 unsigned long long tot_reads
= 0, tot_writes
= 0,
808 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
811 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
812 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
813 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
814 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
816 printf("Allocating Judy Array for %u-bit keys\n", key_bits
);
817 test_ja
= cds_ja_new(key_bits
);
819 printf("Error allocating judy array.\n");
828 for (i
= 0; i
< nr_readers
; i
++) {
829 err
= pthread_create(&tid_reader
[i
],
830 NULL
, test_ja_rw_thr_reader
,
835 for (i
= 0; i
< nr_writers
; i
++) {
836 err
= pthread_create(&tid_writer
[i
],
837 NULL
, test_ja_rw_thr_writer
,
847 rcu_thread_offline_qsbr();
851 remain
= sleep(remain
);
852 } while (remain
> 0);
856 for (i
= 0; i
< nr_readers
; i
++) {
857 err
= pthread_join(tid_reader
[i
], &tret
);
860 tot_reads
+= count_reader
[i
];
862 for (i
= 0; i
< nr_writers
; i
++) {
863 err
= pthread_join(tid_writer
[i
], &tret
);
866 tot_writes
+= count_writer
[i
].update_ops
;
867 tot_add
+= count_writer
[i
].add
;
868 tot_add_exist
+= count_writer
[i
].add_exist
;
869 tot_remove
+= count_writer
[i
].remove
;
871 rcu_thread_online_qsbr();
873 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
875 fprintf(stderr
, "Error destroying judy array\n");
889 int check_memory_leaks(void)
891 unsigned long na
, nf
;
893 na
= uatomic_read(&test_nodes_allocated
);
894 nf
= uatomic_read(&test_nodes_freed
);
896 fprintf(stderr
, "Memory leak of %ld test nodes detected. Allocated: %lu, freed: %lu\n",
903 int main(int argc
, char **argv
)
905 int i
, j
, a
, ret
, err
;
907 struct sigaction act
;
910 show_usage(argc
, argv
);
914 err
= sscanf(argv
[1], "%u", &nr_readers
);
916 show_usage(argc
, argv
);
920 err
= sscanf(argv
[2], "%u", &nr_writers
);
922 show_usage(argc
, argv
);
926 err
= sscanf(argv
[3], "%lu", &duration
);
928 show_usage(argc
, argv
);
932 for (i
= 4; i
< argc
; i
++) {
933 if (argv
[i
][0] != '-')
935 switch (argv
[i
][1]) {
938 yield_active
|= YIELD_READ
;
941 yield_active
|= YIELD_WRITE
;
946 show_usage(argc
, argv
);
950 cpu_affinities
[next_aff
++] = a
;
952 printf_verbose("Adding CPU %d affinity\n", a
);
956 show_usage(argc
, argv
);
959 rduration
= atol(argv
[++i
]);
963 show_usage(argc
, argv
);
966 wdelay
= atol(argv
[++i
]);
972 add_ratio
= atoi(argv
[++i
]);
978 lookup_pool_offset
= atol(argv
[++i
]);
981 write_pool_offset
= atol(argv
[++i
]);
984 init_pool_offset
= atol(argv
[++i
]);
987 lookup_pool_size
= atol(argv
[++i
]);
990 write_pool_size
= atol(argv
[++i
]);
993 init_pool_size
= atol(argv
[++i
]);
1002 key_bits
= atol(argv
[++i
]);
1005 key_mul
= atoll(argv
[++i
]);
1019 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
1020 duration
, nr_readers
, nr_writers
);
1021 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
1022 printf_verbose("Reader duration : %lu loops.\n", rduration
);
1023 printf_verbose("Add ratio: %u%%.\n", add_ratio
);
1024 printf_verbose("Mode:%s%s.\n",
1026 add_unique
? " uniquify" : ( add_replace
? " replace" : " insert"));
1027 printf_verbose("Key multiplication factor: %" PRIu64
".\n", key_mul
);
1028 printf_verbose("Init pool size offset %lu size %lu.\n",
1029 init_pool_offset
, init_pool_size
);
1030 printf_verbose("Lookup pool size offset %lu size %lu.\n",
1031 lookup_pool_offset
, lookup_pool_size
);
1032 printf_verbose("Update pool size offset %lu size %lu.\n",
1033 write_pool_offset
, write_pool_size
);
1034 if (validate_lookup
)
1035 printf_verbose("Validating lookups.\n");
1037 printf_verbose("Memory leak dection activated.\n");
1038 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
1039 "main", pthread_self(), (unsigned long)gettid());
1041 memset(&act
, 0, sizeof(act
));
1042 ret
= sigemptyset(&act
.sa_mask
);
1044 perror("sigemptyset");
1047 act
.sa_handler
= test_ja_rw_sigusr1_handler
;
1048 act
.sa_flags
= SA_RESTART
;
1049 ret
= sigaction(SIGUSR1
, &act
, NULL
);
1051 perror("sigaction");
1055 err
= create_all_cpu_call_rcu_data(0);
1057 printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");
1060 rcu_register_thread();
1063 ret
= do_sanity_test();
1068 /* Wait for in-flight call_rcu free to complete for leak detection */
1071 ret
|= check_memory_leaks();
1073 rcu_unregister_thread();
1074 free_all_cpu_call_rcu_data();
1077 printf("Test ended with error: %d\n", ret
);
1083 * Hash Population needs to be seen as a RCU reader
1084 * thread from the point of view of resize.
1086 rcu_register_thread();
1087 ret
= (get_populate_hash_cb())();
1090 rcu_thread_offline();
1092 /* teardown counter thread */
1093 act
.sa_handler
= SIG_IGN
;
1094 act
.sa_flags
= SA_RESTART
;
1095 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1097 perror("sigaction");
1101 char msg
[1] = { 0x42 };
1105 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1106 } while (ret
== -1L && errno
== EINTR
);
1110 rcu_thread_online();
1112 printf("Counting nodes... ");
1113 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1115 test_delete_all_nodes(test_ht
);
1117 rcu_thread_offline();
1119 printf("Approximation before node accounting: %ld nodes.\n",
1121 printf("Nodes deleted from hash table before destroy: "
1124 printf("Approximation after node accounting: %ld nodes.\n",
1127 ret
= cds_lfht_destroy(test_ht
, NULL
);
1129 printf_verbose("final delete aborted\n");
1131 printf_verbose("final delete success\n");
1132 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1134 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1136 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1137 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1138 argv
[0], duration
, nr_readers
, rduration
,
1139 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1140 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1141 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1142 rcu_unregister_thread();