patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	jijiang.liu@intel.com, stable@dpdk.org
Subject: [dpdk-stable] [PATCH v3 6/6] examples/tep_termination: rework the port setup logic
Date: Thu,  2 Apr 2020 10:19:53 -0700	[thread overview]
Message-ID: <20200402171953.13356-7-stephen@networkplumber.org> (raw)
In-Reply-To: <20200402171953.13356-1-stephen@networkplumber.org>

The handling of ports in this application had many problems.
It was checking for things that can never happen with current
DPDK library (like rte_ethdev_avail_count() >= RTE_MAX_ETHPORTS)
and it was not checking if the port was owned and should
not be used directly. Also the variable nb_ports was used
as both local and global variable.

Fix by rewriting the initialization logic to iterate over
valid ports and check if there are any leftovers.

Fixes: a50245ede72a ("examples/tep_term: initialize VXLAN sample")
Cc: jijiang.liu@intel.com
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/tep_termination/Makefile    |  2 +
 examples/tep_termination/main.c      | 70 ++++++++++------------------
 examples/tep_termination/meson.build |  1 +
 3 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/examples/tep_termination/Makefile b/examples/tep_termination/Makefile
index 645112498d33..f55331fb24c2 100644
--- a/examples/tep_termination/Makefile
+++ b/examples/tep_termination/Makefile
@@ -26,6 +26,7 @@ CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
 LDFLAGS_STATIC = -Wl,-Bstatic $(shell $(PKGCONF) --static --libs libdpdk)
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -Wno-deprecated-declarations
 
 build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
@@ -61,6 +62,7 @@ endif
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -Wno-deprecated-declarations
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 include $(RTE_SDK)/mk/rte.extapp.mk
 endif
diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c
index ab956ad7ce96..beb3ff7d78e0 100644
--- a/examples/tep_termination/main.c
+++ b/examples/tep_termination/main.c
@@ -149,8 +149,6 @@ static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
 static unsigned lcore_ids[RTE_MAX_LCORE];
 uint16_t ports[RTE_MAX_ETHPORTS];
 
-static unsigned nb_ports; /**< The number of ports specified in command line */
-
 /* ethernet addresses of ports */
 struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
 
@@ -268,7 +266,6 @@ tep_termination_parse_args(int argc, char **argv)
 {
 	int opt, ret;
 	int option_index;
-	unsigned i;
 	const char *prgname = argv[0];
 	static struct option long_option[] = {
 		{CMD_LINE_OPT_NB_DEVICES, required_argument, NULL, 0},
@@ -474,18 +471,6 @@ tep_termination_parse_args(int argc, char **argv)
 		}
 	}
 
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (enabled_port_mask & (1 << i))
-			ports[nb_ports++] = (uint8_t)i;
-	}
-
-	if ((nb_ports ==  0) || (nb_ports > MAX_SUP_PORTS)) {
-		RTE_LOG(INFO, VHOST_PORT, "Current enabled port number is %u,"
-			"but only %u port can be enabled\n", nb_ports,
-			MAX_SUP_PORTS);
-		return -1;
-	}
-
 	return 0;
 }
 
@@ -493,28 +478,29 @@ tep_termination_parse_args(int argc, char **argv)
  * Update the global var NB_PORTS and array PORTS
  * according to system ports number and return valid ports number
  */
-static unsigned
-check_ports_num(unsigned max_nb_ports)
+static unsigned int
+get_ports(void)
 {
-	unsigned valid_nb_ports = nb_ports;
-	unsigned portid;
-
-	if (nb_ports > max_nb_ports) {
-		RTE_LOG(INFO, VHOST_PORT, "\nSpecified port number(%u) "
-			" exceeds total system port number(%u)\n",
-			nb_ports, max_nb_ports);
-		nb_ports = max_nb_ports;
+	uint32_t port_mask = enabled_port_mask;
+	unsigned int valid_nb_ports = 0;
+	uint16_t portid;
+
+	RTE_ETH_FOREACH_DEV(portid) {
+		uint32_t mask = 1u << portid;
+
+		if ((mask & port_mask) == 0)
+			continue;
+
+		port_mask &= ~mask;
+		ports[valid_nb_ports++] = portid;
 	}
 
-	for (portid = 0; portid < nb_ports; portid++) {
-		if (!rte_eth_dev_is_valid_port(ports[portid])) {
-			RTE_LOG(INFO, VHOST_PORT,
-				"\nSpecified port ID(%u) is not valid\n",
-				ports[portid]);
-			ports[portid] = INVALID_PORT_ID;
-			valid_nb_ports--;
-		}
+	if (port_mask != 0) {
+		RTE_LOG(INFO, VHOST_PORT,
+			"\nInvalid ports %#x specified in portmask\n",
+			port_mask);
 	}
+
 	return valid_nb_ports;
 }
 
@@ -1123,7 +1109,7 @@ main(int argc, char *argv[])
 {
 	struct rte_mempool *mbuf_pool = NULL;
 	unsigned lcore_id, core_id = 0;
-	unsigned nb_ports, valid_nb_ports;
+	unsigned int valid_nb_ports;
 	int ret;
 	uint16_t portid;
 	uint16_t queue_id;
@@ -1148,20 +1134,14 @@ main(int argc, char *argv[])
 	/* set the number of swithcing cores available */
 	nb_switching_cores = rte_lcore_count()-1;
 
-	/* Get the number of physical ports. */
-	nb_ports = rte_eth_dev_count_avail();
-
-	/*
-	 * Update the global var NB_PORTS and global array PORTS
-	 * and get value of var VALID_NB_PORTS according to system ports number
-	 */
-	valid_nb_ports = check_ports_num(nb_ports);
-
-	if ((valid_nb_ports == 0) || (valid_nb_ports > MAX_SUP_PORTS)) {
+	/* Set ports[] array based on system ports and port mask */
+	valid_nb_ports = get_ports();
+	if (valid_nb_ports == 0 || valid_nb_ports > MAX_SUP_PORTS) {
 		rte_exit(EXIT_FAILURE, "Current enabled port number is %u,"
-			"but only %u port can be enabled\n", nb_ports,
+			"but only %u port can be enabled\n", valid_nb_ports,
 			MAX_SUP_PORTS);
 	}
+
 	/* Create the mbuf pool. */
 	mbuf_pool = rte_pktmbuf_pool_create(
 			"MBUF_POOL",
diff --git a/examples/tep_termination/meson.build b/examples/tep_termination/meson.build
index f65d689802a3..ddadf1c2aede 100644
--- a/examples/tep_termination/meson.build
+++ b/examples/tep_termination/meson.build
@@ -9,6 +9,7 @@
 if not is_linux
 	build = false
 endif
+allow_experimental_apis = true
 deps += ['hash', 'vhost']
 cflags += '-Wno-deprecated-declarations'
 sources = files(
-- 
2.20.1


  parent reply	other threads:[~2020-04-02 17:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200312172047.19973-1-stephen@networkplumber.org>
2020-03-12 17:20 ` [dpdk-stable] [PATCH 1/7] ethdev: add function to test port ownership Stephen Hemminger
2020-03-15  7:45   ` Matan Azrad
2020-03-12 17:20 ` [dpdk-stable] [PATCH 2/7] examples/l2fwd-cat: block attempts to use owned ports Stephen Hemminger
2020-03-15  7:51   ` Matan Azrad
2020-03-12 17:20 ` [dpdk-stable] [PATCH 3/7] examples/l3fwd: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-stable] [PATCH 4/7] examples/l3fwd-acl: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-stable] [PATCH 5/7] examples/l3fwd-power: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-stable] [PATCH 6/7] examples/tep_termination: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-stable] [PATCH 7/7] examples/vhost: " Stephen Hemminger
     [not found] ` <20200316160923.5335-1-stephen@networkplumber.org>
2020-03-16 16:09   ` [dpdk-stable] [PATCH v2 2/6] examples/l2fwd-cat: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-stable] [PATCH v2 3/6] examples/l3fwd: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-stable] [PATCH v2 4/6] examples/l3fwd-acl: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-stable] [PATCH v2 5/6] examples/l3fwd-power: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-stable] [PATCH v2 6/6] examples/tep_termination: " Stephen Hemminger
     [not found] ` <20200402171953.13356-1-stephen@networkplumber.org>
2020-04-02 17:19   ` [dpdk-stable] [PATCH v3 2/6] examples/l2fwd-cat: make applicaton aware of port ownership Stephen Hemminger
2020-04-10 15:47     ` Ferruh Yigit
2020-04-02 17:19   ` [dpdk-stable] [PATCH v3 3/6] examples/l3fwd: " Stephen Hemminger
2020-04-02 17:19   ` [dpdk-stable] [PATCH v3 4/6] examples/l3fwd-acl: " Stephen Hemminger
2020-04-02 17:19   ` [dpdk-stable] [PATCH v3 5/6] examples/l3fwd-power: " Stephen Hemminger
2020-04-02 17:19   ` Stephen Hemminger [this message]
2020-04-10 16:16     ` [dpdk-stable] [PATCH v3 6/6] examples/tep_termination: rework the port setup logic 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=20200402171953.13356-7-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=jijiang.liu@intel.com \
    --cc=stable@dpdk.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).