public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern
Date: Thu,  1 May 2025 19:56:37 +0100	[thread overview]
Message-ID: <bafcd4da1148fdff2890c6ee186bfb516f434a65.1746125619.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1746125619.git.asml.silence@gmail.com>

-v option tells to make the outgoing traffic to follow a pattern, which
is repeating all lower case letters. zcrx already has an option to
verify received data.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/send-zerocopy.c | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index b4721672..ab67d189 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -76,11 +76,12 @@ static int  cfg_payload_len;
 static int  cfg_port		= 8000;
 static int  cfg_runtime_ms	= 4200;
 static bool cfg_rx_poll		= false;
+static bool cfg_verify;
 
 static socklen_t cfg_alen;
 static char *str_addr = NULL;
 
-static char payload_buf[IP_MAXPACKET] __attribute__((aligned(4096)));
+static char payload_buf[IP_MAXPACKET + 26] __attribute__((aligned(4096)));
 static char *payload;
 static struct thread_data threads[MAX_THREADS];
 static pthread_barrier_t barrier;
@@ -376,7 +377,7 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
 	}
 
 	iov.iov_base = payload;
-	iov.iov_len = cfg_payload_len;
+	iov.iov_len = cfg_payload_len + 26;
 
 	ret = io_uring_register_buffers(&ring, &iov, 1);
 	if (ret)
@@ -403,13 +404,18 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
 		unsigned msg_flags = MSG_WAITALL;
 
 		for (i = 0; i < cfg_nr_reqs; i++) {
+			char *buf = payload;
+
+			if (cfg_verify && cfg_type == SOCK_STREAM)
+				buf += td->bytes % 26;
+
 			sqe = io_uring_get_sqe(&ring);
 
 			if (!cfg_zc)
-				io_uring_prep_send(sqe, fd, payload,
+				io_uring_prep_send(sqe, fd, buf,
 						   cfg_payload_len, 0);
 			else {
-				io_uring_prep_send_zc(sqe, fd, payload,
+				io_uring_prep_send_zc(sqe, fd, buf,
 						     cfg_payload_len, msg_flags, 0);
 				if (cfg_fixed_buf) {
 					sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
@@ -527,7 +533,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:I:b:l:dC:T:Ry")) != -1) {
+	while ((c = getopt(argc, argv, "46D:p:s:t:n:z:I:b:l:dC:T:Ryv")) != -1) {
 		switch (c) {
 		case '4':
 			if (cfg_family != PF_UNSPEC)
@@ -582,12 +588,19 @@ static void parse_opts(int argc, char **argv)
 		case 'R':
 			cfg_rx = 1;
 			break;
+		case 'v':
+			cfg_verify = true;
+			break;
 		case 'y':
 			cfg_rx_poll = 1;
 			break;
 		}
 	}
 
+	available_buffer_len = cfg_payload_len;
+	if (cfg_verify)
+		available_buffer_len += 26;
+
 	cfg_test = argv[argc - 1];
 	if (!strcmp(cfg_test, "tcp"))
 		cfg_type = SOCK_STREAM;
@@ -604,8 +617,13 @@ static void parse_opts(int argc, char **argv)
 		t_error(1, 0, "-n: submit batch can't be zero");
 	if (cfg_ifname && cfg_rx)
 		t_error(1, 0, "Interface can only be specified for tx");
-	if (cfg_nr_reqs > 1 && cfg_type == SOCK_STREAM)
+	if (cfg_nr_reqs > 1 && cfg_type == SOCK_STREAM) {
 		printf("warning: submit batching >1 with TCP sockets will cause data reordering");
+		if (cfg_verify)
+			t_error(1, 0, "can't verify data because of reordering");
+	}
+	if (cfg_rx && cfg_verify)
+		t_error(1, 0, "Server mode doesn't support data verification");
 
 	str_addr = daddr;
 
@@ -637,8 +655,10 @@ int main(int argc, char **argv)
 
 	pthread_barrier_init(&barrier, NULL, cfg_nr_threads);
 
-	for (i = 0; i < IP_MAXPACKET; i++)
-		payload[i] = 'a' + (i % 26);
+	if (cfg_verify) {
+		for (i = 0; i < available_buffer_len + 26; i++)
+			payload[i] = 'a' + (i % 26);
+	}
 
 	for (i = 0; i < cfg_nr_threads; i++) {
 		td = &threads[i];
-- 
2.48.1


  parent reply	other threads:[~2025-05-01 18:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-01 18:56 [PATCH liburing 0/4] add more features to the zcrx benchmark Pavel Begunkov
2025-05-01 18:56 ` [PATCH liburing 1/4] examples/send-zc: warn about data reordering Pavel Begunkov
2025-05-01 18:56 ` [PATCH liburing 2/4] examples/send-zc: option to bind socket to device Pavel Begunkov
2025-05-01 18:56 ` Pavel Begunkov [this message]
2025-05-02 15:26   ` [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern Jens Axboe
2025-05-02 15:58     ` Pavel Begunkov
2025-05-01 18:56 ` [PATCH liburing 4/4] examples/zcrx: be more verbose on verification failure 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=bafcd4da1148fdff2890c6ee186bfb516f434a65.1746125619.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --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