From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Wei <dw@davidwei.uk>
Subject: [PATCH liburing 1/2] examples/send-zerocopy: add data verification
Date: Wed, 9 Apr 2025 18:58:35 +0100 [thread overview]
Message-ID: <86a0ceded6a54e1580a17bd549b1059326ae09f9.1744221361.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1744221361.git.asml.silence@gmail.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
examples/send-zerocopy.c | 50 +++++++++++++++++++++++++++++++++++++---
1 file changed, 47 insertions(+), 3 deletions(-)
diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index a50896c6..b0f2a76a 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -58,6 +58,13 @@ struct thread_data {
int fd;
};
+enum {
+ VERIFY_DISABLED = 0,
+ VERIFY_SEQ,
+
+ __MAX_VERIFY,
+};
+
static bool cfg_reg_ringfd = true;
static bool cfg_fixed_files = 1;
static bool cfg_zc = 1;
@@ -74,8 +81,8 @@ static int cfg_type = 0;
static int cfg_payload_len;
static int cfg_port = 8000;
static int cfg_runtime_ms = 4200;
+static int cfg_verify = 0;
static bool cfg_rx_poll = false;
-
static socklen_t cfg_alen;
static char *str_addr = NULL;
@@ -198,13 +205,30 @@ static int do_poll(int fd, int events)
return ret && (pfd.revents & events);
}
+static void verify_buffer(struct thread_data *td, char *buffer, size_t size)
+{
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ char d = payload[i];
+ char e = (td->bytes + i) % 26 + 'a';
+
+ if (e != d)
+ t_error(1, -EINVAL, "data mismatch");
+ }
+}
+
/* Flush all outstanding bytes for the tcp receive queue */
static int do_flush_tcp(struct thread_data *td, int fd)
{
int ret;
+ if (cfg_verify == VERIFY_SEQ)
+ ret = recv(fd, payload_buf, sizeof(payload_buf), 0);
+ else
+ ret = recv(fd, NULL, 1 << 21, MSG_TRUNC | MSG_DONTWAIT);
+
/* MSG_TRUNC flushes up to len bytes */
- ret = recv(fd, NULL, 1 << 21, MSG_TRUNC | MSG_DONTWAIT);
if (ret == -1 && errno == EAGAIN)
return 0;
if (ret == -1)
@@ -212,6 +236,9 @@ static int do_flush_tcp(struct thread_data *td, int fd)
if (!ret)
return 1;
+ if (cfg_verify == VERIFY_SEQ)
+ verify_buffer(td, payload_buf, ret);
+
td->packets++;
td->bytes += ret;
return 0;
@@ -391,6 +418,11 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
unsigned buf_idx = 0;
unsigned msg_flags = MSG_WAITALL;
+ if (cfg_verify) {
+ for (i = 0; i < cfg_payload_len; i++)
+ payload[i] = 'a' + ((i + td->bytes) % 26);
+ }
+
for (i = 0; i < cfg_nr_reqs; i++) {
sqe = io_uring_get_sqe(&ring);
@@ -515,7 +547,7 @@ static void parse_opts(int argc, char **argv)
cfg_payload_len = max_payload_len;
- while ((c = getopt(argc, argv, "46D:p:s:t:n:z:b:l:dC:T:Ry")) != -1) {
+ while ((c = getopt(argc, argv, "46v:D:p:s:t:n:z:b:l:dC:T:Ry")) != -1) {
switch (c) {
case '4':
if (cfg_family != PF_UNSPEC)
@@ -570,9 +602,21 @@ static void parse_opts(int argc, char **argv)
case 'y':
cfg_rx_poll = 1;
break;
+ case 'v':
+ cfg_verify = strtoul(optarg, NULL, 0);
+ break;
}
}
+ if (cfg_verify >= __MAX_VERIFY)
+ t_error(1, 0, "unsupported data verification type");
+ if (cfg_verify) {
+ if (!cfg_rx && cfg_zc)
+ t_error(1, 0, "verification doesn't work with sendzc");
+ if (cfg_verify == VERIFY_SEQ && cfg_nr_reqs > 1 && !cfg_zc)
+ t_error(1, 0, "sequence verification invalid inflight number");
+ }
+
if (cfg_nr_reqs > MAX_SUBMIT_NR)
t_error(1, 0, "-n: submit batch nr exceeds max (%d)", MAX_SUBMIT_NR);
if (cfg_payload_len > max_payload_len)
--
2.48.1
next prev parent reply other threads:[~2025-04-09 17:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 17:58 [PATCH liburing 0/2] add zcrx example Pavel Begunkov
2025-04-09 17:58 ` Pavel Begunkov [this message]
2025-04-09 17:58 ` [PATCH liburing 2/2] examples: add a " Pavel Begunkov
2025-04-09 23:00 ` Pavel Begunkov
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 \
--in-reply-to=86a0ceded6a54e1580a17bd549b1059326ae09f9.1744221361.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=dw@davidwei.uk \
--cc=io-uring@vger.kernel.org \
/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