regressions/ck_ring: Always treat buffer as opaque.

ck_pring
Samy Al Bahra 11 years ago
parent f9ae05b15a
commit fdc2061935

@ -20,9 +20,8 @@ main(int argc, char *argv[])
{ {
int i, r, size; int i, r, size;
uint64_t s, e, e_a, d_a; uint64_t s, e, e_a, d_a;
struct entry *buffer;
struct entry entry = {0, 0}; struct entry entry = {0, 0};
ck_ring_buffer_t buf; ck_ring_buffer_t *buf;
ck_ring_t ring; ck_ring_t ring;
if (argc != 2) { if (argc != 2) {
@ -34,13 +33,12 @@ main(int argc, char *argv[])
ck_error("ERROR: Size must be a power of 2 greater than 4.\n"); ck_error("ERROR: Size must be a power of 2 greater than 4.\n");
} }
buffer = malloc(sizeof(struct entry) * size); buf = malloc(sizeof(ck_ring_buffer_t) * size);
if (buffer == NULL) { if (buf == NULL) {
ck_error("ERROR: Failed to allocate buffer\n"); ck_error("ERROR: Failed to allocate buffer\n");
} }
ck_ring_init(&ring, size); ck_ring_init(&ring, size);
buf.ring = buffer;
e_a = d_a = s = e = 0; e_a = d_a = s = e = 0;
for (r = 0; r < ITERATIONS; r++) { for (r = 0; r < ITERATIONS; r++) {

@ -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();
} }

@ -66,14 +66,14 @@ test(void *c)
bool r; bool r;
ck_barrier_centralized_state_t sense = ck_barrier_centralized_state_t sense =
CK_BARRIER_CENTRALIZED_STATE_INITIALIZER; CK_BARRIER_CENTRALIZED_STATE_INITIALIZER;
ck_ring_buffer_t buf; ck_ring_buffer_t *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);
} }
buf.ring = context->buffer; buffer = context->buffer;
if (context->tid == 0) { if (context->tid == 0) {
struct entry *entries; struct entry *entries;
@ -90,11 +90,11 @@ test(void *c)
entries[i].tid = 0; entries[i].tid = 0;
if (i & 1) { if (i & 1) {
r = ck_ring_enqueue_spsc(ring, buf, r = ck_ring_enqueue_spsc(ring, buffer,
entries + i); entries + i);
} else { } else {
r = ck_ring_enqueue_spsc_size(ring, r = ck_ring_enqueue_spsc_size(ring,
buf, entries + i, &s); buffer, entries + i, &s);
if ((int)s != i) { if ((int)s != i) {
ck_error("Size is %u, expected %d\n", ck_error("Size is %u, expected %d\n",
@ -120,9 +120,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_spsc(ring + context->previous, while (ck_ring_dequeue_spsc(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",
@ -135,13 +135,13 @@ 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_spsc(ring + context->tid, r = ck_ring_enqueue_spsc(ring + context->tid,
buf, entry); buffer, entry);
} else { } else {
r = ck_ring_enqueue_spsc_size(ring + r = ck_ring_enqueue_spsc_size(ring +
context->tid, buf, entry, &s); context->tid, buffer, entry, &s);
if ((int)s >= size) { if ((int)s >= size) {
ck_error("Size %u is out of range %d\n", ck_error("Size %u is out of range %d\n",
@ -159,7 +159,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i, r; int i, r;
void *buffer; ck_ring_buffer_t *buffer;
pthread_t *thread; pthread_t *thread;
if (argc != 4) { if (argc != 4) {
@ -198,7 +198,7 @@ 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);
_context[i].buffer = buffer; _context[i].buffer = buffer;
ck_ring_init(ring + i, size + 1); ck_ring_init(ring + i, size + 1);

Loading…
Cancel
Save