We check twice for all entering conditions in _io_uring_get_cqe(), first to set flags, and the second to potentially break the loop. Save it into a need_enter var. Also, don't set IORING_ENTER_GETEVENTS when there is already enough of events in the CQ. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- src/queue.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/queue.c b/src/queue.c index c2facfd..4fb4ea7 100644 --- a/src/queue.c +++ b/src/queue.c @@ -92,6 +92,7 @@ static int _io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt int err; do { + bool need_enter = false; bool cq_overflow_flush = false; unsigned flags = 0; unsigned nr_available; @@ -107,12 +108,15 @@ static int _io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt } cq_overflow_flush = true; } - if (data->wait_nr || cq_overflow_flush) + if (data->wait_nr > nr_available || cq_overflow_flush) { flags = IORING_ENTER_GETEVENTS | data->get_flags; - if (data->submit) + need_enter = true; + } + if (data->submit) { sq_ring_needs_enter(ring, &flags); - if (data->wait_nr <= nr_available && !data->submit && - !cq_overflow_flush) + need_enter = true; + } + if (!need_enter) break; ret = __sys_io_uring_enter2(ring->ring_fd, data->submit, -- 2.24.0