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 1096D1B109 for ; Fri, 19 Oct 2018 04:08:03 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5D949229F2; Thu, 18 Oct 2018 22:08:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 18 Oct 2018 22:08:02 -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=lJVaptiSfQ dgjUDDrYtlUXbLpx2am4KyCAMdidkdksE=; b=HTIPsJ4U1fybRzs20vPeY/vPqe Fx3IXy7cxjOTsVHK7fcVnl3wDQNT/voeUsskABjfvoBrTd9w3g2AMx+99VFaYf3u Urw/87ojrKfnP3MFLsCEhgZwmcmj0DFQdz+nFoec6t7jnvIAJs0HqwEuh8UMTkVL /FbupgJKdPa6CbpNw= 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=lJVaptiSfQdgjUDDrYtlUXbLpx2am4KyCAMdidkdksE=; b=Sv8w22Ow wpA3kM7U3cEfJ3k5goZ3ZvR3Mix0KWdNHKSQAfVcRHQge2ng4iViGRNyVjJDfh/y 4kqTb3T9ev2zQ0UUjKvgrKgdYI09HCTzpItDzBjdMhy1YjnLPBVAqzB7rkDHBTij 7sQ78QiJw3FC8KLuR+2ENeJsGxf/W0kf4myGxxhnqSMS2hwuN6VWQPZq7FRLeK8K OED4pCza0whmOUG+Cp1INddbsT/mHWTUXKoYXtlX8TxhQNwuT4pb2+GyY3RVYVDe b5OzrwNZI/uS40RuWOR97+GI4SeYiwxx4vuGy+ivJHaGcCwuBSxBtoMzxdWbCBxb NcJLmwZIDM/ocw== 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 3A870102E2; Thu, 18 Oct 2018 22:08:01 -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: Fri, 19 Oct 2018 04:07:52 +0200 Message-Id: <20181019020757.27698-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019020757.27698-1-thomas@monjalon.net> References: <20180907233929.21950-1-thomas@monjalon.net> <20181019020757.27698-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 1/6] app/testpmd: update port list for multiple removals 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: Fri, 19 Oct 2018 02:08:03 -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 | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 5dbbf783f..2c0b4a021 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2186,6 +2186,31 @@ 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; i++) { /* iterate in ports_ids */ + if (rte_eth_devices[ports_ids[i]].state != RTE_ETH_DEV_UNUSED) + continue; + /* skip unused ports at the end */ + while (i <= last_port_idx && + rte_eth_devices[ports_ids[last_port_idx]].state + == RTE_ETH_DEV_UNUSED) + 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 +2340,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 +2356,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