All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, netdev@vger.kernel.org
Subject: [PATCH io_uring 03/16] io_uring/zcrx: add RQ iterator
Date: Fri,  7 Aug 2026 14:19:21 +0100	[thread overview]
Message-ID: <5d2933ea7bcf9c19c44e43afb3638d7afb362b3c.1786108672.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1786108672.git.asml.silence@gmail.com>

Add a iterator structure and helper functions for the refill queue
processing to avoid polluting io_zcrx_ring_refill() with extra state
and logic once it's extended in following patches.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/zcrx.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index fbc190075e2f..805424fdd573 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -1088,6 +1088,10 @@ void io_unregister_zcrx(struct io_ring_ctx *ctx)
 	xa_destroy(&ctx->zcrx_ctxs);
 }
 
+struct zcrx_rq_iter {
+	int rqes_left;
+};
+
 static inline u32 zcrx_rq_entries(struct zcrx_rq *rq)
 {
 	u32 entries;
@@ -1103,6 +1107,24 @@ static struct io_uring_zcrx_rqe *zcrx_next_rqe(struct zcrx_rq *rq, unsigned mask
 	return &rq->rqes[idx];
 }
 
+static inline void zcrx_rq_iter_init(struct zcrx_rq_iter *it,
+				     struct zcrx_rq *rq)
+{
+	it->rqes_left = min_t(unsigned, zcrx_rq_entries(rq), ZCRX_REFILL_CAP);
+}
+
+static inline bool zcrx_rq_iter_next(struct zcrx_rq_iter *it,
+				     struct zcrx_rq *rq,
+				     struct io_uring_zcrx_rqe **rqe)
+{
+	it->rqes_left--;
+	if (unlikely(it->rqes_left < 0))
+		return false;
+
+	*rqe = zcrx_next_rqe(rq, rq->nr_entries - 1);
+	return true;
+}
+
 static inline bool io_parse_rqe(struct io_uring_zcrx_rqe *rqe,
 				struct io_zcrx_ifq *ifq,
 				struct net_iov **ret_niov)
@@ -1131,17 +1153,15 @@ static unsigned io_zcrx_ring_refill(struct page_pool *pp,
 				    netmem_ref *netmems, unsigned to_alloc)
 {
 	struct zcrx_rq *rq = &ifq->rq;
-	unsigned int mask = rq->nr_entries - 1;
-	unsigned int rqes_left;
+	struct io_uring_zcrx_rqe *rqe;
+	struct zcrx_rq_iter it;
 	unsigned allocated = 0;
 
 	guard(spinlock_bh)(&rq->lock);
 
-	rqes_left = zcrx_rq_entries(rq);
-	rqes_left = min_t(unsigned, rqes_left, ZCRX_REFILL_CAP);
+	zcrx_rq_iter_init(&it, rq);
 
-	for (; rqes_left; rqes_left--) {
-		struct io_uring_zcrx_rqe *rqe = zcrx_next_rqe(rq, mask);
+	while (zcrx_rq_iter_next(&it, rq, &rqe)) {
 		struct net_iov *niov;
 		netmem_ref netmem;
 
-- 
2.54.0


  parent reply	other threads:[~2026-08-07 13:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 13:19 [PATCH io_uring 00/16] zcrx update for-7.3 Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 01/16] io_uring/zcrx: scale refilling with large pages Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 02/16] io_uring/zcrx: move RQ head/tail to separate cache lines Pavel Begunkov
2026-08-10 17:35   ` Mina Almasry
2026-08-11 13:16     ` Pavel Begunkov
2026-08-11 16:58       ` Mina Almasry
2026-08-07 13:19 ` Pavel Begunkov [this message]
2026-08-07 13:19 ` [PATCH io_uring 04/16] io_uring/zcrx: cache RQ tail Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 05/16] io_uring/zcrx: coalesce same-niov RQEs on refill Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 06/16] io_uring/zcrx: constify area_reg on import Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 07/16] io_urint/zcrx: narrow var scope in io_zcrx_recv_skb() Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 08/16] io_uring/zcrx: don't reload skb_shinfo Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 09/16] io_uring/zcrx: add helper for deriving area token Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 10/16] io_uring/zcrx: don't pass ifq_reg to area creation Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 11/16] io_uring/zcrx: split dmabuf unmap and release Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 12/16] io_uring/zcrx: unmap under netdev lock Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 13/16] io_uring/zcrx: move freelist lock to struct zcrx Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 14/16] io_uring/zcrx: keep array of areas Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 15/16] io_uring/zcrx: lock area creation with pp_lock Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 16/16] io_uring/zcrx: add dynamic area provisioning Pavel Begunkov
2026-08-16  0:02 ` [PATCH io_uring 00/16] zcrx update for-7.3 Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5d2933ea7bcf9c19c44e43afb3638d7afb362b3c.1786108672.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=io-uring@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.