liburing icon indicating copy to clipboard operation
liburing copied to clipboard

io_uring_buf_ring_cq_advance parameter change suggestion

Open bnbajwa opened this issue 3 years ago • 1 comments

io_uring_buf_ring_cq_advance(io_uring*, io_uring_buf_ring*, int count) currently commits 'count' number of previously added buffers and at the same time it advances cq ring by the same amount.

I suggest that instead of a single 'count' parameter, there should be two: buf_count and cqe_count. So this function would commit 'buf_count' previously added buffers and advance cq ring by 'cqe_count'.

I suggest this because typically in each iteration of an event loop, the number of cqes that use a provided buffer is less than the total number of cqes consumed in that iteration. So, after each iteration the number of provided buffers to commit back will be less than the number of cqes consumed

What do you think?

bnbajwa avatar Jul 01 '22 21:07 bnbajwa

That's not a bad idea, but it should be added separately and take the two counts. I'd be happy to take a patch that does that, as I do think it makes sense if you have mixed requests completing.

axboe avatar Jul 01 '22 22:07 axboe

I was about to make a new issue for this. I have the same exact proposal, for the same exact reason. Two counts would make it PERFECT

uNetworkingAB avatar May 12 '23 06:05 uNetworkingAB

It seems like just changing this function would do it:

IOURINGINLINE void io_uring_buf_ring_cq_advance(struct io_uring *ring, struct io_uring_buf_ring *br, int count) { br->tail += count; io_uring_cq_advance(ring, count); }

uNetworkingAB avatar May 12 '23 06:05 uNetworkingAB

Something like this should do it:

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 70c177431faf..28eba2e57535 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1382,6 +1382,14 @@ IOURINGINLINE void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
 	io_uring_smp_store_release(&br->tail, new_tail);
 }
 
+IOURINGINLINE void __io_uring_buf_ring_cq_advance(struct io_uring *ring,
+						  struct io_uring_buf_ring *br,
+						  int cq_count, int buf_count)
+{
+	br->tail += buf_count;
+	io_uring_cq_advance(ring, cq_count);
+}
+
 /*
  * Make 'count' new buffers visible to the kernel while at the same time
  * advancing the CQ ring seen entries. This can be used when the application
@@ -1393,8 +1401,7 @@ IOURINGINLINE void io_uring_buf_ring_cq_advance(struct io_uring *ring,
 						struct io_uring_buf_ring *br,
 						int count)
 {
-	br->tail += count;
-	io_uring_cq_advance(ring, count);
+	__io_uring_buf_ring_cq_advance(ring, br, count, count);
 }
 
 #ifndef LIBURING_INTERNAL
diff --git a/src/liburing-ffi.map b/src/liburing-ffi.map
index 0a5e12ca764a..ceca51a4a2ee 100644
--- a/src/liburing-ffi.map
+++ b/src/liburing-ffi.map
@@ -120,6 +120,7 @@ LIBURING_2.4 {
 		io_uring_recvmsg_cmsg_firsthdr;
 		io_uring_prep_socket_direct;
 		io_uring_buf_ring_cq_advance;
+		__io_uring_buf_ring_cq_advance;
 		io_uring_prep_mkdir;
 		io_uring_wait_cqe_nr;
 		io_uring_prep_unlink;

axboe avatar May 12 '23 14:05 axboe

Added, with documentation update.

axboe avatar May 12 '23 15:05 axboe