expand send / zc tests
PATCH 1/5 tests: improve zc cflags handling
In reply to Pavel BegunkovAdd a couple of tweaks, count nr_cqes on in the loop, so it's easier to adapt for other test cases.
--- test/send-zerocopy.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
test/send-zerocopy.c +10 -10
@@ -288,9 +288,9 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_seif (mix_register) real_fixed_buf =rand () &1 ; -if (cork && i != nr_reqs -1 ) +if (i != nr_reqs -1 ) msg_flags |=MSG_MORE ; -if (i == nr_reqs -1 ) +else cur_size = chunk_size_last; sqe =io_uring_get_sqe (ring);
@@ -335,7 +335,7 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_sereturn 1 ; } - nr_cqes =2 * nr_reqs +1 ; + nr_cqes = nr_reqs +1 ;for (i =0 ; i < nr_cqes; i++) {int expected = chunk_size;
@@ -352,13 +352,19 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_seio_uring_cqe_seen (ring, cqe);continue ; } - +if ((cqe->flags &IORING_CQE_F_MORE ) && (cqe->flags &IORING_CQE_F_NOTIF )) { +fprintf (stderr,"unexpected cflags %i res %i\n" , + cqe->flags, cqe->res); +return 1 ; + }if (cqe->user_data >= nr_reqs) {fprintf (stderr,"invalid user_data %lu\n" , (unsigned long )cqe->user_data);return 1 ; }if (!(cqe->flags &IORING_CQE_F_NOTIF )) { +if (cqe->flags &IORING_CQE_F_MORE ) + nr_cqes++;if (cqe->user_data == nr_reqs -1 ) expected = chunk_size_last;if (cqe->res != expected) {
@@ -367,12 +373,6 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_sereturn 1 ; } } -if ((cqe->flags &IORING_CQE_F_MORE ) == - (cqe->flags &IORING_CQE_F_NOTIF )) { -fprintf (stderr,"unexpected cflags %i res %i\n" , - cqe->flags, cqe->res); -return 1 ; - }io_uring_cqe_seen (ring, cqe); }
Signature · 1 line
2.38.0
cover expand send / zc tests
Patch 4 adds sendmsg testing with various iov lengths and configurations. Patch 5 tests IORING_RECVSEND_POLL_FIRST. And patch 3 enables same testing for non-zerocopy sends as we currently have poor coverage.
Pavel Begunkov (5):
tests: improve zc cflags handling
tests: pass params in a struct
tests: add non-zc tests in send-zerocopy.c
tests: add tests for retries with long iovec
tests: test poll_first
test/send-zerocopy.c | 188 ++++++++++++++++++++++++++++++------------- 1 file changed, 133 insertions(+), 55 deletions(-)
Signature · 1 line
2.38.0
PATCH 2/5 tests: pass params in a struct
--- test/send-zerocopy.c | 81 ++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 36 deletions(-)
test/send-zerocopy.c +45 -36
@@ -254,25 +254,34 @@ static int create_socketpair_ip(struct sockaddr_storage *addr,return 0 ; } +struct send_conf { +bool fixed_buf; +bool mix_register; +bool cork; +bool force_async; +bool use_sendmsg; +bool tcp; +int buf_index; +struct sockaddr_storage *addr; +}; +static int do_test_inet_send (struct io_uring *ring,int sock_client,int sock_server, -bool fixed_buf,struct sockaddr_storage *addr, -bool cork,bool mix_register, -int buf_idx,bool force_async,bool use_sendmsg) +struct send_conf *conf) {struct iovec iov[CORK_REQS ];struct msghdr msghdr[CORK_REQS ];const unsigned zc_flags =0 ;struct io_uring_sqe *sqe;struct io_uring_cqe *cqe; -int nr_reqs = cork ?CORK_REQS :1 ; +int nr_reqs = conf->cork ?CORK_REQS :1 ;int i, ret, nr_cqes, addr_len =0 ; -size_t send_size = buffers_iov[buf_idx].iov_len; +size_t send_size = buffers_iov[conf->buf_index].iov_len;size_t chunk_size = send_size / nr_reqs;size_t chunk_size_last = send_size - chunk_size * (nr_reqs -1 ); -char *buf = buffers_iov[buf_idx].iov_base; +char *buf = buffers_iov[conf->buf_index].iov_base; -if (addr) { -sa_family_t fam = ((struct sockaddr_in *)addr)->sin_family; +if (conf->addr) { +sa_family_t fam = ((struct sockaddr_in *)conf->addr)->sin_family; addr_len = (fam ==AF_INET ) ?sizeof (struct sockaddr_in ) :sizeof (struct sockaddr_in6 );
@@ -281,11 +290,11 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_sememset (rx_buffer,0 , send_size);for (i =0 ; i < nr_reqs; i++) { -bool real_fixed_buf = fixed_buf; +bool real_fixed_buf = conf->fixed_buf;size_t cur_size = chunk_size;int msg_flags =MSG_WAITALL ; -if (mix_register) +if (conf->mix_register) real_fixed_buf =rand () &1 ;if (i != nr_reqs -1 )
@@ -295,15 +304,15 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se sqe =io_uring_get_sqe (ring); -if (!use_sendmsg) { +if (!conf->use_sendmsg) {io_uring_prep_send_zc (sqe, sock_client, buf + i * chunk_size, cur_size, msg_flags, zc_flags);if (real_fixed_buf) { sqe->ioprio |=IORING_RECVSEND_FIXED_BUF ; - sqe->buf_index = buf_idx; + sqe->buf_index = conf->buf_index; } -if (addr) -io_uring_prep_send_set_addr (sqe, (const struct sockaddr *)addr, +if (conf->addr) +io_uring_prep_send_set_addr (sqe, (const struct sockaddr *)conf->addr, addr_len); }else {io_uring_prep_sendmsg_zc (sqe, sock_client, &msghdr[i], msg_flags);
@@ -313,13 +322,13 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se iov[i].iov_base = buf + i * chunk_size; msghdr[i].msg_iov = &iov[i]; msghdr[i].msg_iovlen =1 ; -if (addr) { - msghdr[i].msg_name = addr; +if (conf->addr) { + msghdr[i].msg_name = conf->addr; msghdr[i].msg_namelen = addr_len; } } sqe->user_data = i; -if (force_async) +if (conf->force_async) sqe->flags |=IOSQE_ASYNC ;if (i != nr_reqs -1 ) sqe->flags |=IOSQE_IO_LINK ;
@@ -388,6 +397,7 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_sestatic int test_inet_send (struct io_uring *ring) { +struct send_conf conf;struct sockaddr_storage addr;int sock_client =-1 , sock_server =-1 ;int ret, j, i;
@@ -409,35 +419,34 @@ static int test_inet_send(struct io_uring *ring) }for (i =0 ; i <256 ; i++) { -int buf_flavour = i &3 ; -bool fixed_buf = i &4 ; -struct sockaddr_storage *addr_arg = (i &8 ) ? &addr :NULL ; -bool cork = i &16 ; -bool mix_register = i &32 ; -bool force_async = i &64 ; -bool use_sendmsg = i &128 ; - -if (buf_flavour ==BUF_T_LARGE && !tcp) + conf.buf_index = i &3 ; + conf.fixed_buf = i &4 ; + conf.addr = (i &8 ) ? &addr :NULL ; + conf.cork = i &16 ; + conf.mix_register = i &32 ; + conf.force_async = i &64 ; + conf.use_sendmsg = i &128 ; + conf.tcp = tcp; + +if (conf.buf_index ==BUF_T_LARGE && !tcp)continue ; -if (!buffers_iov[buf_flavour].iov_base) +if (!buffers_iov[conf.buf_index].iov_base)continue ; -if (tcp && (cork || addr_arg)) +if (tcp && (conf.cork || conf.addr))continue ; -if (mix_register && (!cork || fixed_buf)) +if (conf.mix_register && (!conf.cork || conf.fixed_buf))continue ; -if (!client_connect && addr_arg ==NULL ) +if (!client_connect && conf.addr ==NULL )continue ; -if (use_sendmsg && (mix_register || fixed_buf || !has_sendmsg)) +if (conf.use_sendmsg && (conf.mix_register || conf.fixed_buf || !has_sendmsg))continue ; - ret =do_test_inet_send (ring, sock_client, sock_server, fixed_buf, - addr_arg, cork, mix_register, - buf_flavour, force_async, use_sendmsg); + ret =do_test_inet_send (ring, sock_client, sock_server, &conf);if (ret) {fprintf (stderr,"send failed fixed buf %i, conn %i, addr %i, " "cork %i\n" , - fixed_buf, client_connect, !!addr_arg, - cork); + conf.fixed_buf, client_connect, !!conf.addr, + conf.cork);return 1 ; } }
Signature · 1 line
2.38.0
PATCH 3/5 tests: add non-zc tests in send-zerocopy.c
In reply to Pavel BegunkovWe don't have good tests for normal non-zerocopy paths. Add them to test_inet_send(), which covers lots of different cases. We can move it into send_recv.c or so later.
--- test/send-zerocopy.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
test/send-zerocopy.c +27 -4
@@ -261,6 +261,7 @@ struct send_conf {bool force_async;bool use_sendmsg;bool tcp; +bool zc;int buf_index;struct sockaddr_storage *addr; };
@@ -305,8 +306,14 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se sqe =io_uring_get_sqe (ring);if (!conf->use_sendmsg) { -io_uring_prep_send_zc (sqe, sock_client, buf + i * chunk_size, - cur_size, msg_flags, zc_flags); +if (conf->zc) { +io_uring_prep_send_zc (sqe, sock_client, buf + i * chunk_size, + cur_size, msg_flags, zc_flags); + }else { +io_uring_prep_send (sqe, sock_client, buf + i * chunk_size, + cur_size, msg_flags); + } +if (real_fixed_buf) { sqe->ioprio |=IORING_RECVSEND_FIXED_BUF ; sqe->buf_index = conf->buf_index;
@@ -315,7 +322,10 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_seio_uring_prep_send_set_addr (sqe, (const struct sockaddr *)conf->addr, addr_len); }else { -io_uring_prep_sendmsg_zc (sqe, sock_client, &msghdr[i], msg_flags); +if (conf->zc) +io_uring_prep_sendmsg_zc (sqe, sock_client, &msghdr[i], msg_flags); +else +io_uring_prep_sendmsg (sqe, sock_client, &msghdr[i], msg_flags);memset (&msghdr[i],0 ,sizeof (msghdr[i])); iov[i].iov_len = cur_size;
@@ -418,7 +428,7 @@ static int test_inet_send(struct io_uring *ring)return 1 ; } -for (i =0 ; i <256 ; i++) { +for (i =0 ; i <512 ; i++) { conf.buf_index = i &3 ; conf.fixed_buf = i &4 ; conf.addr = (i &8 ) ? &addr :NULL ;
@@ -426,8 +436,19 @@ static int test_inet_send(struct io_uring *ring) conf.mix_register = i &32 ; conf.force_async = i &64 ; conf.use_sendmsg = i &128 ; + conf.zc = i &256 ; conf.tcp = tcp; +if (!conf.zc) { +if (conf.mix_register || conf.fixed_buf) +continue ; +/* +* Non zerocopy send w/ addr was added together with sendmsg_zc, +* skip if we the kernel doesn't support it. +*/ +if (conf.addr && !has_sendmsg) +continue ; + }if (conf.buf_index ==BUF_T_LARGE && !tcp)continue ;if (!buffers_iov[conf.buf_index].iov_base)
@@ -440,6 +461,8 @@ static int test_inet_send(struct io_uring *ring)continue ;if (conf.use_sendmsg && (conf.mix_register || conf.fixed_buf || !has_sendmsg))continue ; +if (msg_zc_set && !conf.zc) +continue ; ret =do_test_inet_send (ring, sock_client, sock_server, &conf);if (ret) {
Signature · 1 line
2.38.0
PATCH 4/5 tests: add tests for retries with long iovec
In reply to Pavel Begunkov--- test/send-zerocopy.c | 58 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-)
test/send-zerocopy.c +50 -8
@@ -44,6 +44,7 @@#define HOST "127.0.0.1"#define HOSTV6 "::1" +#define MAX_IOV 32#define CORK_REQS 5#define RX_TAG 10000#define BUFFER_OFFSET 41
@@ -262,6 +263,8 @@ struct send_conf {bool use_sendmsg;bool tcp;bool zc; +bool iovec; +bool long_iovec;int buf_index;struct sockaddr_storage *addr; };
@@ -269,7 +272,7 @@ struct send_conf {static int do_test_inet_send (struct io_uring *ring,int sock_client,int sock_server,struct send_conf *conf) { -struct iovec iov[CORK_REQS ]; +struct iovec iov[MAX_IOV ];struct msghdr msghdr[CORK_REQS ];const unsigned zc_flags =0 ;struct io_uring_sqe *sqe;
@@ -281,6 +284,8 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_sesize_t chunk_size_last = send_size - chunk_size * (nr_reqs -1 );char *buf = buffers_iov[conf->buf_index].iov_base; +assert (MAX_IOV >=CORK_REQS ); +if (conf->addr) {sa_family_t fam = ((struct sockaddr_in *)conf->addr)->sin_family;
@@ -322,16 +327,46 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_seio_uring_prep_send_set_addr (sqe, (const struct sockaddr *)conf->addr, addr_len); }else { +struct iovec *io; +int iov_len; +if (conf->zc)io_uring_prep_sendmsg_zc (sqe, sock_client, &msghdr[i], msg_flags);else io_uring_prep_sendmsg (sqe, sock_client, &msghdr[i], msg_flags); +if (!conf->iovec) { + io = &iov[i]; + iov_len =1 ; + iov[i].iov_len = cur_size; + iov[i].iov_base = buf + i * chunk_size; + }else { +char *it = buf; +int j; + +assert (nr_reqs ==1 ); + iov_len = conf->long_iovec ?MAX_IOV :4 ; + io = iov; + +for (j =0 ; j < iov_len; j++) + io[j].iov_len =1 ; +/* first want to be easily advanced */ + io[0 ].iov_base = it; + it += io[0 ].iov_len; +/* this should cause retry */ + io[1 ].iov_len = chunk_size - iov_len +1 ; + io[1 ].iov_base = it; + it += io[1 ].iov_len; +/* fill the rest */ +for (j =2 ; j < iov_len; j++) { + io[j].iov_base = it; + it += io[j].iov_len; + } + } +memset (&msghdr[i],0 ,sizeof (msghdr[i])); - iov[i].iov_len = cur_size; - iov[i].iov_base = buf + i * chunk_size; - msghdr[i].msg_iov = &iov[i]; - msghdr[i].msg_iovlen =1 ; + msghdr[i].msg_iov = io; + msghdr[i].msg_iovlen = iov_len;if (conf->addr) { msghdr[i].msg_name = conf->addr; msghdr[i].msg_namelen = addr_len;
@@ -428,7 +463,9 @@ static int test_inet_send(struct io_uring *ring)return 1 ; } -for (i =0 ; i <512 ; i++) { +for (i =0 ; i <2048 ; i++) { +bool regbuf; + conf.buf_index = i &3 ; conf.fixed_buf = i &4 ; conf.addr = (i &8 ) ? &addr :NULL ;
@@ -437,10 +474,15 @@ static int test_inet_send(struct io_uring *ring) conf.force_async = i &64 ; conf.use_sendmsg = i &128 ; conf.zc = i &256 ; + conf.iovec = i &512 ; + conf.long_iovec = i &1024 ; conf.tcp = tcp; + regbuf = conf.mix_register || conf.fixed_buf; +if (conf.iovec && (!conf.use_sendmsg || regbuf || conf.cork)) +continue ;if (!conf.zc) { -if (conf.mix_register || conf.fixed_buf) +if (regbuf)continue ;/* * Non zerocopy send w/ addr was added together with sendmsg_zc,
@@ -459,7 +501,7 @@ static int test_inet_send(struct io_uring *ring)continue ;if (!client_connect && conf.addr ==NULL )continue ; -if (conf.use_sendmsg && (conf.mix_register || conf.fixed_buf || !has_sendmsg)) +if (conf.use_sendmsg && (regbuf || !has_sendmsg))continue ;if (msg_zc_set && !conf.zc)continue ;
Signature · 1 line
2.38.0
PATCH 5/5 tests: test poll_first
In reply to Pavel Begunkov--- test/send-zerocopy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
test/send-zerocopy.c +5 -1
@@ -265,6 +265,7 @@ struct send_conf {bool zc;bool iovec;bool long_iovec; +bool poll_first;int buf_index;struct sockaddr_storage *addr; };
@@ -375,6 +376,8 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se sqe->user_data = i;if (conf->force_async) sqe->flags |=IOSQE_ASYNC ; +if (conf->poll_first) + sqe->ioprio |=IORING_RECVSEND_POLL_FIRST ;if (i != nr_reqs -1 ) sqe->flags |=IOSQE_IO_LINK ; }
@@ -463,7 +466,7 @@ static int test_inet_send(struct io_uring *ring)return 1 ; } -for (i =0 ; i <2048 ; i++) { +for (i =0 ; i <4096 ; i++) {bool regbuf; conf.buf_index = i &3 ;
@@ -476,6 +479,7 @@ static int test_inet_send(struct io_uring *ring) conf.zc = i &256 ; conf.iovec = i &512 ; conf.long_iovec = i &1024 ; + conf.poll_first = i &2048 ; conf.tcp = tcp; regbuf = conf.mix_register || conf.fixed_buf;
Signature · 1 line
2.38.0
Quoted 4 lines · Pavel Begunkov
Patch 4 adds sendmsg testing with various iov lengths and configurations. Patch 5 tests
IORING_RECVSEND_POLL_FIRST. And patch 3 enables same testing for non-zerocopy sends as we currently have poor coverage.
Quoted 8 lines
Pavel Begunkov (5):
tests: improve zc cflags handling
tests: pass params in a struct
tests: add non-zc tests insend-zerocopy.c
tests: add tests for retries with long iovec
tests: testpoll_first[...]
Applied, thanks!
[1/5] tests: improve zc cflags handling
(no commit info)
[2/5] tests: pass params in a struct
(no commit info)
[3/5] tests: add non-zc tests in send-zerocopy.c
(no commit info)
[4/5] tests: add tests for retries with long iovec
(no commit info)
[5/5] tests: test poll_first
(no commit info)
Best regards,
Signature · 1 line
Jens Axboe