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 void set_affinity(void)
90 #if HAVE_SCHED_SETAFFINITY
91 ret
= pthread_mutex_lock(&affinity_mutex
);
93 perror("Error in pthread mutex lock");
96 cpu
= cpu_affinities
[next_aff
++];
97 ret
= pthread_mutex_unlock(&affinity_mutex
);
99 perror("Error in pthread mutex unlock");
104 #if SCHED_SETAFFINITY_ARGS == 2
105 sched_setaffinity(0, &mask
);
107 sched_setaffinity(0, sizeof(mask
), &mask
);
109 #endif /* HAVE_SCHED_SETAFFINITY */
112 void rcu_copy_mutex_lock(void)
115 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
117 perror("Error in pthread mutex lock");
122 void rcu_copy_mutex_unlock(void)
126 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
128 perror("Error in pthread mutex unlock");
133 void free_node_cb(struct rcu_head
*head
)
135 struct ja_test_node
*node
=
136 caa_container_of(head
, struct ja_test_node
, node
.head
);
142 void test_delete_all_nodes(struct cds_lfht
*ht
)
144 struct cds_lfht_iter iter
;
145 struct lfht_test_node
*node
;
146 unsigned long count
= 0;
148 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
151 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
153 call_rcu(&node
->head
, free_node_cb
);
156 printf("deleted %lu nodes.\n", count
);
160 void show_usage(int argc
, char **argv
)
162 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
164 printf(" [-r] [-w] (yield reader and/or writer)\n");
166 printf(" [-d delay] (writer period (us))\n");
167 printf(" [-c duration] (reader C.S. duration (in loops))\n");
168 printf(" [-v] (verbose output)\n");
169 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
170 printf(" [-u] Add unique keys.\n");
171 printf(" [-s] Replace existing keys.\n");
172 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
173 printf(" [-r ratio] Add ratio (in %% of add+removal).\n");
174 printf(" [-k] Populate init nodes.\n");
175 printf(" [-R offset] Lookup pool offset.\n");
176 printf(" [-S offset] Write pool offset.\n");
177 printf(" [-T offset] Init pool offset.\n");
178 printf(" [-M size] Lookup pool size.\n");
179 printf(" [-N size] Write pool size.\n");
180 printf(" [-O size] Init pool size.\n");
181 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
182 printf(" [-t] Do sanity test.\n");
183 printf(" [-B] Key bits for multithread test (default: 32).\n");
184 printf(" [-m factor] Key multiplication factor.\n");
190 int test_8bit_key(void)
195 /* Test with 8-bit key */
196 test_ja
= cds_ja_new(8);
198 printf("Error allocating judy array.\n");
203 printf("Test #1: add keys (8-bit).\n");
204 for (key
= 0; key
< 200; key
++) {
205 struct ja_test_node
*node
=
206 calloc(sizeof(*node
), 1);
208 ja_test_node_init(node
, key
);
210 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
213 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
220 printf("Test #2: successful key lookup (8-bit).\n");
221 for (key
= 0; key
< 200; key
++) {
222 struct cds_hlist_head head
;
225 head
= cds_ja_lookup(test_ja
, key
);
226 if (cds_hlist_empty(&head
)) {
227 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
233 printf("Test #3: unsuccessful key lookup (8-bit).\n");
234 for (key
= 200; key
< 240; key
++) {
235 struct cds_hlist_head head
;
238 head
= cds_ja_lookup(test_ja
, key
);
239 if (!cds_hlist_empty(&head
)) {
241 "Error unexpected lookup node %" PRIu64
"\n",
248 printf("Test #4: remove keys (8-bit).\n");
249 for (key
= 0; key
< 200; key
++) {
250 struct cds_hlist_head head
;
251 struct ja_test_node
*node
;
254 head
= cds_ja_lookup(test_ja
, key
);
255 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
257 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
260 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
262 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
265 call_rcu(&node
->node
.head
, free_node_cb
);
266 head
= cds_ja_lookup(test_ja
, key
);
267 if (!cds_hlist_empty(&head
)) {
268 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
275 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
277 fprintf(stderr
, "Error destroying judy array\n");
284 int test_16bit_key(void)
289 /* Test with 16-bit key */
290 test_ja
= cds_ja_new(16);
292 printf("Error allocating judy array.\n");
297 printf("Test #1: add keys (16-bit).\n");
298 for (key
= 0; key
< 10000; key
++) {
299 //for (key = 0; key < 65536; key+=256) {
300 struct ja_test_node
*node
=
301 calloc(sizeof(*node
), 1);
303 ja_test_node_init(node
, key
);
305 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
308 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
315 printf("Test #2: successful key lookup (16-bit).\n");
316 for (key
= 0; key
< 10000; key
++) {
317 //for (key = 0; key < 65536; key+=256) {
318 struct cds_hlist_head head
;
321 head
= cds_ja_lookup(test_ja
, key
);
322 if (cds_hlist_empty(&head
)) {
323 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
329 printf("Test #3: unsuccessful key lookup (16-bit).\n");
330 for (key
= 11000; key
<= 11002; key
++) {
331 struct cds_hlist_head head
;
334 head
= cds_ja_lookup(test_ja
, key
);
335 if (!cds_hlist_empty(&head
)) {
337 "Error unexpected lookup node %" PRIu64
"\n",
344 printf("Test #4: remove keys (16-bit).\n");
345 for (key
= 0; key
< 10000; key
++) {
346 //for (key = 0; key < 65536; key+=256) {
347 struct cds_hlist_head head
;
348 struct ja_test_node
*node
;
351 head
= cds_ja_lookup(test_ja
, key
);
352 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
354 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
357 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
359 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
362 call_rcu(&node
->node
.head
, free_node_cb
);
363 head
= cds_ja_lookup(test_ja
, key
);
364 if (!cds_hlist_empty(&head
)) {
365 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
372 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
374 fprintf(stderr
, "Error destroying judy array\n");
381 * nr_dup is number of nodes per key.
384 int test_sparse_key(unsigned int bits
, int nr_dup
)
386 uint64_t key
, max_key
;
387 int zerocount
, i
, ret
;
390 max_key
= UINT64_MAX
;
392 max_key
= (1ULL << bits
) - 1;
394 printf("Sparse key test begins for %u-bit keys\n", bits
);
395 /* Test with 16-bit key */
396 test_ja
= cds_ja_new(bits
);
398 printf("Error allocating judy array.\n");
403 printf("Test #1: add keys (%u-bit).\n", bits
);
404 for (i
= 0; i
< nr_dup
; i
++) {
406 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
407 struct ja_test_node
*node
=
408 calloc(sizeof(*node
), 1);
410 ja_test_node_init(node
, key
);
412 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
415 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
425 printf("Test #2: successful key lookup (%u-bit).\n", bits
);
427 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
428 struct cds_hlist_head head
;
429 struct ja_test_node
*node
;
430 struct cds_hlist_node
*pos
;
434 head
= cds_ja_lookup(test_ja
, key
);
435 if (cds_hlist_empty(&head
)) {
436 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
439 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
442 if (count
!= nr_dup
) {
443 fprintf(stderr
, "Unexpected number of match for key %" PRIu64
", expected %d, got %d.\n", key
, nr_dup
, count
);
451 printf("Test #3: unsuccessful key lookup (%u-bit).\n", bits
);
453 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
454 struct cds_hlist_head head
;
457 head
= cds_ja_lookup(test_ja
, key
+ 42);
458 if (!cds_hlist_empty(&head
)) {
460 "Error unexpected lookup node %" PRIu64
"\n",
470 printf("Test #4: remove keys (16-bit).\n");
472 for (key
= 0; key
<= max_key
&& (key
!= 0 || zerocount
< 1); key
+= 1ULL << (bits
- 8)) {
473 struct cds_hlist_head head
;
474 struct ja_test_node
*node
;
475 struct cds_hlist_node
*pos
;
479 head
= cds_ja_lookup(test_ja
, key
);
482 cds_hlist_for_each_entry_rcu(node
, pos
, &head
, node
.list
) {
483 struct cds_hlist_head testhead
;
487 fprintf(stderr
, "Error lookup node %" PRIu64
"\n", key
);
490 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
492 fprintf(stderr
, "Error (%d) removing node %" PRIu64
"\n", ret
, key
);
495 call_rcu(&node
->node
.head
, free_node_cb
);
496 testhead
= cds_ja_lookup(test_ja
, key
);
497 if (count
< nr_dup
&& cds_hlist_empty(&testhead
)) {
498 fprintf(stderr
, "Error: no node found after deletion of some nodes of a key\n");
502 head
= cds_ja_lookup(test_ja
, key
);
503 if (!cds_hlist_empty(&head
)) {
504 fprintf(stderr
, "Error lookup %" PRIu64
": %p (after delete) failed. Node is not expected.\n", key
, head
.next
);
513 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
515 fprintf(stderr
, "Error destroying judy array\n");
518 printf("Test ends\n");
524 int do_sanity_test(void)
528 printf("Sanity test start.\n");
530 for (i
= 0; i
< 3; i
++) {
531 ret
= test_8bit_key();
535 rcu_quiescent_state();
537 ret
= test_16bit_key();
541 rcu_quiescent_state();
544 for (i
= 8; i
<= 64; i
*= 2) {
545 /* nr of nodes per key */
546 for (j
= 1; j
< 4; j
++) {
547 ret
= test_sparse_key(i
, j
);
551 rcu_quiescent_state();
554 printf("Sanity test end.\n");
559 enum urcu_ja_addremove
{
563 }; /* 1: add, -1 remove, 0: random */
565 static enum urcu_ja_addremove addremove
; /* 1: add, -1 remove, 0: random */
568 void test_ja_rw_sigusr1_handler(int signo
)
572 printf("Add/Remove: random.\n");
573 addremove
= AR_RANDOM
;
576 printf("Add/Remove: remove only.\n");
577 addremove
= AR_REMOVE
;
580 printf("Add/Remove: add only.\n");
587 void *test_ja_rw_thr_reader(void *_count
)
589 unsigned long long *count
= _count
;
590 struct cds_hlist_head head
;
593 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
594 "reader", pthread_self(), (unsigned long) gettid());
598 rcu_register_thread();
608 /* note: only looking up ulong keys */
609 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % lookup_pool_size
) + lookup_pool_offset
;
611 head
= cds_ja_lookup(test_ja
, key
);
612 if (cds_hlist_empty(&head
)) {
613 if (validate_lookup
) {
614 printf("[ERROR] Lookup cannot find initial node.\n");
617 URCU_TLS(lookup_fail
)++;
619 URCU_TLS(lookup_ok
)++;
621 rcu_debug_yield_read();
622 if (caa_unlikely(rduration
))
623 loop_sleep(rduration
);
625 URCU_TLS(nr_reads
)++;
626 if (caa_unlikely(!test_duration_read()))
628 if (caa_unlikely((URCU_TLS(nr_reads
) & ((1 << 10) - 1)) == 0))
629 rcu_quiescent_state();
632 rcu_unregister_thread();
634 *count
= URCU_TLS(nr_reads
);
635 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
636 "reader", pthread_self(), (unsigned long) gettid());
637 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
638 pthread_self(), URCU_TLS(lookup_fail
),
639 URCU_TLS(lookup_ok
));
646 return ((unsigned int) rand_r(&URCU_TLS(rand_lookup
)) % 100) < add_ratio
;
650 void *test_ja_rw_thr_writer(void *_count
)
652 struct wr_count
*count
= _count
;
653 struct cds_hlist_head head
;
657 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
658 "writer", pthread_self(), (unsigned long) gettid());
662 rcu_register_thread();
670 if ((addremove
== AR_ADD
)
671 || (addremove
== AR_RANDOM
&& is_add())) {
672 struct ja_test_node
*node
= malloc(sizeof(*node
));
673 struct cds_ja_node
*ret_node
;
675 /* note: only inserting ulong keys */
676 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
678 ja_test_node_init(node
, key
);
681 ret_node
= cds_ja_add_unique(test_ja
, key
, &node
->node
);
682 if (ret_node
!= &node
->node
) {
684 URCU_TLS(nr_addexist
)++;
688 } else if (add_replace
) {
689 assert(0); /* not implemented yet. */
691 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
693 fprintf(stderr
, "Error in cds_ja_add: %d\n", ret
);
701 struct ja_test_node
*node
;
704 /* note: only deleting ulong keys */
705 key
= ((unsigned long) rand_r(&URCU_TLS(rand_lookup
)) % write_pool_size
) + write_pool_offset
;
710 head
= cds_ja_lookup(test_ja
, key
);
711 node
= cds_hlist_first_entry_rcu(&head
, struct ja_test_node
, node
.list
);
713 ret
= cds_ja_del(test_ja
, key
, &node
->node
);
715 call_rcu(&node
->node
.head
, free_node_cb
);
718 URCU_TLS(nr_delnoent
)++;
721 URCU_TLS(nr_delnoent
)++;
726 URCU_TLS(nr_writes
)++;
727 if (caa_unlikely(!test_duration_write()))
729 if (caa_unlikely(wdelay
))
731 if (caa_unlikely((URCU_TLS(nr_writes
) & ((1 << 10) - 1)) == 0))
732 rcu_quiescent_state();
735 rcu_unregister_thread();
737 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
738 "writer", pthread_self(), (unsigned long) gettid());
739 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
740 "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add
),
741 URCU_TLS(nr_addexist
), URCU_TLS(nr_del
),
742 URCU_TLS(nr_delnoent
));
743 count
->update_ops
= URCU_TLS(nr_writes
);
744 count
->add
= URCU_TLS(nr_add
);
745 count
->add_exist
= URCU_TLS(nr_addexist
);
746 count
->remove
= URCU_TLS(nr_del
);
751 int do_mt_populate_ja(void)
753 struct cds_hlist_head head
;
760 printf("Starting rw test\n");
762 for (iter
= init_pool_offset
; iter
< init_pool_offset
+ init_pool_size
; iter
++) {
763 struct ja_test_node
*node
= malloc(sizeof(*node
));
766 /* note: only inserting ulong keys */
767 key
= (unsigned long) iter
;
769 ja_test_node_init(node
, key
);
771 ret
= cds_ja_add(test_ja
, key
, &node
->node
);
773 URCU_TLS(nr_writes
)++;
776 fprintf(stderr
, "Error (%d) adding node %" PRIu64
"\n",
787 pthread_t
*tid_reader
, *tid_writer
;
790 unsigned long long *count_reader
;
791 struct wr_count
*count_writer
;
792 unsigned long long tot_reads
= 0, tot_writes
= 0,
793 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
796 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
797 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
798 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
799 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
801 printf("Allocating Judy Array for %u-bit keys\n", key_bits
);
802 test_ja
= cds_ja_new(key_bits
);
804 printf("Error allocating judy array.\n");
813 for (i
= 0; i
< nr_readers
; i
++) {
814 err
= pthread_create(&tid_reader
[i
],
815 NULL
, test_ja_rw_thr_reader
,
820 for (i
= 0; i
< nr_writers
; i
++) {
821 err
= pthread_create(&tid_writer
[i
],
822 NULL
, test_ja_rw_thr_writer
,
832 rcu_thread_offline_qsbr();
836 remain
= sleep(remain
);
837 } while (remain
> 0);
841 for (i
= 0; i
< nr_readers
; i
++) {
842 err
= pthread_join(tid_reader
[i
], &tret
);
845 tot_reads
+= count_reader
[i
];
847 for (i
= 0; i
< nr_writers
; i
++) {
848 err
= pthread_join(tid_writer
[i
], &tret
);
851 tot_writes
+= count_writer
[i
].update_ops
;
852 tot_add
+= count_writer
[i
].add
;
853 tot_add_exist
+= count_writer
[i
].add_exist
;
854 tot_remove
+= count_writer
[i
].remove
;
856 rcu_thread_online_qsbr();
858 ret
= cds_ja_destroy(test_ja
, free_node_cb
);
860 fprintf(stderr
, "Error destroying judy array\n");
873 int main(int argc
, char **argv
)
875 int i
, j
, a
, ret
, err
;
877 struct sigaction act
;
880 show_usage(argc
, argv
);
884 err
= sscanf(argv
[1], "%u", &nr_readers
);
886 show_usage(argc
, argv
);
890 err
= sscanf(argv
[2], "%u", &nr_writers
);
892 show_usage(argc
, argv
);
896 err
= sscanf(argv
[3], "%lu", &duration
);
898 show_usage(argc
, argv
);
902 for (i
= 4; i
< argc
; i
++) {
903 if (argv
[i
][0] != '-')
905 switch (argv
[i
][1]) {
908 yield_active
|= YIELD_READ
;
911 yield_active
|= YIELD_WRITE
;
916 show_usage(argc
, argv
);
920 cpu_affinities
[next_aff
++] = a
;
922 printf_verbose("Adding CPU %d affinity\n", a
);
926 show_usage(argc
, argv
);
929 rduration
= atol(argv
[++i
]);
933 show_usage(argc
, argv
);
936 wdelay
= atol(argv
[++i
]);
942 add_ratio
= atoi(argv
[++i
]);
948 lookup_pool_offset
= atol(argv
[++i
]);
951 write_pool_offset
= atol(argv
[++i
]);
954 init_pool_offset
= atol(argv
[++i
]);
957 lookup_pool_size
= atol(argv
[++i
]);
960 write_pool_size
= atol(argv
[++i
]);
963 init_pool_size
= atol(argv
[++i
]);
972 key_bits
= atol(argv
[++i
]);
975 key_mul
= atoll(argv
[++i
]);
986 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
987 duration
, nr_readers
, nr_writers
);
988 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
989 printf_verbose("Reader duration : %lu loops.\n", rduration
);
990 printf_verbose("Add ratio: %u%%.\n", add_ratio
);
991 printf_verbose("Mode:%s%s.\n",
993 add_unique
? " uniquify" : ( add_replace
? " replace" : " insert"));
994 printf_verbose("Key multiplication factor: %" PRIu64
".\n", key_mul
);
995 printf_verbose("Init pool size offset %lu size %lu.\n",
996 init_pool_offset
, init_pool_size
);
997 printf_verbose("Lookup pool size offset %lu size %lu.\n",
998 lookup_pool_offset
, lookup_pool_size
);
999 printf_verbose("Update pool size offset %lu size %lu.\n",
1000 write_pool_offset
, write_pool_size
);
1001 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
1002 "main", pthread_self(), (unsigned long)gettid());
1004 memset(&act
, 0, sizeof(act
));
1005 ret
= sigemptyset(&act
.sa_mask
);
1007 perror("sigemptyset");
1010 act
.sa_handler
= test_ja_rw_sigusr1_handler
;
1011 act
.sa_flags
= SA_RESTART
;
1012 ret
= sigaction(SIGUSR1
, &act
, NULL
);
1014 perror("sigaction");
1018 err
= create_all_cpu_call_rcu_data(0);
1020 printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");
1023 rcu_register_thread();
1026 ret
= do_sanity_test();
1031 rcu_unregister_thread();
1032 free_all_cpu_call_rcu_data();
1035 printf("Test ended with error: %d\n", ret
);
1041 * Hash Population needs to be seen as a RCU reader
1042 * thread from the point of view of resize.
1044 rcu_register_thread();
1045 ret
= (get_populate_hash_cb())();
1048 rcu_thread_offline();
1050 /* teardown counter thread */
1051 act
.sa_handler
= SIG_IGN
;
1052 act
.sa_flags
= SA_RESTART
;
1053 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1055 perror("sigaction");
1059 char msg
[1] = { 0x42 };
1063 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1064 } while (ret
== -1L && errno
== EINTR
);
1068 rcu_thread_online();
1070 printf("Counting nodes... ");
1071 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1073 test_delete_all_nodes(test_ht
);
1075 rcu_thread_offline();
1077 printf("Approximation before node accounting: %ld nodes.\n",
1079 printf("Nodes deleted from hash table before destroy: "
1082 printf("Approximation after node accounting: %ld nodes.\n",
1085 ret
= cds_lfht_destroy(test_ht
, NULL
);
1087 printf_verbose("final delete aborted\n");
1089 printf_verbose("final delete success\n");
1090 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1092 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1094 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1095 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1096 argv
[0], duration
, nr_readers
, rduration
,
1097 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1098 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1099 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1100 rcu_unregister_thread();