netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taehee Yoo <ap420073@gmail.com>
To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@google.com, andrew+netdev@lunn.ch, shuah@kernel.org,
	almasrymina@google.com, sdf@fomichev.me, jdamato@fastly.com,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: ap420073@gmail.com
Subject: [PATCH net-next] selftests: devmem: configure HDS threshold
Date: Mon, 30 Jun 2025 09:28:18 +0000	[thread overview]
Message-ID: <20250630092818.1449599-1-ap420073@gmail.com> (raw)

The devmem TCP requires the hds-thresh value to be 0, but it doesn't
change it automatically.
Therefore, configure_hds_thresh() is added to handle this.

The run_devmem_tests() now tests hds_thresh, but it skips test if the
hds_thresh_max value is 0.

Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 .../selftests/drivers/net/hw/ncdevmem.c       | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/tools/testing/selftests/drivers/net/hw/ncdevmem.c b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
index cc9b40d9c5d5..d78b5e5697d7 100644
--- a/tools/testing/selftests/drivers/net/hw/ncdevmem.c
+++ b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
@@ -349,6 +349,72 @@ static int configure_headersplit(bool on)
 	return ret;
 }
 
+static int configure_hds_thresh(int len)
+{
+	struct ethtool_rings_get_req *get_req;
+	struct ethtool_rings_get_rsp *get_rsp;
+	struct ethtool_rings_set_req *req;
+	struct ynl_error yerr;
+	struct ynl_sock *ys;
+	int ret;
+
+	ys = ynl_sock_create(&ynl_ethtool_family, &yerr);
+	if (!ys) {
+		fprintf(stderr, "YNL: %s\n", yerr.msg);
+		return -1;
+	}
+
+	req = ethtool_rings_set_req_alloc();
+	ethtool_rings_set_req_set_header_dev_index(req, ifindex);
+	ethtool_rings_set_req_set_hds_thresh(req, len);
+	ret = ethtool_rings_set(ys, req);
+	if (ret < 0)
+		fprintf(stderr, "YNL failed: %s\n", ys->err.msg);
+	ethtool_rings_set_req_free(req);
+
+	if (ret == 0) {
+		get_req = ethtool_rings_get_req_alloc();
+		ethtool_rings_get_req_set_header_dev_index(get_req, ifindex);
+		get_rsp = ethtool_rings_get(ys, get_req);
+		ethtool_rings_get_req_free(get_req);
+		if (get_rsp)
+			fprintf(stderr, "HDS threshold: %d\n",
+				get_rsp->hds_thresh);
+		ethtool_rings_get_rsp_free(get_rsp);
+	}
+
+	ynl_sock_destroy(ys);
+
+	return ret;
+}
+
+static int get_hds_thresh_max(void)
+{
+	struct ethtool_rings_get_req *get_req;
+	struct ethtool_rings_get_rsp *get_rsp;
+	struct ynl_error yerr;
+	unsigned int ret = 0;
+	struct ynl_sock *ys;
+
+	ys = ynl_sock_create(&ynl_ethtool_family, &yerr);
+	if (!ys) {
+		fprintf(stderr, "YNL: %s\n", yerr.msg);
+		return -1;
+	}
+
+	get_req = ethtool_rings_get_req_alloc();
+	ethtool_rings_get_req_set_header_dev_index(get_req, ifindex);
+	get_rsp = ethtool_rings_get(ys, get_req);
+	ethtool_rings_get_req_free(get_req);
+	if (get_rsp)
+		ret = get_rsp->hds_thresh_max;
+	ethtool_rings_get_rsp_free(get_rsp);
+
+	ynl_sock_destroy(ys);
+
+	return ret;
+}
+
 static int configure_rss(void)
 {
 	return run_command("sudo ethtool -X %s equal %d >&2", ifname, start_queue);
@@ -565,6 +631,9 @@ static int do_server(struct memory_buffer *mem)
 	if (configure_headersplit(1))
 		error(1, 0, "Failed to enable TCP header split\n");
 
+	if (configure_hds_thresh(0))
+		error(1, 0, "Failed to set HDS threshold\n");
+
 	/* Configure RSS to divert all traffic from our devmem queues */
 	if (configure_rss())
 		error(1, 0, "Failed to configure rss\n");
@@ -725,10 +794,14 @@ static int do_server(struct memory_buffer *mem)
 void run_devmem_tests(void)
 {
 	struct memory_buffer *mem;
+	int hds_thresh_max = 0;
 	struct ynl_sock *ys;
 
 	mem = provider->alloc(getpagesize() * NUM_PAGES);
 
+	hds_thresh_max = get_hds_thresh_max();
+	if (hds_thresh_max < 0)
+		error(1, 0, "Failed to get hds_thresh_max");
 	/* Configure RSS to divert all traffic from our devmem queues */
 	if (configure_rss())
 		error(1, 0, "rss error\n");
@@ -750,6 +823,19 @@ void run_devmem_tests(void)
 	if (configure_headersplit(1))
 		error(1, 0, "Failed to configure header split\n");
 
+	/* Do not test hds_thresh if hds_thresh_max value is 0 */
+	if (hds_thresh_max) {
+		if (configure_hds_thresh(1))
+			error(1, 0, "Failed to configure HDS threshold\n");
+
+		if (!bind_rx_queue(ifindex, mem->fd, create_queues(),
+				   num_queues, &ys))
+			error(1, 0, "Configure dmabuf with non-zero HDS threshold should have failed\n");
+
+		if (configure_hds_thresh(0))
+			error(1, 0, "Failed to configure HDS threshold\n");
+	}
+
 	if (bind_rx_queue(ifindex, mem->fd, create_queues(), num_queues, &ys))
 		error(1, 0, "Failed to bind\n");
 
-- 
2.34.1


             reply	other threads:[~2025-06-30  9:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30  9:28 Taehee Yoo [this message]
2025-06-30 15:09 ` [PATCH net-next] selftests: devmem: configure HDS threshold Stanislav Fomichev
2025-07-01  3:05   ` Taehee Yoo
2025-06-30 16:11 ` Mina Almasry
2025-07-01  3:11   ` Taehee Yoo

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=20250630092818.1449599-1-ap420073@gmail.com \
    --to=ap420073@gmail.com \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jdamato@fastly.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).