static void * test(void *c) { struct context *context = c; struct entry *entry; int i, j; bool r; ck_barrier_centralized_state_t sense = CK_BARRIER_CENTRALIZED_STATE_INITIALIZER; if (aff_iterate(&a)) { perror("ERROR: Could not affine thread"); exit(EXIT_FAILURE); } if (context->tid == 0) { struct entry *entries; entries = malloc(sizeof(struct entry) * size); assert(entries != NULL); if (ck_ring_size(ring) != 0) { ck_error("More entries than expected: %u > 0\n", ck_ring_size(ring)); } for (i = 0; i < size; i++) { entries[i].value = i; entries[i].tid = 0; r = ck_ring_enqueue_spsc(ring, entries + i); assert(r != false); } if (ck_ring_size(ring) != (unsigned int)size) { ck_error("Less entries than expected: %u < %d\n", ck_ring_size(ring), size); } if (ck_ring_capacity(ring) != ck_ring_size(ring) + 1) { ck_error("Capacity less than expected: %u < %u\n", ck_ring_size(ring), ck_ring_capacity(ring)); } } ck_barrier_centralized(&barrier, &sense, nthr); for (i = 0; i < ITERATIONS; i++) { for (j = 0; j < size; j++) { while (ck_ring_dequeue_spsc(ring + context->previous, &entry) == false); if (context->previous != (unsigned int)entry->tid) { ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); } if (entry->value != j) { ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); } entry->tid = context->tid; r = ck_ring_enqueue_spsc(ring + context->tid, entry); assert(r == true); } } return NULL; }
static void * test(void *c) { struct context *context = c; struct entry *entry; unsigned int s; int i, j; bool r; ck_ring_buffer_t *buffer = context->buffer; ck_barrier_centralized_state_t sense = CK_BARRIER_CENTRALIZED_STATE_INITIALIZER; if (aff_iterate(&a)) { perror("ERROR: Could not affine thread"); exit(EXIT_FAILURE); } if (context->tid == 0) { struct entry *entries; entries = malloc(sizeof(struct entry) * size); assert(entries != NULL); if (ck_ring_size(ring) != 0) { ck_error("More entries than expected: %u > 0\n", ck_ring_size(ring)); } for (i = 0; i < size; i++) { entries[i].value = i; entries[i].tid = 0; if (i & 1) { r = ck_ring_enqueue_spmc(ring, buffer, entries + i); } else { r = ck_ring_enqueue_spmc_size(ring, buffer, entries + i, &s); if ((int)s != i) { ck_error("Size is %u, expected %d.\n", s, size); } } assert(r != false); } if (ck_ring_size(ring) != (unsigned int)size) { ck_error("Less entries than expected: %u < %d\n", ck_ring_size(ring), size); } if (ck_ring_capacity(ring) != ck_ring_size(ring) + 1) { ck_error("Capacity less than expected: %u < %u\n", ck_ring_size(ring), ck_ring_capacity(ring)); } } /* * Wait for all threads. The idea here is to maximize the contention. */ ck_barrier_centralized(&barrier, &sense, nthr); for (i = 0; i < ITERATIONS; i++) { for (j = 0; j < size; j++) { buffer = _context[context->previous].buffer; while (ck_ring_dequeue_spmc(ring + context->previous, buffer, &entry) == false); if (context->previous != (unsigned int)entry->tid) { ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); } if (entry->value < 0 || entry->value >= size) { ck_error("[%u:%p] %u </> %u\n", context->tid, (void *)entry, entry->tid, context->previous); } entry->tid = context->tid; buffer = context->buffer; if (i & 1) { r = ck_ring_enqueue_spmc(ring + context->tid, buffer, entry); } else { r = ck_ring_enqueue_spmc_size(ring + context->tid, buffer, entry, &s); if ((int)s >= size) { ck_error("Size %u out of range of %d\n", s, size); } } assert(r == true); } } return NULL; }