From 740019d28b835bf45a15c8660467f22231dcd268 Mon Sep 17 00:00:00 2001 From: Caleb Sander Mateos Date: Thu, 17 Jul 2025 11:23:35 -0600 Subject: [PATCH] engines/io_uring: remove loop over CQEs in fio_ioring_cqring_reap() Currently fio_ioring_cqring_reap() loops over each available CQE, re-loading the tail index, incrementing local variables, and checking whether the max requested CQEs have been seen. Avoid the loop by computing the number of available CQEs as tail - head and capping it to the requested max. Signed-off-by: Caleb Sander Mateos --- engines/io_uring.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/engines/io_uring.c b/engines/io_uring.c index 2d7edcc8..df90a332 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -678,20 +678,15 @@ static int fio_ioring_cqring_reap(struct thread_data *td, unsigned int max) { struct ioring_data *ld = td->io_ops_data; struct io_cq_ring *ring = &ld->cq_ring; - unsigned head, reaped = 0; + unsigned head = *ring->head; + unsigned available = atomic_load_acquire(ring->tail) - head; - head = *ring->head; - do { - if (head == atomic_load_acquire(ring->tail)) - break; - reaped++; - head++; - } while (reaped < max); - - if (reaped) - atomic_store_release(ring->head, head); + if (!available) + return 0; - return reaped; + available = min(available, max); + atomic_store_release(ring->head, head + available); + return available; } static int fio_ioring_getevents(struct thread_data *td, unsigned int min, -- 2.25.1