From: Dylan Yudaken <[email protected]>
To: <[email protected]>, <[email protected]>, <[email protected]>
Cc: <[email protected]>, Dylan Yudaken <[email protected]>
Subject: [PATCH liburing 2/4] add mask parameter to io_uring_buf_ring_add
Date: Mon, 13 Jun 2022 06:12:51 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
man/io_uring_buf_ring_add.3 | 5 +++++
man/io_uring_buf_ring_mask.3 | 27 +++++++++++++++++++++++++++
src/include/liburing.h | 13 +++++++++++--
test/send_recvmsg.c | 3 ++-
4 files changed, 45 insertions(+), 3 deletions(-)
create mode 100644 man/io_uring_buf_ring_mask.3
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 <[email protected]>
+.\"
+.\" 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
@@ -1089,14 +1089,23 @@ static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
return NULL;
}
+/*
+ * 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;
--
2.30.2
next prev parent reply other threads:[~2022-06-13 15:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 13:12 [PATCH liburing 0/4] Buffer ring API fixes Dylan Yudaken
2022-06-13 13:12 ` [PATCH liburing 1/4] remove non-existent manpage reference Dylan Yudaken
2022-06-13 13:12 ` Dylan Yudaken [this message]
2022-06-13 13:12 ` [PATCH liburing 3/4] add io_uring_buf_ring_init Dylan Yudaken
2022-06-13 13:12 ` [PATCH liburing 4/4] buf-ring: add tests that cycle through the provided buffer ring Dylan Yudaken
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox