io_uring: optimise io_uring_enter()
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 19 Mar 2021 17:22:30 +0000 (17:22 +0000)
committerJens Axboe <axboe@kernel.dk>
Sun, 11 Apr 2021 23:41:58 +0000 (17:41 -0600)
Add unlikely annotations, because my compiler pretty much mispredicts
every first check, and apart jumping around in the fast path, it also
generates extra instructions, like in advance setting ret value.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index 12e2ec7..13a64b1 100644 (file)
@@ -9183,31 +9183,31 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
                size_t, argsz)
 {
        struct io_ring_ctx *ctx;
-       long ret = -EBADF;
        int submitted = 0;
        struct fd f;
+       long ret;
 
        io_run_task_work();
 
-       if (flags & ~(IORING_ENTER_GETEVENTS | IORING_ENTER_SQ_WAKEUP |
-                       IORING_ENTER_SQ_WAIT | IORING_ENTER_EXT_ARG))
+       if (unlikely(flags & ~(IORING_ENTER_GETEVENTS | IORING_ENTER_SQ_WAKEUP |
+                              IORING_ENTER_SQ_WAIT | IORING_ENTER_EXT_ARG)))
                return -EINVAL;
 
        f = fdget(fd);
-       if (!f.file)
+       if (unlikely(!f.file))
                return -EBADF;
 
        ret = -EOPNOTSUPP;
-       if (f.file->f_op != &io_uring_fops)
+       if (unlikely(f.file->f_op != &io_uring_fops))
                goto out_fput;
 
        ret = -ENXIO;
        ctx = f.file->private_data;
-       if (!percpu_ref_tryget(&ctx->refs))
+       if (unlikely(!percpu_ref_tryget(&ctx->refs)))
                goto out_fput;
 
        ret = -EBADFD;
-       if (ctx->flags & IORING_SETUP_R_DISABLED)
+       if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED))
                goto out;
 
        /*