From 6b6f52b9b74219d5d7c93e61d21250bb47ecfe66 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 1 Sep 2022 08:34:32 -0600 Subject: [PATCH] t/io_uring: minor optimizations to IO init fast path 1) Only read SQ ring head at the start of prep, we don't need to read it at every iteration. 2) Initialize SQ ring index at init time, rather than in the fast path. Signed-off-by: Jens Axboe --- t/io_uring.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/t/io_uring.c b/t/io_uring.c index 5b46015a..9d580b5a 100644 --- a/t/io_uring.c +++ b/t/io_uring.c @@ -658,11 +658,12 @@ static int prep_more_ios_uring(struct submitter *s, int max_ios) { struct io_sq_ring *ring = &s->sq_ring; unsigned index, tail, next_tail, prepped = 0; + unsigned int head = atomic_load_acquire(ring->head); next_tail = tail = *ring->tail; do { next_tail++; - if (next_tail == atomic_load_acquire(ring->head)) + if (next_tail == head) break; index = tail & sq_ring_mask; @@ -670,7 +671,6 @@ static int prep_more_ios_uring(struct submitter *s, int max_ios) init_io_pt(s, index); else init_io(s, index); - ring->array[index] = index; prepped++; tail = next_tail; } while (prepped < max_ios); @@ -908,7 +908,7 @@ static int setup_ring(struct submitter *s) struct io_sq_ring *sring = &s->sq_ring; struct io_cq_ring *cring = &s->cq_ring; struct io_uring_params p; - int ret, fd; + int ret, fd, i; void *ptr; size_t len; @@ -1003,6 +1003,10 @@ static int setup_ring(struct submitter *s) cring->ring_entries = ptr + p.cq_off.ring_entries; cring->cqes = ptr + p.cq_off.cqes; cq_ring_mask = *cring->ring_mask; + + for (i = 0; i < p.sq_entries; i++) + sring->array[i] = i; + return 0; } -- 2.25.1