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;
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 { \
*/
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);
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;
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(),
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);
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);
}
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)++;
}
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);
}
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");
}
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);
case 'M':
test_sync = TEST_SYNC_MUTEX;
break;
+ case 'w':
+ test_wait_empty = 1;
+ break;
case 'f':
test_force_sync = 1;
break;
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",
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);
}
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);
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;
}