#define IORING_FLAG_GETEVENTS (1 << 1)
#define DEPTH 32
-#define RING_SIZE (DEPTH + 1)
#define BATCH_SUBMIT 8
#define BATCH_COMPLETE 8
#define BS 4096
+static unsigned sq_ring_mask = DEPTH - 1;
+static unsigned cq_ring_mask = (2 * DEPTH) - 1;
+
struct submitter {
pthread_t thread;
unsigned long max_blocks;
static int prep_more_ios(struct submitter *s, int fd, int max_ios)
{
struct aio_sq_ring *ring = s->sq_ring;
- u32 tail, next_tail, prepped = 0;
+ u32 index, tail, next_tail, prepped = 0;
next_tail = tail = ring->tail;
do {
next_tail++;
- if (next_tail == ring->nr_events)
- next_tail = 0;
-
barrier();
if (next_tail == ring->head)
break;
- init_io(s, fd, &s->iocbs[tail]);
- s->sq_ring->array[tail] = tail;
+ index = tail & sq_ring_mask;
+ init_io(s, fd, &s->iocbs[index]);
+ s->sq_ring->array[index] = index;
prepped++;
tail = next_tail;
} while (prepped < max_ios);
barrier();
if (head == ring->tail)
break;
- ev = &ring->events[head];
+ ev = &ring->events[head & cq_ring_mask];
if (ev->res != BS) {
struct iocb *iocb = ev->obj;
s->cachemiss++;
reaped++;
head++;
- if (head == ring->nr_events)
- head = 0;
} while (1);
s->inflight -= reaped;
arm_sig_int();
- size = sizeof(struct iocb) * RING_SIZE;
+ size = sizeof(struct iocb) * DEPTH;
if (posix_memalign(&p, 4096, size))
return 1;
memset(p, 0, size);
s->iocbs = p;
- size = sizeof(struct aio_sq_ring) + RING_SIZE * sizeof(u32);
+ size = sizeof(struct aio_sq_ring) + DEPTH * sizeof(u32);
if (posix_memalign(&p, 4096, size))
return 1;
s->sq_ring = p;
memset(p, 0, size);
- s->sq_ring->nr_events = RING_SIZE;
+ s->sq_ring->nr_events = DEPTH;
s->sq_ring->iocbs = (u64) s->iocbs;
/* CQ ring must be twice as big */
size = sizeof(struct aio_cq_ring) +
- 2 * RING_SIZE * sizeof(struct io_event);
+ 2 * DEPTH * sizeof(struct io_event);
if (posix_memalign(&p, 4096, size))
return 1;
s->cq_ring = p;
memset(p, 0, size);
- s->cq_ring->nr_events = 2 * RING_SIZE;
+ s->cq_ring->nr_events = 2 * DEPTH;
- for (j = 0; j < RING_SIZE; j++) {
+ for (j = 0; j < DEPTH; j++) {
struct iocb *iocb = &s->iocbs[j];
if (posix_memalign(&iocb->u.c.buf, BS, BS)) {
s->sq_ring->sq_thread_cpu = sq_thread_cpu;
}
- err = io_setup2(RING_SIZE, flags, s->sq_ring, s->cq_ring, &s->ioc);
+ err = io_setup2(DEPTH, flags, s->sq_ring, s->cq_ring, &s->ioc);
if (err) {
printf("ctx_init failed: %s, %d\n", strerror(errno), err);
return 1;