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 160C95689 for ; Wed, 24 Oct 2018 15:41:24 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A98CD22054; Wed, 24 Oct 2018 09:41:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 24 Oct 2018 09:41:23 -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=YxpnhGGxJ7 PwgVW9pPQRxAyw6MrTml7DYrA5C48kWU8=; b=fsBMe1vvg+zEX07zCphYvWfI9B jRO8EOGqMp4Yoj+5feUFDfgsabhLW+zE9q0x485flKDg/cgPnO18aiS2lkI4ydMf I0dmh9ihn3rvtF4BLsVU4bD9Vp9lTwS7wG87ZGy87OnmW/FspqIh+8H0Wbzv9Bjn hQYs18TYfwBVK/i9E= 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=YxpnhGGxJ7PwgVW9pPQRxAyw6MrTml7DYrA5C48kWU8=; b=SrYUJVI+ RHo/4Q7DE9OdD5J+M0nnWWVDbPLWcbtyrSJ4V6AlsUNIfIeuT8Ntbi16E0YYELwh ppNK8MfFelEhQ+2xO1JiAbgKPsi0I9ZmSHF3lrC7WeBut5Brz4uBFhUXY8E9yz/B HXC88brYdywdqvdTXW2YTCNRLNsRnSB6o2DF65DMj1I8b5U34wJKeGAPpyadfE0m 1ycENrWIsgCirzjSigSdLvyTZ55b0+zuvXYseGWgbNVVMJ7evXfrrWdNxvI0s5vu wxvdtvdDxlDvPEdiViOoy9iv6jXNuNbe7RG8CHIVcgL7IkkIUo6U5j9md8wSYNTD ywdgqAjcNz1qGQ== 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 7358EE4122; Wed, 24 Oct 2018 09:41:22 -0400 (EDT) From: Thomas Monjalon To: bernard.iremonger@intel.com, jingjing.wu@intel.com, wenzhuo.lu@intel.com Cc: dev@dpdk.org, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Wed, 24 Oct 2018 15:41:08 +0200 Message-Id: <20181024134111.26771-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181024134111.26771-1-thomas@monjalon.net> References: <20181024134111.26771-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/5] app/testpmd: merge ports list update functions 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: Wed, 24 Oct 2018 13:41:24 -0000 The arrays ports_ids and fwd_ports_ids require the same kind of update when some ports are removed or added. The functions update_fwd_ports() and remove_unused_fwd_ports() are merged in the new function remove_invalid_ports(). The part for adding new port is moved into setup_attached_port(). Signed-off-by: Thomas Monjalon --- app/test-pmd/testpmd.c | 74 +++++++++++++----------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 56e408cdf..21627ecb6 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1609,31 +1609,6 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore) } } -/* - * Update the forward ports list. - */ -void -update_fwd_ports(portid_t new_pid) -{ - unsigned int i; - unsigned int new_nb_fwd_ports = 0; - int move = 0; - - for (i = 0; i < nb_fwd_ports; ++i) { - if (port_id_is_invalid(fwd_ports_ids[i], DISABLED_WARN)) - move = 1; - else if (move) - fwd_ports_ids[new_nb_fwd_ports++] = fwd_ports_ids[i]; - else - new_nb_fwd_ports++; - } - if (new_pid < RTE_MAX_ETHPORTS) - fwd_ports_ids[new_nb_fwd_ports++] = new_pid; - - nb_fwd_ports = new_nb_fwd_ports; - nb_cfg_ports = new_nb_fwd_ports; -} - /* * Launch packet forwarding configuration. */ @@ -2188,28 +2163,25 @@ stop_port(portid_t pid) } static void -remove_unused_fwd_ports(void) +remove_invalid_ports_in(portid_t *array, portid_t *total) { - int i; - int last_port_idx = nb_ports - 1; + portid_t i; + portid_t new_total = 0; - 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); + for (i = 0; i < *total; i++) + if (!port_id_is_invalid(array[i], DISABLED_WARN)) { + array[new_total] = array[i]; + new_total++; + } + *total = new_total; +} + +static void +remove_invalid_ports(void) +{ + remove_invalid_ports_in(ports_ids, &nb_ports); + remove_invalid_ports_in(fwd_ports_ids, &nb_fwd_ports); + nb_cfg_ports = nb_fwd_ports; } void @@ -2254,7 +2226,7 @@ close_port(portid_t pid) port_flow_flush(pi); rte_eth_dev_close(pi); - remove_unused_fwd_ports(); + remove_invalid_ports(); if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0) @@ -2339,13 +2311,11 @@ setup_attached_port(portid_t pi) reconfig(pi, socket_id); rte_eth_promiscuous_enable(pi); - ports_ids[nb_ports] = pi; - nb_ports = rte_eth_dev_count_avail(); - + ports_ids[nb_ports++] = pi; + fwd_ports_ids[nb_fwd_ports++] = pi; + nb_cfg_ports = nb_fwd_ports; ports[pi].port_status = RTE_PORT_STOPPED; - update_fwd_ports(pi); - printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports); printf("Done\n"); } @@ -2391,7 +2361,7 @@ detach_port_device(portid_t port_id) } } - remove_unused_fwd_ports(); + remove_invalid_ports(); printf("Device of port %u is detached\n", port_id); printf("Now total ports is %d\n", nb_ports); -- 2.19.0