add zcrx example
cover add zcrx example
We need a simple example for zcrx to show case how the api works and how to use features. Take the selftest and strip it off tx.
Anything supporting tcp can play a role of the sender, but for data verification (-v) it needs to follow the data pattern. Implement it in send-zerocopy -z0.
Pavel Begunkov (2):
examples/send-zerocopy: add data verification
examples: add a zcrx example
examples/Makefile | 1 + examples/send-zerocopy.c | 50 +++++- examples/zcrx.c | 362 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 410 insertions(+), 3 deletions(-) create mode 100644 examples/zcrx.c
Signature · 1 line
2.48.1
PATCH 1/2 examples/send-zerocopy: add data verification
Signed-off-by Pavel Begunkov <[email protected]>
--- examples/send-zerocopy.c | 50 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-)
examples/send-zerocopy.c +47 -3
@@ -58,6 +58,13 @@ struct thread_data {int fd; }; +enum { +VERIFY_DISABLED =0 , +VERIFY_SEQ , + + __MAX_VERIFY, +}; +static bool cfg_reg_ringfd = true;static bool cfg_fixed_files =1 ;static bool cfg_zc =1 ;
@@ -74,8 +81,8 @@ static int cfg_type = 0;static int cfg_payload_len;static int cfg_port =8000 ;static int cfg_runtime_ms =4200 ; +static int cfg_verify =0 ;static bool cfg_rx_poll = false; -static socklen_t cfg_alen;static char *str_addr =NULL ;
@@ -198,13 +205,30 @@ static int do_poll(int fd, int events)return ret && (pfd.revents & events); } +static void verify_buffer (struct thread_data *td,char *buffer,size_t size) +{ +size_t i; + +for (i =0 ; i < size; i++) { +char d = payload[i]; +char e = (td->bytes + i) %26 +'a' ; + +if (e != d) +t_error (1 , -EINVAL ,"data mismatch" ); + } +} +/* Flush all outstanding bytes for the tcp receive queue */ static int do_flush_tcp (struct thread_data *td,int fd) {int ret; +if (cfg_verify ==VERIFY_SEQ ) + ret =recv (fd, payload_buf,sizeof (payload_buf),0 ); +else + ret =recv (fd,NULL ,1 <<21 ,MSG_TRUNC |MSG_DONTWAIT ); +/* MSG_TRUNC flushes up to len bytes */ - ret =recv (fd,NULL ,1 <<21 ,MSG_TRUNC |MSG_DONTWAIT );if (ret ==-1 && errno ==EAGAIN )return 0 ;if (ret ==-1 )
@@ -212,6 +236,9 @@ static int do_flush_tcp(struct thread_data *td, int fd)if (!ret)return 1 ; +if (cfg_verify ==VERIFY_SEQ ) +verify_buffer (td, payload_buf, ret); + td->packets++; td->bytes += ret;return 0 ;
@@ -391,6 +418,11 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)unsigned buf_idx =0 ;unsigned msg_flags =MSG_WAITALL ; +if (cfg_verify) { +for (i =0 ; i < cfg_payload_len; i++) + payload[i] ='a' + ((i + td->bytes) %26 ); + } +for (i =0 ; i < cfg_nr_reqs; i++) { sqe =io_uring_get_sqe (&ring);
@@ -515,7 +547,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,"46v:D:p:s:t:n:z:b:l:dC:T:Ry" )) !=-1 ) {switch (c) {case '4' :if (cfg_family !=PF_UNSPEC )
@@ -570,9 +602,21 @@ static void parse_opts(int argc, char **argv)case 'y' : cfg_rx_poll =1 ;break ; +case 'v' : + cfg_verify =strtoul (optarg,NULL ,0 ); +break ; } } +if (cfg_verify >= __MAX_VERIFY) +t_error (1 ,0 ,"unsupported data verification type" ); +if (cfg_verify) { +if (!cfg_rx && cfg_zc) +t_error (1 ,0 ,"verification doesn't work with sendzc" ); +if (cfg_verify ==VERIFY_SEQ && cfg_nr_reqs >1 && !cfg_zc) +t_error (1 ,0 ,"sequence verification invalid inflight number" ); + } +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)
Signature · 1 line
2.48.1
PATCH 2/2 examples: add a zcrx example
In reply to Pavel BegunkovCopy-pasted from selftests/.../iou_zcrx.c by David.
Signed-off-by Pavel Begunkov <[email protected]>
--- examples/Makefile | 1 + examples/zcrx.c | 362 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 363 insertions(+) create mode 100644 examples/zcrx.c
examples/Makefile +1 -0
@@ -32,6 +32,7 @@ example_srcs := \ send-zerocopy.c \ rsrc-update-bench.c \ proxy.c \ + zcrx.c \ kdigest.c all_targets :=
examples/zcrx.c new file +362 -0
362 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH liburing 2/2] examples: add a zcrx example
On 4/9/25 18:58, Pavel Begunkov wrote:
...
Quoted 18 lines
examples/zcrx.c new file +18
-0+static void parse_opts (int argc,char **argv) +{ +struct sockaddr_in6 *addr6 = (void *) &cfg_addr; +int c; + +if (argc <=1 ) +usage (argv[0 ]); + +while ((c =getopt (argc, argv,"vp:i:q:o:" )) !=-1 ) { +switch (c) { +case 'p' : + cfg_port =strtoul (optarg,NULL ,0 ); +break ; +case 'i' : + cfg_ifname = optarg; +break ; +case 'o' : { + cfg_oneshot = true;
examples/zcrx.c line 348
Quoted 10 lines
examples/zcrx.c new file +10
-0+ cfg_oneshot_recvs =strtoul (optarg,NULL ,0 ); +break ; + } +case 'q' : + cfg_queue_id =strtoul (optarg,NULL ,0 ); +break ; + } +case 'v' : + cfg_verify_data = true; +break ;
Sth went wrong here, I'll need to resend.
Signature · 1 line
Pavel Begunkov