public inbox for [email protected]
 help / color / mirror / Atom feed
From: Stefano Garzarella <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected], [email protected]
Subject: [PATCH liburing v2 3/5] Add helpers to set and get eventfd notification status
Date: Wed, 20 May 2020 19:07:12 +0200	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This patch adds the new IORING_CQ_EVENTFD_DISABLED flag. It can be
used to disable/enable notifications from the kernel when a
request is completed and queued to the CQ ring.

We also add two helpers function to check if the notifications are
enabled and to toggle them.

If the kernel doesn't provide CQ ring flags, the notifications are
always enabled if an eventfd is registered.

Signed-off-by: Stefano Garzarella <[email protected]>
---
v1 -> v2:
- renamed io_uring_cq_eventfd_toggle()
- return EOPNOTSUPP only if we need to change the flag
---
 src/include/liburing.h          | 33 +++++++++++++++++++++++++++++++++
 src/include/liburing/io_uring.h |  7 +++++++
 2 files changed, 40 insertions(+)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index adc8db9..0192b47 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -9,7 +9,9 @@ extern "C" {
 #include <sys/socket.h>
 #include <sys/uio.h>
 #include <sys/stat.h>
+#include <errno.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <inttypes.h>
 #include <time.h>
 #include "liburing/compat.h"
@@ -445,6 +447,37 @@ static inline unsigned io_uring_cq_ready(struct io_uring *ring)
 	return io_uring_smp_load_acquire(ring->cq.ktail) - *ring->cq.khead;
 }
 
+static inline bool io_uring_cq_eventfd_enabled(struct io_uring *ring)
+{
+	if (!ring->cq.kflags)
+		return true;
+
+	return !(*ring->cq.kflags & IORING_CQ_EVENTFD_DISABLED);
+}
+
+static inline int io_uring_cq_eventfd_toggle(struct io_uring *ring,
+					     bool enabled)
+{
+	uint32_t flags;
+
+	if (!!enabled == io_uring_cq_eventfd_enabled(ring))
+		return 0;
+
+	if (!ring->cq.kflags)
+		return -EOPNOTSUPP;
+
+	flags = *ring->cq.kflags;
+
+	if (enabled)
+		flags &= ~IORING_CQ_EVENTFD_DISABLED;
+	else
+		flags |= IORING_CQ_EVENTFD_DISABLED;
+
+	IO_URING_WRITE_ONCE(*ring->cq.kflags, flags);
+
+	return 0;
+}
+
 /*
  * Return an IO completion, waiting for 'wait_nr' completions if one isn't
  * readily available. Returns 0 with cqe_ptr filled in on success, -errno on
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 9860a8a..92c2269 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -210,6 +210,13 @@ struct io_cqring_offsets {
 	__u64 resv2;
 };
 
+/*
+ * cq_ring->flags
+ */
+
+/* disable eventfd notifications */
+#define IORING_CQ_EVENTFD_DISABLED	(1U << 0)
+
 /*
  * io_uring_enter(2) flags
  */
-- 
2.25.4


  parent reply	other threads:[~2020-05-20 17:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 17:07 [PATCH liburing v2 0/5] liburing: add helpers to enable/disable eventfd notifications Stefano Garzarella
2020-05-20 17:07 ` [PATCH liburing v2 1/5] Add CQ ring 'flags' field Stefano Garzarella
2020-05-20 17:07 ` [PATCH liburing v2 2/5] man/io_uring_setup.2: add 'flags' field in the struct io_cqring_offsets Stefano Garzarella
2020-05-20 17:07 ` Stefano Garzarella [this message]
2020-05-20 17:07 ` [PATCH liburing v2 4/5] man/io_uring_register.2: add IORING_CQ_EVENTFD_DISABLED description Stefano Garzarella
2020-05-20 17:07 ` [PATCH liburing v2 5/5] Add test/eventfd-disable.c test case Stefano Garzarella
2020-05-20 17:12 ` [PATCH liburing v2 0/5] liburing: add helpers to enable/disable eventfd notifications 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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox