diff mbox series

[liburing,v2,03/12] add io_uring_submit_and_get_events and io_uring_get_events

Message ID 20220901093303.1974274-4-dylany@fb.com (mailing list archive)
State New
Headers show
Series Defer taskrun changes | expand

Commit Message

Dylan Yudaken Sept. 1, 2022, 9:32 a.m. UTC
With deferred task running, we would like to be able to combine submit
with get events (regardless of if there are CQE's available), or if there
is nothing to submit then simply do an enter with IORING_ENTER_GETEVENTS
set, in order to process any available work.

Expose these APIs

Signed-off-by: Dylan Yudaken <dylany@fb.com>
---
 src/include/liburing.h |  2 ++
 src/queue.c            | 26 ++++++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)

Comments

Jens Axboe Sept. 1, 2022, 6:36 p.m. UTC | #1
On 9/1/22 3:32 AM, Dylan Yudaken wrote:
> With deferred task running, we would like to be able to combine submit
> with get events (regardless of if there are CQE's available), or if there
> is nothing to submit then simply do an enter with IORING_ENTER_GETEVENTS
> set, in order to process any available work.
> 
> Expose these APIs

Maybe this is added later, but man page entries are missing for these
two.

We also need get these added to the liburing.map.
Dylan Yudaken Sept. 5, 2022, 8:31 a.m. UTC | #2
On Thu, 2022-09-01 at 12:36 -0600, Jens Axboe wrote:
> On 9/1/22 3:32 AM, Dylan Yudaken wrote:
> > With deferred task running, we would like to be able to combine
> > submit
> > with get events (regardless of if there are CQE's available), or if
> > there
> > is nothing to submit then simply do an enter with
> > IORING_ENTER_GETEVENTS
> > set, in order to process any available work.
> > 
> > Expose these APIs
> 
> Maybe this is added later, but man page entries are missing for these
> two.
> 
> We also need get these added to the liburing.map.
> 

OK I'll do both of these and do a v3
diff mbox series

Patch

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 6e868472b77a..3c5097b255de 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -202,6 +202,8 @@  int io_uring_register_file_alloc_range(struct io_uring *ring,
 int io_uring_register_notifications(struct io_uring *ring, unsigned nr,
 				    struct io_uring_notification_slot *slots);
 int io_uring_unregister_notifications(struct io_uring *ring);
+int io_uring_get_events(struct io_uring *ring);
+int io_uring_submit_and_get_events(struct io_uring *ring);
 
 /*
  * io_uring syscalls.
diff --git a/src/queue.c b/src/queue.c
index a670a8ecd20d..b012a3dd950b 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -130,6 +130,15 @@  int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,
 	return _io_uring_get_cqe(ring, cqe_ptr, &data);
 }
 
+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);
+}
+
 /*
  * Fill in an array of IO completions up to count, if any are available.
  * Returns the amount of IO completions filled.
@@ -164,11 +173,7 @@  again:
 		return 0;
 
 	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);
+		io_uring_get_events(ring);
 		overflow_checked = true;
 		goto again;
 	}
@@ -340,9 +345,9 @@  int io_uring_wait_cqe_timeout(struct io_uring *ring,
  * Returns number of sqes submitted
  */
 static int __io_uring_submit(struct io_uring *ring, unsigned submitted,
-			     unsigned wait_nr)
+			     unsigned wait_nr, bool getevents)
 {
-	bool cq_needs_enter = wait_nr || cq_ring_needs_enter(ring);
+	bool cq_needs_enter = getevents || wait_nr || cq_ring_needs_enter(ring);
 	unsigned flags;
 	int ret;
 
@@ -363,7 +368,7 @@  static int __io_uring_submit(struct io_uring *ring, unsigned submitted,
 
 static int __io_uring_submit_and_wait(struct io_uring *ring, unsigned wait_nr)
 {
-	return __io_uring_submit(ring, __io_uring_flush_sq(ring), wait_nr);
+	return __io_uring_submit(ring, __io_uring_flush_sq(ring), wait_nr, false);
 }
 
 /*
@@ -386,6 +391,11 @@  int io_uring_submit_and_wait(struct io_uring *ring, unsigned wait_nr)
 	return __io_uring_submit_and_wait(ring, wait_nr);
 }
 
+int io_uring_submit_and_get_events(struct io_uring *ring)
+{
+	return __io_uring_submit(ring, __io_uring_flush_sq(ring), 0, true);
+}
+
 #ifdef LIBURING_INTERNAL
 struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
 {