io_uring/zcrx: add CQE based notifications and stats reporting
Subsystems (6)
cover io_uring/zcrx: add CQE based notifications and stats reporting
The zcrx path can encounter various conditions that lead to internal fallbacks or errors. These errors can have a large impact on performance and functionality but are not yet not being reported to the user which is then unable to take action.
This series addresses this problem by adding a new notification system paired with a statistics structure. The notification system currently report out of buffer and packets that fallback to copy. The statistics structure report the number and total size of packets that were copied rather than received via the zero-copy path.
The out of buffer notification allows the user to actually adjust the buffer sizing when registering zcrx support for the ifq. Some future work could allow the user to add more memory on the fly to the pool so the page allocator doesn't run out of memory.
This series can be tested using the include kselftest modification and using the liburing series that updates headers and tests/examples so that it uses notifications and statistics.
Clément Léger (4):
io_uring/zcrx: notify user on frag copy fallback io_uring/zcrx: add shared-memory notification statistics
Documentation: networking: document zcrx notifications and statistics
selftests: iou-zcrx: add notification and stats test for zcrx
Pavel Begunkov (1):
io_uring/zcrx: notify user when out of buffers
Documentation/networking/iou-zcrx.rst | 106 ++++++++++++ include/uapi/linux/io_uring/query.h | 12 ++ include/uapi/linux/io_uring/zcrx.h | 34 +++- io_uring/query.c | 14 ++ io_uring/zcrx.c | 151 +++++++++++++++++- io_uring/zcrx.h | 13 +- .../selftests/drivers/net/hw/iou-zcrx.c | 112 +++++++++++-- .../selftests/drivers/net/hw/iou-zcrx.py | 49 +++++- 8 files changed, 475 insertions(+), 16 deletions(-)
Signature · 1 line
Clément Léger
PATCH 1/5 io_uring/zcrx: notify user when out of buffers
From: Pavel Begunkov <[email protected]>
There are currently no easy ways for the user to know if zcrx is out of buffers and page pool fails to allocate. Add uapi for zcrx to communicate it back.
It's implemented as a separate CQE, which for now is posted to the creator ctx. To use it, on registration the user space needs to pass an instance of struct zcrx_notification_desc, which tells the kernel the user_data for resulting CQEs and which event types are expected / allowed.
When an allowed event happens, zcrx will post a CQE containing the specified user_data, and lower bits of cqe->res will be set to the event mask. Before the kernel could post another notification of the given type, the user needs to acknowledge that it processed the previous one by issuing IORING_REGISTER_ZCRX_CTRL with ZCRX_CTRL_ARM_NOTIFICATION.
The only notification type the patch implements yet is ZCRX_NOTIF_NO_BUFFERS. Next commit adds copy fallback signaling.
--- include/uapi/linux/io_uring/zcrx.h | 22 ++++++- io_uring/zcrx.c | 98 +++++++++++++++++++++++++++++- io_uring/zcrx.h | 11 +++- 3 files changed, 128 insertions(+), 3 deletions(-)
include/uapi/linux/io_uring/zcrx.h +21 -1
@@ -65,6 +65,18 @@ enum zcrx_features {* value in struct io_uring_zcrx_ifq_reg::rx_buf_len. */ ZCRX_FEATURE_RX_PAGE_SIZE =1 <<0 , + ZCRX_FEATURE_NOTIFICATION = 1 << 1, +}; + +enum zcrx_notification_type { +ZCRX_NOTIF_NO_BUFFERS =1 <<0 , +}; + +struct zcrx_notification_desc { +__u64 user_data; +__u32 type_mask; +__u32 __resv1; +__u64 __resv2[10 ]; };/*
@@ -82,12 +94,14 @@ struct io_uring_zcrx_ifq_reg {struct io_uring_zcrx_offsets offsets;__u32 zcrx_id;__u32 rx_buf_len; -__u64 __resv[3 ]; +__u64 notif_desc;/* see struct zcrx_notification_desc */ +__u64 __resv[2 ]; };enum zcrx_ctrl_op {ZCRX_CTRL_FLUSH_RQ ,ZCRX_CTRL_EXPORT , +ZCRX_CTRL_ARM_NOTIFICATION , __ZCRX_CTRL_LAST, };
@@ -101,6 +115,11 @@ struct zcrx_ctrl_export {__u32 __resv1[11 ]; }; +struct zcrx_ctrl_arm_notif { +__u32 type_mask; +__u32 __resv[11 ]; +}; +struct zcrx_ctrl {__u32 zcrx_id;__u32 op;/* see enum zcrx_ctrl_op */
@@ -109,6 +128,7 @@ struct zcrx_ctrl {union {struct zcrx_ctrl_export zc_export;struct zcrx_ctrl_flush_rq zc_flush; +struct zcrx_ctrl_arm_notif zc_arm_notif; }; };
io_uring/zcrx.c +97 -1
175 lines not on this page · raw message
io_uring/zcrx.h +10 -1
@@ -9,7 +9,9 @@#include <net/net_trackers.h> #define ZCRX_SUPPORTED_REG_FLAGS (ZCRX_REG_IMPORT | ZCRX_REG_NODEV) -#define ZCRX_FEATURES (ZCRX_FEATURE_RX_PAGE_SIZE) +#define ZCRX_FEATURES (ZCRX_FEATURE_RX_PAGE_SIZE |\ + ZCRX_FEATURE_NOTIFICATION) +#define ZCRX_NOTIF_TYPE_MASK (ZCRX_NOTIF_NO_BUFFERS)struct io_zcrx_mem {unsigned long size;
@@ -72,6 +74,13 @@ struct io_zcrx_ifq {*/ struct mutex pp_lock;struct io_mapped_region rq_region; + +/* Locks the access to notifification context data */ +spinlock_t ctx_lock; +struct io_ring_ctx *master_ctx; +u32 allowed_notif_mask; +u32 fired_notifs; +u64 notif_data; };#if defined(CONFIG_IO_URING_ZCRX )
Signature · 1 line
2.52.0
Pavel Begunkov
maintainerRe: [PATCH 1/5] io_uring/zcrx: notify user when out of buffers
Quoted 1 line · Clément Léger
From: Pavel Begunkov <[email protected]>
...
io_uring/zcrx.c static unsigned io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *if · line 1134
Quoted 9 lines
io_uring/zcrx.c +9
-0+static void zcrx_notif_tw (struct io_tw_req tw_req,io_tw_token_t tw) +{ +struct io_kiocb *req = tw_req.req; +struct io_ring_ctx *ctx = req->ctx; + +io_post_aux_cqe (ctx, req->cqe.user_data, req->cqe.res,0 ); +percpu_ref_put (&ctx->refs); +kfree_rcu (req, rcu_head); +}
Note to myself:
io_poison_req(req);kmem_cache_free(req_cachep, req);
Signature · 1 line
Pavel Begunkov
Pavel Begunkov
maintainerRe: [PATCH 1/5] io_uring/zcrx: notify user when out of buffers
In reply to Clément LégerQuoted 1 line · Clément Léger
From: Pavel Begunkov <[email protected]>
...> static inline struct page *io_zcrx_iov_page(const struct net_iov *niov)
Quoted 11 lines
{ struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);io_uring/zcrx.c +1
-0@@ -531,6 +541,7 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) ifq->if_rxq =-1 ;spin_lock_init (&ifq->rq.lock); +spin_lock_init (&ifq->ctx_lock);mutex_init (&ifq->pp_lock);refcount_set (&ifq->refs,1 );refcount_set (&ifq->user_refs,1 );
io_uring/zcrx.c static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) · line 603
Quoted 8 lines
io_uring/zcrx.c +5
-0@@ -585,6 +596,11 @@ static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq)if (ifq->dev)put_device (ifq->dev); + scoped_guard(spinlock_bh, &ifq->ctx_lock) { +if (ifq->master_ctx) +percpu_ref_put (&ifq->master_ctx->refs); + } +
Something very odd happened here. It's not my patch but rather an edited squash of two other patches. This particular hunk creates a circular dependency, i.e. io_uring waits for this reference to be put down before destroying the zcrx instance that triggers io_zcrx_ifq_free.
Signature · 1 line
Pavel Begunkov
PATCH 2/5 io_uring/zcrx: notify user on frag copy fallback
In reply to Clément LégerAdd a ZCRX_NOTIF_COPY notification type to signal userspace when a received fragment could not be delivered using zero-copy and was instead copied into a buffer.
--- include/uapi/linux/io_uring/zcrx.h | 1 + io_uring/zcrx.c | 7 ++++++- io_uring/zcrx.h | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-)
include/uapi/linux/io_uring/zcrx.h +1 -0
@@ -70,6 +70,7 @@ enum zcrx_features {enum zcrx_notification_type {ZCRX_NOTIF_NO_BUFFERS =1 <<0 , +ZCRX_NOTIF_COPY =1 <<1 };struct zcrx_notification_desc {
io_uring/zcrx.c +6 -1
@@ -1510,8 +1510,13 @@ static int io_zcrx_copy_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, const skb_frag_t *frag, int off, int len) { struct page *page = skb_frag_page(frag); +int ret; + + ret =io_zcrx_copy_chunk (req, ifq, page, off +skb_frag_off (frag), len); +if (ret >0 ) +zcrx_send_notif (ifq,ZCRX_NOTIF_COPY ); -return io_zcrx_copy_chunk (req, ifq, page, off +skb_frag_off (frag), len); +return ret; } static int io_zcrx_recv_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
io_uring/zcrx.h +2 -1
@@ -11,7 +11,8 @@#define ZCRX_SUPPORTED_REG_FLAGS (ZCRX_REG_IMPORT | ZCRX_REG_NODEV)#define ZCRX_FEATURES (ZCRX_FEATURE_RX_PAGE_SIZE |\ ZCRX_FEATURE_NOTIFICATION) -#define ZCRX_NOTIF_TYPE_MASK (ZCRX_NOTIF_NO_BUFFERS) +#define ZCRX_NOTIF_TYPE_MASK (ZCRX_NOTIF_NO_BUFFERS |\ + ZCRX_NOTIF_COPY)struct io_zcrx_mem {unsigned long size;
Signature · 1 line
2.52.0
Pavel Begunkov
maintainerRe: [PATCH 2/5] io_uring/zcrx: notify user on frag copy fallback
Quoted 28 lines · Clément Léger
Add a
ZCRX_NOTIF_COPYnotification type to signal userspace when a received fragment could not be delivered using zero-copy and was instead copied into a buffer.Signed-off-by Clément Léger <[email protected]>--- include/uapi/linux/io_uring/zcrx.h | 1 + io_uring/zcrx.c | 7 ++++++- io_uring/zcrx.h | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-)include/uapi/linux/io_uring/zcrx.h +1
-0@@ -70,6 +70,7 @@ enum zcrx_features {enum zcrx_notification_type {ZCRX_NOTIF_NO_BUFFERS =1 <<0 , +ZCRX_NOTIF_COPY =1 <<1 };struct zcrx_notification_desc {io_uring/zcrx.c +0
-0
io_uring/zcrx.c static int io_zcrx_copy_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, · line 1517
Quoted 8 lines
io_uring/zcrx.c +5
-0@@ -1510,8 +1510,13 @@ static int io_zcrx_copy_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, const skb_frag_t *frag, int off, int len) { struct page *page = skb_frag_page(frag); +int ret; + + ret =io_zcrx_copy_chunk (req, ifq, page, off +skb_frag_off (frag), len); +if (ret >0 ) +zcrx_send_notif (ifq,ZCRX_NOTIF_COPY );
We also copy the linear part if present, depends on the semantics would make sense adding it there as well.
Pavel Begunkov
PATCH 3/5 io_uring/zcrx: add shared-memory notification statistics
In reply to Clément LégerAdd support for an optional stats struct embedded in the refill queue region, allowing userspace to monitor copy-fallback and no-buffers events in real-time.
Userspace queries the stats struct size and alignment via IO_URING_QUERY_ZCRX (notif_stats_size / notif_stats_alignment), then provides a stats_offset in zcrx_notification_desc pointing to a location within the refill queue region.
The kernel updates the stats counters in-place using atomic ops on every copy-fallback and no-buffers event.
--- include/uapi/linux/io_uring/query.h | 12 +++++++ include/uapi/linux/io_uring/zcrx.h | 15 +++++++-- io_uring/query.c | 14 ++++++++ io_uring/zcrx.c | 50 +++++++++++++++++++++++++++-- io_uring/zcrx.h | 1 + 5 files changed, 88 insertions(+), 4 deletions(-)
include/uapi/linux/io_uring/query.h +12 -0
@@ -23,6 +23,7 @@ enum {IO_URING_QUERY_OPCODES =0 ,IO_URING_QUERY_ZCRX =1 ,IO_URING_QUERY_SCQ =2 , +IO_URING_QUERY_ZCRX_NOTIF =3 , __IO_URING_QUERY_MAX, };
@@ -62,6 +63,17 @@ struct io_uring_query_zcrx {__u64 __resv2; }; +struct io_uring_query_zcrx_notif { +/* Bitmask of supported ZCRX_NOTIF_* flags*/ +__u32 notif_flags; +/* Size of io_uring_zcrx_notif_stats */ +__u32 notif_stats_size; +/* Required alignment for the stats struct within the region (ie stats_offset) */ +__u32 notif_stats_off_alignment; +__u32 resv1; +__u64 __resv2[10 ]; +}; +struct io_uring_query_scq {/* The SQ/CQ rings header size */ __u64 hdr_size;
include/uapi/linux/io_uring/zcrx.h +13 -2
@@ -73,11 +73,22 @@ enum zcrx_notification_type { ZCRX_NOTIF_COPY = 1 << 1 }; +enum zcrx_notification_desc_flags { +/* If set, stats_offset holds a valid offset to a notif_stats struct */ +ZCRX_NOTIF_DESC_FLAG_STATS =1 <<0 , +}; + +struct io_uring_zcrx_notif_stats { +__u64 copy_count;/* cumulative copy-fallback CQEs */ +__u64 copy_bytes;/* cumulative bytes copied */ +}; +struct zcrx_notification_desc {__u64 user_data;__u32 type_mask; -__u32 __resv1; -__u64 __resv2[10 ]; +__u32 flags;/* see enum zcrx_notification_desc_flags */ +__u64 stats_offset;/* offset from the beginning of refill ring region for stats */ +__u64 __resv2[9 ]; };/*
io_uring/query.c +14 -0
@@ -9,6 +9,7 @@union io_query_data {struct io_uring_query_opcode opcodes;struct io_uring_query_zcrx zcrx; +struct io_uring_query_zcrx_notif zcrx_notif;struct io_uring_query_scq scq; };
@@ -44,6 +45,16 @@ static ssize_t io_query_zcrx(union io_query_data *data)return sizeof (*e); } +static ssize_t io_query_zcrx_notif (union io_query_data *data) +{ +struct io_uring_query_zcrx_notif *e = &data->zcrx_notif; + + e->notif_flags =ZCRX_NOTIF_TYPE_MASK ; + e->notif_stats_size =sizeof (struct io_uring_zcrx_notif_stats ); + e->notif_stats_off_alignment = __alignof__(struct io_uring_zcrx_notif_stats ); +return sizeof (*e); +} +static ssize_t io_query_scq (union io_query_data *data) {struct io_uring_query_scq *e = &data->scq;
@@ -83,6 +94,9 @@ static int io_handle_query_entry(union io_query_data *data, void __user *uhdr,case IO_URING_QUERY_ZCRX : ret =io_query_zcrx (data);break ; +case IO_URING_QUERY_ZCRX_NOTIF : + ret =io_query_zcrx_notif (data); +break ;case IO_URING_QUERY_SCQ : ret =io_query_scq (data);break ;
io_uring/zcrx.c +48 -2
87 lines not on this page · raw message
io_uring/zcrx.h +1 -0
@@ -82,6 +82,7 @@ struct io_zcrx_ifq {u32 allowed_notif_mask;u32 fired_notifs;u64 notif_data; +struct io_uring_zcrx_notif_stats *notif_stats; };#if defined(CONFIG_IO_URING_ZCRX )
Signature · 1 line
2.52.0
PATCH 4/5 Documentation: networking: document zcrx notifications and statistics
In reply to Clément LégerDocument the zcrx notification system and shared-memory statistics that were introduced to let userspace monitor zero-copy receive health. The notification section covers the two notification types (ZCRX_NOTIF_NO_BUFFERS, ZCRX_NOTIF_COPY), registration via zcrx_notification_desc, and the fire-once / re-arm mechanism via ZCRX_CTRL_ARM_NOTIFICATION. The statistics section covers the optional shared-memory io_uring_zcrx_notif_stats structure placed in the refill ring region, including how to query its layout via IO_URING_QUERY_ZCRX_NOTIF.
--- Documentation/networking/iou-zcrx.rst | 106 ++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
Documentation/networking/iou-zcrx.rst +106 -0
@@ -196,6 +196,112 @@ Return buffers back to the kernel to be used again:: rqe->len = cqe->res; IO_URING_WRITE_ONCE(*refill_ring.ktail, ++refill_ring.rq_tail); +Notifications +------------- + +When zero-copy receive encounters conditions that affect performance or +functionality, the kernel can notify userspace via dedicated CQE notifications. +The application must register a notification descriptor during +``IORING_REGISTER_ZCRX_IFQ`` to receive them. + +Supported features can be detected by checking for ``ZCRX_FEATURE_NOTIFICATION`` +in the features bitmask returned by ``IO_URING_QUERY_ZCRX``. + +**Notification types** + +``ZCRX_NOTIF_NO_BUFFERS`` + Fired when the page pool fails to allocate because the zcrx buffer area is + exhausted. + +``ZCRX_NOTIF_COPY`` + Fired when a received fragment could not be delivered zero-copy and was + instead copied into a buffer. + +**Registering notifications** + +Allocate and fill a ``struct zcrx_notification_desc``:: + + struct zcrx_notification_desc notif = { + .user_data = MY_NOTIF_USER_DATA, + .type_mask = ZCRX_NOTIF_NO_BUFFERS | ZCRX_NOTIF_COPY, + }; + + reg.notif_desc = (__u64)(unsigned long)¬if; + +``user_data`` is the value that will appear in the notification CQE's +``user_data`` field. ``type_mask`` selects which notification types the +application wants to receive. + +When a registered event occurs, the kernel posts a CQE with the specified +``user_data`` and ``cqe->res`` set to a bitmask of the triggered notification +types. + +**Rate limiting** + +Each notification type fires once until the application explicitly re-arms it. +To re-arm, issue ``IORING_REGISTER_ZCRX_CTRL`` with +``ZCRX_CTRL_ARM_NOTIFICATION``:: + + struct zcrx_ctrl ctrl = { + .zcrx_id = zcrx_id, + .op = ZCRX_CTRL_ARM_NOTIFICATION, + .zc_arm_notif = { + .type_mask = ZCRX_NOTIF_NO_BUFFERS | ZCRX_NOTIF_COPY, + }, + }; + + io_uring_register(ring_fd, IORING_REGISTER_ZCRX_CTRL, &ctrl, 0); + +Only notification types that have previously fired can be re-armed. + +Notification statistics +----------------------- + +In addition to CQE-based notifications, the kernel can maintain a shared-memory +statistics structure that is updated on every relevant event. All stats are +updated regardless of which notification flags were registered. + +The statistics structure layout and alignment requirements can be queried via +``IO_URING_QUERY_ZCRX_NOTIF``. The application must query the structure size +and alignment requirements so that it allocates enough memory for the region +to fit both the refill ring and the stats structure. + +To enable statistics, place the stats structure after the refill ring entries +within the same mapped region, and set the ``ZCRX_NOTIF_DESC_FLAG_STATS`` flag +in the notification descriptor:: + + /* Compute offset for the stats struct (after refill ring entries) */ + size_t stats_offset = ring_size; + ring_size += ALIGN_UP(sizeof(struct io_uring_zcrx_notif_stats), PAGE_SIZE); + + /* Map the region with the extra space */ + ring_ptr = mmap(NULL, ring_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); + + struct zcrx_notification_desc notif = { + .user_data = MY_NOTIF_USER_DATA, + .type_mask = ZCRX_NOTIF_COPY, + .flags = ZCRX_NOTIF_DESC_FLAG_STATS, + .stats_offset = stats_offset, + }; + +The ``stats_offset`` must satisfy the alignment reported by +``notif_stats_off_alignment`` and must point to a location within the mapped +region that does not overlap with the refill ring header or entries. + +Application can read stat counters them at any time:: + + volatile struct io_uring_zcrx_notif_stats *stats = + (void *)((char *)ring_ptr + stats_offset); + + printf("copy fallbacks: %llu (%llu bytes)\n", + IO_URING_READ_ONCE(stats->copy_count), + IO_URING_READ_ONCE(stats->copy_bytes)); + +``copy_count`` is incremented each time a fragment is copied instead of being +delivered via zero-copy. ``copy_bytes`` accumulates the total number of bytes +copied. + Area chunking -------------
Signature · 1 line
2.52.0
PATCH 5/5 selftests: iou-zcrx: add notification and stats test for zcrx
In reply to Clément LégerAdd a selftest to verify that ZCRX notification are properly delivered to userspace and that the shared-memory notification stats (copy_count, copy_bytes) are correctly incremented when zero-copy RX falls back to copying or when it runs out of buffers.
The test registers a notification descriptor during IORING_REGISTER_ZCRX_IFQ with a stats region placed after the refill queue entries. A new -n flag verifies that the copy fallback is triggered and -b/-a flags allows to check for out of buffer notification.
To reliably trigger copy fallback, the Python test uses a new single_no_flow() setup variant that configures tcp-data-split and RSS but without ethtool flow rule. Without flow steering, traffic arrives on non-zcrx queues as regular pages, forcing the kernel copy-fallback path in io_zcrx_copy_frag().
Out-of-buffer notification is verified by using a smaller receive area and by avoiding recycling the buffers so that the kernel runs out of buffer quickly.
--- .../selftests/drivers/net/hw/iou-zcrx.c | 112 ++++++++++++++++-- .../selftests/drivers/net/hw/iou-zcrx.py | 49 +++++++- 2 files changed, 149 insertions(+), 12 deletions(-)
tools/testing/selftests/drivers/net/hw/iou-zcrx.c +102 -10
@@ -52,7 +52,27 @@ struct t_io_uring_zcrx_ifq_reg {struct io_uring_zcrx_offsets offsets;__u32 zcrx_id;__u32 rx_buf_len; -__u64 __resv[3 ]; +__u64 notif_desc; +__u64 __resv[2 ]; +}; + +#define ZCRX_NOTIF_NO_BUFFERS (1 << 0) +#define ZCRX_NOTIF_COPY (1 << 1) +#define ZCRX_NOTIF_DESC_FLAG_STATS (1 << 0) + +#define NOTIF_USER_DATA 3 + +struct t_zcrx_notification_desc { +__u64 user_data; +__u32 type_mask; +__u32 flags; +__u64 stats_offset; +__u64 __resv2[9 ]; +}; + +struct t_io_uring_zcrx_notif_stats { +__u64 copy_count; +__u64 copy_bytes; };static long page_size;
@@ -84,7 +104,10 @@ static int cfg_oneshot_recvs;static int cfg_send_size =SEND_SIZE ;static struct sockaddr_in6 cfg_addr;static unsigned int cfg_rx_buf_len; +static size_t cfg_area_size;static bool cfg_dry_run; +static bool cfg_copy_fallback; +static bool cfg_no_buffers;static char *payload;static void *area_ptr;
@@ -95,6 +118,8 @@ static unsigned long area_token;static int connfd;static bool stop;static size_t received; +static unsigned int notif_received_mask; +static size_t notif_stats_offset;static unsigned long gettimeofday_ms (void ) {
@@ -142,6 +167,7 @@ static void setup_zcrx(struct io_uring *ring) {unsigned int ifindex;unsigned int rq_entries =4096 ; +size_t area_size = cfg_area_size ? cfg_area_size :AREA_SIZE ;int ret; ifindex =if_nametoindex (cfg_ifname);
@@ -150,7 +176,7 @@ static void setup_zcrx(struct io_uring *ring)if (cfg_rx_buf_len && cfg_rx_buf_len != page_size) { area_ptr = mmap(NULL, - AREA_SIZE, + area_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB,
@@ -162,7 +188,7 @@ static void setup_zcrx(struct io_uring *ring) } }else { area_ptr = mmap(NULL, - AREA_SIZE, + area_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0,
@@ -172,6 +198,12 @@ static void setup_zcrx(struct io_uring *ring) } ring_size =get_refill_ring_size (rq_entries); + +if (cfg_copy_fallback) { + notif_stats_offset = ring_size; + ring_size +=ALIGN_UP (sizeof (struct t_io_uring_zcrx_notif_stats ), page_size); + } + ring_ptr = mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
@@ -187,10 +219,11 @@ static void setup_zcrx(struct io_uring *ring)struct io_uring_zcrx_area_reg area_reg = { .addr = (__u64 )(unsigned long )area_ptr, - .len =AREA_SIZE , + .len = area_size, .flags =0 , }; +struct t_zcrx_notification_desc notif_desc;struct t_io_uring_zcrx_ifq_reg reg = { .if_idx = ifindex, .if_rxq = cfg_queue_id,
@@ -200,11 +233,32 @@ static void setup_zcrx(struct io_uring *ring) .rx_buf_len = cfg_rx_buf_len, }; +if (cfg_copy_fallback || cfg_no_buffers) { +__u32 type_mask =0 ; + +if (cfg_copy_fallback) + type_mask =ZCRX_NOTIF_COPY ; +if (cfg_no_buffers) + type_mask =ZCRX_NOTIF_NO_BUFFERS ; + +memset (¬if_desc,0 ,sizeof (notif_desc)); + notif_desc.user_data =NOTIF_USER_DATA ; + notif_desc.type_mask = type_mask; +if (cfg_copy_fallback) { + notif_desc.flags =ZCRX_NOTIF_DESC_FLAG_STATS ; + notif_desc.stats_offset = notif_stats_offset; + } + reg.notif_desc = (__u64 )(unsigned long )¬if_desc; + } + ret =io_uring_register_ifq (ring, (void *)®);if (cfg_rx_buf_len && (ret == -EINVAL || ret == -EOPNOTSUPP || ret == -ERANGE )) {printf ("Large chunks are not supported %i\n" , ret);exit (SKIP_CODE ); + }else if ((cfg_copy_fallback || cfg_no_buffers) && ret == -EINVAL ) { +printf ("Notifications not supported %i\n" , ret); +exit (SKIP_CODE ); }else if (ret) {error (1 ,0 ,"io_uring_register_ifq(): %d" , ret); }
@@ -304,10 +358,13 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) } received += n; - rqe = &rq_ring.rqes[(rq_ring.rq_tail & rq_mask)]; - rqe->off = (rcqe->off & ~IORING_ZCRX_AREA_MASK ) | area_token; - rqe->len = cqe->res; -io_uring_smp_store_release (rq_ring.ktail, ++rq_ring.rq_tail); +/* Skip ring refill so that we ran out of buffers quickly */ +if (!cfg_no_buffers) { + rqe = &rq_ring.rqes[(rq_ring.rq_tail & rq_mask)]; + rqe->off = (rcqe->off & ~IORING_ZCRX_AREA_MASK ) | area_token; + rqe->len = cqe->res; +io_uring_smp_store_release (rq_ring.ktail, ++rq_ring.rq_tail); + } }static void server_loop (struct io_uring *ring)
@@ -324,8 +381,15 @@ static void server_loop(struct io_uring *ring)process_accept (ring, cqe); else if (cqe->user_data == 2) process_recvzc(ring, cqe); - else + else if ((cfg_copy_fallback || cfg_no_buffers) && + cqe->user_data == NOTIF_USER_DATA) { + notif_received_mask |= cqe->res; +if (cfg_no_buffers && + (cqe->res &ZCRX_NOTIF_NO_BUFFERS )) + stop = true; + } else {error (1 ,0 ,"unknown cqe" ); + } count++; }io_uring_cq_advance (ring, count);
@@ -374,6 +438,23 @@ static void run_server(void)if (!stop)error (1 ,0 ,"test failed\n" ); + +if (cfg_copy_fallback) { +struct t_io_uring_zcrx_notif_stats *stats = + (void *)((char *)ring_ptr + notif_stats_offset); + +if (!(notif_received_mask &ZCRX_NOTIF_COPY )) +error (1 ,0 ,"expected copy fallback notification" ); +if (!IO_URING_READ_ONCE (stats->copy_count)) +error (1 ,0 ,"expected copy_count > 0" ); +if (!IO_URING_READ_ONCE (stats->copy_bytes)) +error (1 ,0 ,"expected copy_bytes > 0" ); + } + +if (cfg_no_buffers) { +if (!(notif_received_mask &ZCRX_NOTIF_NO_BUFFERS )) +error (1 ,0 ,"expected no-buffers notification" ); + } }static void run_client (void )
@@ -425,7 +506,7 @@ static void parse_opts(int argc, char **argv)usage (argv[0 ]); cfg_payload_len = max_payload_len; -while ((c =getopt (argc, argv,"sch:p:l:i:q:o:z:x:d" )) !=-1 ) { +while ((c =getopt (argc, argv,"sch:p:l:i:q:o:z:x:a:dnb" )) !=-1 ) {switch (c) {case 's' :if (cfg_client)
@@ -466,8 +547,19 @@ static void parse_opts(int argc, char **argv)case 'd' : cfg_dry_run = true;break ; +case 'n' : + cfg_copy_fallback = true; +break ; +case 'b' : + cfg_no_buffers = true; +break ; +case 'a' : + cfg_area_size =strtoul (optarg,NULL ,0 ) * page_size; +break ; } } +if (cfg_copy_fallback && cfg_no_buffers) +error (1 ,0 ,"Pass one of -n or -b" );if (cfg_server && addr)error (1 ,0 ,"Receiver cannot have -h specified" );
tools/testing/selftests/drivers/net/hw/iou-zcrx.py +47 -2
79 lines not on this page · raw message
Signature · 1 line
2.52.0