Commit | Line | Data |
---|---|---|
5d82d004 MD |
1 | /* |
2 | * test_glib_hash.c | |
3 | * | |
4 | * Userspace RCU library - test program | |
5 | * | |
6 | * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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. | |
21 | */ | |
22 | ||
23 | #define _GNU_SOURCE | |
24 | #include <stdio.h> | |
25 | #include <pthread.h> | |
26 | #include <stdlib.h> | |
27 | #include <string.h> | |
28 | #include <sys/types.h> | |
29 | #include <sys/wait.h> | |
30 | #include <unistd.h> | |
31 | #include <stdio.h> | |
32 | #include <assert.h> | |
33 | #include <sched.h> | |
34 | #include <errno.h> | |
35 | #include <glib.h> | |
36 | ||
37 | #ifdef __linux__ | |
38 | #include <syscall.h> | |
39 | #endif | |
40 | ||
41 | #define DEFAULT_HASH_SIZE 32 | |
42 | #define DEFAULT_RAND_POOL 1000000 | |
43 | ||
44 | /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ | |
45 | #define CACHE_LINE_SIZE 4096 | |
46 | ||
47 | /* hardcoded number of CPUs */ | |
48 | #define NR_CPUS 16384 | |
49 | ||
50 | #if defined(_syscall0) | |
51 | _syscall0(pid_t, gettid) | |
52 | #elif defined(__NR_gettid) | |
53 | static inline pid_t gettid(void) | |
54 | { | |
55 | return syscall(__NR_gettid); | |
56 | } | |
57 | #else | |
58 | #warning "use pid as tid" | |
59 | static inline pid_t gettid(void) | |
60 | { | |
61 | return getpid(); | |
62 | } | |
63 | #endif | |
64 | ||
65 | #ifndef DYNAMIC_LINK_TEST | |
66 | #define _LGPL_SOURCE | |
67 | #else | |
68 | #define debug_yield_read() | |
69 | #endif | |
70 | #include <urcu.h> | |
71 | #include <urcu-call-rcu.h> | |
72 | ||
73 | struct wr_count { | |
74 | unsigned long update_ops; | |
75 | unsigned long add; | |
76 | unsigned long remove; | |
77 | }; | |
78 | ||
79 | static unsigned int __thread rand_lookup; | |
80 | static unsigned long __thread nr_add; | |
81 | static unsigned long __thread nr_addexist; | |
82 | static unsigned long __thread nr_del; | |
83 | static unsigned long __thread nr_delnoent; | |
84 | static unsigned long __thread lookup_fail; | |
85 | static unsigned long __thread lookup_ok; | |
86 | ||
87 | static GHashTable *test_ht; | |
88 | ||
89 | struct test_data { | |
90 | int a; | |
91 | int b; | |
92 | }; | |
93 | ||
94 | static volatile int test_go, test_stop; | |
95 | ||
96 | static unsigned long wdelay; | |
97 | ||
98 | static unsigned long duration; | |
99 | ||
100 | /* read-side C.S. duration, in loops */ | |
101 | static unsigned long rduration; | |
102 | ||
103 | static unsigned long init_hash_size = DEFAULT_HASH_SIZE; | |
104 | static unsigned long rand_pool = DEFAULT_RAND_POOL; | |
105 | static int add_only, add_unique; | |
106 | ||
107 | static inline void loop_sleep(unsigned long l) | |
108 | { | |
109 | while(l-- != 0) | |
110 | caa_cpu_relax(); | |
111 | } | |
112 | ||
113 | static int verbose_mode; | |
114 | ||
115 | #define printf_verbose(fmt, args...) \ | |
116 | do { \ | |
117 | if (verbose_mode) \ | |
118 | printf(fmt, ## args); \ | |
119 | } while (0) | |
120 | ||
121 | static unsigned int cpu_affinities[NR_CPUS]; | |
122 | static unsigned int next_aff = 0; | |
123 | static int use_affinity = 0; | |
124 | ||
125 | pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; | |
126 | ||
127 | static void set_affinity(void) | |
128 | { | |
129 | cpu_set_t mask; | |
130 | int cpu; | |
131 | int ret; | |
132 | ||
133 | if (!use_affinity) | |
134 | return; | |
135 | ||
136 | ret = pthread_mutex_lock(&affinity_mutex); | |
137 | if (ret) { | |
138 | perror("Error in pthread mutex lock"); | |
139 | exit(-1); | |
140 | } | |
141 | cpu = cpu_affinities[next_aff++]; | |
142 | ret = pthread_mutex_unlock(&affinity_mutex); | |
143 | if (ret) { | |
144 | perror("Error in pthread mutex unlock"); | |
145 | exit(-1); | |
146 | } | |
147 | CPU_ZERO(&mask); | |
148 | CPU_SET(cpu, &mask); | |
149 | sched_setaffinity(0, sizeof(mask), &mask); | |
150 | } | |
151 | ||
152 | /* | |
153 | * returns 0 if test should end. | |
154 | */ | |
155 | static int test_duration_write(void) | |
156 | { | |
157 | return !test_stop; | |
158 | } | |
159 | ||
160 | static int test_duration_read(void) | |
161 | { | |
162 | return !test_stop; | |
163 | } | |
164 | ||
165 | static unsigned long long __thread nr_writes; | |
166 | static unsigned long long __thread nr_reads; | |
167 | ||
168 | static unsigned int nr_readers; | |
169 | static unsigned int nr_writers; | |
170 | ||
171 | pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; | |
172 | ||
173 | void rcu_copy_mutex_lock(void) | |
174 | { | |
175 | int ret; | |
176 | ret = pthread_mutex_lock(&rcu_copy_mutex); | |
177 | if (ret) { | |
178 | perror("Error in pthread mutex lock"); | |
179 | exit(-1); | |
180 | } | |
181 | } | |
182 | ||
183 | void rcu_copy_mutex_unlock(void) | |
184 | { | |
185 | int ret; | |
186 | ||
187 | ret = pthread_mutex_unlock(&rcu_copy_mutex); | |
188 | if (ret) { | |
189 | perror("Error in pthread mutex unlock"); | |
190 | exit(-1); | |
191 | } | |
192 | } | |
193 | ||
194 | /* | |
195 | * Hash function | |
196 | * Source: http://burtleburtle.net/bob/c/lookup3.c | |
197 | * Originally Public Domain | |
198 | */ | |
199 | ||
200 | #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) | |
201 | ||
202 | #define mix(a, b, c) \ | |
203 | do { \ | |
204 | a -= c; a ^= rot(c, 4); c += b; \ | |
205 | b -= a; b ^= rot(a, 6); a += c; \ | |
206 | c -= b; c ^= rot(b, 8); b += a; \ | |
207 | a -= c; a ^= rot(c, 16); c += b; \ | |
208 | b -= a; b ^= rot(a, 19); a += c; \ | |
209 | c -= b; c ^= rot(b, 4); b += a; \ | |
210 | } while (0) | |
211 | ||
212 | #define final(a, b, c) \ | |
213 | { \ | |
214 | c ^= b; c -= rot(b, 14); \ | |
215 | a ^= c; a -= rot(c, 11); \ | |
216 | b ^= a; b -= rot(a, 25); \ | |
217 | c ^= b; c -= rot(b, 16); \ | |
218 | a ^= c; a -= rot(c, 4);\ | |
219 | b ^= a; b -= rot(a, 14); \ | |
220 | c ^= b; c -= rot(b, 24); \ | |
221 | } | |
222 | ||
223 | static __attribute__((unused)) | |
224 | uint32_t hash_u32( | |
225 | const uint32_t *k, /* the key, an array of uint32_t values */ | |
226 | size_t length, /* the length of the key, in uint32_ts */ | |
227 | uint32_t initval) /* the previous hash, or an arbitrary value */ | |
228 | { | |
229 | uint32_t a, b, c; | |
230 | ||
231 | /* Set up the internal state */ | |
232 | a = b = c = 0xdeadbeef + (((uint32_t) length) << 2) + initval; | |
233 | ||
234 | /*----------------------------------------- handle most of the key */ | |
235 | while (length > 3) { | |
236 | a += k[0]; | |
237 | b += k[1]; | |
238 | c += k[2]; | |
239 | mix(a, b, c); | |
240 | length -= 3; | |
241 | k += 3; | |
242 | } | |
243 | ||
244 | /*----------------------------------- handle the last 3 uint32_t's */ | |
245 | switch (length) { /* all the case statements fall through */ | |
246 | case 3: c += k[2]; | |
247 | case 2: b += k[1]; | |
248 | case 1: a += k[0]; | |
249 | final(a, b, c); | |
250 | case 0: /* case 0: nothing left to add */ | |
251 | break; | |
252 | } | |
253 | /*---------------------------------------------- report the result */ | |
254 | return c; | |
255 | } | |
256 | ||
257 | static | |
258 | void hashword2( | |
259 | const uint32_t *k, /* the key, an array of uint32_t values */ | |
260 | size_t length, /* the length of the key, in uint32_ts */ | |
261 | uint32_t *pc, /* IN: seed OUT: primary hash value */ | |
262 | uint32_t *pb) /* IN: more seed OUT: secondary hash value */ | |
263 | { | |
264 | uint32_t a, b, c; | |
265 | ||
266 | /* Set up the internal state */ | |
267 | a = b = c = 0xdeadbeef + ((uint32_t) (length << 2)) + *pc; | |
268 | c += *pb; | |
269 | ||
270 | /*----------------------------------------- handle most of the key */ | |
271 | while (length > 3) { | |
272 | a += k[0]; | |
273 | b += k[1]; | |
274 | c += k[2]; | |
275 | mix(a, b, c); | |
276 | length -= 3; | |
277 | k += 3; | |
278 | } | |
279 | ||
280 | /*----------------------------------- handle the last 3 uint32_t's */ | |
281 | switch (length) { /* all the case statements fall through */ | |
282 | case 3: c += k[2]; | |
283 | case 2: b += k[1]; | |
284 | case 1: a += k[0]; | |
285 | final(a, b, c); | |
286 | case 0: /* case 0: nothing left to add */ | |
287 | break; | |
288 | } | |
289 | /*---------------------------------------------- report the result */ | |
290 | *pc = c; | |
291 | *pb = b; | |
292 | } | |
293 | ||
294 | #if (CAA_BITS_PER_LONG == 32) | |
295 | static | |
296 | unsigned long test_hash(const void *_key, size_t length, unsigned long seed) | |
297 | { | |
298 | unsigned long key = (unsigned long) _key; | |
299 | unsigned long v; | |
300 | ||
301 | assert(length == sizeof(unsigned long)); | |
302 | return hash_u32(&v, 1, seed); | |
303 | } | |
304 | #else | |
305 | static | |
306 | unsigned long test_hash(const void *_key, size_t length, unsigned long seed) | |
307 | { | |
308 | union { | |
309 | uint64_t v64; | |
310 | uint32_t v32[2]; | |
311 | } v; | |
312 | union { | |
313 | uint64_t v64; | |
314 | uint32_t v32[2]; | |
315 | } key; | |
316 | ||
317 | assert(length == sizeof(unsigned long)); | |
318 | v.v64 = (uint64_t) seed; | |
319 | key.v64 = (uint64_t) _key; | |
320 | hashword2(key.v32, 2, &v.v32[0], &v.v32[1]); | |
321 | return v.v64; | |
322 | } | |
323 | #endif | |
324 | ||
325 | static | |
326 | unsigned long test_compare(const void *key1, size_t key1_len, | |
327 | const void *key2, size_t key2_len) | |
328 | { | |
329 | if (unlikely(key1_len != key2_len)) | |
330 | return -1; | |
331 | assert(key1_len == sizeof(unsigned long)); | |
332 | if (key1 == key2) | |
333 | return 0; | |
334 | else | |
335 | return 1; | |
336 | } | |
337 | ||
338 | static | |
339 | guint test_hash_fct(const void *key) | |
340 | { | |
341 | return test_hash(key, sizeof(void *), 0x42); | |
342 | } | |
343 | ||
344 | static | |
345 | gboolean test_compare_fct(const void *a, const void *b) | |
346 | { | |
347 | return !test_compare(a, sizeof(void *), b, sizeof(void *)); | |
348 | } | |
349 | ||
350 | void *thr_reader(void *_count) | |
351 | { | |
352 | unsigned long long *count = _count; | |
353 | void *node; | |
354 | ||
355 | printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", | |
356 | "reader", pthread_self(), (unsigned long)gettid()); | |
357 | ||
358 | set_affinity(); | |
359 | ||
360 | rcu_register_thread(); | |
361 | ||
362 | while (!test_go) | |
363 | { | |
364 | } | |
365 | cmm_smp_mb(); | |
366 | ||
367 | for (;;) { | |
368 | rcu_copy_mutex_lock(); | |
369 | node = g_hash_table_lookup(test_ht, | |
370 | (void *)(unsigned long)(rand_r(&rand_lookup) % rand_pool)); | |
371 | if (node == NULL) | |
372 | lookup_fail++; | |
373 | else | |
374 | lookup_ok++; | |
375 | debug_yield_read(); | |
376 | if (unlikely(rduration)) | |
377 | loop_sleep(rduration); | |
378 | rcu_copy_mutex_unlock(); | |
379 | nr_reads++; | |
380 | if (unlikely(!test_duration_read())) | |
381 | break; | |
382 | } | |
383 | ||
384 | rcu_unregister_thread(); | |
385 | ||
386 | *count = nr_reads; | |
387 | printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", | |
388 | "reader", pthread_self(), (unsigned long)gettid()); | |
389 | printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n", | |
390 | pthread_self(), lookup_fail, lookup_ok); | |
391 | return ((void*)1); | |
392 | ||
393 | } | |
394 | ||
395 | void *thr_writer(void *_count) | |
396 | { | |
397 | void *node, *ret_node; | |
398 | struct wr_count *count = _count; | |
399 | int ret; | |
400 | ||
401 | printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", | |
402 | "writer", pthread_self(), (unsigned long)gettid()); | |
403 | ||
404 | set_affinity(); | |
405 | ||
406 | rcu_register_thread(); | |
407 | ||
408 | while (!test_go) | |
409 | { | |
410 | } | |
411 | cmm_smp_mb(); | |
412 | ||
413 | for (;;) { | |
414 | if (add_only || rand_r(&rand_lookup) & 1) { | |
415 | node = malloc(1); | |
416 | rcu_copy_mutex_lock(); | |
417 | //if (add_unique) | |
418 | // ret_node = ht_add_unique(test_ht, node); | |
419 | //else | |
420 | g_hash_table_insert(test_ht, | |
421 | (void *)(unsigned long)(rand_r(&rand_lookup) % rand_pool), | |
422 | node); | |
423 | rcu_copy_mutex_unlock(); | |
424 | //if (add_unique && ret_node != node) { | |
425 | // free(node); | |
426 | // nr_addexist++; | |
427 | //} else | |
428 | nr_add++; | |
429 | } else { | |
430 | /* May delete */ | |
431 | rcu_copy_mutex_lock(); | |
432 | ret = g_hash_table_remove(test_ht, | |
433 | (void *)(unsigned long)(rand_r(&rand_lookup) % rand_pool)); | |
434 | rcu_copy_mutex_unlock(); | |
435 | if (ret) { | |
436 | nr_del++; | |
437 | } else | |
438 | nr_delnoent++; | |
439 | } | |
440 | #if 0 | |
441 | //if (nr_writes % 100000 == 0) { | |
442 | if (nr_writes % 1000 == 0) { | |
443 | rcu_read_lock(); | |
444 | if (rand_r(&rand_lookup) & 1) { | |
445 | ht_resize(test_ht, 1); | |
446 | } else { | |
447 | ht_resize(test_ht, -1); | |
448 | } | |
449 | rcu_read_unlock(); | |
450 | } | |
451 | #endif //0 | |
452 | nr_writes++; | |
453 | if (unlikely(!test_duration_write())) | |
454 | break; | |
455 | if (unlikely(wdelay)) | |
456 | loop_sleep(wdelay); | |
457 | } | |
458 | ||
459 | rcu_unregister_thread(); | |
460 | ||
461 | printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", | |
462 | "writer", pthread_self(), (unsigned long)gettid()); | |
463 | printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, " | |
464 | "nr_delnoent %lu\n", pthread_self(), nr_add, | |
465 | nr_addexist, nr_del, nr_delnoent); | |
466 | count->update_ops = nr_writes; | |
467 | count->add = nr_add; | |
468 | count->remove = nr_del; | |
469 | return ((void*)2); | |
470 | } | |
471 | ||
472 | void show_usage(int argc, char **argv) | |
473 | { | |
474 | printf("Usage : %s nr_readers nr_writers duration (s)", argv[0]); | |
475 | #ifdef DEBUG_YIELD | |
476 | printf(" [-r] [-w] (yield reader and/or writer)"); | |
477 | #endif | |
478 | printf(" [-d delay] (writer period (us))"); | |
479 | printf(" [-c duration] (reader C.S. duration (in loops))"); | |
480 | printf(" [-v] (verbose output)"); | |
481 | printf(" [-a cpu#] [-a cpu#]... (affinity)"); | |
482 | printf(" [-p size] (random key value pool size)"); | |
483 | printf(" [-h size] (initial hash table size)"); | |
484 | printf(" [-u] Uniquify add."); | |
485 | printf(" [-i] Add only (no removal)."); | |
486 | printf("\n"); | |
487 | } | |
488 | ||
489 | int main(int argc, char **argv) | |
490 | { | |
491 | int err; | |
492 | pthread_t *tid_reader, *tid_writer; | |
493 | void *tret; | |
494 | unsigned long long *count_reader; | |
495 | struct wr_count *count_writer; | |
496 | unsigned long long tot_reads = 0, tot_writes = 0, | |
497 | tot_add = 0, tot_remove = 0; | |
498 | unsigned long count, removed; | |
499 | int i, a, ret; | |
500 | ||
501 | if (argc < 4) { | |
502 | show_usage(argc, argv); | |
503 | return -1; | |
504 | } | |
505 | ||
506 | err = sscanf(argv[1], "%u", &nr_readers); | |
507 | if (err != 1) { | |
508 | show_usage(argc, argv); | |
509 | return -1; | |
510 | } | |
511 | ||
512 | err = sscanf(argv[2], "%u", &nr_writers); | |
513 | if (err != 1) { | |
514 | show_usage(argc, argv); | |
515 | return -1; | |
516 | } | |
517 | ||
518 | err = sscanf(argv[3], "%lu", &duration); | |
519 | if (err != 1) { | |
520 | show_usage(argc, argv); | |
521 | return -1; | |
522 | } | |
523 | ||
524 | for (i = 4; i < argc; i++) { | |
525 | if (argv[i][0] != '-') | |
526 | continue; | |
527 | switch (argv[i][1]) { | |
528 | #ifdef DEBUG_YIELD | |
529 | case 'r': | |
530 | yield_active |= YIELD_READ; | |
531 | break; | |
532 | case 'w': | |
533 | yield_active |= YIELD_WRITE; | |
534 | break; | |
535 | #endif | |
536 | case 'a': | |
537 | if (argc < i + 2) { | |
538 | show_usage(argc, argv); | |
539 | return -1; | |
540 | } | |
541 | a = atoi(argv[++i]); | |
542 | cpu_affinities[next_aff++] = a; | |
543 | use_affinity = 1; | |
544 | printf_verbose("Adding CPU %d affinity\n", a); | |
545 | break; | |
546 | case 'c': | |
547 | if (argc < i + 2) { | |
548 | show_usage(argc, argv); | |
549 | return -1; | |
550 | } | |
551 | rduration = atol(argv[++i]); | |
552 | break; | |
553 | case 'd': | |
554 | if (argc < i + 2) { | |
555 | show_usage(argc, argv); | |
556 | return -1; | |
557 | } | |
558 | wdelay = atol(argv[++i]); | |
559 | break; | |
560 | case 'v': | |
561 | verbose_mode = 1; | |
562 | break; | |
563 | case 'p': | |
564 | if (argc < i + 2) { | |
565 | show_usage(argc, argv); | |
566 | return -1; | |
567 | } | |
568 | rand_pool = atol(argv[++i]); | |
569 | break; | |
570 | case 'h': | |
571 | if (argc < i + 2) { | |
572 | show_usage(argc, argv); | |
573 | return -1; | |
574 | } | |
575 | init_hash_size = atol(argv[++i]); | |
576 | break; | |
577 | case 'u': | |
578 | add_unique = 1; | |
579 | break; | |
580 | case 'i': | |
581 | add_only = 1; | |
582 | break; | |
583 | } | |
584 | } | |
585 | ||
586 | /* Check if hash size is power of 2 */ | |
587 | if (init_hash_size && init_hash_size & (init_hash_size - 1)) { | |
588 | printf("Error: Hash table size %lu is not a power of 2.\n", | |
589 | init_hash_size); | |
590 | return -1; | |
591 | } | |
592 | ||
593 | printf_verbose("running test for %lu seconds, %u readers, %u writers.\n", | |
594 | duration, nr_readers, nr_writers); | |
595 | printf_verbose("Writer delay : %lu loops.\n", wdelay); | |
596 | printf_verbose("Reader duration : %lu loops.\n", rduration); | |
597 | printf_verbose("Random pool size : %lu.\n", rand_pool); | |
598 | printf_verbose("Mode:%s%s.\n", | |
599 | add_only ? " add only" : " add/remove", | |
600 | add_unique ? " uniquify" : ""); | |
601 | printf_verbose("Initial hash table size: %lu buckets.\n", init_hash_size); | |
602 | printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", | |
603 | "main", pthread_self(), (unsigned long)gettid()); | |
604 | ||
605 | tid_reader = malloc(sizeof(*tid_reader) * nr_readers); | |
606 | tid_writer = malloc(sizeof(*tid_writer) * nr_writers); | |
607 | count_reader = malloc(sizeof(*count_reader) * nr_readers); | |
608 | count_writer = malloc(sizeof(*count_writer) * nr_writers); | |
609 | //test_ht = ht_new(test_hash, test_compare, 0x42UL, | |
610 | // init_hash_size, call_rcu); | |
611 | test_ht = g_hash_table_new_full(test_hash_fct, test_compare_fct, | |
612 | NULL, free); | |
613 | ||
614 | err = create_all_cpu_call_rcu_data(0); | |
615 | assert(!err); | |
616 | ||
617 | next_aff = 0; | |
618 | ||
619 | for (i = 0; i < nr_readers; i++) { | |
620 | err = pthread_create(&tid_reader[i], NULL, thr_reader, | |
621 | &count_reader[i]); | |
622 | if (err != 0) | |
623 | exit(1); | |
624 | } | |
625 | for (i = 0; i < nr_writers; i++) { | |
626 | err = pthread_create(&tid_writer[i], NULL, thr_writer, | |
627 | &count_writer[i]); | |
628 | if (err != 0) | |
629 | exit(1); | |
630 | } | |
631 | ||
632 | cmm_smp_mb(); | |
633 | ||
634 | test_go = 1; | |
635 | ||
636 | sleep(duration); | |
637 | ||
638 | test_stop = 1; | |
639 | ||
640 | for (i = 0; i < nr_readers; i++) { | |
641 | err = pthread_join(tid_reader[i], &tret); | |
642 | if (err != 0) | |
643 | exit(1); | |
644 | tot_reads += count_reader[i]; | |
645 | } | |
646 | for (i = 0; i < nr_writers; i++) { | |
647 | err = pthread_join(tid_writer[i], &tret); | |
648 | if (err != 0) | |
649 | exit(1); | |
650 | tot_writes += count_writer[i].update_ops; | |
651 | tot_add += count_writer[i].add; | |
652 | tot_remove += count_writer[i].remove; | |
653 | } | |
654 | #if 0 | |
655 | printf("Counting nodes... "); | |
656 | fflush(stdout); | |
657 | ht_count_nodes(test_ht, &count, &removed); | |
658 | printf("done.\n"); | |
659 | if (count || removed) | |
660 | printf("WARNING: nodes left in the hash table upon destroy: " | |
661 | "%lu nodes + %lu logically removed.\n", count, removed); | |
662 | ret = ht_destroy(test_ht); | |
663 | #endif | |
664 | g_hash_table_destroy(test_ht); | |
665 | ||
666 | if (ret) | |
667 | printf_verbose("final delete aborted\n"); | |
668 | else | |
669 | printf_verbose("final delete success\n"); | |
670 | printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, | |
671 | tot_writes); | |
672 | printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu " | |
673 | "nr_writers %3u " | |
674 | "wdelay %6lu rand_pool %12llu nr_reads %12llu nr_writes %12llu nr_ops %12llu " | |
675 | "nr_add %12llu nr_remove %12llu nr_leaked %12llu\n", | |
676 | argv[0], duration, nr_readers, rduration, | |
677 | nr_writers, wdelay, rand_pool, tot_reads, tot_writes, | |
678 | tot_reads + tot_writes, tot_add, tot_remove, | |
679 | tot_add - tot_remove - count); | |
680 | free(tid_reader); | |
681 | free(tid_writer); | |
682 | free(count_reader); | |
683 | free(count_writer); | |
684 | return 0; | |
685 | } |