|
|
@ -43,7 +43,7 @@ struct context {
|
|
|
|
unsigned int tid;
|
|
|
|
unsigned int tid;
|
|
|
|
unsigned int previous;
|
|
|
|
unsigned int previous;
|
|
|
|
unsigned int next;
|
|
|
|
unsigned int next;
|
|
|
|
void *buffer;
|
|
|
|
ck_ring_buffer_t *buffer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct entry {
|
|
|
|
struct entry {
|
|
|
@ -71,9 +71,9 @@ test_spmc(void *c)
|
|
|
|
unsigned int seed;
|
|
|
|
unsigned int seed;
|
|
|
|
int i, k, j, tid;
|
|
|
|
int i, k, j, tid;
|
|
|
|
struct context *context = c;
|
|
|
|
struct context *context = c;
|
|
|
|
ck_ring_buffer_t buf;
|
|
|
|
ck_ring_buffer_t *buffer;
|
|
|
|
|
|
|
|
|
|
|
|
buf.ring = context->buffer;
|
|
|
|
buffer = context->buffer;
|
|
|
|
if (aff_iterate(&a)) {
|
|
|
|
if (aff_iterate(&a)) {
|
|
|
|
perror("ERROR: Could not affine thread");
|
|
|
|
perror("ERROR: Could not affine thread");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
@ -90,10 +90,10 @@ test_spmc(void *c)
|
|
|
|
|
|
|
|
|
|
|
|
/* Keep trying until we encounter at least one node. */
|
|
|
|
/* Keep trying until we encounter at least one node. */
|
|
|
|
if (j & 1) {
|
|
|
|
if (j & 1) {
|
|
|
|
while (ck_ring_dequeue_spmc(&ring_spmc, buf,
|
|
|
|
while (ck_ring_dequeue_spmc(&ring_spmc, buffer,
|
|
|
|
&o) == false);
|
|
|
|
&o) == false);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
while (ck_ring_trydequeue_spmc(&ring_spmc, buf,
|
|
|
|
while (ck_ring_trydequeue_spmc(&ring_spmc, buffer,
|
|
|
|
&o) == false);
|
|
|
|
&o) == false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -138,12 +138,10 @@ test(void *c)
|
|
|
|
unsigned int s;
|
|
|
|
unsigned int s;
|
|
|
|
int i, j;
|
|
|
|
int i, j;
|
|
|
|
bool r;
|
|
|
|
bool r;
|
|
|
|
ck_ring_buffer_t buf;
|
|
|
|
ck_ring_buffer_t *buffer = context->buffer;
|
|
|
|
ck_barrier_centralized_state_t sense =
|
|
|
|
ck_barrier_centralized_state_t sense =
|
|
|
|
CK_BARRIER_CENTRALIZED_STATE_INITIALIZER;
|
|
|
|
CK_BARRIER_CENTRALIZED_STATE_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
|
|
buf.ring = context->buffer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (aff_iterate(&a)) {
|
|
|
|
if (aff_iterate(&a)) {
|
|
|
|
perror("ERROR: Could not affine thread");
|
|
|
|
perror("ERROR: Could not affine thread");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
@ -165,10 +163,10 @@ test(void *c)
|
|
|
|
entries[i].tid = 0;
|
|
|
|
entries[i].tid = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (i & 1) {
|
|
|
|
if (i & 1) {
|
|
|
|
r = ck_ring_enqueue_spmc(ring, buf,
|
|
|
|
r = ck_ring_enqueue_spmc(ring, buffer,
|
|
|
|
entries + i);
|
|
|
|
entries + i);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
r = ck_ring_enqueue_spmc_size(ring, buf,
|
|
|
|
r = ck_ring_enqueue_spmc_size(ring, buffer,
|
|
|
|
entries + i, &s);
|
|
|
|
entries + i, &s);
|
|
|
|
|
|
|
|
|
|
|
|
if ((int)s != i) {
|
|
|
|
if ((int)s != i) {
|
|
|
@ -198,9 +196,9 @@ test(void *c)
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ITERATIONS; i++) {
|
|
|
|
for (i = 0; i < ITERATIONS; i++) {
|
|
|
|
for (j = 0; j < size; j++) {
|
|
|
|
for (j = 0; j < size; j++) {
|
|
|
|
buf.ring = _context[context->previous].buffer;
|
|
|
|
buffer = _context[context->previous].buffer;
|
|
|
|
while (ck_ring_dequeue_spmc(ring + context->previous,
|
|
|
|
while (ck_ring_dequeue_spmc(ring + context->previous,
|
|
|
|
buf, &entry) == false);
|
|
|
|
buffer, &entry) == false);
|
|
|
|
|
|
|
|
|
|
|
|
if (context->previous != (unsigned int)entry->tid) {
|
|
|
|
if (context->previous != (unsigned int)entry->tid) {
|
|
|
|
ck_error("[%u:%p] %u != %u\n",
|
|
|
|
ck_error("[%u:%p] %u != %u\n",
|
|
|
@ -213,14 +211,14 @@ test(void *c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
entry->tid = context->tid;
|
|
|
|
entry->tid = context->tid;
|
|
|
|
buf.ring = context->buffer;
|
|
|
|
buffer = context->buffer;
|
|
|
|
|
|
|
|
|
|
|
|
if (i & 1) {
|
|
|
|
if (i & 1) {
|
|
|
|
r = ck_ring_enqueue_spmc(ring + context->tid,
|
|
|
|
r = ck_ring_enqueue_spmc(ring + context->tid,
|
|
|
|
buf, entry);
|
|
|
|
buffer, entry);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
r = ck_ring_enqueue_spmc_size(ring + context->tid,
|
|
|
|
r = ck_ring_enqueue_spmc_size(ring + context->tid,
|
|
|
|
buf, entry, &s);
|
|
|
|
buffer, entry, &s);
|
|
|
|
|
|
|
|
|
|
|
|
if ((int)s >= size) {
|
|
|
|
if ((int)s >= size) {
|
|
|
|
ck_error("Size %u out of range of %d\n",
|
|
|
|
ck_error("Size %u out of range of %d\n",
|
|
|
@ -238,10 +236,9 @@ int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
int i, r;
|
|
|
|
void *buffer;
|
|
|
|
|
|
|
|
unsigned long l;
|
|
|
|
unsigned long l;
|
|
|
|
pthread_t *thread;
|
|
|
|
pthread_t *thread;
|
|
|
|
ck_ring_buffer_t buf;
|
|
|
|
ck_ring_buffer_t *buffer;
|
|
|
|
|
|
|
|
|
|
|
|
if (argc != 4) {
|
|
|
|
if (argc != 4) {
|
|
|
|
ck_error("Usage: validate <threads> <affinity delta> <size>\n");
|
|
|
|
ck_error("Usage: validate <threads> <affinity delta> <size>\n");
|
|
|
@ -280,9 +277,9 @@ main(int argc, char *argv[])
|
|
|
|
_context[i].previous = i - 1;
|
|
|
|
_context[i].previous = i - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buffer = malloc(sizeof(void *) * (size + 1));
|
|
|
|
buffer = malloc(sizeof(ck_ring_buffer_t) * (size + 1));
|
|
|
|
assert(buffer);
|
|
|
|
assert(buffer);
|
|
|
|
memset(buffer, 0, sizeof(void *) * (size + 1));
|
|
|
|
memset(buffer, 0, sizeof(ck_ring_buffer_t) * (size + 1));
|
|
|
|
_context[i].buffer = buffer;
|
|
|
|
_context[i].buffer = buffer;
|
|
|
|
ck_ring_init(ring + i, size + 1);
|
|
|
|
ck_ring_init(ring + i, size + 1);
|
|
|
|
r = pthread_create(thread + i, NULL, test, _context + i);
|
|
|
|
r = pthread_create(thread + i, NULL, test, _context + i);
|
|
|
@ -295,11 +292,10 @@ main(int argc, char *argv[])
|
|
|
|
fprintf(stderr, " done\n");
|
|
|
|
fprintf(stderr, " done\n");
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "SPMC test:\n");
|
|
|
|
fprintf(stderr, "SPMC test:\n");
|
|
|
|
buffer = malloc(sizeof(void *) * (size + 1));
|
|
|
|
buffer = malloc(sizeof(ck_ring_buffer_t) * (size + 1));
|
|
|
|
assert(buffer);
|
|
|
|
assert(buffer);
|
|
|
|
memset(buffer, 0, sizeof(void *) * (size + 1));
|
|
|
|
memset(buffer, 0, sizeof(void *) * (size + 1));
|
|
|
|
ck_ring_init(&ring_spmc, size + 1);
|
|
|
|
ck_ring_init(&ring_spmc, size + 1);
|
|
|
|
buf.ring = buffer;
|
|
|
|
|
|
|
|
for (i = 0; i < nthr - 1; i++) {
|
|
|
|
for (i = 0; i < nthr - 1; i++) {
|
|
|
|
_context[i].buffer = buffer;
|
|
|
|
_context[i].buffer = buffer;
|
|
|
|
r = pthread_create(thread + i, NULL, test_spmc, _context + i);
|
|
|
|
r = pthread_create(thread + i, NULL, test_spmc, _context + i);
|
|
|
@ -318,14 +314,15 @@ main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
|
|
/* Wait until queue is not full. */
|
|
|
|
/* Wait until queue is not full. */
|
|
|
|
if (l & 1) {
|
|
|
|
if (l & 1) {
|
|
|
|
while (ck_ring_enqueue_spmc(&ring_spmc, buf,
|
|
|
|
while (ck_ring_enqueue_spmc(&ring_spmc,
|
|
|
|
|
|
|
|
buffer,
|
|
|
|
entry) == false)
|
|
|
|
entry) == false)
|
|
|
|
ck_pr_stall();
|
|
|
|
ck_pr_stall();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
unsigned int s;
|
|
|
|
unsigned int s;
|
|
|
|
|
|
|
|
|
|
|
|
while (ck_ring_enqueue_spmc_size(&ring_spmc,
|
|
|
|
while (ck_ring_enqueue_spmc_size(&ring_spmc,
|
|
|
|
buf, entry, &s) == false) {
|
|
|
|
buffer, entry, &s) == false) {
|
|
|
|
ck_pr_stall();
|
|
|
|
ck_pr_stall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|