Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org,
	daniel@iogearbox.net, netdev@vger.kernel.org,
	maciej.fijalkowski@intel.com
Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com,
	joamaki@gmail.com, bpf@vger.kernel.org, yhs@fb.com,
	andrii@kernel.org
Subject: [PATCH bpf-next 11/17] selftests: xsk: validate tx stats on tx thread
Date: Tue, 27 Jul 2021 15:17:47 +0200	[thread overview]
Message-ID: <20210727131753.10924-12-magnus.karlsson@gmail.com> (raw)
In-Reply-To: <20210727131753.10924-1-magnus.karlsson@gmail.com>

From: Magnus Karlsson <magnus.karlsson@intel.com>

Validate the tx stats on the Tx thread instead of the Rx
tread. Depending on your settings, you might not be allowed to query
the statistics of a socket you do not own, so better to do this on the
correct thread to start with.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 tools/testing/selftests/bpf/xdpxceiver.c | 55 ++++++++++++++++++------
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index cbd6739faeb5..327129f83fef 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -647,23 +647,22 @@ static void tx_only_all(struct ifobject *ifobject)
 	complete_tx_only_all(ifobject);
 }
 
-static void stats_validate(struct ifobject *ifobject)
+static bool rx_stats_are_valid(struct ifobject *ifobject)
 {
+	u32 xsk_stat = 0, expected_stat = opt_pkt_count;
+	struct xsk_socket *xsk = ifobject->xsk->xsk;
+	int fd = xsk_socket__fd(xsk);
 	struct xdp_statistics stats;
 	socklen_t optlen;
 	int err;
-	struct xsk_socket *xsk = stat_test_type == STAT_TEST_TX_INVALID ?
-							ifdict[!ifobject->ifdict_index]->xsk->xsk :
-							ifobject->xsk->xsk;
-	int fd = xsk_socket__fd(xsk);
-	unsigned long xsk_stat = 0, expected_stat = opt_pkt_count;
-
-	sigvar = 0;
 
 	optlen = sizeof(stats);
 	err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen);
-	if (err)
-		return;
+	if (err) {
+		ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n",
+				      __func__, -err, strerror(-err));
+		return true;
+	}
 
 	if (optlen == sizeof(struct xdp_statistics)) {
 		switch (stat_test_type) {
@@ -671,8 +670,7 @@ static void stats_validate(struct ifobject *ifobject)
 			xsk_stat = stats.rx_dropped;
 			break;
 		case STAT_TEST_TX_INVALID:
-			xsk_stat = stats.tx_invalid_descs;
-			break;
+			return true;
 		case STAT_TEST_RX_FULL:
 			xsk_stat = stats.rx_ring_full;
 			expected_stat -= RX_FULL_RXQSIZE;
@@ -685,8 +683,33 @@ static void stats_validate(struct ifobject *ifobject)
 		}
 
 		if (xsk_stat == expected_stat)
-			sigvar = 1;
+			return true;
+	}
+
+	return false;
+}
+
+static void tx_stats_validate(struct ifobject *ifobject)
+{
+	struct xsk_socket *xsk = ifobject->xsk->xsk;
+	int fd = xsk_socket__fd(xsk);
+	struct xdp_statistics stats;
+	socklen_t optlen;
+	int err;
+
+	optlen = sizeof(stats);
+	err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen);
+	if (err) {
+		ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n",
+				      __func__, -err, strerror(-err));
+		return;
 	}
+
+	if (stats.tx_invalid_descs == opt_pkt_count)
+		return;
+
+	ksft_test_result_fail("ERROR: [%s] tx_invalid_descs incorrect. Got [%u] expected [%u]\n",
+			      __func__, stats.tx_invalid_descs, opt_pkt_count);
 }
 
 static void thread_common_ops(struct ifobject *ifobject, void *bufs)
@@ -772,6 +795,9 @@ static void *worker_testapp_validate_tx(void *arg)
 	print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname);
 	tx_only_all(ifobject);
 
+	if (stat_test_type == STAT_TEST_TX_INVALID)
+		tx_stats_validate(ifobject);
+
 	testapp_cleanup_xsk_res(ifobject);
 	pthread_exit(NULL);
 }
@@ -797,7 +823,8 @@ static void *worker_testapp_validate_rx(void *arg)
 		if (test_type != TEST_TYPE_STATS) {
 			rx_pkt(ifobject->xsk, fds);
 		} else {
-			stats_validate(ifobject);
+			if (rx_stats_are_valid(ifobject))
+				break;
 		}
 		if (sigvar)
 			break;
-- 
2.29.0


  parent reply	other threads:[~2021-07-27 13:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 13:17 [PATCH bpf-next 00/17] selftests: xsk: various simplifications Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 01/17] selftests: xsk: remove color mode Magnus Karlsson
2021-07-27 16:43   ` Yonghong Song
2021-07-28  6:12     ` Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 02/17] selftests: xsk: remove the num_tx_packets option Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 03/17] selftests: xsk: remove unused variables Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 04/17] selftests: xsk: set rlimit per thread Magnus Karlsson
2021-07-27 18:39   ` Yonghong Song
2021-07-28  6:13     ` Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 05/17] selftests: xsk: return correct error codes Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 06/17] selftests: xsk: simplify the retry code Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 07/17] selftests: xsk: remove end-of-test packet Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 08/17] selftests: xsk: disassociate umem size with packets sent Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 09/17] selftests: xsk: rename worker_* functions that are not thred entry points Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 10/17] selftests: xsk: simplify packet validation in xsk tests Magnus Karlsson
2021-07-27 13:17 ` Magnus Karlsson [this message]
2021-07-27 13:17 ` [PATCH bpf-next 12/17] selftests: xsk: decrease batch size Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 13/17] selftests: xsk: remove cleanup at end of program Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 14/17] selftests: xsk: generate packet directly in umem Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 15/17] selftests: xsk: generate packets from specification Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 16/17] selftests: xsk: make enums lower case Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 17/17] selftests: xsk: preface options with opt Magnus Karlsson

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=20210727131753.10924-12-magnus.karlsson@gmail.com \
    --to=magnus.karlsson@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ciara.loftus@intel.com \
    --cc=daniel@iogearbox.net \
    --cc=joamaki@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    --subject='Re: [PATCH bpf-next 11/17] selftests: xsk: validate tx stats on tx thread' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).