* [PATCH liburing v2 0/5] enchance zc benchmarks
@ 2025-05-02 16:53 Pavel Begunkov
2025-05-02 16:53 ` [PATCH liburing v2 1/5] examples/send-zc: warn about data reordering Pavel Begunkov
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:53 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.
v2: add patch 4
fix ghost variable build errors
Pavel Begunkov (5):
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/send-zc: record time on disconnect
examples/zcrx: be more verbose on verification failure
examples/send-zerocopy.c | 110 ++++++++++++++++++++++++++++-----------
examples/zcrx.c | 3 +-
2 files changed, 81 insertions(+), 32 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH liburing v2 1/5] examples/send-zc: warn about data reordering
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
@ 2025-05-02 16:53 ` Pavel Begunkov
2025-05-02 16:53 ` [PATCH liburing v2 2/5] examples/send-zc: option to bind socket to device Pavel Begunkov
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:53 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 v2 2/5] examples/send-zc: option to bind socket to device
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 ` Pavel Begunkov
2025-05-02 16:54 ` [PATCH liburing v2 3/5] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:53 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 v2 3/5] examples/send-zc: optionally fill data with a pattern
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
2025-05-02 16:54 ` [PATCH liburing v2 4/5] examples/send-zc: record time on disconnect Pavel Begunkov
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:54 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 | 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH liburing v2 4/5] examples/send-zc: record time on disconnect
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
` (2 preceding siblings ...)
2025-05-02 16:54 ` [PATCH liburing v2 3/5] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
@ 2025-05-02 16:54 ` 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
5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:54 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Record time even if the other end broke connection, the server can
specify a small timeout, and without the change we won't be able to
print stats at the end.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
examples/send-zerocopy.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index a7465812..be8da2fc 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -458,7 +458,7 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
td->bytes += cqe->res;
} else if (cqe->res == -ECONNREFUSED || cqe->res == -EPIPE ||
cqe->res == -ECONNRESET) {
- fprintf(stderr, "Connection failure\n");
+ printf("Connection failure %i\n", cqe->res);
goto out_fail;
} else if (cqe->res != -EAGAIN) {
t_error(1, cqe->res, "send failed");
@@ -469,9 +469,9 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
break;
} while ((++loop % 16 != 0) || gettimeofday_ms() < tstart + cfg_runtime_ms);
+out_fail:
td->dt_ms = gettimeofday_ms() - tstart;
-out_fail:
shutdown(fd, SHUT_RDWR);
if (close(fd))
t_error(1, errno, "close");
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH liburing v2 5/5] examples/zcrx: be more verbose on verification failure
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
` (3 preceding siblings ...)
2025-05-02 16:54 ` [PATCH liburing v2 4/5] examples/send-zc: record time on disconnect Pavel Begunkov
@ 2025-05-02 16:54 ` Pavel Begunkov
2025-05-04 16:53 ` [PATCH liburing v2 0/5] enchance zc benchmarks Jens Axboe
5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2025-05-02 16:54 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 v2 0/5] enchance zc benchmarks
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
` (4 preceding siblings ...)
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 ` Jens Axboe
5 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2025-05-04 16:53 UTC (permalink / raw)
To: io-uring, Pavel Begunkov
On Fri, 02 May 2025 17:53:57 +0100, Pavel Begunkov wrote:
> The patchset adds options for binding to a device and for filling with
> a pattern for data verification. Also, improve warning and error
> messages.
>
> v2: add patch 4
> fix ghost variable build errors
>
> [...]
Applied, thanks!
[1/5] examples/send-zc: warn about data reordering
commit: 4dca51bbabda1453a2ed2d9fb1276ed0df0629a4
[2/5] examples/send-zc: option to bind socket to device
commit: 78d0ed571c1314d9506b446c72839800c21d873b
[3/5] examples/send-zc: optionally fill data with a pattern
commit: 1c6ed372b015bf237c03fba1f72b5cd06b1aa4b1
[4/5] examples/send-zc: record time on disconnect
commit: fb7248c4bae46eabef651367f43d13944c3cf8bb
[5/5] examples/zcrx: be more verbose on verification failure
commit: 7fd79781a239e403e182220a77dd0758d93d3ca0
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-04 16:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH liburing v2 3/5] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox