zcrx example and other changes
cover zcrx example and other changes
We need a simple example for zcrx to show case how the api works and how to use features. Patch 5 is a brushed up version of the zcrx selftest.
Apart from that update headers and use the kernel return zcrx id.
Pavel Begunkov (5):
Update io_uring.h for zcrx
tests/zcrx: rename a test
tests/zcrx: use returned right zcrx id
examples: add extra helpers
examples: add a zcrx example
examples/Makefile | 1 + examples/helpers.c | 15 ++ examples/helpers.h | 6 + examples/zcrx.c | 335 ++++++++++++++++++++++++++++++++ src/include/liburing/io_uring.h | 4 +- test/zcrx.c | 21 +- 6 files changed, 372 insertions(+), 10 deletions(-) create mode 100644 examples/zcrx.c
Signature · 1 line
2.48.1
PATCH 1/5 Update io_uring.h for zcrx
Pull in an updated version if struct io_uring_zcrx_ifq_reg
--- src/include/liburing/io_uring.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/include/liburing/io_uring.h +3 -1
@@ -977,7 +977,9 @@ struct io_uring_zcrx_ifq_reg {__u64 region_ptr;/* struct io_uring_region_desc * */ struct io_uring_zcrx_offsets offsets; -__u64 __resv[4 ]; +__u32 zcrx_id; +__u32 __resv2; +__u64 __resv[3 ]; };#ifdef __cplusplus
Signature · 1 line
2.48.1
PATCH 2/5 tests/zcrx: rename a test
In reply to Pavel BegunkovThere should've been some mishap for a test to be called "test_invalid_invalid_request", rename it.
--- test/zcrx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
test/zcrx.c +2 -2
@@ -401,7 +401,7 @@ static struct io_uring_cqe *submit_and_wait_one(struct io_uring *ring)return cqe; } -static int test_invalid_invalid_request (void *area) +static int test_invalid_zcrx_request (void *area) {struct io_uring_cqe *cqe;struct io_uring_sqe *sqe;
@@ -901,7 +901,7 @@ int main(int argc, char *argv[])return ret; } - ret =test_invalid_invalid_request (area); + ret =test_invalid_zcrx_request (area);if (ret) {fprintf (stderr,"test_invalid_ifq_collision failed\n" );return ret;
Signature · 1 line
2.48.1
PATCH 3/5 tests/zcrx: use returned right zcrx id
In reply to Pavel BegunkovNow we return the zcrx id back to the user, use it.
--- test/zcrx.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
test/zcrx.c +10 -7
@@ -344,7 +344,7 @@ static int test_area_access(void)return T_EXIT_PASS ; } -static int create_ring_with_ifq (struct io_uring *ring,void *area) +static int create_ring_with_ifq (struct io_uring *ring,void *area,__u32 *id) {struct io_uring_zcrx_area_reg area_reg = { .addr = (__u64 )(unsigned long )area,
@@ -371,6 +371,7 @@ static int create_ring_with_ifq(struct io_uring *ring, void *area)fprintf (stderr,"ifq register failed %d\n" , ret);return T_EXIT_FAIL ; } + *id = reg.zcrx_id;return 0 ; }
@@ -406,9 +407,10 @@ static int test_invalid_zcrx_request(void *area)struct io_uring_cqe *cqe;struct io_uring_sqe *sqe;struct io_uring ring; +__u32 zcrx_id;int ret, fds[2 ]; - ret =create_ring_with_ifq (&ring, area); + ret =create_ring_with_ifq (&ring, area, &zcrx_id);if (ret !=T_SETUP_OK ) {fprintf (stderr,"ifq-ring create failed: %d\n" , ret);return T_EXIT_FAIL ;
@@ -422,7 +424,7 @@ static int test_invalid_zcrx_request(void *area)/* invalid file */ sqe =io_uring_get_sqe (&ring); -test_io_uring_prep_zcrx (sqe, ring.ring_fd,0 ); +test_io_uring_prep_zcrx (sqe, ring.ring_fd, zcrx_id); cqe =submit_and_wait_one (&ring);if (!cqe) {
@@ -441,7 +443,7 @@ static int test_invalid_zcrx_request(void *area)/* invalid ifq idx */ sqe =io_uring_get_sqe (&ring); -test_io_uring_prep_zcrx (sqe, fds[0 ],1 ); +test_io_uring_prep_zcrx (sqe, fds[0 ], zcrx_id +1 ); cqe =submit_and_wait_one (&ring);if (!cqe) {
@@ -478,7 +480,8 @@ struct recv_data {struct io_uring_zcrx_rq rq_ring; }; -static int recv_prep (struct io_uring *ring,struct recv_data *rd,int *sock) +static int recv_prep (struct io_uring *ring,struct recv_data *rd,int *sock, +__u32 zcrx_id) {struct sockaddr_in saddr;struct io_uring_sqe *sqe;
@@ -526,7 +529,7 @@ static int recv_prep(struct io_uring *ring, struct recv_data *rd, int *sock) sqe =io_uring_get_sqe (ring);io_uring_prep_rw (IORING_OP_RECV_ZC , sqe, use_fd,NULL ,0 ,0 ); - sqe->zcrx_ifq_idx =0 ; + sqe->zcrx_ifq_idx = zcrx_id; sqe->ioprio |=IORING_RECV_MULTISHOT ; sqe->user_data =2 ;
@@ -693,7 +696,7 @@ static void *recv_fn(void *data) rd->rq_ring.rq_tail =0 ; rd->rq_ring.ring_entries = reg.rq_entries; - ret =recv_prep (&ring, rd, &sock); + ret =recv_prep (&ring, rd, &sock, reg.zcrx_id);if (ret) {fprintf (stderr,"recv_prep failed: %d\n" , ret); goto err;
Signature · 1 line
2.48.1
PATCH 4/5 examples: add extra helpers
In reply to Pavel Begunkov--- examples/helpers.c | 15 +++++++++++++++ examples/helpers.h | 6 ++++++ 2 files changed, 21 insertions(+)
examples/helpers.c +15 -0
@@ -9,6 +9,7 @@#include <sys/socket.h> #include <sys/time.h> #include <unistd.h> +#include <stdarg.h> #include "helpers.h"
@@ -70,3 +71,17 @@ void *aligned_alloc(size_t alignment, size_t size)return ret; } + +void t_error (int status,int errnum,const char *format, ...) +{ +va_list args; +va_start (args, format); + +vfprintf (stderr, format, args); +if (errnum) +fprintf (stderr,": %s" ,strerror (errnum)); + +fprintf (stderr,"\n" ); +va_end (args); +exit (status); +}
examples/helpers.h +6 -0
@@ -2,6 +2,10 @@#ifndef LIBURING_EX_HELPERS_H #define LIBURING_EX_HELPERS_H +#include <stddef.h> + +#define T_ALIGN_UP (v, align) (((v) + (align) - 1) & ~((align) - 1)) +int setup_listening_socket (int port,int ipv6);/*
@@ -11,4 +15,6 @@ int setup_listening_socket(int port, int ipv6);*/ void *aligned_alloc (size_t alignment,size_t size); +void t_error (int status,int errnum,const char *format, ...); +#endif
Signature · 1 line
2.48.1
PATCH 5/5 examples: add a zcrx example
In reply to Pavel BegunkovCopy-pasted from selftests/.../iou_zcrx.c by David and brushed up on top.
--- examples/Makefile | 1 + examples/zcrx.c | 335 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 336 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 +335 -0
335 lines not on this page · raw message
Signature · 1 line
2.48.1
Quoted 6 lines · Pavel Begunkov
We need a simple example for zcrx to show case how the api works and how to use features. Patch 5 is a brushed up version of the zcrx selftest.
Apart from that update headers and use the kernel return zcrx id.
Quoted 8 lines
Pavel Begunkov (5):
Updateio_uring.hfor zcrx
tests/zcrx: rename a test
tests/zcrx: use returned right zcrx id
examples: add extra helpers
examples: add a zcrx example[...]
Applied, thanks!
[1/5] Update io_uring.h for zcrx
(no commit info)
[2/5] tests/zcrx: rename a test
(no commit info)
[3/5] tests/zcrx: use returned right zcrx id
(no commit info)
[4/5] examples: add extra helpers
(no commit info)
[5/5] examples: add a zcrx example
(no commit info)
Best regards,
Signature · 1 line
Jens Axboe