aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Yudaken <dylany@fb.com>2022-06-13 06:12:51 -0700
committerJens Axboe <axboe@kernel.dk>2022-06-13 07:58:10 -0600
commit2c9bc6ba8529c28da2b2afeffea88958ca315e5a (patch)
tree32936c640828c51f16d739e472fab6ef41aecb91
parent7d25ba48783b8d6960dbd1c8e54f6862ee5a9afb (diff)
downloadliburing-2c9bc6ba8529c28da2b2afeffea88958ca315e5a.tar.gz
add mask parameter to io_uring_buf_ring_add
Without the mask parameter, it's not feasible to use this API without knowing where the tail is and performing some arithmetic Signed-off-by: Dylan Yudaken <dylany@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--man/io_uring_buf_ring_add.35
-rw-r--r--man/io_uring_buf_ring_mask.327
-rw-r--r--src/include/liburing.h13
-rw-r--r--test/send_recvmsg.c3
4 files changed, 45 insertions, 3 deletions
diff --git a/man/io_uring_buf_ring_add.3 b/man/io_uring_buf_ring_add.3
index 741cba6..9d8283b 100644
--- a/man/io_uring_buf_ring_add.3
+++ b/man/io_uring_buf_ring_add.3
@@ -13,6 +13,7 @@ io_uring_buf_ring_add \- add buffers to a shared buffer ring
.BI " void *" addr ",
.BI " unsigned int " len ",
.BI " unsigned short " bid ",
+.BI " int " mask ",
.BI " int " buf_offset ");"
.fi
.SH DESCRIPTION
@@ -28,6 +29,9 @@ and is of
bytes of length.
.I bid
is the buffer ID, which will be returned in the CQE.
+.I mask
+is the size mask of the ring, available from
+.BR io_uring_buf_ring_mask (3) .
.I buf_offset
is the offset to insert at from the current tail. If just one buffer is provided
before the ring tail is committed with
@@ -44,5 +48,6 @@ must be incremented by one for each buffer added.
None
.SH SEE ALSO
.BR io_uring_register_buf_ring (3),
+.BR io_uring_buf_ring_mask (3),
.BR io_uring_buf_ring_advance (3),
.BR io_uring_buf_ring_cq_advance (3)
diff --git a/man/io_uring_buf_ring_mask.3 b/man/io_uring_buf_ring_mask.3
new file mode 100644
index 0000000..9160663
--- /dev/null
+++ b/man/io_uring_buf_ring_mask.3
@@ -0,0 +1,27 @@
+.\" Copyright (C) 2022 Dylan Yudaken <dylany@fb.com>
+.\"
+.\" SPDX-License-Identifier: LGPL-2.0-or-later
+.\"
+.TH io_uring_buf_ring_mask 3 "June 13, 2022" "liburing-2.2" "liburing Manual"
+.SH NAME
+io_uring_buf_ring_mask \- Calculate buffer ring mask size
+.SH SYNOPSIS
+.nf
+.B #include <liburing.h>
+.PP
+.BI "int io_uring_buf_ring_mask(__u32 " ring_entries ");"
+.fi
+.SH DESCRIPTION
+.PP
+.BR io_uring_buf_ring_mask (3)
+calculates the appropriate size mask for a buffer ring.
+.IR ring_entries
+is the ring entries as specified in
+.BR io_uring_register_buf_ring (3) .
+
+.SH RETURN VALUE
+Size mask for the buffer ring.
+
+.SH SEE ALSO
+.BR io_uring_register_buf_ring (3),
+.BR io_uring_buf_ring_add (3)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 6eece30..9beef0b 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1090,13 +1090,22 @@ static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
}
/*
+ * Return the appropriate mask for a buffer ring of size 'ring_entries'
+ */
+static inline int io_uring_buf_ring_mask(__u32 ring_entries)
+{
+ return ring_entries - 1;
+}
+
+/*
* Assign 'buf' with the addr/len/buffer ID supplied
*/
static inline void io_uring_buf_ring_add(struct io_uring_buf_ring *br,
void *addr, unsigned int len,
- unsigned short bid, int buf_offset)
+ unsigned short bid, int mask,
+ int buf_offset)
{
- struct io_uring_buf *buf = &br->bufs[br->tail + buf_offset];
+ struct io_uring_buf *buf = &br->bufs[(br->tail + buf_offset) & mask];
buf->addr = (unsigned long) (uintptr_t) addr;
buf->len = len;
diff --git a/test/send_recvmsg.c b/test/send_recvmsg.c
index 44a01b0..6f18bae 100644
--- a/test/send_recvmsg.c
+++ b/test/send_recvmsg.c
@@ -199,7 +199,8 @@ static void *recv_fn(void *data)
}
br = ptr;
- io_uring_buf_ring_add(br, buf, sizeof(buf), BUF_BID, 0);
+ io_uring_buf_ring_add(br, buf, sizeof(buf), BUF_BID,
+ io_uring_buf_ring_mask(1), 0);
io_uring_buf_ring_advance(br, 1);
} else {
struct io_uring_sqe *sqe;