From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4D63BA0562; Thu, 2 Apr 2020 19:21:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B4B8F1BFD1; Thu, 2 Apr 2020 19:20:13 +0200 (CEST) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by dpdk.org (Postfix) with ESMTP id 801CA1BF4F for ; Thu, 2 Apr 2020 19:20:11 +0200 (CEST) Received: by mail-pg1-f173.google.com with SMTP id r4so667983pgg.4 for ; Thu, 02 Apr 2020 10:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sUMR01S/YIkpWMDDAJP2AboXvR5VIfAsd2eiFf5CcZg=; b=jVq09ixKJ0i7RCme+TMeGUcBCUwEpL8Z7bLbIH6/XJ9kSzy2M9bDTJaY1Vjf9G437h dJEnt3WhMsJAW26Eul8bUTZRhCI7NWtw/CMqB01qd5FVaxIiUUmb1m9XhI2OGErcAf1m zWZkNJadr4/gPOFeqecCuoa2wJgAqv1Dg8ACOzGFiU8h2u6Zk58IBwDMRfbFVfdQMoYq eFu5gKAy5ci6bdj2EI3ZyfVbEj/dtiYoXtEYNYQWidX09obSh3Vo1XRVD3W4vDWs01ld ztr/SEuVaT/JYSsE1iBmxOjGk2iNdej5UTNM8UjDDnzoVxrS0X+HNsPjiNjaolIix6Jv E1XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sUMR01S/YIkpWMDDAJP2AboXvR5VIfAsd2eiFf5CcZg=; b=Ia9nxvAC9KoORlf/R9zWzhhnqlR25jozh2P22JOcoJoKDO9sQhl1qPTck1myrxp2/z wODWmqIA/S8YT9+W1fj1MDg0NWwW67HQAdl0fRidCSxuQNfrfhVMIj4GaN96zgCedgwg zR4/FAS+AqwFFvnL9TWVP4cVey4O3z/Tu+e/bjnqW9YgTvhgKH62/I3DiCvaReqpsG4p zokuVP2KAzh8FStEbyRxYfSCpvxCd+MOC6pxSbcmGYfeVI97cQLea0TIjxuBmekstr5U g2nW1c8cTsLbrLLp+oJEWungaumEmAW+E1YmedLGxogKAqVfsZLcZchs0LovmF8bCF9c I2hA== X-Gm-Message-State: AGi0Pub02NzmgclZivcvjWEz1SFL5E+dtRL3zJu6WYCM8Hk9FhOAEUev MFU1Mn2Nb+zfePr7BTOsTfAxOiQEAseMlA== X-Google-Smtp-Source: APiQypIZ6WSJI6wiAR661mPBK+6wjvu/gGI66l9ZE/GxBBb4WqIY68D2GiErtdHQCHGHlJBHUXKJXw== X-Received: by 2002:a65:6250:: with SMTP id q16mr4414506pgv.9.1585848010167; Thu, 02 Apr 2020 10:20:10 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id y28sm4152347pfp.128.2020.04.02.10.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 10:20:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , jijiang.liu@intel.com, stable@dpdk.org Date: Thu, 2 Apr 2020 10:19:53 -0700 Message-Id: <20200402171953.13356-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200402171953.13356-1-stephen@networkplumber.org> References: <20200312172047.19973-1-stephen@networkplumber.org> <20200402171953.13356-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 6/6] examples/tep_termination: rework the port setup logic X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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