[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240315140726.22291-5-tushar.vyavahare@intel.com>
Date: Fri, 15 Mar 2024 14:07:24 +0000
From: Tushar Vyavahare <tushar.vyavahare@...el.com>
To: bpf@...r.kernel.org
Cc: netdev@...r.kernel.org,
bjorn@...nel.org,
magnus.karlsson@...el.com,
maciej.fijalkowski@...el.com,
jonathan.lemon@...il.com,
davem@...emloft.net,
kuba@...nel.org,
pabeni@...hat.com,
ast@...nel.org,
daniel@...earbox.net,
tirthendu.sarkar@...el.com,
tushar.vyavahare@...el.com
Subject: [PATCH bpf-next 4/6] selftests/xsk: implement set_hw_ring_size function to configure interface ring size
Introduce a new function called set_hw_ring_size that allows for the
dynamic configuration of the ring size within the interface.
Signed-off-by: Tushar Vyavahare <tushar.vyavahare@...el.com>
---
tools/testing/selftests/bpf/xskxceiver.c | 35 ++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 32005bfb9c9f..aafa78307586 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -441,6 +441,41 @@ static int get_hw_ring_size(struct ifobject *ifobj)
return 0;
}
+static int set_hw_ring_size(struct ifobject *ifobj, u32 tx, u32 rx)
+{
+ struct ethtool_ringparam ring_param = {0};
+ struct ifreq ifr = {0};
+ int sockfd, ret;
+ u32 ctr = 0;
+
+ sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0)
+ return errno;
+
+ memcpy(ifr.ifr_name, ifobj->ifname, sizeof(ifr.ifr_name));
+
+ ring_param.tx_pending = tx;
+ ring_param.rx_pending = rx;
+
+ ring_param.cmd = ETHTOOL_SRINGPARAM;
+ ifr.ifr_data = (char *)&ring_param;
+
+ while (ctr++ < SOCK_RECONF_CTR) {
+ ret = ioctl(sockfd, SIOCETHTOOL, &ifr);
+ if (!ret)
+ break;
+ /* Retry if it fails */
+ if (ctr >= SOCK_RECONF_CTR) {
+ close(sockfd);
+ return errno;
+ }
+ usleep(USLEEP_MAX);
+ }
+
+ close(sockfd);
+ return 0;
+}
+
static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
struct ifobject *ifobj_rx)
{
--
2.34.1
Powered by blists - more mailing lists