All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 4/6] io_uring/eventfd: move trigger check into a helper
Date: Sat, 21 Sep 2024 01:59:50 -0600	[thread overview]
Message-ID: <20240921080307.185186-5-axboe@kernel.dk> (raw)
In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk>

It's a bit hard to read what guards the triggering, move it into a
helper and add a comment explaining it too. This additionally moves
the ev_fd == NULL check in there as well.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/eventfd.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c
index 58e76f4d1e00..0946d3da88d3 100644
--- a/io_uring/eventfd.c
+++ b/io_uring/eventfd.c
@@ -63,6 +63,17 @@ static bool __io_eventfd_signal(struct io_ev_fd *ev_fd)
 	return true;
 }
 
+/*
+ * Trigger if eventfd_async isn't set, or if it's set and the caller is
+ * an async worker. If ev_fd isn't valid, obviously return false.
+ */
+static bool io_eventfd_trigger(struct io_ev_fd *ev_fd)
+{
+	if (ev_fd)
+		return !ev_fd->eventfd_async || io_wq_current_is_worker();
+	return false;
+}
+
 void io_eventfd_signal(struct io_ring_ctx *ctx)
 {
 	struct io_ev_fd *ev_fd = NULL;
@@ -83,9 +94,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx)
 	 * completed between the NULL check of ctx->io_ev_fd at the start of
 	 * the function and rcu_read_lock.
 	 */
-	if (unlikely(!ev_fd))
-		return;
-	if (ev_fd->eventfd_async && !io_wq_current_is_worker())
+	if (!io_eventfd_trigger(ev_fd))
 		return;
 	if (!refcount_inc_not_zero(&ev_fd->refs))
 		return;
-- 
2.45.2


  parent reply	other threads:[~2024-09-21  8:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-21  7:59 [PATCHSET next 0/6] Move eventfd cq tracking into io_ev_fd Jens Axboe
2024-09-21  7:59 ` [PATCH 1/6] io_uring/eventfd: abstract out ev_fd put helper Jens Axboe
2024-09-21  7:59 ` [PATCH 2/6] io_uring/eventfd: check for the need to async notifier earlier Jens Axboe
2024-09-21  7:59 ` [PATCH 3/6] io_uring/eventfd: move actual signaling part into separate helper Jens Axboe
2024-09-21  7:59 ` Jens Axboe [this message]
2024-09-21  7:59 ` [PATCH 5/6] io_uring/eventfd: abstract out ev_fd grab + release helpers Jens Axboe
2024-09-21  7:59 ` [PATCH 6/6] io_uring/eventfd: move ctx->evfd_last_cq_tail into io_ev_fd Jens Axboe
2024-09-21  8:18   ` Jens Axboe
2024-09-30 14:28 ` [PATCHSET next 0/6] Move eventfd cq tracking " Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240921080307.185186-5-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.