regressions/ck_ring: Fix use of uninitialized data.

Execution history exists such that first thread will dequeue
from an uninitialized ring buffer. The unit test has been
(un)fortunate in that it would busy-wait during dequeue.
Full barrier semantics will enforce visibility.

Reported by: Maxime Henrion <mhenrion@gma....>.
ck_pring
Samy Al Bahra 12 years ago
parent 900d203aa9
commit d55e588ee4

@ -11,16 +11,20 @@ check: all
./ck_ring_spmc_template $(CORES) 1 65536
ck_ring_spsc_template: ck_ring_spsc_template.c ../../../include/ck_ring.h
$(CC) $(CFLAGS) -o ck_ring_spsc_template ck_ring_spsc_template.c
$(CC) $(CFLAGS) -o ck_ring_spsc_template ck_ring_spsc_template.c \
../../../src/ck_barrier_centralized.c
ck_ring_spmc_template: ck_ring_spmc_template.c ../../../include/ck_ring.h
$(CC) $(CFLAGS) -o ck_ring_spmc_template ck_ring_spmc_template.c
$(CC) $(CFLAGS) -o ck_ring_spmc_template ck_ring_spmc_template.c \
../../../src/ck_barrier_centralized.c
ck_ring_spsc: ck_ring_spsc.c ../../../include/ck_ring.h
$(CC) $(CFLAGS) -o ck_ring_spsc ck_ring_spsc.c
$(CC) $(CFLAGS) -o ck_ring_spsc ck_ring_spsc.c \
../../../src/ck_barrier_centralized.c
ck_ring_spmc: ck_ring_spmc.c ../../../include/ck_ring.h
$(CC) $(CFLAGS) -o ck_ring_spmc ck_ring_spmc.c
$(CC) $(CFLAGS) -o ck_ring_spmc ck_ring_spmc.c \
../../../src/ck_barrier_centralized.c
clean:
rm -rf *~ *.o $(OBJECTS) *.dSYM

@ -30,6 +30,7 @@
#include <string.h>
#include <pthread.h>
#include <ck_barrier.h>
#include <ck_ring.h>
#include <ck_spinlock.h>
#include "../../common.h"
@ -57,15 +58,15 @@ static ck_ring_t *ring;
static ck_ring_t ring_spmc CK_CC_CACHELINE;
static struct affinity a;
static int size;
static volatile int barrier;
static int eb;
static ck_barrier_centralized_t barrier = CK_BARRIER_CENTRALIZED_INITIALIZER;
static void *
test_spmc(void *c)
{
unsigned int observed = 0;
int i, j, tid;
unsigned long previous = 0;
int i, j, tid;
(void)c;
if (aff_iterate(&a)) {
@ -121,6 +122,8 @@ test(void *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");
@ -155,11 +158,12 @@ test(void *c)
ck_error("Capacity less than expected: %u < %u\n",
ck_ring_size(ring), ck_ring_capacity(ring));
}
barrier = 1;
}
while (barrier == 0);
/*
* 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++) {
@ -240,6 +244,7 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL);
fprintf(stderr, " done\n");
fprintf(stderr, "SPMC test:\n");

@ -30,6 +30,7 @@
#include <string.h>
#include <pthread.h>
#include <ck_barrier.h>
#include <ck_ring.h>
#include <ck_spinlock.h>
#include "../../common.h"
@ -58,15 +59,15 @@ static CK_RING_INSTANCE(spmc_ring) ring_spmc CK_CC_CACHELINE;
static int nthr;
static struct affinity a;
static int size;
static volatile int barrier;
static int eb;
static ck_barrier_centralized_t barrier = CK_BARRIER_CENTRALIZED_INITIALIZER;
static void *
test_spmc(void *c)
{
unsigned int observed = 0;
int i, j, tid;
unsigned long previous = 0;
int i, j, tid;
(void)c;
if (aff_iterate(&a)) {
@ -122,6 +123,8 @@ test(void *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");
@ -151,11 +154,9 @@ test(void *c)
ck_error("Capacity less than expected: %u < %u\n",
CK_RING_SIZE(spmc_ring, ring), CK_RING_CAPACITY(spmc_ring, ring));
}
barrier = 1;
}
while (barrier == 0);
ck_barrier_centralized(&barrier, &sense, nthr);
for (i = 0; i < ITERATIONS; i++) {
for (j = 0; j < size; j++) {
@ -236,6 +237,7 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL);
fprintf(stderr, " done\n");
fprintf(stderr, "SPMC test:\n");

@ -29,6 +29,7 @@
#include <stdio.h>
#include <pthread.h>
#include <ck_barrier.h>
#include <ck_ring.h>
#include "../../common.h"
@ -51,7 +52,7 @@ static int nthr;
static ck_ring_t *ring;
static struct affinity a;
static int size;
static volatile int barrier;
static ck_barrier_centralized_t barrier = CK_BARRIER_CENTRALIZED_INITIALIZER;
static void *
test(void *c)
@ -60,6 +61,8 @@ test(void *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");
@ -94,11 +97,9 @@ test(void *c)
ck_error("Capacity less than expected: %u < %u\n",
ck_ring_size(ring), ck_ring_capacity(ring));
}
barrier = 1;
}
while (barrier == 0);
ck_barrier_centralized(&barrier, &sense, nthr);
for (i = 0; i < ITERATIONS; i++) {
for (j = 0; j < size; j++) {

@ -29,6 +29,7 @@
#include <stdio.h>
#include <pthread.h>
#include <ck_barrier.h>
#include <ck_ring.h>
#include "../../common.h"
@ -52,7 +53,7 @@ static int nthr;
static CK_RING_INSTANCE(entry_ring) *ring;
static struct affinity a;
static int size;
static volatile int barrier;
static ck_barrier_centralized_t barrier = CK_BARRIER_CENTRALIZED_INITIALIZER;
static void *
test(void *c)
@ -61,6 +62,8 @@ test(void *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");
@ -91,11 +94,9 @@ test(void *c)
CK_RING_SIZE(entry_ring, ring),
CK_RING_CAPACITY(entry_ring, ring));
}
barrier = 1;
}
while (barrier == 0);
ck_barrier_centralized(&barrier, &sense, nthr);
for (i = 0; i < ITERATIONS; i++) {
for (j = 0; j < size; j++) {

Loading…
Cancel
Save