From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: netdev@vger.kernel.org
Cc: magnus.karlsson@intel.com, stfomichev@gmail.com, kuba@kernel.org,
pabeni@redhat.com, tushar.vyavahare@intel.com,
kerneljasonxing@gmail.com, bjorn@kernel.org,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: [PATCH v6 net-next 11/15] selftests: xsk: wait up to --timeout for the RX stats and a busy bind
Date: Fri, 27 Nov 2026 16:05:23 +0100 [thread overview]
Message-ID: <20261127150527.1122049-12-maciej.fijalkowski@intel.com> (raw)
In-Reply-To: <20261127150527.1122049-1-maciej.fijalkowski@intel.com>
Two waits are too short on a slow kernel, e.g. a debug one:
- STAT_RX_FULL and STAT_FILL_EMPTY check a stat 1 ms after RX took its
share, while TX can still be sending the rest. Poll the stat instead.
- TEARDOWN rebinds to the queue of a socket it just closed, which the
kernel releases from a work item, but xsk_configure() gives up after
10 tries 10 ms apart. Retry only on EBUSY, and bind TX before READY,
as RX does, so that the retries do not eat into the RX timeout.
Both now wait for up to --timeout seconds.
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 113 +++++++++++-------
.../testing/selftests/net/lib/xsk/test_xsk.h | 1 -
.../selftests/net/lib/xsk/xskxceiver.c | 2 +-
.../selftests/net/lib/xsk/xskxceiver.h | 1 -
4 files changed, 71 insertions(+), 46 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 4b8cf5a3d387..a0ad1df00212 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1563,46 +1563,57 @@ static int validate_rx_dropped(struct ifobject *ifobject)
return TEST_FAILURE;
}
-static int validate_rx_full(struct ifobject *ifobject)
+/* TX sends more packets than RX takes, and the stat counts those that find the
+ * RX ring full or the fill ring empty. RX can take its share well before TX
+ * sends the rest, so wait for the stat to count one.
+ */
+static int wait_rx_stat(struct ifobject *ifobject, bool fill_empty)
{
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
struct xsk_socket *xsk = ifobject->xsk->xsk;
struct xdp_statistics stats;
+ u64 cnt;
int err;
- usleep(1000);
- err = kick_rx(ifobject->xsk);
+ err = gettimeofday(&tv_now, NULL);
if (err)
return TEST_FAILURE;
+ timeradd(&tv_now, &tv_timeout, &tv_end);
- err = get_xsk_stats(xsk, &stats);
- if (err)
- return TEST_FAILURE;
+ do {
+ usleep(1000);
+ err = kick_rx(ifobject->xsk);
+ if (err)
+ return TEST_FAILURE;
- if (stats.rx_ring_full)
- return TEST_PASS;
+ err = get_xsk_stats(xsk, &stats);
+ if (err)
+ return TEST_FAILURE;
+
+ cnt = fill_empty ? stats.rx_fill_ring_empty_descs :
+ stats.rx_ring_full;
+ if (cnt)
+ return TEST_PASS;
+
+ err = gettimeofday(&tv_now, NULL);
+ if (err)
+ return TEST_FAILURE;
+ } while (!timercmp(&tv_now, &tv_end, >));
+ ksft_print_msg("ERROR: [%s] %s is 0 after %u s\n", __func__,
+ fill_empty ? "rx_fill_ring_empty_descs" : "rx_ring_full",
+ thread_tmout);
return TEST_FAILURE;
}
-static int validate_fill_empty(struct ifobject *ifobject)
+static int validate_rx_full(struct ifobject *ifobject)
{
- struct xsk_socket *xsk = ifobject->xsk->xsk;
- struct xdp_statistics stats;
- int err;
-
- usleep(1000);
- err = kick_rx(ifobject->xsk);
- if (err)
- return TEST_FAILURE;
-
- err = get_xsk_stats(xsk, &stats);
- if (err)
- return TEST_FAILURE;
-
- if (stats.rx_fill_ring_empty_descs)
- return TEST_PASS;
+ return wait_rx_stat(ifobject, false);
+}
- return TEST_FAILURE;
+static int validate_fill_empty(struct ifobject *ifobject)
+{
+ return wait_rx_stat(ifobject, true);
}
static int validate_tx_invalid_descs(struct ifobject *ifobject)
@@ -1635,23 +1646,32 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)
static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
struct xsk_umem_info *umem)
{
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
int i, ret;
+ if (gettimeofday(&tv_now, NULL))
+ return -errno;
+ timeradd(&tv_now, &tv_timeout, &tv_end);
+
for (i = 0; i < test->nb_sockets; i++) {
bool shared = !!i;
- u32 ctr = 0;
- while (ctr++ < SOCK_RECONF_CTR) {
+ /* The kernel releases the queue of a closed socket
+ * asynchronously, so a bind to it can fail with EBUSY for a
+ * while after the previous step or test case.
+ */
+ do {
ret = xsk_configure_socket(&ifobject->xsk_arr[i], umem,
- ifobject, shared);
- if (!ret)
+ ifobject, shared);
+ if (ret != -EBUSY)
break;
-
- /* Retry if it fails as xsk_socket__create() is asynchronous */
- if (ctr >= SOCK_RECONF_CTR)
- return ret;
usleep(USLEEP_MAX);
- }
+ if (gettimeofday(&tv_now, NULL))
+ return -errno;
+ } while (!timercmp(&tv_now, &tv_end, >));
+ if (ret)
+ return ret;
+
if (ifobject->busy_poll) {
ret = enable_busy_poll(&ifobject->xsk_arr[i]);
if (ret)
@@ -1771,12 +1791,6 @@ static int testapp_validate_tx_endpoint(struct test_spec *test,
{
int err;
- if (test->current_step == 1) {
- err = thread_common_ops(test, ifobject);
- if (err)
- return err;
- }
-
err = send_pkts(test, ifobject);
if (!err && ifobject->validation_func)
@@ -1829,8 +1843,7 @@ static int testapp_validate_rx_endpoint(struct test_spec *test,
/* An MTU or XDP program change can reset a NIC, which takes the link down on
* both hosts. Each endpoint makes those changes before it is ready, so once
* both are, wait while the local link is down. This is best effort: it misses
- * a reset that a driver has yet to start, and one on the bind of a TX socket,
- * which comes after the wait.
+ * a reset that a driver has yet to start.
*/
static int wait_link_up(struct test_spec *test)
{
@@ -1867,13 +1880,27 @@ static int sync_endpoints(struct test_spec *test)
int worker_testapp_validate_tx(struct test_spec *test)
{
+ struct ifobject *ifobject = test->ifobj_tx;
int err;
+ /* Bind before READY, as RX does, so that a bind retry does not take
+ * from the receive timeout of RX, which starts after READY.
+ */
+ if (test->current_step == 1) {
+ err = thread_common_ops(test, ifobject);
+ if (err) {
+ ksft_print_msg("TX endpoint setup failed at step %u: %d\n",
+ test->current_step, err);
+ xsk_peer_abort(ctrl_peer);
+ return err;
+ }
+ }
+
err = sync_endpoints(test);
if (err)
return err;
- err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
+ err = testapp_validate_tx_endpoint(test, ifobject);
if (err && err != TEST_SKIP) {
ksft_print_msg("TX endpoint traffic failed at step %u: %d\n",
test->current_step, err);
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 15534f4ec8f4..ee840ccdfcbf 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -28,7 +28,6 @@
#define MAX_ETH_PKT_SIZE 1518
#define MAX_INTERFACE_NAME_CHARS 16
#define MAX_TEST_NAME_SIZE 48
-#define SOCK_RECONF_CTR 10
#define USLEEP_MAX 10000
#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 7ef6f08538bd..07e4cadfb164 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -186,7 +186,7 @@ static void print_usage(char **argv)
" the caller steers the test flow to the bound queue\n"
" --queue N AF_XDP queue to bind (default 0)\n"
" --max-frags N Fragment limit for TOO_MANY_FRAGS (default by mode)\n"
- " --timeout SEC Traffic and link timeout (default 3)\n"
+ " --timeout SEC Traffic, link and bind timeout (default 3)\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.h b/tools/testing/selftests/net/lib/xsk/xskxceiver.h
index 3ca518df23ad..2365bda57a4b 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.h
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.h
@@ -24,7 +24,6 @@
#define MAX_TEARDOWN_ITER 10
#define MAX_ETH_JUMBO_SIZE 9000
-#define SOCK_RECONF_CTR 10
#define RX_FULL_RXQSIZE 32
#define UMEM_HEADROOM_TEST_SIZE 128
#define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1)
--
2.43.0
next prev parent reply other threads:[~2026-11-27 15:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported() Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 02/15] selftests: xsk: factor endpoint work out of pthread wrappers Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 03/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 04/15] selftests: xsk: drop the single-interface loopback mode Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 05/15] selftests: xsk: collect interface capabilities in struct xsk_caps Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 06/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 07/15] selftests: xsk: run one test case per xskxceiver invocation Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 08/15] selftests: xsk: run the RX and TX endpoints in separate processes Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 09/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 10/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts Maciej Fijalkowski
2026-11-27 15:05 ` Maciej Fijalkowski [this message]
2026-11-27 15:05 ` [PATCH v6 net-next 12/15] selftests: xsk: list the endpoint roles of the test cases Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 13/15] selftests: drv-net: rename nsim_test to sw_test Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 14/15] selftests: drv-net: decouple local link setup from netdevsim Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 15/15] selftests: drv-net: run the AF_XDP tests over veth or a NIC Maciej Fijalkowski
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=20261127150527.1122049-12-maciej.fijalkowski@intel.com \
--to=maciej.fijalkowski@intel.com \
--cc=bjorn@kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stfomichev@gmail.com \
--cc=tushar.vyavahare@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox