[PATCH net-next v3 4/6] selftests: net: add multithread client support to iou-zcrx
From: Juanlu Herrero <hidden>
Date: 2026-07-22 20:42:25
Subsystem:
kernel selftest framework, networking drivers, the rest · Maintainers:
Shuah Khan, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Add pthreads to the iou-zcrx client so that multiple connections can be established simultaneously. Each client thread connects to the server and sends its payload independently. Introduce the -t option to control the number of threads (default 1), preserving backwards compatibility with existing tests. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Juanlu Herrero <redacted> --- .../testing/selftests/drivers/net/hw/Makefile | 2 +- .../selftests/drivers/net/hw/iou-zcrx.c | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 234db5c2c90cc..3cab3b4adbb2e 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile@@ -88,5 +88,5 @@ include ../../../net/ynl.mk include ../../../net/bpf.mk ifeq ($(HAS_IOURING_ZCRX),y) -$(OUTPUT)/iou-zcrx: LDLIBS += -luring +$(OUTPUT)/iou-zcrx: LDLIBS += -luring -lpthread endif
diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
index 9b62fd0703e61..7bc61f3b70ca6 100644
--- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
+++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c@@ -4,6 +4,7 @@ #include <error.h> #include <fcntl.h> #include <limits.h> +#include <pthread.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h>
@@ -85,9 +86,12 @@ static int cfg_send_size = SEND_SIZE; static struct sockaddr_in6 cfg_addr; static unsigned int cfg_rx_buf_len; static bool cfg_dry_run; +static int cfg_num_threads = 1; static char *payload; +#define CONNS_PER_THREAD 4 + struct thread_ctx { struct io_uring ring; void *area_ptr;
@@ -379,7 +383,7 @@ static void run_server(void) error(1, 0, "test failed\n"); } -static void run_client(void) +static void *client_worker(void *arg) { ssize_t to_send = cfg_send_size; ssize_t sent = 0;
@@ -405,12 +409,37 @@ static void run_client(void) } close(fd); + return NULL; +} + +static void run_client(void) +{ + int conns_per_thread = cfg_num_threads > 1 ? CONNS_PER_THREAD : 1; + int total_conns = conns_per_thread * cfg_num_threads; + pthread_t *threads; + int i, ret; + + threads = calloc(total_conns, sizeof(*threads)); + if (!threads) + error(1, 0, "calloc()"); + + for (i = 0; i < total_conns; i++) { + ret = pthread_create(&threads[i], NULL, client_worker, NULL); + if (ret) + error(1, ret, "pthread_create()"); + } + + for (i = 0; i < total_conns; i++) + pthread_join(threads[i], NULL); + + free(threads); } static void usage(const char *filepath) { error(1, 0, "Usage: %s (-4|-6) (-s|-c) -h<server_ip> -p<port> " - "-l<payload_size> -i<ifname> -q<rxq_id>", filepath); + "-l<payload_size> -i<ifname> -q<rxq_id> -t<num_threads>", + filepath); } static void parse_opts(int argc, char **argv)
@@ -428,7 +457,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:dt:")) != -1) { switch (c) { case 's': if (cfg_client)
@@ -469,6 +498,9 @@ static void parse_opts(int argc, char **argv) case 'd': cfg_dry_run = true; break; + case 't': + cfg_num_threads = strtoul(optarg, NULL, 0); + break; } }
--
2.53.0-Meta