X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_wfs.c;h=2a031fe25850cc62d3943e77f05a83cd6c1ddd69;hp=1c852b9dd0abce809d5e7b679300673c88bbe469;hb=d14301c29dfc8761d54c4a289416d67606682675;hpb=d05e9936ac167ead3a0ff5ca8ad0ade762bcda18 diff --git a/tests/test_urcu_wfs.c b/tests/test_urcu_wfs.c index 1c852b9..2a031fe 100644 --- a/tests/test_urcu_wfs.c +++ b/tests/test_urcu_wfs.c @@ -34,38 +34,20 @@ #include #include #include -#include #include #include #include - -#ifdef __linux__ -#include -#endif +#include +#include "cpuset.h" +#include "thread-id.h" /* hardcoded number of CPUs */ #define NR_CPUS 16384 -#if defined(_syscall0) -_syscall0(pid_t, gettid) -#elif defined(__NR_gettid) -static inline pid_t gettid(void) -{ - return syscall(__NR_gettid); -} -#else -#warning "use pid as tid" -static inline pid_t gettid(void) -{ - return getpid(); -} -#endif - #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE #endif -#include #include /* @@ -112,12 +94,6 @@ static int use_affinity = 0; pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; -#ifndef HAVE_CPU_SET_T -typedef unsigned long cpu_set_t; -# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0) -# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0) -#endif - static void set_affinity(void) { #if HAVE_SCHED_SETAFFINITY @@ -171,6 +147,7 @@ static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues); static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues); static DEFINE_URCU_TLS(unsigned long long, nr_empty_dest_enqueues); static DEFINE_URCU_TLS(unsigned long long, nr_pop_all); +static DEFINE_URCU_TLS(unsigned long long, nr_pop_last); static unsigned int nr_enqueuers; static unsigned int nr_dequeuers; @@ -182,9 +159,8 @@ static void *thr_enqueuer(void *_count) unsigned long long *count = _count; bool was_nonempty; - printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "enqueuer", (unsigned long) pthread_self(), - (unsigned long) gettid()); + printf_verbose("thread_begin %s, tid %lu\n", + "enqueuer", urcu_get_thread_id()); set_affinity(); @@ -215,14 +191,13 @@ fail: count[0] = URCU_TLS(nr_enqueues); count[1] = URCU_TLS(nr_successful_enqueues); count[2] = URCU_TLS(nr_empty_dest_enqueues); - printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, " - "enqueues %llu successful_enqueues %llu, " - "empty_dest_enqueues %llu\n", - pthread_self(), - (unsigned long) gettid(), - URCU_TLS(nr_enqueues), - URCU_TLS(nr_successful_enqueues), - URCU_TLS(nr_empty_dest_enqueues)); + printf_verbose("enqueuer thread_end, tid %lu, " + "enqueues %llu successful_enqueues %llu, " + "empty_dest_enqueues %llu\n", + urcu_get_thread_id(), + URCU_TLS(nr_enqueues), + URCU_TLS(nr_successful_enqueues), + URCU_TLS(nr_empty_dest_enqueues)); return ((void*)1); } @@ -230,14 +205,17 @@ fail: static void do_test_pop(enum test_sync sync) { struct cds_wfs_node *node; + int state; if (sync == TEST_SYNC_MUTEX) cds_wfs_pop_lock(&s); - node = __cds_wfs_pop_blocking(&s); + node = __cds_wfs_pop_with_state_blocking(&s, &state); if (sync == TEST_SYNC_MUTEX) cds_wfs_pop_unlock(&s); if (node) { + if (state & CDS_WFS_STATE_LAST) + URCU_TLS(nr_pop_last)++; free(node); URCU_TLS(nr_successful_dequeues)++; } @@ -256,10 +234,11 @@ static void do_test_pop_all(enum test_sync sync) cds_wfs_pop_unlock(&s); /* Check if empty */ - if (cds_wfs_first_blocking(head) == NULL) + if (cds_wfs_first(head) == NULL) return; URCU_TLS(nr_pop_all)++; + URCU_TLS(nr_pop_last)++; cds_wfs_for_each_blocking_safe(head, node, n) { free(node); @@ -271,11 +250,10 @@ static void do_test_pop_all(enum test_sync sync) static void *thr_dequeuer(void *_count) { unsigned long long *count = _count; - unsigned int counter; + unsigned int counter = 0; - printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "dequeuer", (unsigned long) pthread_self(), - (unsigned long) gettid()); + printf_verbose("thread_begin %s, tid %lu\n", + "dequeuer", urcu_get_thread_id()); set_affinity(); @@ -306,26 +284,31 @@ static void *thr_dequeuer(void *_count) loop_sleep(rduration); } - printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " - "dequeues %llu, successful_dequeues %llu " - "pop_all %llu\n", - pthread_self(), - (unsigned long) gettid(), - URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues), - URCU_TLS(nr_pop_all)); + printf_verbose("dequeuer thread_end, tid %lu, " + "dequeues %llu, successful_dequeues %llu " + "pop_all %llu pop_last %llu\n", + urcu_get_thread_id(), + URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues), + URCU_TLS(nr_pop_all), + URCU_TLS(nr_pop_last)); count[0] = URCU_TLS(nr_dequeues); count[1] = URCU_TLS(nr_successful_dequeues); count[2] = URCU_TLS(nr_pop_all); + count[3] = URCU_TLS(nr_pop_last); return ((void*)2); } -static void test_end(struct cds_wfs_stack *s, unsigned long long *nr_dequeues) +static void test_end(struct cds_wfs_stack *s, unsigned long long *nr_dequeues, + unsigned long long *nr_pop_last) { struct cds_wfs_node *node; + int state; do { - node = cds_wfs_pop_blocking(s); + node = cds_wfs_pop_with_state_blocking(s, &state); if (node) { + if (state & CDS_WFS_STATE_LAST) + (*nr_pop_last)++; free(node); (*nr_dequeues)++; } @@ -334,17 +317,19 @@ static void test_end(struct cds_wfs_stack *s, unsigned long long *nr_dequeues) static void show_usage(int argc, char **argv) { - printf("Usage : %s nr_dequeuers nr_enqueuers duration (s)", argv[0]); - printf(" [-d delay] (enqueuer period (in loops))"); - printf(" [-c duration] (dequeuer period (in loops))"); - printf(" [-v] (verbose output)"); - printf(" [-a cpu#] [-a cpu#]... (affinity)"); - printf(" [-p] (test pop)"); - printf(" [-P] (test pop_all, enabled by default)"); - printf(" [-M] (use mutex external synchronization)"); - printf(" Note: default: no external synchronization used."); - printf(" [-f] (force user-provided synchronization)"); - printf(" [-w] Wait for dequeuer to empty stack"); + printf("Usage : %s nr_dequeuers nr_enqueuers duration (s) \n", + argv[0]); + printf("OPTIONS:\n"); + printf(" [-d delay] (enqueuer period (in loops))\n"); + printf(" [-c duration] (dequeuer period (in loops))\n"); + printf(" [-v] (verbose output)\n"); + printf(" [-a cpu#] [-a cpu#]... (affinity)\n"); + printf(" [-p] (test pop)\n"); + printf(" [-P] (test pop_all, enabled by default)\n"); + printf(" [-M] (use mutex external synchronization)\n"); + printf(" Note: default: no external synchronization used.\n"); + printf(" [-f] (force user-provided synchronization)\n"); + printf(" [-w] Wait for dequeuer to empty stack\n"); printf("\n"); } @@ -358,7 +343,7 @@ int main(int argc, char **argv) unsigned long long tot_successful_enqueues = 0, tot_successful_dequeues = 0, tot_empty_dest_enqueues = 0, - tot_pop_all = 0; + tot_pop_all = 0, tot_pop_last = 0; unsigned long long end_dequeues = 0; int i, a, retval = 0; @@ -464,14 +449,13 @@ int main(int argc, char **argv) printf_verbose("Wait for dequeuers to empty stack.\n"); printf_verbose("Writer delay : %lu loops.\n", rduration); printf_verbose("Reader duration : %lu loops.\n", wdelay); - printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", - "main", (unsigned long) pthread_self(), - (unsigned long) gettid()); + printf_verbose("thread %-6s, tid %lu\n", + "main", urcu_get_thread_id()); tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); count_enqueuer = malloc(3 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(3 * sizeof(*count_dequeuer) * nr_dequeuers); + count_dequeuer = malloc(4 * sizeof(*count_dequeuer) * nr_dequeuers); cds_wfs_init(&s); next_aff = 0; @@ -484,7 +468,7 @@ int main(int argc, char **argv) } for (i = 0; i < nr_dequeuers; i++) { err = pthread_create(&tid_dequeuer[i], NULL, thr_dequeuer, - &count_dequeuer[3 * i]); + &count_dequeuer[4 * i]); if (err != 0) exit(1); } @@ -524,34 +508,36 @@ int main(int argc, char **argv) err = pthread_join(tid_dequeuer[i], &tret); if (err != 0) exit(1); - tot_dequeues += count_dequeuer[3 * i]; - tot_successful_dequeues += count_dequeuer[3 * i + 1]; - tot_pop_all += count_dequeuer[3 * i + 2]; + tot_dequeues += count_dequeuer[4 * i]; + tot_successful_dequeues += count_dequeuer[4 * i + 1]; + tot_pop_all += count_dequeuer[4 * i + 2]; + tot_pop_last += count_dequeuer[4 * i + 3]; } - test_end(&s, &end_dequeues); + test_end(&s, &end_dequeues, &tot_pop_last); printf_verbose("total number of enqueues : %llu, dequeues %llu\n", tot_enqueues, tot_dequeues); printf_verbose("total number of successful enqueues : %llu, " "enqueues to empty dest : %llu, " "successful dequeues %llu, " - "pop_all : %llu\n", + "pop_all : %llu, pop_last : %llu\n", tot_successful_enqueues, tot_empty_dest_enqueues, tot_successful_dequeues, - tot_pop_all); + tot_pop_all, tot_pop_last); printf("SUMMARY %-25s testdur %4lu nr_enqueuers %3u wdelay %6lu " "nr_dequeuers %3u " "rdur %6lu nr_enqueues %12llu nr_dequeues %12llu " "successful enqueues %12llu enqueues to empty dest %12llu " "successful dequeues %12llu pop_all %12llu " - "end_dequeues %llu nr_ops %12llu\n", + "pop_last %llu end_dequeues %llu nr_ops %12llu\n", argv[0], duration, nr_enqueuers, wdelay, nr_dequeuers, rduration, tot_enqueues, tot_dequeues, tot_successful_enqueues, tot_empty_dest_enqueues, - tot_successful_dequeues, tot_pop_all, end_dequeues, + tot_successful_dequeues, tot_pop_all, tot_pop_last, + end_dequeues, tot_enqueues + tot_dequeues); if (tot_successful_enqueues != tot_successful_dequeues + end_dequeues) { printf("WARNING! Discrepancy between nr succ. enqueues %llu vs " @@ -561,16 +547,14 @@ int main(int argc, char **argv) retval = 1; } /* - * If only using pop_all to dequeue, the enqueuer should see - * exactly as many empty queues than the number of non-empty - * stacks dequeued. + * The enqueuer should see exactly as many empty queues than the + * number of non-empty stacks dequeued. */ - if (test_wait_empty && test_pop_all && !test_pop - && tot_empty_dest_enqueues != tot_pop_all) { + if (tot_empty_dest_enqueues != tot_pop_last) { printf("WARNING! Discrepancy between empty enqueue (%llu) and " - "number of non-empty pop_all (%llu)\n", + "number of pop last (%llu)\n", tot_empty_dest_enqueues, - tot_pop_all); + tot_pop_last); retval = 1; } free(count_enqueuer);