From b46877edc9a94009ebbb33a461b21dad9bd40964 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 30 Sep 2024 09:21:17 -0600 Subject: [PATCH] t/io_uring: only load tail once per reap loop It'll never change with the settings that t/io_uring uses to setup the ring - and even if it could, it's still cheaper to just read the tail once per reap. Signed-off-by: Jens Axboe --- t/io_uring.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/t/io_uring.c b/t/io_uring.c index aa6e09e9ed..0fa01837bb 100644 --- a/t/io_uring.c +++ b/t/io_uring.c @@ -699,14 +699,15 @@ static int reap_events_uring(struct submitter *s) { struct io_cq_ring *ring = &s->cq_ring; struct io_uring_cqe *cqe; - unsigned head, reaped = 0; + unsigned tail, head, reaped = 0; int last_idx = -1, stat_nr = 0; head = *ring->head; + tail = atomic_load_acquire(ring->tail); do { struct file *f; - if (head == atomic_load_acquire(ring->tail)) + if (head == tail) break; cqe = &ring->cqes[head & cq_ring_mask]; if (!do_nop) { @@ -755,16 +756,17 @@ static int reap_events_uring_pt(struct submitter *s) { struct io_cq_ring *ring = &s->cq_ring; struct io_uring_cqe *cqe; - unsigned head, reaped = 0; + unsigned head, tail, reaped = 0; int last_idx = -1, stat_nr = 0; unsigned index; int fileno; head = *ring->head; + tail = atomic_load_acquire(ring->tail); do { struct file *f; - if (head == atomic_load_acquire(ring->tail)) + if (head == tail) break; index = head & cq_ring_mask; cqe = &ring->cqes[index << 1];