regressions/ck_epoch: Multiple writers for synchronize unit test.

ck_pring
Samy Al Bahra 12 years ago
parent dac91d1edd
commit 657c50f823

@ -1,12 +1,13 @@
.PHONY: check clean distribution
OBJECTS=ck_stack ck_epoch_synchronize ck_epoch_poll
HALF=`expr $(CORES) / 2`
all: $(OBJECTS)
check: all
./ck_stack $(CORES) 1
./ck_epoch_synchronize $(CORES) 1
./ck_epoch_synchronize $(HALF) $(HALF) 1
./ck_epoch_poll $(CORES) 1
ck_epoch_synchronize: ck_epoch_synchronize.c ../../../include/ck_stack.h ../../../include/ck_epoch.h ../../../src/ck_epoch.c
@ -22,4 +23,4 @@ clean:
rm -rf *~ *.o $(OBJECTS) *.dSYM
include ../../../build/regressions.build
CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE
CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE -O0 -g3

@ -45,10 +45,13 @@
#include "../../common.h"
static unsigned int n_rd;
static unsigned int n_wr;
static unsigned int n_threads;
static unsigned int barrier;
static unsigned int e_barrier;
static unsigned int readers;
static unsigned int writers;
#ifndef PAIRS_S
#define PAIRS_S 10000
@ -138,10 +141,10 @@ read_thread(void *unused CK_CC_UNUSED)
}
static void *
thread(void *unused CK_CC_UNUSED)
write_thread(void *unused CK_CC_UNUSED)
{
struct node **entry, *e;
unsigned int i, j;
unsigned int i, j, tid;
ck_epoch_record_t record;
ck_stack_entry_t *s;
@ -152,6 +155,7 @@ thread(void *unused CK_CC_UNUSED)
exit(EXIT_FAILURE);
}
tid = ck_pr_faa_uint(&writers, 1);
ck_pr_inc_uint(&barrier);
while (ck_pr_load_uint(&barrier) < n_threads);
@ -177,31 +181,38 @@ thread(void *unused CK_CC_UNUSED)
while (ck_pr_load_uint(&readers) == 0)
ck_pr_stall();
fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c", (double)j / ITERATE_S, animate[i % strlen(animate)]);
if (tid == 0) {
fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c",
(double)j / ITERATE_S, animate[i % strlen(animate)]);
}
for (i = 0; i < PAIRS_S; i++) {
ck_epoch_begin(&stack_epoch, &record);
s = ck_stack_pop_upmc(&stack);
e = stack_container(s);
ck_epoch_end(&stack_epoch, &record);
ck_epoch_synchronize(&stack_epoch, &record);
if (i & 1) {
ck_epoch_call(&stack_epoch, &record, &e->epoch_entry, destructor);
} else {
destructor(&e->epoch_entry);
}
if (tid == 0 && i % 8192)
fprintf(stderr, "\b%c", animate[i % strlen(animate)]);
if (i % 8192) {
fprintf(stderr, "\b%c", animate[i % strlen(animate)]);
destructor(&e->epoch_entry);
}
}
}
ck_epoch_synchronize(&stack_epoch, &record);
fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n",
if (tid == 0) {
fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n",
record.n_peak,
(double)record.n_peak / ((double)PAIRS_S * ITERATE_S) * 100,
record.n_dispatch);
}
ck_pr_inc_uint(&e_barrier);
while (ck_pr_load_uint(&e_barrier) < n_threads);
@ -214,23 +225,27 @@ main(int argc, char *argv[])
unsigned int i;
pthread_t *threads;
if (argc != 3) {
fprintf(stderr, "Usage: stack <threads> <affinity delta>\n");
if (argc != 4) {
fprintf(stderr, "Usage: stack <#readers> <#writers> <affinity delta>\n");
exit(EXIT_FAILURE);
}
n_threads = atoi(argv[1]);
a.delta = atoi(argv[2]);
n_rd = atoi(argv[1]);
n_wr = atoi(argv[2]);
n_threads = n_wr + n_rd;
a.delta = atoi(argv[3]);
a.request = 0;
threads = malloc(sizeof(pthread_t) * n_threads);
ck_epoch_init(&stack_epoch);
for (i = 0; i < n_threads - 1; i++)
for (i = 0; i < n_rd; i++)
pthread_create(threads + i, NULL, read_thread, NULL);
pthread_create(threads + i, NULL, thread, NULL);
do {
pthread_create(threads + i, NULL, write_thread, NULL);
} while (++i < n_wr + n_rd);
for (i = 0; i < n_threads; i++)
pthread_join(threads[i], NULL);

Loading…
Cancel
Save