t/io_uring: only load tail once per reap loop
authorJens Axboe <axboe@kernel.dk>
Mon, 30 Sep 2024 15:21:17 +0000 (09:21 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 30 Sep 2024 15:21:17 +0000 (09:21 -0600)
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 <axboe@kernel.dk>
t/io_uring.c

index aa6e09e9edf94b3438e434dac0f4e21bb113d964..0fa01837bbf5259815dcda19ba18e28e6a197b40 100644 (file)
@@ -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];