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
;
154 static const struct cds_lfht_mm_type
*memory_backend
;
156 static unsigned long init_pool_offset
, lookup_pool_offset
, write_pool_offset
;
157 static unsigned long init_pool_size
= DEFAULT_RAND_POOL
,
158 lookup_pool_size
= DEFAULT_RAND_POOL
,
159 write_pool_size
= DEFAULT_RAND_POOL
;
160 static int validate_lookup
;
162 static int count_pipe
[2];
164 static inline void loop_sleep(unsigned long l
)
170 static int verbose_mode
;
172 #define printf_verbose(fmt, args...) \
175 printf(fmt, ## args); \
178 static unsigned int cpu_affinities
[NR_CPUS
];
179 static unsigned int next_aff
= 0;
180 static int use_affinity
= 0;
182 pthread_mutex_t affinity_mutex
= PTHREAD_MUTEX_INITIALIZER
;
184 static void set_affinity(void)
193 ret
= pthread_mutex_lock(&affinity_mutex
);
195 perror("Error in pthread mutex lock");
198 cpu
= cpu_affinities
[next_aff
++];
199 ret
= pthread_mutex_unlock(&affinity_mutex
);
201 perror("Error in pthread mutex unlock");
206 sched_setaffinity(0, sizeof(mask
), &mask
);
213 } addremove
; /* 1: add, -1 remove, 0: random */
216 void sigusr1_handler(int signo
)
220 printf("Add/Remove: random.\n");
221 addremove
= AR_RANDOM
;
224 printf("Add/Remove: remove only.\n");
225 addremove
= AR_REMOVE
;
228 printf("Add/Remove: add only.\n");
235 void sigusr2_handler(int signo
)
237 char msg
[1] = { 0x42 };
241 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
242 } while (ret
== -1L && errno
== EINTR
);
246 * returns 0 if test should end.
248 static int test_duration_write(void)
253 static int test_duration_read(void)
258 static unsigned long long __thread nr_writes
;
259 static unsigned long long __thread nr_reads
;
261 static unsigned int nr_readers
;
262 static unsigned int nr_writers
;
264 pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
266 void rcu_copy_mutex_lock(void)
269 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
271 perror("Error in pthread mutex lock");
276 void rcu_copy_mutex_unlock(void)
280 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
282 perror("Error in pthread mutex unlock");
289 * Source: http://burtleburtle.net/bob/c/lookup3.c
290 * Originally Public Domain
293 #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
295 #define mix(a, b, c) \
297 a -= c; a ^= rot(c, 4); c += b; \
298 b -= a; b ^= rot(a, 6); a += c; \
299 c -= b; c ^= rot(b, 8); b += a; \
300 a -= c; a ^= rot(c, 16); c += b; \
301 b -= a; b ^= rot(a, 19); a += c; \
302 c -= b; c ^= rot(b, 4); b += a; \
305 #define final(a, b, c) \
307 c ^= b; c -= rot(b, 14); \
308 a ^= c; a -= rot(c, 11); \
309 b ^= a; b -= rot(a, 25); \
310 c ^= b; c -= rot(b, 16); \
311 a ^= c; a -= rot(c, 4);\
312 b ^= a; b -= rot(a, 14); \
313 c ^= b; c -= rot(b, 24); \
316 static __attribute__((unused
))
318 const uint32_t *k
, /* the key, an array of uint32_t values */
319 size_t length
, /* the length of the key, in uint32_ts */
320 uint32_t initval
) /* the previous hash, or an arbitrary value */
324 /* Set up the internal state */
325 a
= b
= c
= 0xdeadbeef + (((uint32_t) length
) << 2) + initval
;
327 /*----------------------------------------- handle most of the key */
337 /*----------------------------------- handle the last 3 uint32_t's */
338 switch (length
) { /* all the case statements fall through */
343 case 0: /* case 0: nothing left to add */
346 /*---------------------------------------------- report the result */
352 const uint32_t *k
, /* the key, an array of uint32_t values */
353 size_t length
, /* the length of the key, in uint32_ts */
354 uint32_t *pc
, /* IN: seed OUT: primary hash value */
355 uint32_t *pb
) /* IN: more seed OUT: secondary hash value */
359 /* Set up the internal state */
360 a
= b
= c
= 0xdeadbeef + ((uint32_t) (length
<< 2)) + *pc
;
363 /*----------------------------------------- handle most of the key */
373 /*----------------------------------- handle the last 3 uint32_t's */
374 switch (length
) { /* all the case statements fall through */
379 case 0: /* case 0: nothing left to add */
382 /*---------------------------------------------- report the result */
387 #if (CAA_BITS_PER_LONG == 32)
389 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
391 unsigned int key
= (unsigned int) _key
;
393 assert(length
== sizeof(unsigned int));
394 return hash_u32(&key
, 1, seed
);
398 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
409 assert(length
== sizeof(unsigned long));
410 v
.v64
= (uint64_t) seed
;
411 key
.v64
= (uint64_t) _key
;
412 hashword2(key
.v32
, 2, &v
.v32
[0], &v
.v32
[1]);
418 unsigned long test_compare(const void *key1
, size_t key1_len
,
419 const void *key2
, size_t key2_len
)
421 if (caa_unlikely(key1_len
!= key2_len
))
423 assert(key1_len
== sizeof(unsigned long));
431 int test_match(struct cds_lfht_node
*node
, const void *key
)
433 struct lfht_test_node
*test_node
= to_test_node(node
);
435 return !test_compare(test_node
->key
, test_node
->key_len
,
436 key
, sizeof(unsigned long));
440 void cds_lfht_test_lookup(struct cds_lfht
*ht
, void *key
, size_t key_len
,
441 struct cds_lfht_iter
*iter
)
443 assert(key_len
== sizeof(unsigned long));
445 cds_lfht_lookup(ht
, test_hash(key
, key_len
, TEST_HASH_SEED
),
446 test_match
, key
, iter
);
449 void *thr_count(void *arg
)
451 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
452 "counter", pthread_self(), (unsigned long)gettid());
454 rcu_register_thread();
458 long approx_before
, approx_after
;
462 rcu_thread_offline();
463 len
= read(count_pipe
[0], buf
, 1);
465 if (caa_unlikely(!test_duration_read()))
470 printf("Counting nodes... ");
473 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
,
477 printf("Approximation before node accounting: %ld nodes.\n",
479 printf("Accounting of nodes in the hash table: "
482 printf("Approximation after node accounting: %ld nodes.\n",
485 rcu_unregister_thread();
489 void *thr_reader(void *_count
)
491 unsigned long long *count
= _count
;
492 struct lfht_test_node
*node
;
493 struct cds_lfht_iter iter
;
495 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
496 "reader", pthread_self(), (unsigned long)gettid());
500 rcu_register_thread();
509 cds_lfht_test_lookup(test_ht
,
510 (void *)(((unsigned long) rand_r(&rand_lookup
) % lookup_pool_size
) + lookup_pool_offset
),
511 sizeof(void *), &iter
);
512 node
= cds_lfht_iter_get_test_node(&iter
);
514 if (validate_lookup
) {
515 printf("[ERROR] Lookup cannot find initial node.\n");
523 if (caa_unlikely(rduration
))
524 loop_sleep(rduration
);
527 if (caa_unlikely(!test_duration_read()))
529 if (caa_unlikely((nr_reads
& ((1 << 10) - 1)) == 0))
530 rcu_quiescent_state();
533 rcu_unregister_thread();
536 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
537 "reader", pthread_self(), (unsigned long)gettid());
538 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
539 pthread_self(), lookup_fail
, lookup_ok
);
545 void free_node_cb(struct rcu_head
*head
)
547 struct lfht_test_node
*node
=
548 caa_container_of(head
, struct lfht_test_node
, head
);
552 void *thr_writer(void *_count
)
554 struct lfht_test_node
*node
;
555 struct cds_lfht_node
*ret_node
;
556 struct cds_lfht_iter iter
;
557 struct wr_count
*count
= _count
;
560 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
561 "writer", pthread_self(), (unsigned long)gettid());
565 rcu_register_thread();
573 if ((addremove
== AR_ADD
|| add_only
)
574 || (addremove
== AR_RANDOM
&& rand_r(&rand_lookup
) & 1)) {
575 node
= malloc(sizeof(struct lfht_test_node
));
576 lfht_test_node_init(node
,
577 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
581 ret_node
= cds_lfht_add_unique(test_ht
,
582 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
583 test_match
, node
->key
, &node
->node
);
586 ret_node
= cds_lfht_add_replace(test_ht
,
587 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
588 test_match
, node
->key
, &node
->node
);
590 cds_lfht_add(test_ht
,
591 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
595 if (add_unique
&& ret_node
!= &node
->node
) {
599 if (add_replace
&& ret_node
) {
600 call_rcu(&to_test_node(ret_node
)->head
,
610 cds_lfht_test_lookup(test_ht
,
611 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
612 sizeof(void *), &iter
);
613 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
616 node
= cds_lfht_iter_get_test_node(&iter
);
617 call_rcu(&node
->head
, free_node_cb
);
623 //if (nr_writes % 100000 == 0) {
624 if (nr_writes
% 1000 == 0) {
626 if (rand_r(&rand_lookup
) & 1) {
627 ht_resize(test_ht
, 1);
629 ht_resize(test_ht
, -1);
635 if (caa_unlikely(!test_duration_write()))
637 if (caa_unlikely(wdelay
))
639 if (caa_unlikely((nr_writes
& ((1 << 10) - 1)) == 0))
640 rcu_quiescent_state();
643 rcu_unregister_thread();
645 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
646 "writer", pthread_self(), (unsigned long)gettid());
647 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
648 "nr_delnoent %lu\n", pthread_self(), nr_add
,
649 nr_addexist
, nr_del
, nr_delnoent
);
650 count
->update_ops
= nr_writes
;
652 count
->add_exist
= nr_addexist
;
653 count
->remove
= nr_del
;
657 static int populate_hash(void)
659 struct lfht_test_node
*node
;
660 struct cds_lfht_node
*ret_node
;
665 if ((add_unique
|| add_replace
) && init_populate
* 10 > init_pool_size
) {
666 printf("WARNING: required to populate %lu nodes (-k), but random "
667 "pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a "
668 "larger random pool (-p option). This may take a while...\n", init_populate
, init_pool_size
);
671 while (nr_add
< init_populate
) {
672 node
= malloc(sizeof(struct lfht_test_node
));
673 lfht_test_node_init(node
,
674 (void *)(((unsigned long) rand_r(&rand_lookup
) % init_pool_size
) + init_pool_offset
),
678 ret_node
= cds_lfht_add_unique(test_ht
,
679 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
680 test_match
, node
->key
, &node
->node
);
683 ret_node
= cds_lfht_add_replace(test_ht
,
684 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
685 test_match
, node
->key
, &node
->node
);
687 cds_lfht_add(test_ht
,
688 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
692 if (add_unique
&& ret_node
!= &node
->node
) {
696 if (add_replace
&& ret_node
) {
697 call_rcu(&to_test_node(ret_node
)->head
, free_node_cb
);
709 void test_delete_all_nodes(struct cds_lfht
*ht
)
711 struct cds_lfht_iter iter
;
712 struct lfht_test_node
*node
;
713 unsigned long count
= 0;
715 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
718 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
720 call_rcu(&node
->head
, free_node_cb
);
723 printf("deleted %lu nodes.\n", count
);
726 void show_usage(int argc
, char **argv
)
728 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
730 printf(" [-r] [-w] (yield reader and/or writer)\n");
732 printf(" [-d delay] (writer period (us))\n");
733 printf(" [-c duration] (reader C.S. duration (in loops))\n");
734 printf(" [-v] (verbose output)\n");
735 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
736 printf(" [-h size] (initial number of buckets)\n");
737 printf(" [-m size] (minimum number of allocated buckets)\n");
738 printf(" [-n size] (maximum number of buckets)\n");
739 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
740 printf(" [-u] Uniquify add (no redundant keys).\n");
741 printf(" [-s] Replace (swap) entries.\n");
742 printf(" [-i] Add only (no removal).\n");
743 printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
744 printf(" [-A] Automatically resize hash table.\n");
745 printf(" [-B order|chunk|mmap] Specify the memory backend.\n");
746 printf(" [-R offset] Lookup pool offset.\n");
747 printf(" [-S offset] Write pool offset.\n");
748 printf(" [-T offset] Init pool offset.\n");
749 printf(" [-M size] Lookup pool size.\n");
750 printf(" [-N size] Write pool size.\n");
751 printf(" [-O size] Init pool size.\n");
752 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
756 int main(int argc
, char **argv
)
759 pthread_t
*tid_reader
, *tid_writer
;
762 unsigned long long *count_reader
;
763 struct wr_count
*count_writer
;
764 unsigned long long tot_reads
= 0, tot_writes
= 0,
765 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
767 long approx_before
, approx_after
;
769 struct sigaction act
;
773 show_usage(argc
, argv
);
777 err
= sscanf(argv
[1], "%u", &nr_readers
);
779 show_usage(argc
, argv
);
783 err
= sscanf(argv
[2], "%u", &nr_writers
);
785 show_usage(argc
, argv
);
789 err
= sscanf(argv
[3], "%lu", &duration
);
791 show_usage(argc
, argv
);
795 for (i
= 4; i
< argc
; i
++) {
796 if (argv
[i
][0] != '-')
798 switch (argv
[i
][1]) {
801 yield_active
|= YIELD_READ
;
804 yield_active
|= YIELD_WRITE
;
809 show_usage(argc
, argv
);
813 cpu_affinities
[next_aff
++] = a
;
815 printf_verbose("Adding CPU %d affinity\n", a
);
819 show_usage(argc
, argv
);
822 rduration
= atol(argv
[++i
]);
826 show_usage(argc
, argv
);
829 wdelay
= atol(argv
[++i
]);
836 show_usage(argc
, argv
);
839 init_hash_size
= atol(argv
[++i
]);
843 show_usage(argc
, argv
);
846 min_hash_alloc_size
= atol(argv
[++i
]);
850 show_usage(argc
, argv
);
853 max_hash_buckets_size
= atol(argv
[++i
]);
857 printf("Please specify at most one of -s or -u.\n");
864 printf("Please specify at most one of -s or -u.\n");
873 init_populate
= atol(argv
[++i
]);
880 show_usage(argc
, argv
);
884 if (!strcmp("order", argv
[i
]))
885 memory_backend
= &cds_lfht_mm_order
;
886 else if (!strcmp("chunk", argv
[i
]))
887 memory_backend
= &cds_lfht_mm_chunk
;
888 else if (!strcmp("mmap", argv
[i
]))
889 memory_backend
= &cds_lfht_mm_mmap
;
891 printf("Please specify memory backend with order|chunk|mmap.\n");
896 lookup_pool_offset
= atol(argv
[++i
]);
899 write_pool_offset
= atol(argv
[++i
]);
902 init_pool_offset
= atol(argv
[++i
]);
905 lookup_pool_size
= atol(argv
[++i
]);
908 write_pool_size
= atol(argv
[++i
]);
911 init_pool_size
= atol(argv
[++i
]);
920 /* Check if hash size is power of 2 */
921 if (init_hash_size
&& init_hash_size
& (init_hash_size
- 1)) {
922 printf("Error: Initial number of buckets (%lu) is not a power of 2.\n",
927 if (min_hash_alloc_size
&& min_hash_alloc_size
& (min_hash_alloc_size
- 1)) {
928 printf("Error: Minimum number of allocated buckets (%lu) is not a power of 2.\n",
929 min_hash_alloc_size
);
933 if (max_hash_buckets_size
&& max_hash_buckets_size
& (max_hash_buckets_size
- 1)) {
934 printf("Error: Maximum number of buckets (%lu) is not a power of 2.\n",
935 max_hash_buckets_size
);
939 memset(&act
, 0, sizeof(act
));
940 ret
= sigemptyset(&act
.sa_mask
);
942 perror("sigemptyset");
945 act
.sa_handler
= sigusr1_handler
;
946 act
.sa_flags
= SA_RESTART
;
947 ret
= sigaction(SIGUSR1
, &act
, NULL
);
953 ret
= pipe(count_pipe
);
959 /* spawn counter thread */
960 err
= pthread_create(&tid_count
, NULL
, thr_count
,
965 act
.sa_handler
= sigusr2_handler
;
966 act
.sa_flags
= SA_RESTART
;
967 ret
= sigaction(SIGUSR2
, &act
, NULL
);
973 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
974 duration
, nr_readers
, nr_writers
);
975 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
976 printf_verbose("Reader duration : %lu loops.\n", rduration
);
977 printf_verbose("Mode:%s%s.\n",
978 add_only
? " add only" : " add/remove",
979 add_unique
? " uniquify" : ( add_replace
? " replace" : " insert"));
980 printf_verbose("Initial number of buckets: %lu buckets.\n", init_hash_size
);
981 printf_verbose("Minimum number of allocated buckets: %lu buckets.\n", min_hash_alloc_size
);
982 printf_verbose("Maximum number of buckets: %lu buckets.\n", max_hash_buckets_size
);
983 printf_verbose("Init pool size offset %lu size %lu.\n",
984 init_pool_offset
, init_pool_size
);
985 printf_verbose("Lookup pool size offset %lu size %lu.\n",
986 lookup_pool_offset
, lookup_pool_size
);
987 printf_verbose("Update pool size offset %lu size %lu.\n",
988 write_pool_offset
, write_pool_size
);
989 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
990 "main", pthread_self(), (unsigned long)gettid());
992 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
993 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
994 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
995 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
997 err
= create_all_cpu_call_rcu_data(0);
1000 if (memory_backend
) {
1001 test_ht
= _cds_lfht_new(init_hash_size
, min_hash_alloc_size
,
1002 max_hash_buckets_size
,
1003 (opt_auto_resize
? CDS_LFHT_AUTO_RESIZE
: 0) |
1004 CDS_LFHT_ACCOUNTING
, memory_backend
,
1007 test_ht
= cds_lfht_new(init_hash_size
, min_hash_alloc_size
,
1008 max_hash_buckets_size
,
1009 (opt_auto_resize
? CDS_LFHT_AUTO_RESIZE
: 0) |
1010 CDS_LFHT_ACCOUNTING
, NULL
);
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
= populate_hash();
1021 rcu_thread_offline();
1025 for (i
= 0; i
< nr_readers
; i
++) {
1026 err
= pthread_create(&tid_reader
[i
], NULL
, thr_reader
,
1031 for (i
= 0; i
< nr_writers
; i
++) {
1032 err
= pthread_create(&tid_writer
[i
], NULL
, thr_writer
,
1044 remain
= sleep(remain
);
1045 } while (remain
> 0);
1049 for (i
= 0; i
< nr_readers
; i
++) {
1050 err
= pthread_join(tid_reader
[i
], &tret
);
1053 tot_reads
+= count_reader
[i
];
1055 for (i
= 0; i
< nr_writers
; i
++) {
1056 err
= pthread_join(tid_writer
[i
], &tret
);
1059 tot_writes
+= count_writer
[i
].update_ops
;
1060 tot_add
+= count_writer
[i
].add
;
1061 tot_add_exist
+= count_writer
[i
].add_exist
;
1062 tot_remove
+= count_writer
[i
].remove
;
1065 /* teardown counter thread */
1066 act
.sa_handler
= SIG_IGN
;
1067 act
.sa_flags
= SA_RESTART
;
1068 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1070 perror("sigaction");
1074 char msg
[1] = { 0x42 };
1078 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1079 } while (ret
== -1L && errno
== EINTR
);
1081 err
= pthread_join(tid_count
, &tret
);
1086 rcu_thread_online();
1088 printf("Counting nodes... ");
1089 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1091 test_delete_all_nodes(test_ht
);
1093 rcu_thread_offline();
1095 printf("Approximation before node accounting: %ld nodes.\n",
1097 printf("Nodes deleted from hash table before destroy: "
1100 printf("Approximation after node accounting: %ld nodes.\n",
1103 ret
= cds_lfht_destroy(test_ht
, NULL
);
1105 printf_verbose("final delete aborted\n");
1107 printf_verbose("final delete success\n");
1108 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1110 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1112 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1113 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1114 argv
[0], duration
, nr_readers
, rduration
,
1115 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1116 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1117 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1118 rcu_unregister_thread();
1119 free_all_cpu_call_rcu_data();