vectored registered buffer support and tests
v2 cover vectored registered buffer support and tests
It should give good coverage, I plan to extend read-write.c to use it as well.
v2: Rename the new test
Fix helpers opcodes
Use the helper
Update map
Pavel Begunkov (4):
Add vectored registered buffer req init helpers
test/sendzc: test registered vectored buffers
tests/helpers: add t_create_socketpair_ip
tests: targeted registered vector tests
src/include/liburing.h | 31 +++ src/liburing-ffi.map | 3 + test/Makefile | 1 + test/helpers.c | 111 ++++++++ test/helpers.h | 5 + test/send-zerocopy.c | 138 ++-------- test/vec-regbuf.c | 605 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 780 insertions(+), 114 deletions(-) create mode 100644 test/vec-regbuf.c
Signature · 1 line
2.48.1
PATCH v2 1/4 Add vectored registered buffer req init helpers
--- src/include/liburing.h | 31 +++++++++++++++++++++++++++++++ src/liburing-ffi.map | 3 +++ 2 files changed, 34 insertions(+)
src/include/liburing.h +31 -0
@@ -556,6 +556,16 @@ IOURINGINLINE void io_uring_prep_read_fixed(struct io_uring_sqe *sqe, int fd, sqe->buf_index = (__u16 ) buf_index; } +IOURINGINLINE void io_uring_prep_readv_fixed(struct io_uring_sqe *sqe, int fd, +const struct iovec *iovecs, +unsigned nr_vecs,__u64 offset, +int flags,int buf_index) +{ +io_uring_prep_readv2 (sqe, fd, iovecs, nr_vecs, offset, flags); + sqe->opcode =IORING_OP_READV_FIXED ; + sqe->buf_index = (__u16 )buf_index; +} + IOURINGINLINE void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,const struct iovec *iovecs,unsigned nr_vecs,__u64 offset)
@@ -580,6 +590,16 @@ IOURINGINLINE void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd, sqe->buf_index = (__u16 ) buf_index; } +IOURINGINLINE void io_uring_prep_writev_fixed(struct io_uring_sqe *sqe, int fd, +const struct iovec *iovecs, +unsigned nr_vecs,__u64 offset, +int flags,int buf_index) +{ +io_uring_prep_writev2 (sqe, fd, iovecs, nr_vecs, offset, flags); + sqe->opcode =IORING_OP_WRITEV_FIXED ; + sqe->buf_index = (__u16 )buf_index; +} + IOURINGINLINE void io_uring_prep_recvmsg(struct io_uring_sqe *sqe, int fd,struct msghdr *msg,unsigned flags) {
@@ -964,6 +984,17 @@ IOURINGINLINE void io_uring_prep_sendmsg_zc(struct io_uring_sqe *sqe, int fd, sqe->opcode =IORING_OP_SENDMSG_ZC ; } +IOURINGINLINE void io_uring_prep_sendmsg_zc_fixed(struct io_uring_sqe *sqe, +int fd, +const struct msghdr *msg, +unsigned flags, +unsigned buf_index) +{ +io_uring_prep_sendmsg_zc (sqe, fd, msg, flags); + sqe->ioprio |=IORING_RECVSEND_FIXED_BUF ; + sqe->buf_index = buf_index; +} + IOURINGINLINE void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,void *buf,size_t len,int flags) {
src/liburing-ffi.map +3 -0
@@ -230,4 +230,7 @@ LIBURING_2.10 { global: io_uring_register_ifq; io_uring_prep_epoll_wait; + io_uring_prep_writev_fixed; + io_uring_prep_readv_fixed; + io_uring_prep_sendmsg_zc_fixed; } LIBURING_2.9;
Signature · 1 line
2.48.1
PATCH v2 2/4 test/sendzc: test registered vectored buffers
In reply to Pavel Begunkov--- test/send-zerocopy.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
test/send-zerocopy.c +13 -2
@@ -69,6 +69,7 @@ static size_t page_sz;static char *tx_buffer, *rx_buffer;static struct iovec buffers_iov[__BUF_NR]; +static bool has_regvec;static bool has_sendzc;static bool has_sendmsg;static bool hit_enomem;
@@ -96,6 +97,7 @@ static int probe_zc_support(void) has_sendzc = p->ops_len >IORING_OP_SEND_ZC ; has_sendmsg = p->ops_len >IORING_OP_SENDMSG_ZC ; + has_regvec = p->ops_len >IORING_OP_READV_FIXED ;io_uring_queue_exit (&ring);free (p);return 0 ;
@@ -448,6 +450,11 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_seelse io_uring_prep_sendmsg (sqe, sock_client, &msghdr[i], msg_flags); +if (real_fixed_buf) { + sqe->ioprio |=IORING_RECVSEND_FIXED_BUF ; + sqe->buf_index = conf->buf_index; + } +if (!conf->iovec) { io = &iov[i]; iov_len =1 ;
@@ -619,7 +626,11 @@ static int test_inet_send(struct io_uring *ring) conf.tcp = tcp; regbuf = conf.mix_register || conf.fixed_buf; -if (conf.iovec && (!conf.use_sendmsg || regbuf || conf.cork)) +if (!tcp && conf.long_iovec) +continue ; +if (conf.use_sendmsg && regbuf && !has_regvec) +continue ; +if (conf.iovec && (!conf.use_sendmsg || conf.cork))continue ;if (!conf.zc) {if (regbuf)
@@ -637,7 +648,7 @@ static int test_inet_send(struct io_uring *ring)continue ;if (!client_connect && conf.addr ==NULL )continue ; -if (conf.use_sendmsg && (regbuf || !has_sendmsg)) +if (conf.use_sendmsg && !has_sendmsg)continue ;if (msg_zc_set && !conf.zc)continue ;
Signature · 1 line
2.48.1
PATCH v2 3/4 tests/helpers: add t_create_socketpair_ip
In reply to Pavel Begunkovcreate_socketpair_ip() is useful for zerocopy tx testing as it needs TCP sockets and not just AF_UNIX. There will be tx zc tests in more files, so move the function to helpers.
--- test/helpers.c | 111 ++++++++++++++++++++++++++++++++++++++ test/helpers.h | 5 ++ test/send-zerocopy.c | 123 ++++--------------------------------------- 3 files changed, 127 insertions(+), 112 deletions(-)
test/helpers.c +111 -0
@@ -373,3 +373,114 @@ void *aligned_alloc(size_t alignment, size_t size)return ret; } + +int t_create_socketpair_ip (struct sockaddr_storage *addr, +int *sock_client,int *sock_server, +bool ipv6,bool client_connect, +bool msg_zc,bool tcp,const char *name) +{ +socklen_t addr_size; +int family, sock, listen_sock =-1 ; +int ret; + +memset (addr,0 ,sizeof (*addr)); +if (ipv6) { +struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; + + family =AF_INET6 ; + saddr->sin6_family = family; + saddr->sin6_port =htons (0 ); + addr_size =sizeof (*saddr); + }else { +struct sockaddr_in *saddr = (struct sockaddr_in *)addr; + + family =AF_INET ; + saddr->sin_family = family; + saddr->sin_port =htons (0 ); + saddr->sin_addr.s_addr =htonl (INADDR_ANY ); + addr_size =sizeof (*saddr); + } + +/* server sock setup */ +if (tcp) { + sock = listen_sock =socket (family,SOCK_STREAM ,IPPROTO_TCP ); + }else { + sock = *sock_server =socket (family,SOCK_DGRAM ,0 ); + } +if (sock <0 ) { +perror ("socket" ); +return 1 ; + } + + ret =bind (sock, (struct sockaddr *)addr, addr_size); +if (ret <0 ) { +perror ("bind" ); +return 1 ; + } + + ret =getsockname (sock, (struct sockaddr *)addr, &addr_size); +if (ret <0 ) { +fprintf (stderr,"getsockname failed %i\n" , errno); +return 1 ; + } + +if (tcp) { + ret =listen (sock,128 ); +assert (ret !=-1 ); + } + +if (ipv6) { +struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; + +inet_pton (AF_INET6 , name, &(saddr->sin6_addr)); + }else { +struct sockaddr_in *saddr = (struct sockaddr_in *)addr; + +inet_pton (AF_INET , name, &saddr->sin_addr); + } + +/* client sock setup */ +if (tcp) { + *sock_client =socket (family,SOCK_STREAM ,IPPROTO_TCP ); +assert (client_connect); + }else { + *sock_client =socket (family,SOCK_DGRAM ,0 ); + } +if (*sock_client <0 ) { +perror ("socket" ); +return 1 ; + } +if (client_connect) { + ret =connect (*sock_client, (struct sockaddr *)addr, addr_size); +if (ret <0 ) { +perror ("connect" ); +return 1 ; + } + } +if (msg_zc) { +#ifdef SO_ZEROCOPY +int val =1 ; + +/* +* NOTE: apps must not set SO_ZEROCOPY when using io_uring zc. +* It's only here to test interactions with MSG_ZEROCOPY. +*/ +if (setsockopt (*sock_client,SOL_SOCKET ,SO_ZEROCOPY , &val,sizeof (val))) { +perror ("setsockopt zc" ); +return 1 ; + } +#else +fprintf (stderr,"no SO_ZEROCOPY\n" ); +return 1 ; +#endif + } +if (tcp) { + *sock_server =accept (listen_sock,NULL ,NULL ); +if (!*sock_server) { +fprintf (stderr,"can't accept\n" ); +return 1 ; + } +close (listen_sock); + } +return 0 ; +}
test/helpers.h +5 -0
@@ -81,6 +81,11 @@ struct iovec *t_create_buffers(size_t buf_num, size_t buf_size);*/ int t_create_socket_pair (int fd[2 ],bool stream); +int t_create_socketpair_ip (struct sockaddr_storage *addr, +int *sock_client,int *sock_server, +bool ipv6,bool client_connect, +bool msg_zc,bool tcp,const char *name); +/* * Helper for setting up a ring and checking for user privs */
test/send-zerocopy.c +11 -112
141 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v2 4/4 tests: targeted registered vector tests
In reply to Pavel BegunkovThe main part here is to exercise various iovec->bvec reallocation scenarios, but it also checks edge cases and validates final data.
--- test/Makefile | 1 + test/vec-regbuf.c | 605 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 606 insertions(+) create mode 100644 test/vec-regbuf.c
test/Makefile +1 -0
@@ -241,6 +241,7 @@ test_srcs := \ wq-aff.c \ xattr.c \ zcrx.c \ + vec-regbuf.c \ # EOL # Please keep this list sorted alphabetically.
test/vec-regbuf.c new file +605 -0
605 lines not on this page · raw message
Signature · 1 line
2.48.1
Quoted 9 lines · Pavel Begunkov
It should give good coverage, I plan to extend
read-write.cto use it as well.v2: Rename the new test
Fix helpers opcodes
Use the helper
Update map[...]
Applied, thanks!
[1/4] Add vectored registered buffer req init helpers
commit: d3540589b4ea399af71aa1dd616a64afca590a60
[2/4] test/sendzc: test registered vectored buffers
commit: 24f835c083eeea1e03e11a86042155b7f3068f11
[3/4] tests/helpers: add t_create_socketpair_ip
commit: 8b9a92ac1bd3b8c752fc52e9590cd18fda14ac8a
[4/4] tests: targeted registered vector tests
commit: b5b2e9f064b16a8f2390d52a0f290152c14a84d2Best regards,
Signature · 1 line
Jens Axboe