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
45 * Note: the hash seed should be a random value for hash tables
46 * targeting production environments to provide protection against
47 * denial of service attacks. We keep it a static value within this test
48 * program to compare identical benchmark runs.
50 #define TEST_HASH_SEED 0x42UL
52 /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */
53 #define CACHE_LINE_SIZE 4096
55 /* hardcoded number of CPUs */
59 #define poison_free(ptr) \
61 memset(ptr, 0x42, sizeof(*(ptr))); \
65 #define poison_free(ptr) free(ptr)
70 #if defined(_syscall0)
71 _syscall0(pid_t
, gettid
)
72 #elif defined(__NR_gettid)
73 static inline pid_t
gettid(void)
75 return syscall(__NR_gettid
);
78 #warning "use pid as tid"
79 static inline pid_t
gettid(void)
85 #ifndef DYNAMIC_LINK_TEST
88 #define debug_yield_read()
90 #include <urcu-qsbr.h>
91 #include <urcu/rculfhash.h>
92 #include <urcu-call-rcu.h>
95 unsigned long update_ops
;
97 unsigned long add_exist
;
101 static unsigned int __thread rand_lookup
;
102 static unsigned long __thread nr_add
;
103 static unsigned long __thread nr_addexist
;
104 static unsigned long __thread nr_del
;
105 static unsigned long __thread nr_delnoent
;
106 static unsigned long __thread lookup_fail
;
107 static unsigned long __thread lookup_ok
;
109 static struct cds_lfht
*test_ht
;
116 struct lfht_test_node
{
117 struct cds_lfht_node node
;
119 unsigned int key_len
;
120 /* cache-cold for iteration */
121 struct rcu_head head
;
124 static inline struct lfht_test_node
*
125 to_test_node(struct cds_lfht_node
*node
)
127 return caa_container_of(node
, struct lfht_test_node
, node
);
131 void lfht_test_node_init(struct lfht_test_node
*node
, void *key
,
134 cds_lfht_node_init(&node
->node
);
136 node
->key_len
= key_len
;
139 static inline struct lfht_test_node
*
140 cds_lfht_iter_get_test_node(struct cds_lfht_iter
*iter
)
142 return to_test_node(cds_lfht_iter_get_node(iter
));
145 static volatile int test_go
, test_stop
;
147 static unsigned long wdelay
;
149 static unsigned long duration
;
151 /* read-side C.S. duration, in loops */
152 static unsigned long rduration
;
154 static unsigned long init_hash_size
= DEFAULT_HASH_SIZE
;
155 static unsigned long min_hash_alloc_size
= DEFAULT_MIN_ALLOC_SIZE
;
156 static unsigned long max_hash_buckets_size
= (1UL << 20);
157 static unsigned long init_populate
;
158 static int opt_auto_resize
;
159 static int add_only
, add_unique
, add_replace
;
160 static const struct cds_lfht_mm_type
*memory_backend
;
162 static unsigned long init_pool_offset
, lookup_pool_offset
, write_pool_offset
;
163 static unsigned long init_pool_size
= DEFAULT_RAND_POOL
,
164 lookup_pool_size
= DEFAULT_RAND_POOL
,
165 write_pool_size
= DEFAULT_RAND_POOL
;
166 static int validate_lookup
;
168 static int count_pipe
[2];
170 static inline void loop_sleep(unsigned long l
)
176 static int verbose_mode
;
178 #define printf_verbose(fmt, args...) \
181 printf(fmt, ## args); \
184 static unsigned int cpu_affinities
[NR_CPUS
];
185 static unsigned int next_aff
= 0;
186 static int use_affinity
= 0;
188 pthread_mutex_t affinity_mutex
= PTHREAD_MUTEX_INITIALIZER
;
190 static void set_affinity(void)
199 ret
= pthread_mutex_lock(&affinity_mutex
);
201 perror("Error in pthread mutex lock");
204 cpu
= cpu_affinities
[next_aff
++];
205 ret
= pthread_mutex_unlock(&affinity_mutex
);
207 perror("Error in pthread mutex unlock");
212 sched_setaffinity(0, sizeof(mask
), &mask
);
219 } addremove
; /* 1: add, -1 remove, 0: random */
222 void sigusr1_handler(int signo
)
226 printf("Add/Remove: random.\n");
227 addremove
= AR_RANDOM
;
230 printf("Add/Remove: remove only.\n");
231 addremove
= AR_REMOVE
;
234 printf("Add/Remove: add only.\n");
241 void sigusr2_handler(int signo
)
243 char msg
[1] = { 0x42 };
247 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
248 } while (ret
== -1L && errno
== EINTR
);
252 * returns 0 if test should end.
254 static int test_duration_write(void)
259 static int test_duration_read(void)
264 static unsigned long long __thread nr_writes
;
265 static unsigned long long __thread nr_reads
;
267 static unsigned int nr_readers
;
268 static unsigned int nr_writers
;
270 pthread_mutex_t rcu_copy_mutex
= PTHREAD_MUTEX_INITIALIZER
;
272 void rcu_copy_mutex_lock(void)
275 ret
= pthread_mutex_lock(&rcu_copy_mutex
);
277 perror("Error in pthread mutex lock");
282 void rcu_copy_mutex_unlock(void)
286 ret
= pthread_mutex_unlock(&rcu_copy_mutex
);
288 perror("Error in pthread mutex unlock");
295 * Source: http://burtleburtle.net/bob/c/lookup3.c
296 * Originally Public Domain
299 #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
301 #define mix(a, b, c) \
303 a -= c; a ^= rot(c, 4); c += b; \
304 b -= a; b ^= rot(a, 6); a += c; \
305 c -= b; c ^= rot(b, 8); b += a; \
306 a -= c; a ^= rot(c, 16); c += b; \
307 b -= a; b ^= rot(a, 19); a += c; \
308 c -= b; c ^= rot(b, 4); b += a; \
311 #define final(a, b, c) \
313 c ^= b; c -= rot(b, 14); \
314 a ^= c; a -= rot(c, 11); \
315 b ^= a; b -= rot(a, 25); \
316 c ^= b; c -= rot(b, 16); \
317 a ^= c; a -= rot(c, 4);\
318 b ^= a; b -= rot(a, 14); \
319 c ^= b; c -= rot(b, 24); \
322 static __attribute__((unused
))
324 const uint32_t *k
, /* the key, an array of uint32_t values */
325 size_t length
, /* the length of the key, in uint32_ts */
326 uint32_t initval
) /* the previous hash, or an arbitrary value */
330 /* Set up the internal state */
331 a
= b
= c
= 0xdeadbeef + (((uint32_t) length
) << 2) + initval
;
333 /*----------------------------------------- handle most of the key */
343 /*----------------------------------- handle the last 3 uint32_t's */
344 switch (length
) { /* all the case statements fall through */
349 case 0: /* case 0: nothing left to add */
352 /*---------------------------------------------- report the result */
358 const uint32_t *k
, /* the key, an array of uint32_t values */
359 size_t length
, /* the length of the key, in uint32_ts */
360 uint32_t *pc
, /* IN: seed OUT: primary hash value */
361 uint32_t *pb
) /* IN: more seed OUT: secondary hash value */
365 /* Set up the internal state */
366 a
= b
= c
= 0xdeadbeef + ((uint32_t) (length
<< 2)) + *pc
;
369 /*----------------------------------------- handle most of the key */
379 /*----------------------------------- handle the last 3 uint32_t's */
380 switch (length
) { /* all the case statements fall through */
385 case 0: /* case 0: nothing left to add */
388 /*---------------------------------------------- report the result */
393 #if (CAA_BITS_PER_LONG == 32)
395 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
397 unsigned int key
= (unsigned int) _key
;
399 assert(length
== sizeof(unsigned int));
400 return hash_u32(&key
, 1, seed
);
404 unsigned long test_hash(const void *_key
, size_t length
, unsigned long seed
)
415 assert(length
== sizeof(unsigned long));
416 v
.v64
= (uint64_t) seed
;
417 key
.v64
= (uint64_t) _key
;
418 hashword2(key
.v32
, 2, &v
.v32
[0], &v
.v32
[1]);
424 unsigned long test_compare(const void *key1
, size_t key1_len
,
425 const void *key2
, size_t key2_len
)
427 if (caa_unlikely(key1_len
!= key2_len
))
429 assert(key1_len
== sizeof(unsigned long));
437 int test_match(struct cds_lfht_node
*node
, const void *key
)
439 struct lfht_test_node
*test_node
= to_test_node(node
);
441 return !test_compare(test_node
->key
, test_node
->key_len
,
442 key
, sizeof(unsigned long));
446 void cds_lfht_test_lookup(struct cds_lfht
*ht
, void *key
, size_t key_len
,
447 struct cds_lfht_iter
*iter
)
449 assert(key_len
== sizeof(unsigned long));
451 cds_lfht_lookup(ht
, test_hash(key
, key_len
, TEST_HASH_SEED
),
452 test_match
, key
, iter
);
455 void *thr_count(void *arg
)
457 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
458 "counter", pthread_self(), (unsigned long)gettid());
460 rcu_register_thread();
464 long approx_before
, approx_after
;
468 rcu_thread_offline();
469 len
= read(count_pipe
[0], buf
, 1);
471 if (caa_unlikely(!test_duration_read()))
476 printf("Counting nodes... ");
479 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
,
483 printf("Approximation before node accounting: %ld nodes.\n",
485 printf("Accounting of nodes in the hash table: "
488 printf("Approximation after node accounting: %ld nodes.\n",
491 rcu_unregister_thread();
495 void *thr_reader(void *_count
)
497 unsigned long long *count
= _count
;
498 struct lfht_test_node
*node
;
499 struct cds_lfht_iter iter
;
501 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
502 "reader", pthread_self(), (unsigned long)gettid());
506 rcu_register_thread();
515 cds_lfht_test_lookup(test_ht
,
516 (void *)(((unsigned long) rand_r(&rand_lookup
) % lookup_pool_size
) + lookup_pool_offset
),
517 sizeof(void *), &iter
);
518 node
= cds_lfht_iter_get_test_node(&iter
);
520 if (validate_lookup
) {
521 printf("[ERROR] Lookup cannot find initial node.\n");
529 if (caa_unlikely(rduration
))
530 loop_sleep(rduration
);
533 if (caa_unlikely(!test_duration_read()))
535 if (caa_unlikely((nr_reads
& ((1 << 10) - 1)) == 0))
536 rcu_quiescent_state();
539 rcu_unregister_thread();
542 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
543 "reader", pthread_self(), (unsigned long)gettid());
544 printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
545 pthread_self(), lookup_fail
, lookup_ok
);
551 void free_node_cb(struct rcu_head
*head
)
553 struct lfht_test_node
*node
=
554 caa_container_of(head
, struct lfht_test_node
, head
);
558 void *thr_writer(void *_count
)
560 struct lfht_test_node
*node
;
561 struct cds_lfht_node
*ret_node
;
562 struct cds_lfht_iter iter
;
563 struct wr_count
*count
= _count
;
566 printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
567 "writer", pthread_self(), (unsigned long)gettid());
571 rcu_register_thread();
579 if ((addremove
== AR_ADD
|| add_only
)
580 || (addremove
== AR_RANDOM
&& rand_r(&rand_lookup
) & 1)) {
581 node
= malloc(sizeof(struct lfht_test_node
));
582 lfht_test_node_init(node
,
583 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
587 ret_node
= cds_lfht_add_unique(test_ht
,
588 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
589 test_match
, node
->key
, &node
->node
);
592 ret_node
= cds_lfht_add_replace(test_ht
,
593 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
594 test_match
, node
->key
, &node
->node
);
596 cds_lfht_add(test_ht
,
597 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
601 if (add_unique
&& ret_node
!= &node
->node
) {
605 if (add_replace
&& ret_node
) {
606 call_rcu(&to_test_node(ret_node
)->head
,
616 cds_lfht_test_lookup(test_ht
,
617 (void *)(((unsigned long) rand_r(&rand_lookup
) % write_pool_size
) + write_pool_offset
),
618 sizeof(void *), &iter
);
619 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
622 node
= cds_lfht_iter_get_test_node(&iter
);
623 call_rcu(&node
->head
, free_node_cb
);
629 //if (nr_writes % 100000 == 0) {
630 if (nr_writes
% 1000 == 0) {
632 if (rand_r(&rand_lookup
) & 1) {
633 ht_resize(test_ht
, 1);
635 ht_resize(test_ht
, -1);
641 if (caa_unlikely(!test_duration_write()))
643 if (caa_unlikely(wdelay
))
645 if (caa_unlikely((nr_writes
& ((1 << 10) - 1)) == 0))
646 rcu_quiescent_state();
649 rcu_unregister_thread();
651 printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
652 "writer", pthread_self(), (unsigned long)gettid());
653 printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
654 "nr_delnoent %lu\n", pthread_self(), nr_add
,
655 nr_addexist
, nr_del
, nr_delnoent
);
656 count
->update_ops
= nr_writes
;
658 count
->add_exist
= nr_addexist
;
659 count
->remove
= nr_del
;
663 static int populate_hash(void)
665 struct lfht_test_node
*node
;
666 struct cds_lfht_node
*ret_node
;
671 if ((add_unique
|| add_replace
) && init_populate
* 10 > init_pool_size
) {
672 printf("WARNING: required to populate %lu nodes (-k), but random "
673 "pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a "
674 "larger random pool (-p option). This may take a while...\n", init_populate
, init_pool_size
);
677 while (nr_add
< init_populate
) {
678 node
= malloc(sizeof(struct lfht_test_node
));
679 lfht_test_node_init(node
,
680 (void *)(((unsigned long) rand_r(&rand_lookup
) % init_pool_size
) + init_pool_offset
),
684 ret_node
= cds_lfht_add_unique(test_ht
,
685 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
686 test_match
, node
->key
, &node
->node
);
689 ret_node
= cds_lfht_add_replace(test_ht
,
690 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
691 test_match
, node
->key
, &node
->node
);
693 cds_lfht_add(test_ht
,
694 test_hash(node
->key
, node
->key_len
, TEST_HASH_SEED
),
698 if (add_unique
&& ret_node
!= &node
->node
) {
702 if (add_replace
&& ret_node
) {
703 call_rcu(&to_test_node(ret_node
)->head
, free_node_cb
);
715 void test_delete_all_nodes(struct cds_lfht
*ht
)
717 struct cds_lfht_iter iter
;
718 struct lfht_test_node
*node
;
719 unsigned long count
= 0;
721 cds_lfht_for_each_entry(ht
, &iter
, node
, node
) {
724 ret
= cds_lfht_del(test_ht
, cds_lfht_iter_get_node(&iter
));
726 call_rcu(&node
->head
, free_node_cb
);
729 printf("deleted %lu nodes.\n", count
);
732 void show_usage(int argc
, char **argv
)
734 printf("Usage : %s nr_readers nr_writers duration (s)\n", argv
[0]);
736 printf(" [-r] [-w] (yield reader and/or writer)\n");
738 printf(" [-d delay] (writer period (us))\n");
739 printf(" [-c duration] (reader C.S. duration (in loops))\n");
740 printf(" [-v] (verbose output)\n");
741 printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
742 printf(" [-h size] (initial number of buckets)\n");
743 printf(" [-m size] (minimum number of allocated buckets)\n");
744 printf(" [-n size] (maximum number of buckets)\n");
745 printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
746 printf(" [-u] Uniquify add (no redundant keys).\n");
747 printf(" [-s] Replace (swap) entries.\n");
748 printf(" [-i] Add only (no removal).\n");
749 printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
750 printf(" [-A] Automatically resize hash table.\n");
751 printf(" [-B order|chunk|mmap] Specify the memory backend.\n");
752 printf(" [-R offset] Lookup pool offset.\n");
753 printf(" [-S offset] Write pool offset.\n");
754 printf(" [-T offset] Init pool offset.\n");
755 printf(" [-M size] Lookup pool size.\n");
756 printf(" [-N size] Write pool size.\n");
757 printf(" [-O size] Init pool size.\n");
758 printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
762 int main(int argc
, char **argv
)
765 pthread_t
*tid_reader
, *tid_writer
;
768 unsigned long long *count_reader
;
769 struct wr_count
*count_writer
;
770 unsigned long long tot_reads
= 0, tot_writes
= 0,
771 tot_add
= 0, tot_add_exist
= 0, tot_remove
= 0;
773 long approx_before
, approx_after
;
775 struct sigaction act
;
779 show_usage(argc
, argv
);
783 err
= sscanf(argv
[1], "%u", &nr_readers
);
785 show_usage(argc
, argv
);
789 err
= sscanf(argv
[2], "%u", &nr_writers
);
791 show_usage(argc
, argv
);
795 err
= sscanf(argv
[3], "%lu", &duration
);
797 show_usage(argc
, argv
);
801 for (i
= 4; i
< argc
; i
++) {
802 if (argv
[i
][0] != '-')
804 switch (argv
[i
][1]) {
807 yield_active
|= YIELD_READ
;
810 yield_active
|= YIELD_WRITE
;
815 show_usage(argc
, argv
);
819 cpu_affinities
[next_aff
++] = a
;
821 printf_verbose("Adding CPU %d affinity\n", a
);
825 show_usage(argc
, argv
);
828 rduration
= atol(argv
[++i
]);
832 show_usage(argc
, argv
);
835 wdelay
= atol(argv
[++i
]);
842 show_usage(argc
, argv
);
845 init_hash_size
= atol(argv
[++i
]);
849 show_usage(argc
, argv
);
852 min_hash_alloc_size
= atol(argv
[++i
]);
856 show_usage(argc
, argv
);
859 max_hash_buckets_size
= atol(argv
[++i
]);
863 printf("Please specify at most one of -s or -u.\n");
870 printf("Please specify at most one of -s or -u.\n");
879 init_populate
= atol(argv
[++i
]);
886 show_usage(argc
, argv
);
890 if (!strcmp("order", argv
[i
]))
891 memory_backend
= &cds_lfht_mm_order
;
892 else if (!strcmp("chunk", argv
[i
]))
893 memory_backend
= &cds_lfht_mm_chunk
;
894 else if (!strcmp("mmap", argv
[i
]))
895 memory_backend
= &cds_lfht_mm_mmap
;
897 printf("Please specify memory backend with order|chunk|mmap.\n");
902 lookup_pool_offset
= atol(argv
[++i
]);
905 write_pool_offset
= atol(argv
[++i
]);
908 init_pool_offset
= atol(argv
[++i
]);
911 lookup_pool_size
= atol(argv
[++i
]);
914 write_pool_size
= atol(argv
[++i
]);
917 init_pool_size
= atol(argv
[++i
]);
926 /* Check if hash size is power of 2 */
927 if (init_hash_size
&& init_hash_size
& (init_hash_size
- 1)) {
928 printf("Error: Initial number of buckets (%lu) is not a power of 2.\n",
933 if (min_hash_alloc_size
&& min_hash_alloc_size
& (min_hash_alloc_size
- 1)) {
934 printf("Error: Minimum number of allocated buckets (%lu) is not a power of 2.\n",
935 min_hash_alloc_size
);
939 if (max_hash_buckets_size
&& max_hash_buckets_size
& (max_hash_buckets_size
- 1)) {
940 printf("Error: Maximum number of buckets (%lu) is not a power of 2.\n",
941 max_hash_buckets_size
);
945 memset(&act
, 0, sizeof(act
));
946 ret
= sigemptyset(&act
.sa_mask
);
948 perror("sigemptyset");
951 act
.sa_handler
= sigusr1_handler
;
952 act
.sa_flags
= SA_RESTART
;
953 ret
= sigaction(SIGUSR1
, &act
, NULL
);
959 ret
= pipe(count_pipe
);
965 /* spawn counter thread */
966 err
= pthread_create(&tid_count
, NULL
, thr_count
,
971 act
.sa_handler
= sigusr2_handler
;
972 act
.sa_flags
= SA_RESTART
;
973 ret
= sigaction(SIGUSR2
, &act
, NULL
);
979 printf_verbose("running test for %lu seconds, %u readers, %u writers.\n",
980 duration
, nr_readers
, nr_writers
);
981 printf_verbose("Writer delay : %lu loops.\n", wdelay
);
982 printf_verbose("Reader duration : %lu loops.\n", rduration
);
983 printf_verbose("Mode:%s%s.\n",
984 add_only
? " add only" : " add/remove",
985 add_unique
? " uniquify" : ( add_replace
? " replace" : " insert"));
986 printf_verbose("Initial number of buckets: %lu buckets.\n", init_hash_size
);
987 printf_verbose("Minimum number of allocated buckets: %lu buckets.\n", min_hash_alloc_size
);
988 printf_verbose("Maximum number of buckets: %lu buckets.\n", max_hash_buckets_size
);
989 printf_verbose("Init pool size offset %lu size %lu.\n",
990 init_pool_offset
, init_pool_size
);
991 printf_verbose("Lookup pool size offset %lu size %lu.\n",
992 lookup_pool_offset
, lookup_pool_size
);
993 printf_verbose("Update pool size offset %lu size %lu.\n",
994 write_pool_offset
, write_pool_size
);
995 printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
996 "main", pthread_self(), (unsigned long)gettid());
998 tid_reader
= malloc(sizeof(*tid_reader
) * nr_readers
);
999 tid_writer
= malloc(sizeof(*tid_writer
) * nr_writers
);
1000 count_reader
= malloc(sizeof(*count_reader
) * nr_readers
);
1001 count_writer
= malloc(sizeof(*count_writer
) * nr_writers
);
1003 err
= create_all_cpu_call_rcu_data(0);
1006 if (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
, memory_backend
,
1013 test_ht
= cds_lfht_new(init_hash_size
, min_hash_alloc_size
,
1014 max_hash_buckets_size
,
1015 (opt_auto_resize
? CDS_LFHT_AUTO_RESIZE
: 0) |
1016 CDS_LFHT_ACCOUNTING
, NULL
);
1020 * Hash Population needs to be seen as a RCU reader
1021 * thread from the point of view of resize.
1023 rcu_register_thread();
1024 ret
= populate_hash();
1027 rcu_thread_offline();
1031 for (i
= 0; i
< nr_readers
; i
++) {
1032 err
= pthread_create(&tid_reader
[i
], NULL
, thr_reader
,
1037 for (i
= 0; i
< nr_writers
; i
++) {
1038 err
= pthread_create(&tid_writer
[i
], NULL
, thr_writer
,
1050 remain
= sleep(remain
);
1051 } while (remain
> 0);
1055 for (i
= 0; i
< nr_readers
; i
++) {
1056 err
= pthread_join(tid_reader
[i
], &tret
);
1059 tot_reads
+= count_reader
[i
];
1061 for (i
= 0; i
< nr_writers
; i
++) {
1062 err
= pthread_join(tid_writer
[i
], &tret
);
1065 tot_writes
+= count_writer
[i
].update_ops
;
1066 tot_add
+= count_writer
[i
].add
;
1067 tot_add_exist
+= count_writer
[i
].add_exist
;
1068 tot_remove
+= count_writer
[i
].remove
;
1071 /* teardown counter thread */
1072 act
.sa_handler
= SIG_IGN
;
1073 act
.sa_flags
= SA_RESTART
;
1074 ret
= sigaction(SIGUSR2
, &act
, NULL
);
1076 perror("sigaction");
1080 char msg
[1] = { 0x42 };
1084 ret
= write(count_pipe
[1], msg
, 1); /* wakeup thread */
1085 } while (ret
== -1L && errno
== EINTR
);
1087 err
= pthread_join(tid_count
, &tret
);
1092 rcu_thread_online();
1094 printf("Counting nodes... ");
1095 cds_lfht_count_nodes(test_ht
, &approx_before
, &count
, &approx_after
);
1097 test_delete_all_nodes(test_ht
);
1099 rcu_thread_offline();
1101 printf("Approximation before node accounting: %ld nodes.\n",
1103 printf("Nodes deleted from hash table before destroy: "
1106 printf("Approximation after node accounting: %ld nodes.\n",
1109 ret
= cds_lfht_destroy(test_ht
, NULL
);
1111 printf_verbose("final delete aborted\n");
1113 printf_verbose("final delete success\n");
1114 printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads
,
1116 printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
1118 "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
1119 "nr_add %12llu nr_add_fail %12llu nr_remove %12llu nr_leaked %12lld\n",
1120 argv
[0], duration
, nr_readers
, rduration
,
1121 nr_writers
, wdelay
, tot_reads
, tot_writes
,
1122 tot_reads
+ tot_writes
, tot_add
, tot_add_exist
, tot_remove
,
1123 (long long) tot_add
+ init_populate
- tot_remove
- count
);
1124 rcu_unregister_thread();
1125 free_all_cpu_call_rcu_data();