From: Stanislav Fomichev <sdf@google.com>
To: Tushar Vyavahare <tushar.vyavahare@intel.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, bjorn@kernel.org,
magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
jonathan.lemon@gmail.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net,
tirthendu.sarkar@intel.com
Subject: Re: [PATCH bpf-next 3/6] selftests/xsk: implement get_hw_ring_size function to retrieve current and max interface size
Date: Fri, 15 Mar 2024 10:40:47 -0700 [thread overview]
Message-ID: <ZfSIH07rCk3mjjWc@google.com> (raw)
In-Reply-To: <20240315140726.22291-4-tushar.vyavahare@intel.com>
On 03/15, Tushar Vyavahare wrote:
> Introduce a new function called get_hw_size that retrieves both the
> current and maximum size of the interface and stores this information in
> the 'hw_ring' structure.
>
> Signed-off-by: Tushar Vyavahare <tushar.vyavahare@intel.com>
> ---
> tools/testing/selftests/bpf/xskxceiver.c | 32 ++++++++++++++++++++++++
> tools/testing/selftests/bpf/xskxceiver.h | 8 ++++++
> 2 files changed, 40 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index eaa102c8098b..32005bfb9c9f 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -81,6 +81,8 @@
> #include <linux/mman.h>
> #include <linux/netdev.h>
> #include <linux/bitmap.h>
> +#include <linux/sockios.h>
> +#include <linux/ethtool.h>
> #include <arpa/inet.h>
> #include <net/if.h>
> #include <locale.h>
> @@ -95,6 +97,7 @@
> #include <sys/socket.h>
> #include <sys/time.h>
> #include <sys/types.h>
> +#include <sys/ioctl.h>
> #include <unistd.h>
>
> #include "xsk_xdp_progs.skel.h"
> @@ -409,6 +412,35 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
> }
> }
>
> +static int get_hw_ring_size(struct ifobject *ifobj)
> +{
> + struct ethtool_ringparam ring_param = {0};
> + struct ifreq ifr = {0};
> + int sockfd;
> +
> + sockfd = socket(AF_INET, SOCK_DGRAM, 0);
> + if (sockfd < 0)
> + return errno;
> +
> + memcpy(ifr.ifr_name, ifobj->ifname, sizeof(ifr.ifr_name));
> +
> + ring_param.cmd = ETHTOOL_GRINGPARAM;
> + ifr.ifr_data = (char *)&ring_param;
> +
> + if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
> + close(sockfd);
> + return errno;
close(sockfd) can potentially override the errno. Also, return -errno to
match the other cases where errors are < 0.
> + }
> +
> + ifobj->ring.default_tx = ring_param.tx_pending;
> + ifobj->ring.default_rx = ring_param.rx_pending;
> + ifobj->ring.max_tx = ring_param.tx_max_pending;
> + ifobj->ring.max_rx = ring_param.rx_max_pending;
> +
> + close(sockfd);
> + return 0;
> +}
> +
> static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
> struct ifobject *ifobj_rx)
> {
> diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> index 425304e52f35..4f58b70fa781 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.h
> +++ b/tools/testing/selftests/bpf/xskxceiver.h
> @@ -114,6 +114,13 @@ struct pkt_stream {
> bool verbatim;
> };
>
> +struct hw_ring {
> + u32 default_tx;
> + u32 default_rx;
> + u32 max_tx;
> + u32 max_rx;
> +};
> +
> struct ifobject;
> struct test_spec;
> typedef int (*validation_func_t)(struct ifobject *ifobj);
> @@ -130,6 +137,7 @@ struct ifobject {
> struct xsk_xdp_progs *xdp_progs;
> struct bpf_map *xskmap;
> struct bpf_program *xdp_prog;
> + struct hw_ring ring;
Any reason not to store ethtool_ringparam directly here? No need to
introduce new hw_ring.
next prev parent reply other threads:[~2024-03-15 17:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 14:07 [PATCH bpf-next 0/6] Enhancing selftests/xsk Framework: Maximum and Minimum Ring Configurations Tushar Vyavahare
2024-03-15 14:07 ` [PATCH bpf-next 1/6] tools/include: add ethtool_ringparam definition to UAPI header Tushar Vyavahare
2024-03-15 17:33 ` Stanislav Fomichev
2024-03-19 6:42 ` Vyavahare, Tushar
2024-03-15 14:07 ` [PATCH bpf-next 2/6] selftests/xsk: make batch size variable Tushar Vyavahare
2024-03-15 14:07 ` [PATCH bpf-next 3/6] selftests/xsk: implement get_hw_ring_size function to retrieve current and max interface size Tushar Vyavahare
2024-03-15 17:40 ` Stanislav Fomichev [this message]
2024-03-19 6:47 ` Vyavahare, Tushar
2024-03-15 14:07 ` [PATCH bpf-next 4/6] selftests/xsk: implement set_hw_ring_size function to configure interface ring size Tushar Vyavahare
2024-03-15 15:47 ` Alexei Starovoitov
2024-03-19 6:54 ` Vyavahare, Tushar
2024-03-15 17:44 ` Stanislav Fomichev
2024-03-19 6:52 ` Vyavahare, Tushar
2024-03-15 14:07 ` [PATCH bpf-next 5/6] selftests/xsk: test AF_XDP functionality under minimal ring configurations Tushar Vyavahare
2024-03-15 14:07 ` [PATCH bpf-next 6/6] selftests/xsk: enhance framework with a new test case for AF_XDP under max ring sizes Tushar Vyavahare
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=ZfSIH07rCk3mjjWc@google.com \
--to=sdf@google.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tirthendu.sarkar@intel.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;
as well as URLs for NNTP newsgroup(s).