[PATCH liburing 3/5] expose CQ ring overflow state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <dylany@xxxxxx>
---
 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





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux