enchance zc benchmarks
v2 cover enchance zc benchmarks
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(-)
Signature · 1 line
2.48.1
PATCH v2 1/5 examples/send-zc: warn about data reordering
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.
--- examples/send-zerocopy.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
examples/send-zerocopy.c +13 -9
@@ -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++)
Signature · 1 line
2.48.1
PATCH v2 2/5 examples/send-zc: option to bind socket to device
In reply to Pavel BegunkovLet the user to specify the interface for tx.
--- examples/send-zerocopy.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
examples/send-zerocopy.c +17 -1
@@ -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" );
Signature · 1 line
2.48.1
PATCH v2 3/5 examples/send-zc: optionally fill data with a pattern
In reply to Pavel Begunkov-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.
--- examples/send-zerocopy.c | 70 ++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 21 deletions(-)
examples/send-zerocopy.c +49 -21
@@ -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;
Signature · 1 line
2.48.1
PATCH v2 4/5 examples/send-zc: record time on disconnect
In reply to Pavel BegunkovRecord 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.
--- examples/send-zerocopy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/send-zerocopy.c +2 -2
@@ -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" );
Signature · 1 line
2.48.1
PATCH v2 5/5 examples/zcrx: be more verbose on verification failure
In reply to Pavel BegunkovPrint additional info if data verification fails.
--- examples/zcrx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
examples/zcrx.c +2 -1
@@ -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); } }
Signature · 1 line
2.48.1
Quoted 8 lines · Pavel Begunkov
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: 7fd79781a239e403e182220a77dd0758d93d3ca0Best regards,
Signature · 1 line
Jens Axboe