public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing 0/4] add more features to the zcrx benchmark
@ 2025-05-01 18:56 Pavel Begunkov
  2025-05-01 18:56 ` [PATCH liburing 1/4] examples/send-zc: warn about data reordering Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-01 18:56 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

The patchset adds options for binding to a device and for filling with
a pattern for data verification. Also, improve warning and error
messages.

Pavel Begunkov (4):
  examples/send-zc: warn about data reordering
  examples/send-zc: option to bind socket to device
  examples/send-zc: optionally fill data with a pattern
  examples/zcrx: be more verbose on verification failure

 examples/send-zerocopy.c | 72 +++++++++++++++++++++++++++++++---------
 examples/zcrx.c          |  3 +-
 2 files changed, 58 insertions(+), 17 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH liburing 1/4] examples/send-zc: warn about data reordering
  2025-05-01 18:56 [PATCH liburing 0/4] add more features to the zcrx benchmark Pavel Begunkov
@ 2025-05-01 18:56 ` Pavel Begunkov
  2025-05-01 18:56 ` [PATCH liburing 2/4] examples/send-zc: option to bind socket to device Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-01 18:56 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Data can be reordered if there are multiple outstanding write requests
for the same stream / TCP socket. That's fine for a benchmark, but warn
about it.

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

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index a50896c6..c83ef4d9 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -501,6 +501,7 @@ static void usage(const char *filepath)
 
 static void parse_opts(int argc, char **argv)
 {
+	const char *cfg_test;
 	const int max_payload_len = IP_MAXPACKET -
 				    sizeof(struct ipv6hdr) -
 				    sizeof(struct tcphdr) -
@@ -573,10 +574,22 @@ static void parse_opts(int argc, char **argv)
 		}
 	}
 
+	cfg_test = argv[argc - 1];
+	if (!strcmp(cfg_test, "tcp"))
+		cfg_type = SOCK_STREAM;
+	else if (!strcmp(cfg_test, "udp"))
+		cfg_type = SOCK_DGRAM;
+	else
+		t_error(1, 0, "unknown cfg_test %s", cfg_test);
+
 	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)
 		t_error(1, 0, "-s: payload exceeds max (%d)", max_payload_len);
+	if (!cfg_nr_reqs)
+		t_error(1, 0, "-n: submit batch can't be zero");
+	if (cfg_nr_reqs > 1 && cfg_type == SOCK_STREAM)
+		printf("warning: submit batching >1 with TCP sockets will cause data reordering");
 
 	str_addr = daddr;
 
@@ -589,7 +602,6 @@ int main(int argc, char **argv)
 	unsigned long long tsum = 0;
 	unsigned long long packets = 0, bytes = 0;
 	struct thread_data *td;
-	const char *cfg_test;
 	unsigned int i;
 	void *res;
 
@@ -607,14 +619,6 @@ int main(int argc, char **argv)
 		}
 	}
 
-	cfg_test = argv[argc - 1];
-	if (!strcmp(cfg_test, "tcp"))
-		cfg_type = SOCK_STREAM;
-	else if (!strcmp(cfg_test, "udp"))
-		cfg_type = SOCK_DGRAM;
-	else
-		t_error(1, 0, "unknown cfg_test %s", cfg_test);
-
 	pthread_barrier_init(&barrier, NULL, cfg_nr_threads);
 
 	for (i = 0; i < IP_MAXPACKET; i++)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH liburing 2/4] examples/send-zc: option to bind socket to device
  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 ` Pavel Begunkov
  2025-05-01 18:56 ` [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
  2025-05-01 18:56 ` [PATCH liburing 4/4] examples/zcrx: be more verbose on verification failure Pavel Begunkov
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-01 18:56 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Let the user to specify the interface for tx.

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

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index c83ef4d9..b4721672 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -68,6 +68,7 @@ static bool cfg_defer_taskrun = 0;
 static int  cfg_cpu = -1;
 static bool cfg_rx = 0;
 static unsigned  cfg_nr_threads = 1;
+static const char *cfg_ifname;
 
 static int  cfg_family		= PF_UNSPEC;
 static int  cfg_type		= 0;
@@ -343,6 +344,16 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
 	if (fd == -1)
 		t_error(1, errno, "socket t");
 
+	if (cfg_ifname) {
+		struct ifreq ifr;
+
+		memset(&ifr, 0, sizeof(ifr));
+		snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), cfg_ifname);
+
+		if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
+			t_error(1, errno, "Binding to device failed\n");
+	}
+
 	if (connect(fd, (void *)&td->dst_addr, cfg_alen))
 		t_error(1, errno, "connect, idx %i", td->idx);
 
@@ -516,7 +527,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, "46D:p:s:t:n:z:I:b:l:dC:T:Ry")) != -1) {
 		switch (c) {
 		case '4':
 			if (cfg_family != PF_UNSPEC)
@@ -530,6 +541,9 @@ static void parse_opts(int argc, char **argv)
 			cfg_family = PF_INET6;
 			cfg_alen = sizeof(struct sockaddr_in6);
 			break;
+		case 'I':
+			cfg_ifname = optarg;
+			break;
 		case 'D':
 			daddr = optarg;
 			break;
@@ -588,6 +602,8 @@ static void parse_opts(int argc, char **argv)
 		t_error(1, 0, "-s: payload exceeds max (%d)", max_payload_len);
 	if (!cfg_nr_reqs)
 		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)
 		printf("warning: submit batching >1 with TCP sockets will cause data reordering");
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern
  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
  2025-05-02 15:26   ` Jens Axboe
  2025-05-01 18:56 ` [PATCH liburing 4/4] examples/zcrx: be more verbose on verification failure Pavel Begunkov
  3 siblings, 1 reply; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-01 18:56 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

-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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH liburing 4/4] examples/zcrx: be more verbose on verification failure
  2025-05-01 18:56 [PATCH liburing 0/4] add more features to the zcrx benchmark Pavel Begunkov
                   ` (2 preceding siblings ...)
  2025-05-01 18:56 ` [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
@ 2025-05-01 18:56 ` Pavel Begunkov
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-01 18:56 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Print additional info if data verification fails.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/zcrx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/zcrx.c b/examples/zcrx.c
index d31c5b36..6b06e4fa 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -216,7 +216,8 @@ static void verify_data(char *data, size_t size, unsigned long seq)
 		char expected = 'a' + (seq + i) % 26;
 
 		if (data[i] != expected)
-			t_error(1, 0, "payload mismatch at %i", i);
+			t_error(1, 0, "payload mismatch at %i: expected %i vs got %i, seq %li",
+				i, expected, data[i], seq);
 	}
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern
  2025-05-01 18:56 ` [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
@ 2025-05-02 15:26   ` Jens Axboe
  2025-05-02 15:58     ` Pavel Begunkov
  0 siblings, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2025-05-02 15:26 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

> @@ -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;
> +

This variable is nowhere to be found?

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern
  2025-05-02 15:26   ` Jens Axboe
@ 2025-05-02 15:58     ` Pavel Begunkov
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 15:58 UTC (permalink / raw)
  To: Jens Axboe, io-uring

On 5/2/25 16:26, Jens Axboe wrote:
>> @@ -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;
>> +
> 
> This variable is nowhere to be found

And it shouldn't be there in the first place, I'll resend

-- 
Pavel Begunkov


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-05-02 15:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH liburing 3/4] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
2025-05-02 15:26   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox