netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luigi Rizzo <lrizzo@google.com>
To: magnus.karlsson@intel.com, bjorn.topel@intel.com,
	jonathan.lemon@gmail.com, netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, rizzo@iet.unipi.it, Luigi Rizzo <lrizzo@google.com>
Subject: [PATCH] net-af_xdp: use correct number of channels from ethtool
Date: Mon, 18 Nov 2019 14:55:23 -0800	[thread overview]
Message-ID: <20191118225523.41697-1-lrizzo@google.com> (raw)

Drivers use different fields to report the number of channels, so take
the maximum of all fields (rx, tx, other, combined) when determining the
size of the xsk map. The current code used only 'combined' which was set
to 0 in some drivers e.g. mlx4.

Tested: compiled and run xdpsock -q 3 -r -S on mlx4
Signed-off-by: Luigi Rizzo <lrizzo@google.com>
---
 tools/lib/bpf/xsk.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 74d84f36a5b24..8e12269428d08 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -412,6 +412,11 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
 	return 0;
 }
 
+static inline int max_i(int a, int b)
+{
+	return a > b ? a : b;
+}
+
 static int xsk_get_max_queues(struct xsk_socket *xsk)
 {
 	struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
@@ -431,13 +436,18 @@ static int xsk_get_max_queues(struct xsk_socket *xsk)
 		goto out;
 	}
 
-	if (err || channels.max_combined == 0)
+	if (err) {
 		/* If the device says it has no channels, then all traffic
 		 * is sent to a single stream, so max queues = 1.
 		 */
 		ret = 1;
-	else
-		ret = channels.max_combined;
+	} else {
+		/* Take the max of rx, tx, other, combined. Drivers return
+		 * the number of channels in different ways.
+		 */
+		ret = max_i(max_i(channels.max_rx, channels.max_tx),
+			      max_i(channels.max_other, channels.max_combined));
+	}
 
 out:
 	close(fd);
-- 
2.24.0.432.g9d3f5f5b63-goog


             reply	other threads:[~2019-11-18 22:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18 22:55 Luigi Rizzo [this message]
2019-11-18 23:10 ` [PATCH] net-af_xdp: use correct number of channels from ethtool Jakub Kicinski
2019-11-19  0:20   ` Luigi Rizzo

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=20191118225523.41697-1-lrizzo@google.com \
    --to=lrizzo@google.com \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=jonathan.lemon@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=rizzo@iet.unipi.it \
    /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).