t/io_uring: batch stat updates
authorJens Axboe <axboe@kernel.dk>
Sat, 25 Sep 2021 20:38:10 +0000 (14:38 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 25 Sep 2021 20:38:10 +0000 (14:38 -0600)
Track the last clock_index, and batch increments if at all possible.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
t/io_uring.c

index 903e7cf84ebfe25e34f30b22355bfe26b99a6c57..503e5b69f050d42bacf44ffff01611b2f563fb61 100644 (file)
@@ -484,6 +484,7 @@ static int reap_events(struct submitter *s)
        struct io_cq_ring *ring = &s->cq_ring;
        struct io_uring_cqe *cqe;
        unsigned head, reaped = 0;
+       int last_idx = -1, stat_nr = 0;
 
        head = *ring->head;
        do {
@@ -508,12 +509,23 @@ static int reap_events(struct submitter *s)
                if (stats) {
                        int clock_index = cqe->user_data >> 32;
 
+                       if (last_idx != clock_index) {
+                               if (last_idx != -1) {
+                                       add_stat(s, last_idx, stat_nr);
+                                       stat_nr = 0;
+                               }
+                               last_idx = clock_index;
+                       }
+                       stat_nr++;
                        add_stat(s, clock_index, 1);
                }
                reaped++;
                head++;
        } while (1);
 
+       if (stat_nr)
+               add_stat(s, last_idx, stat_nr);
+
        if (reaped) {
                s->inflight -= reaped;
                atomic_store_release(ring->head, head);