From: Mathieu Desnoyers Date: Wed, 5 Dec 2012 13:57:44 +0000 (-0500) Subject: wfstack test: test if number of push to empty vs pop_all match X-Git-Tag: v0.8.0~132 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d05e9936ac167ead3a0ff5ca8ad0ade762bcda18;p=urcu.git wfstack test: test if number of push to empty vs pop_all match Do same as wfcqueue: we can test if number of push to empty stack match the number of pop_all that return non-empty stack. Can be tested with: ./test_urcu_wfs 5 5 10 -w Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_urcu_wfs.c b/tests/test_urcu_wfs.c index e36b822..1c852b9 100644 --- a/tests/test_urcu_wfs.c +++ b/tests/test_urcu_wfs.c @@ -80,7 +80,7 @@ static enum test_sync test_sync; static int test_force_sync; -static volatile int test_go, test_stop; +static volatile int test_go, test_stop_enqueue, test_stop_dequeue; static unsigned long rduration; @@ -97,7 +97,8 @@ static inline void loop_sleep(unsigned long loops) static int verbose_mode; -static int test_pop, test_pop_all; +static int test_pop, test_pop_all, test_wait_empty; +static int test_enqueue_stopped; #define printf_verbose(fmt, args...) \ do { \ @@ -155,12 +156,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop; + return !test_stop_dequeue; } static int test_duration_enqueue(void) { - return !test_stop; + return !test_stop_enqueue; } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -168,6 +169,8 @@ static DEFINE_URCU_TLS(unsigned long long, nr_enqueues); 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 unsigned int nr_enqueuers; static unsigned int nr_dequeuers; @@ -177,6 +180,7 @@ static struct cds_wfs_stack s; 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(), @@ -194,8 +198,10 @@ static void *thr_enqueuer(void *_count) if (!node) goto fail; cds_wfs_node_init(node); - cds_wfs_push(&s, node); + was_nonempty = cds_wfs_push(&s, node); URCU_TLS(nr_successful_enqueues)++; + if (!was_nonempty) + URCU_TLS(nr_empty_dest_enqueues)++; if (caa_unlikely(wdelay)) loop_sleep(wdelay); @@ -205,13 +211,18 @@ fail: break; } + uatomic_inc(&test_enqueue_stopped); 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\n", + "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_enqueues), + URCU_TLS(nr_successful_enqueues), + URCU_TLS(nr_empty_dest_enqueues)); return ((void*)1); } @@ -244,6 +255,12 @@ static void do_test_pop_all(enum test_sync sync) if (sync == TEST_SYNC_MUTEX) cds_wfs_pop_unlock(&s); + /* Check if empty */ + if (cds_wfs_first_blocking(head) == NULL) + return; + + URCU_TLS(nr_pop_all)++; + cds_wfs_for_each_blocking_safe(head, node, n) { free(node); URCU_TLS(nr_successful_dequeues)++; @@ -290,12 +307,15 @@ static void *thr_dequeuer(void *_count) } printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " - "dequeues %llu, successful_dequeues %llu\n", + "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_dequeues), URCU_TLS(nr_successful_dequeues), + URCU_TLS(nr_pop_all)); count[0] = URCU_TLS(nr_dequeues); count[1] = URCU_TLS(nr_successful_dequeues); + count[2] = URCU_TLS(nr_pop_all); return ((void*)2); } @@ -324,6 +344,7 @@ static void show_usage(int argc, char **argv) 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("\n"); } @@ -335,9 +356,11 @@ int main(int argc, char **argv) unsigned long long *count_enqueuer, *count_dequeuer; unsigned long long tot_enqueues = 0, tot_dequeues = 0; unsigned long long tot_successful_enqueues = 0, - tot_successful_dequeues = 0; + tot_successful_dequeues = 0, + tot_empty_dest_enqueues = 0, + tot_pop_all = 0; unsigned long long end_dequeues = 0; - int i, a; + int i, a, retval = 0; if (argc < 4) { show_usage(argc, argv); @@ -402,6 +425,9 @@ int main(int argc, char **argv) case 'M': test_sync = TEST_SYNC_MUTEX; break; + case 'w': + test_wait_empty = 1; + break; case 'f': test_force_sync = 1; break; @@ -434,6 +460,8 @@ int main(int argc, char **argv) printf_verbose("External sync: mutex.\n"); else printf_verbose("External sync: none.\n"); + if (test_wait_empty) + 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", @@ -442,21 +470,21 @@ int main(int argc, char **argv) tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); + count_enqueuer = malloc(3 * sizeof(*count_enqueuer) * nr_enqueuers); + count_dequeuer = malloc(3 * sizeof(*count_dequeuer) * nr_dequeuers); cds_wfs_init(&s); next_aff = 0; for (i = 0; i < nr_enqueuers; i++) { err = pthread_create(&tid_enqueuer[i], NULL, thr_enqueuer, - &count_enqueuer[2 * i]); + &count_enqueuer[3 * i]); if (err != 0) exit(1); } for (i = 0; i < nr_dequeuers; i++) { err = pthread_create(&tid_dequeuer[i], NULL, thr_dequeuer, - &count_dequeuer[2 * i]); + &count_dequeuer[3 * i]); if (err != 0) exit(1); } @@ -471,21 +499,34 @@ int main(int argc, char **argv) write (1, ".", 1); } - test_stop = 1; + test_stop_enqueue = 1; + + if (test_wait_empty) { + while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) { + sleep(1); + } + while (!cds_wfs_empty(&s)) { + sleep(1); + } + } + + test_stop_dequeue = 1; for (i = 0; i < nr_enqueuers; i++) { err = pthread_join(tid_enqueuer[i], &tret); if (err != 0) exit(1); - tot_enqueues += count_enqueuer[2 * i]; - tot_successful_enqueues += count_enqueuer[2 * i + 1]; + tot_enqueues += count_enqueuer[3 * i]; + tot_successful_enqueues += count_enqueuer[3 * i + 1]; + tot_empty_dest_enqueues += count_enqueuer[3 * i + 2]; } for (i = 0; i < nr_dequeuers; i++) { err = pthread_join(tid_dequeuer[i], &tret); if (err != 0) exit(1); - tot_dequeues += count_dequeuer[2 * i]; - tot_successful_dequeues += count_dequeuer[2 * i + 1]; + tot_dequeues += count_dequeuer[3 * i]; + tot_successful_dequeues += count_dequeuer[3 * i + 1]; + tot_pop_all += count_dequeuer[3 * i + 2]; } test_end(&s, &end_dequeues); @@ -493,27 +534,48 @@ int main(int argc, char **argv) printf_verbose("total number of enqueues : %llu, dequeues %llu\n", tot_enqueues, tot_dequeues); printf_verbose("total number of successful enqueues : %llu, " - "successful dequeues %llu\n", - tot_successful_enqueues, tot_successful_dequeues); + "enqueues to empty dest : %llu, " + "successful dequeues %llu, " + "pop_all : %llu\n", + tot_successful_enqueues, + tot_empty_dest_enqueues, + tot_successful_dequeues, + tot_pop_all); printf("SUMMARY %-25s testdur %4lu nr_enqueuers %3u wdelay %6lu " "nr_dequeuers %3u " "rdur %6lu nr_enqueues %12llu nr_dequeues %12llu " - "successful enqueues %12llu successful dequeues %12llu " + "successful enqueues %12llu enqueues to empty dest %12llu " + "successful dequeues %12llu pop_all %12llu " "end_dequeues %llu nr_ops %12llu\n", argv[0], duration, nr_enqueuers, wdelay, nr_dequeuers, rduration, tot_enqueues, tot_dequeues, tot_successful_enqueues, - tot_successful_dequeues, end_dequeues, + tot_empty_dest_enqueues, + tot_successful_dequeues, tot_pop_all, end_dequeues, tot_enqueues + tot_dequeues); - if (tot_successful_enqueues != tot_successful_dequeues + end_dequeues) + if (tot_successful_enqueues != tot_successful_dequeues + end_dequeues) { printf("WARNING! Discrepancy between nr succ. enqueues %llu vs " "succ. dequeues + end dequeues %llu.\n", tot_successful_enqueues, tot_successful_dequeues + end_dequeues); - + 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. + */ + if (test_wait_empty && test_pop_all && !test_pop + && tot_empty_dest_enqueues != tot_pop_all) { + printf("WARNING! Discrepancy between empty enqueue (%llu) and " + "number of non-empty pop_all (%llu)\n", + tot_empty_dest_enqueues, + tot_pop_all); + retval = 1; + } free(count_enqueuer); free(count_dequeuer); free(tid_enqueuer); free(tid_dequeuer); - return 0; + return retval; }