]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring/eventfd: dedup signalling helpers
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 24 Apr 2025 11:31:16 +0000 (12:31 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 24 Apr 2025 14:33:54 +0000 (08:33 -0600)
Consolidate io_eventfd_flush_signal() and io_eventfd_signal(). Not much
of a difference for now, but it prepares it for following changes.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/5beecd4da65d8d2d83df499196f84b329387f6a2.1745493845.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/eventfd.c
io_uring/eventfd.h
io_uring/io_uring.c

index 100d5da94cb95c5e539df7e03f9d5e73c733db50..a9da2d0d7510524dcdabd7c8d1883748722ca9ec 100644 (file)
@@ -112,23 +112,16 @@ static struct io_ev_fd *io_eventfd_grab(struct io_ring_ctx *ctx)
        return NULL;
 }
 
-void io_eventfd_signal(struct io_ring_ctx *ctx)
+void io_eventfd_signal(struct io_ring_ctx *ctx, bool cqe_event)
 {
+       bool skip = false, put_ref = true;
        struct io_ev_fd *ev_fd;
 
        ev_fd = io_eventfd_grab(ctx);
-       if (ev_fd)
-               io_eventfd_release(ev_fd, __io_eventfd_signal(ev_fd));
-}
-
-void io_eventfd_flush_signal(struct io_ring_ctx *ctx)
-{
-       struct io_ev_fd *ev_fd;
-
-       ev_fd = io_eventfd_grab(ctx);
-       if (ev_fd) {
-               bool skip, put_ref = true;
+       if (!ev_fd)
+               return;
 
+       if (cqe_event) {
                /*
                 * Eventfd should only get triggered when at least one event
                 * has been posted. Some applications rely on the eventfd
@@ -142,12 +135,11 @@ void io_eventfd_flush_signal(struct io_ring_ctx *ctx)
                skip = ctx->cached_cq_tail == ev_fd->last_cq_tail;
                ev_fd->last_cq_tail = ctx->cached_cq_tail;
                spin_unlock(&ctx->completion_lock);
-
-               if (!skip)
-                       put_ref = __io_eventfd_signal(ev_fd);
-
-               io_eventfd_release(ev_fd, put_ref);
        }
+
+       if (!skip)
+               put_ref = __io_eventfd_signal(ev_fd);
+       io_eventfd_release(ev_fd, put_ref);
 }
 
 int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
index d394f49c6321059266771f4ba6bd5cc422608b3b..e2f1985c2cf98ec376ccb5f9f90d8cf275f263a1 100644 (file)
@@ -4,5 +4,4 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
                        unsigned int eventfd_async);
 int io_eventfd_unregister(struct io_ring_ctx *ctx);
 
-void io_eventfd_flush_signal(struct io_ring_ctx *ctx);
-void io_eventfd_signal(struct io_ring_ctx *ctx);
+void io_eventfd_signal(struct io_ring_ctx *ctx, bool cqe_event);
index 0dc6c2f1295e2c02cd33b018a3ebe021969a7810..2e4d8e76316a865bc56f9e021a50d8f766845982 100644 (file)
@@ -584,7 +584,7 @@ void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
        if (ctx->drain_active)
                io_queue_deferred(ctx);
        if (ctx->has_evfd)
-               io_eventfd_flush_signal(ctx);
+               io_eventfd_signal(ctx, true);
 }
 
 static inline void __io_cq_lock(struct io_ring_ctx *ctx)
@@ -1199,7 +1199,7 @@ static void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
                if (ctx->flags & IORING_SETUP_TASKRUN_FLAG)
                        atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags);
                if (ctx->has_evfd)
-                       io_eventfd_signal(ctx);
+                       io_eventfd_signal(ctx, false);
        }
 
        nr_wait = atomic_read(&ctx->cq_wait_nr);