All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juanlu Herrero <juanlu@fastmail.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: David Wei <dw@davidwei.uk>,
	netdev@vger.kernel.org,  Jakub Kicinski <kuba@kernel.org>,
	Pavel Begunkov <asml.silence@gmail.com>
Subject: Re: [PATCH net-next v4 5/6] selftests: net: add multithread server support to iou-zcrx
Date: Tue, 4 Aug 2026 11:27:05 -0500	[thread overview]
Message-ID: <anISNwUQeVl1YNwn@jlhe0197-mac> (raw)
In-Reply-To: <812e3fc9-c8dd-4d9e-93c6-585597422718@redhat.com>

On Tue, Aug 04, 2026 at 12:42:41PM -0600, Paolo Abeni wrote:
> 
> 
> On 7/30/26 12:18 AM, Juanlu Herrero wrote:
> > Run the iou-zcrx server as N worker threads, each owning one receive
> > queue with its own io_uring and zero-copy receive (zcrx) ifq, so the
> > test can exercise multi-queue zero-copy receive.
> > 
> > The main thread owns the listening socket, accepts connections, and
> > dispatches each to the worker owning the queue it landed on by matching
> > SO_INCOMING_NAPI_ID against per-queue NAPI IDs.
> > 
> > Assisted-by: Claude:claude-opus-4-8
> > Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
> > ---
> >  .../testing/selftests/drivers/net/hw/Makefile |   5 +-
> >  .../selftests/drivers/net/hw/iou-zcrx.c       | 290 ++++++++++++++----
> >  2 files changed, 226 insertions(+), 69 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
> > index 3cab3b4adbb2e..035581b58bc66 100644
> > --- a/tools/testing/selftests/drivers/net/hw/Makefile
> > +++ b/tools/testing/selftests/drivers/net/hw/Makefile
> > @@ -13,10 +13,6 @@ else
> >  $(warning excluding iouring tests, liburing not installed or too old)
> >  endif
> >  
> > -TEST_GEN_FILES := \
> > -	$(COND_GEN_FILES) \
> > -# end of TEST_GEN_FILES
> > -
> >  TEST_PROGS = \
> >  	csum.py \
> >  	devlink_port_split.py \
> > @@ -71,6 +67,7 @@ TEST_INCLUDES := \
> >  YNL_GEN_FILES := \
> >  	ncdevmem \
> >  	toeplitz \
> > +	$(COND_GEN_FILES) \
> >  # end of YNL_GEN_FILES
> >  TEST_GEN_FILES += $(YNL_GEN_FILES)
> >  TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c))
> > diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
> > index 7bc61f3b70ca6..16259129df46d 100644
> > --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
> > +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
> > @@ -27,6 +27,7 @@
> >  #include <netinet/tcp.h>
> >  #include <netinet/udp.h>
> >  #include <sys/epoll.h>
> > +#include <sys/eventfd.h>
> >  #include <sys/ioctl.h>
> >  #include <sys/mman.h>
> >  #include <sys/resource.h>
> > @@ -38,6 +39,8 @@
> >  #include <sys/wait.h>
> >  
> >  #include <liburing.h>
> > +#include <ynl.h>
> > +#include "netdev-user.h"
> >  
> >  #define SKIP_CODE	42
> >  
> > @@ -91,6 +94,7 @@ static int cfg_num_threads = 1;
> >  static char *payload;
> >  
> >  #define CONNS_PER_THREAD	4
> > +#define MAX_CONNS_PER_THREAD	64
> >  
> >  struct thread_ctx {
> >  	struct io_uring		ring;
> > @@ -99,9 +103,14 @@ struct thread_ctx {
> >  	size_t			ring_size;
> >  	struct io_uring_zcrx_rq	rq_ring;
> >  	unsigned long		area_token;
> > -	int			connfd;
> > -	bool			stop;
> > -	size_t			received;
> > +	int			queue_id;
> > +	int			napi_id;
> > +	int			ready_fd;
> > +	int			start_fd;
> > +
> > +	int			connfds[MAX_CONNS_PER_THREAD];
> > +	size_t			received[MAX_CONNS_PER_THREAD];
> > +	int			nr_conns;
> >  };
> >  
> >  static unsigned long gettimeofday_ms(void)
> > @@ -201,7 +210,7 @@ static void setup_zcrx(struct thread_ctx *ctx)
> >  
> >  	struct t_io_uring_zcrx_ifq_reg reg = {
> >  		.if_idx = ifindex,
> > -		.if_rxq = cfg_queue_id,
> > +		.if_rxq = ctx->queue_id,
> >  		.rq_entries = rq_entries,
> >  		.area_ptr = (__u64)(unsigned long)&area_reg,
> >  		.region_ptr = (__u64)(unsigned long)&region_reg,
> > @@ -226,53 +235,32 @@ static void setup_zcrx(struct thread_ctx *ctx)
> >  	ctx->area_token = area_reg.rq_area_token;
> >  }
> >  
> > -static void add_accept(struct thread_ctx *ctx, int sockfd)
> > +static void add_recvzc(struct thread_ctx *ctx, int conn_idx)
> >  {
> >  	struct io_uring_sqe *sqe;
> >  
> >  	sqe = io_uring_get_sqe(&ctx->ring);
> >  
> > -	io_uring_prep_accept(sqe, sockfd, NULL, NULL, 0);
> > -	sqe->user_data = 1;
> > -}
> > -
> > -static void add_recvzc(struct thread_ctx *ctx, int sockfd)
> > -{
> > -	struct io_uring_sqe *sqe;
> > -
> > -	sqe = io_uring_get_sqe(&ctx->ring);
> > -
> > -	io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, 0, 0);
> > +	io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, ctx->connfds[conn_idx],
> > +			 NULL, 0, 0);
> >  	sqe->ioprio |= IORING_RECV_MULTISHOT;
> > -	sqe->user_data = 2;
> > +	sqe->user_data = conn_idx;
> >  }
> >  
> > -static void add_recvzc_oneshot(struct thread_ctx *ctx, int sockfd, size_t len)
> > +static void add_recvzc_oneshot(struct thread_ctx *ctx, int conn_idx, size_t len)
> >  {
> >  	struct io_uring_sqe *sqe;
> >  
> >  	sqe = io_uring_get_sqe(&ctx->ring);
> >  
> > -	io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, len, 0);
> > +	io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, ctx->connfds[conn_idx],
> > +			 NULL, len, 0);
> >  	sqe->ioprio |= IORING_RECV_MULTISHOT;
> > -	sqe->user_data = 2;
> > +	sqe->user_data = conn_idx;
> >  }
> >  
> > -static void process_accept(struct thread_ctx *ctx, struct io_uring_cqe *cqe)
> > -{
> > -	if (cqe->res < 0)
> > -		error(1, 0, "accept()");
> > -	if (ctx->connfd)
> > -		error(1, 0, "Unexpected second connection");
> > -
> > -	ctx->connfd = cqe->res;
> > -	if (cfg_oneshot)
> > -		add_recvzc_oneshot(ctx, ctx->connfd, page_size);
> > -	else
> > -		add_recvzc(ctx, ctx->connfd);
> > -}
> > -
> > -static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe)
> > +static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe,
> > +			   int conn_idx)
> >  {
> >  	unsigned int rq_mask = ctx->rq_ring.ring_entries - 1;
> >  	struct io_uring_zcrx_cqe *rcqe;
> > @@ -283,7 +271,7 @@ static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe)
> >  	int i;
> >  
> >  	if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs == 0) {
> > -		ctx->stop = true;
> > +		ctx->nr_conns--;
> >  		return;
> >  	}
> >  
> > @@ -292,11 +280,11 @@ static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe)
> >  
> >  	if (cfg_oneshot) {
> >  		if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) {
> > -			add_recvzc_oneshot(ctx, ctx->connfd, page_size);
> > +			add_recvzc_oneshot(ctx, conn_idx, page_size);
> >  			cfg_oneshot_recvs--;
> 
> Sashiko noted that the above update is now racy in multithread tests:
> 
> https://sashiko.dev/#/patchset/20260729221825.42773-1-juanlu%40fastmail.com
> 
> Also please respect the reverse christmas tree order consistently.
> 
> /P
>

I will look into the potential race and fix the reverse christmas tree
ordering in v5. Thanks for the review

Best,
Juanlu

  reply	other threads:[~2026-08-04 16:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 22:18 [PATCH net-next v4 0/6] selftests: net: multithreaded multiqueue iou-zcrx Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 1/6] selftests: net: fix get_refill_ring_size() to use its local variable Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 2/6] selftests: net: remove unused variable in process_recvzc() Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 3/6] selftests: net: refactor server state into struct thread_ctx Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 4/6] selftests: net: add multithread client support to iou-zcrx Juanlu Herrero
2026-08-04 15:47   ` David Wei
2026-08-04 16:28     ` Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 5/6] selftests: net: add multithread server " Juanlu Herrero
2026-08-04 10:42   ` Paolo Abeni
2026-08-04 16:27     ` Juanlu Herrero [this message]
2026-08-04 16:45   ` David Wei
2026-08-04 19:54     ` Juanlu Herrero
2026-07-29 22:18 ` [PATCH net-next v4 6/6] selftests: net: add rss_multiqueue test variant " Juanlu Herrero

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=anISNwUQeVl1YNwn@jlhe0197-mac \
    --to=juanlu@fastmail.com \
    --cc=asml.silence@gmail.com \
    --cc=dw@davidwei.uk \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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.