From: Dylan Yudaken <[email protected]>
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>,
Dylan Yudaken <[email protected]>
Subject: [PATCH liburing 3/5] expose CQ ring overflow state
Date: Thu, 21 Apr 2022 02:14:25 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Allow the application to easily view if the CQ ring is in overflow state, and
also a simple method to flush overflow entries on to the CQ ring.
Explicit flushing can be useful for applications that prefer to have
reduced latency on CQs than to process as many as possible.
Signed-off-by: Dylan Yudaken <[email protected]>
---
src/include/liburing.h | 10 ++++++++++
src/queue.c | 31 +++++++++++++++++++------------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 5c03061..16c31a4 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -135,6 +135,7 @@ int io_uring_submit_and_wait_timeout(struct io_uring *ring,
unsigned wait_nr,
struct __kernel_timespec *ts,
sigset_t *sigmask);
+int io_uring_flush_overflow(struct io_uring *ring);
int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs,
unsigned nr_iovecs);
@@ -781,6 +782,15 @@ static inline unsigned io_uring_cq_ready(const struct io_uring *ring)
return io_uring_smp_load_acquire(ring->cq.ktail) - *ring->cq.khead;
}
+/*
+ * Returns true if there are overflow entries waiting to be flushed onto
+ * the CQ ring
+ */
+static inline bool io_uring_cq_has_overflow(const struct io_uring *ring)
+{
+ return IO_URING_READ_ONCE(*ring->sq.kflags) & IORING_SQ_CQ_OVERFLOW;
+}
+
/*
* Returns true if the eventfd notification is currently enabled
*/
diff --git a/src/queue.c b/src/queue.c
index 856d270..bfcf11f 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -33,14 +33,10 @@ static inline bool sq_ring_needs_enter(struct io_uring *ring, unsigned *flags)
return false;
}
-static inline bool cq_ring_needs_flush(struct io_uring *ring)
-{
- return IO_URING_READ_ONCE(*ring->sq.kflags) & IORING_SQ_CQ_OVERFLOW;
-}
-
static inline bool cq_ring_needs_enter(struct io_uring *ring)
{
- return (ring->flags & IORING_SETUP_IOPOLL) || cq_ring_needs_flush(ring);
+ return (ring->flags & IORING_SETUP_IOPOLL) ||
+ io_uring_cq_has_overflow(ring);
}
struct get_data {
@@ -123,6 +119,21 @@ int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,
return _io_uring_get_cqe(ring, cqe_ptr, &data);
}
+static int io_uring_get_events(struct io_uring *ring)
+{
+ int flags = IORING_ENTER_GETEVENTS;
+
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ flags |= IORING_ENTER_REGISTERED_RING;
+ return ____sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
+}
+
+int io_uring_flush_overflow(struct io_uring *ring)
+{
+ return io_uring_get_events(ring);
+}
+
+
/*
* Fill in an array of IO completions up to count, if any are available.
* Returns the amount of IO completions filled.
@@ -152,12 +163,8 @@ again:
if (overflow_checked)
goto done;
- if (cq_ring_needs_flush(ring)) {
- int flags = IORING_ENTER_GETEVENTS;
-
- if (ring->int_flags & INT_FLAG_REG_RING)
- flags |= IORING_ENTER_REGISTERED_RING;
- ____sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
+ if (io_uring_cq_has_overflow(ring)) {
+ io_uring_get_events(ring);
overflow_checked = true;
goto again;
}
--
2.30.2
next prev parent reply other threads:[~2022-04-21 9:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 9:14 [PATCH liburing 0/5] overflow support Dylan Yudaken
2022-04-21 9:14 ` [PATCH liburing 1/5] fix documentation shortenings Dylan Yudaken
2022-04-21 9:14 ` [PATCH liburing 2/5] update io_uring_enter.2 docs for IORING_FEAT_NODROP Dylan Yudaken
2022-04-21 9:14 ` Dylan Yudaken [this message]
2022-04-21 9:14 ` [PATCH liburing 4/5] add docs for overflow lost errors Dylan Yudaken
2022-04-21 9:14 ` [PATCH liburing 5/5] overflow: add tests Dylan Yudaken
2022-04-21 11:44 ` Ammar Faizi
2022-04-21 13:04 ` Dylan Yudaken
2022-04-21 19:49 ` 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] \
[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