aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-05-17 10:00:28 -0600
committerJens Axboe <axboe@kernel.dk>2022-05-18 14:24:09 -0600
commitc4a10701bd63a11aefe2ee6e0e48006382bd4de0 (patch)
treeac2e1434609319b71f697dd30baf30a77e932d3a
parentf5776b4371a0036875b6173f0673db9079a0381f (diff)
downloadliburing-c4a10701bd63a11aefe2ee6e0e48006382bd4de0.tar.gz
Add combined cq+buf ring advance helper
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/include/liburing.h19
-rw-r--r--test/send_recvmsg.c4
2 files changed, 18 insertions, 5 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index ee65fe8..9a0d23e 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1035,14 +1035,29 @@ static inline void io_uring_buf_ring_add(struct io_uring_buf *buf,
* io_uring_buf_ring_add() has been called 'count' times to fill in new
* buffers.
*/
-static inline void io_uring_buf_ring_increment(struct io_uring_buf_ring *br,
- int count)
+static inline void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
+ int count)
{
unsigned short new_tail = br->tail + count;
io_uring_smp_store_release(&br->tail, new_tail);
}
+/*
+ * 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
+ * is using ring provided buffers and returns buffers while processing CQEs,
+ * avoiding an extra atomic when needing to increment both the CQ ring and
+ * the ring buffer index at the same time.
+ */
+static inline 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);
+}
+
#ifndef LIBURING_INTERNAL
static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
{
diff --git a/test/send_recvmsg.c b/test/send_recvmsg.c
index e989d2c..1fed4af 100644
--- a/test/send_recvmsg.c
+++ b/test/send_recvmsg.c
@@ -201,7 +201,7 @@ static void *recv_fn(void *data)
br = ptr;
io_uring_buf_ring_add(&br->bufs[0], buf, sizeof(buf),
BUF_BID);
- io_uring_buf_ring_increment(br, 1);
+ io_uring_buf_ring_advance(br, 1);
} else {
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
@@ -366,7 +366,6 @@ int main(int argc, char *argv[])
if (argc > 1)
return 0;
-goto foo;
ret = test(0, 0, 0, 1, 0);
if (ret) {
fprintf(stderr, "send_recvmsg 0 0 0 1 0 failed\n");
@@ -433,7 +432,6 @@ goto foo;
return 1;
}
-foo:
ret = test(0, 1, 0, 1, 1);
if (ret) {
fprintf(stderr, "send_recvmsg async 0 1 0 1 1 failed\n");