All of lore.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 v2 3/5] examples/send-zc: optionally fill data with a pattern
Date: Fri,  2 May 2025 17:54:00 +0100	[thread overview]
Message-ID: <bc15b140e8f5d261a091377c874a9042d9bfca2b.1746204705.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1746204705.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 | 70 ++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 21 deletions(-)

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index b4721672..a7465812 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -43,6 +43,8 @@
 
 #include "liburing.h"
 
+#define PATTERN_SIZE	26
+
 #define ZC_TAG 0xfffffffULL
 #define MAX_SUBMIT_NR 512
 #define MAX_THREADS 100
@@ -76,11 +78,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 + PATTERN_SIZE] __attribute__((aligned(4096)));
 static char *payload;
 static struct thread_data threads[MAX_THREADS];
 static pthread_barrier_t barrier;
@@ -376,7 +379,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 + PATTERN_SIZE;
 
 	ret = io_uring_register_buffers(&ring, &iov, 1);
 	if (ret)
@@ -403,13 +406,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 % PATTERN_SIZE;
+
 			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 +535,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,6 +590,9 @@ 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;
@@ -604,8 +615,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;
 
@@ -613,6 +629,32 @@ static void parse_opts(int argc, char **argv)
 		usage(argv[0]);
 }
 
+static void init_buffers(void)
+{
+	size_t size;
+	int i;
+
+	payload = payload_buf;
+	size = sizeof(payload_buf);
+
+	if (cfg_hugetlb) {
+		size = 1 << 21;
+		payload = mmap(NULL, size, PROT_READ | PROT_WRITE,
+				MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB | MAP_ANONYMOUS,
+				-1, 0);
+		if (payload == MAP_FAILED)
+			t_error(0, 1, "huge pages alloc failed");
+	}
+
+	if (cfg_payload_len + PATTERN_SIZE > size)
+		t_error(1, 0, "Buffers are too small");
+
+	if (cfg_verify) {
+		for (i = 0; i < size; i++)
+			payload[i] = 'a' + (i % PATTERN_SIZE);
+	}
+}
+
 int main(int argc, char **argv)
 {
 	unsigned long long tsum = 0;
@@ -622,24 +664,10 @@ int main(int argc, char **argv)
 	void *res;
 
 	parse_opts(argc, argv);
+	init_buffers();
 	set_cpu_affinity();
 
-	payload = payload_buf;
-	if (cfg_hugetlb) {
-		payload = mmap(NULL, 2*1024*1024, PROT_READ | PROT_WRITE,
-				MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB | MAP_ANONYMOUS,
-				-1, 0);
-		if (payload == MAP_FAILED) {
-			fprintf(stderr, "hugetlb alloc failed\n");
-			return 1;
-		}
-	}
-
 	pthread_barrier_init(&barrier, NULL, cfg_nr_threads);
-
-	for (i = 0; i < IP_MAXPACKET; i++)
-		payload[i] = 'a' + (i % 26);
-
 	for (i = 0; i < cfg_nr_threads; i++) {
 		td = &threads[i];
 		td->idx = i;
-- 
2.48.1


  parent reply	other threads:[~2025-05-02 16:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
2025-05-02 16:53 ` [PATCH liburing v2 1/5] examples/send-zc: warn about data reordering Pavel Begunkov
2025-05-02 16:53 ` [PATCH liburing v2 2/5] examples/send-zc: option to bind socket to device Pavel Begunkov
2025-05-02 16:54 ` Pavel Begunkov [this message]
2025-05-02 16:54 ` [PATCH liburing v2 4/5] examples/send-zc: record time on disconnect Pavel Begunkov
2025-05-02 16:54 ` [PATCH liburing v2 5/5] examples/zcrx: be more verbose on verification failure Pavel Begunkov
2025-05-04 16:53 ` [PATCH liburing v2 0/5] enchance zc benchmarks Jens Axboe

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=bc15b140e8f5d261a091377c874a9042d9bfca2b.1746204705.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.