From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 8FDA75F65 for ; Thu, 18 Oct 2018 03:24:07 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 00C0D21F3A; Wed, 17 Oct 2018 21:24:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:24:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=CMVfhs8+KW svicfjFkymXc2BumYWSojDnPixFZq9zWI=; b=Sn55qXIfieNX9oTl95CbSxPVKS /TT9bsufiFRRxqJcBgFsQnB0AEWNI/kUv3RiA0zE6oSGcFicUg5irvag2K3mDcRh /lD9nKLlTTPzI0Ttn20jGboyJrW1thEJG61NcSaS0ZKQfYd/dqVuolbm4m3nLRxL vz+z41DJs1JIs63cA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=CMVfhs8+KWsvicfjFkymXc2BumYWSojDnPixFZq9zWI=; b=C/pEA20l F1SnwucBLVDc5hReCOZRlLb28L2WAvDzbDUoEHJtVu8/WWpCFRHZd/WZIj0DNZvR Lnmo3zRW8LRkudgJIMS24jMltJh+PYEzR8/MoxtHy7mXau3Pko7EcRWgfq4KnCXm rIk3wf6xYGXRjtH+I+L5RBp5SMZ4BF9/D0v80y1mRsixymioySWZAguxH1elFqQx dfzMVjhp3uEBJXtAO+PlkymtVh/wLkzzM1H+VJ/sY2XiZ5tmHoMF4FrHeWUvQMNA 8+ovX6MCTN1X0zrKvolq/+WGufrm7J2wlsV+Jp/B9QKjVTF64bx1x7bbZu0lbmHM UvhL/VyLWFkgJQ== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id C2401102DE; Wed, 17 Oct 2018 21:24:05 -0400 (EDT) From: Thomas Monjalon To: ferruh.yigit@intel.com, arybchenko@solarflare.com Cc: dev@dpdk.org, ophirmu@mellanox.com, bernard.iremonger@intel.com, rahul.lakkireddy@chelsio.com, Wisam Jaddo Date: Thu, 18 Oct 2018 03:23:57 +0200 Message-Id: <20181018012402.1240-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018012402.1240-1-thomas@monjalon.net> References: <20180907233929.21950-1-thomas@monjalon.net> <20181018012402.1240-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 1/6] app/testpmd: fix ports list after removing several at once 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: , X-List-Received-Date: Thu, 18 Oct 2018 01:24:08 -0000 From: Wisam Jaddo When detaching a port, the full rte_device is removed. If the rte_device was hosting several ports, the testpmd list of ports must be updated for multiple removals. Signed-off-by: Wisam Jaddo --- app/test-pmd/testpmd.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 5dbbf783f..c4109417a 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2186,6 +2186,30 @@ stop_port(portid_t pid) printf("Done\n"); } +static void +remove_unused_fwd_ports(void) +{ + int i; + int last_port_idx = nb_ports - 1; + + for (i = 0; i < last_port_idx + 1; i++) { /* iterate in ports_ids */ + if (rte_eth_devices[ports_ids[i]].state == RTE_ETH_DEV_UNUSED) { + /* skip unused ports at the end */ + while (rte_eth_devices[ports_ids[last_port_idx]].state + == RTE_ETH_DEV_UNUSED && i <= last_port_idx) + last_port_idx--; + if (last_port_idx < i) + break; + /* overwrite unused port with last valid port */ + ports_ids[i] = ports_ids[last_port_idx]; + /* decrease ports count */ + last_port_idx--; + } + } + nb_ports = rte_eth_dev_count_avail(); + update_fwd_ports(RTE_MAX_ETHPORTS); +} + void close_port(portid_t pid) { @@ -2315,7 +2339,6 @@ void detach_port(portid_t port_id) { char name[RTE_ETH_NAME_MAX_LEN]; - uint16_t i; printf("Detaching a port...\n"); @@ -2332,16 +2355,7 @@ detach_port(portid_t port_id) return; } - for (i = 0; i < nb_ports; i++) { - if (ports_ids[i] == port_id) { - ports_ids[i] = ports_ids[nb_ports-1]; - ports_ids[nb_ports-1] = 0; - break; - } - } - nb_ports = rte_eth_dev_count_avail(); - - update_fwd_ports(RTE_MAX_ETHPORTS); + remove_unused_fwd_ports(); printf("Port %u is detached. Now total ports is %d\n", port_id, nb_ports); -- 2.19.0