mirror of
https://github.com/torvalds/linux.git
synced 2026-09-14 16:10:02 +02:00
io_uring/zcrx: add RQ iterator
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> Link: https://patch.msgid.link/5d2933ea7bcf9c19c44e43afb3638d7afb362b3c.1786108672.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
433c57e9b1
commit
2292f4fbc5
|
|
@ -1087,6 +1087,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;
|
||||
|
|
@ -1102,6 +1106,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)
|
||||
|
|
@ -1130,17 +1152,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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user