DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tiago Lam <tiago.lam@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, linville@tuxdriver.com,
	Tiago Lam <tiago.lam@intel.com>
Subject: [dpdk-dev] [PATCH 3/3] net/af_packet: Get 'framesz' from the iface's MTU.
Date: Tue, 20 Nov 2018 09:54:57 +0000	[thread overview]
Message-ID: <1542707697-175836-3-git-send-email-tiago.lam@intel.com> (raw)
In-Reply-To: <1542707697-175836-1-git-send-email-tiago.lam@intel.com>

Use the underlying MTU to calculate the framsize to be used for the mmap
RINGs. This is to make it more flexible on deployments with different
MTU requirements, instead of using a pre-defined value of 2048B.

If a 'framsz' option is provided, that value is used instead and the MTU
of the underlying interface is ignored.

Signed-off-by: Tiago Lam <tiago.lam@intel.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 33 ++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 4e95dd7..45ee72b 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -788,7 +788,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
 	unsigned k_idx;
 	unsigned int blockcount;
 	unsigned int blocksize = DFLT_BLOCK_SIZE;
-	unsigned int framesize = DFLT_FRAME_SIZE;
+	unsigned int framesize = 0;
 	unsigned int framecount = DFLT_FRAME_COUNT;
 	unsigned int qpairs = 1;
 	unsigned int qdisc_bypass = 1;
@@ -877,17 +877,40 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
 	}
 
 	ifnamelen = strlen(ifname);
-	if (ifnamelen >= sizeof(ifr.ifr_name)) {
+	if (ifnamelen < sizeof(ifr.ifr_name)) {
+		memcpy(ifr.ifr_name, ifname, ifnamelen);
+		ifr.ifr_name[ifnamelen] = '\0';
+	} else {
 		RTE_LOG(ERR, PMD,
 			"%s: I/F name too long (%s)\n",
 			name, ifname);
 		return -1;
 	}
 
+	/*
+	 * Base framesize on the MTU of the underlying interface, if no
+	 * 'framesz' option is given
+	 */
+	if (!framesize) {
+		if (ioctl(*sockfd, SIOCGIFMTU, &ifr) == -1) {
+			RTE_LOG(ERR, PMD,
+				"%s: ioctl failed (SIOCGIFMTU)",
+				name);
+			framesize = DFLT_FRAME_SIZE;
+		} else {
+			framesize = ifr.ifr_mtu;
+			/*
+			 * Align to TPACKET_ALIGNMENT and add TPACKET2_HDRLEN, to
+			 * account for the extra needed space
+			 */
+			framesize = TPACKET_ALIGN(framesize + TPACKET2_HDRLEN);
+		}
+	}
+
 	if (framesize > blocksize) {
-		PMD_LOG(ERR,
-			"%s: AF_PACKET MMAP frame size exceeds block size!",
-		        name);
+		RTE_LOG(ERR, PMD,
+			"%s: AF_PACKET MMAP frame size (%u) exceeds block size (%u)!",
+		        name, framesize, blocksize);
 		return -1;
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2018-11-20  9:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20  9:54 [dpdk-dev] [PATCH 1/3] net/af_packet: set_mtu() decrements sockaddr twice Tiago Lam
2018-11-20  9:54 ` [dpdk-dev] [PATCH 2/3] net/af_packet: Move parse and validation of iface Tiago Lam
2018-11-20  9:54 ` Tiago Lam [this message]
2018-11-20 10:26 ` [dpdk-dev] [PATCH v2 1/3] net/af_packet: set_mtu() decrements sockaddr twice Tiago Lam
2018-11-20 10:26   ` [dpdk-dev] [PATCH v2 2/3] net/af_packet: move parse and validation of iface Tiago Lam
2018-11-27 17:42     ` Ferruh Yigit
2018-11-20 10:26   ` [dpdk-dev] [PATCH v2 3/3] net/af_packet: get 'framesz' from the iface's MTU Tiago Lam
2018-11-27 17:43     ` Ferruh Yigit
2018-11-27 17:45       ` Ferruh Yigit
2018-11-28 13:12       ` Lam, Tiago
2018-11-28 13:33         ` Ferruh Yigit
2018-12-17  9:21           ` Lam, Tiago
2018-12-21 12:21             ` Ferruh Yigit
2019-02-18 18:01         ` Yigit, Ferruh
2019-03-19 13:16           ` Yigit, Ferruh
2019-03-19 13:16             ` Yigit, Ferruh
2018-11-20 10:29   ` [dpdk-dev] [PATCH v2 1/3] net/af_packet: set_mtu() decrements sockaddr twice Kevin Traynor
2018-11-20 10:45     ` Lam, Tiago
2018-11-27 17:42   ` Ferruh Yigit
2018-12-21 12:29   ` Ferruh Yigit

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=1542707697-175836-3-git-send-email-tiago.lam@intel.com \
    --to=tiago.lam@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=linville@tuxdriver.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).