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 8A8411B0FC for ; Thu, 25 Oct 2018 17:11:23 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 38E1922038; Thu, 25 Oct 2018 11:11:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 25 Oct 2018 11:11: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=jEmi8dTkGu 5YflmzZBCaIdtq/No7MZB0DJBFJyHSzeg=; b=m8rYnHOc3PfoxBnY4eINlHVOWb H/+kR86oEt+5DQhMb8vDNhnRVi9OBJarcrfZaSPNBwG75ocOBgzID8tvC5RPDbFz wBWdlighQzdVnfukw4Gmryx4OmcUFIPjmi8loqyz27OSHVMY9G9ulem4PGys1Dir 88WACKWdIBjEqIrkk= 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=jEmi8dTkGu5YflmzZBCaIdtq/No7MZB0DJBFJyHSzeg=; b=q2HoLPLH +rxlBlAJQOQgEPaXUmjrKrVqch7f492PlScOk9N4s+TbJPaAwpSlfCa1wE7iZn/9 lM60WxiEcpvhVeZfKZSXy2oazW5IaQODZ6AOF+9O3lCi/yEl9dgetSKFVZRPsHrV H9oX1rJDg1+nGZ0Q0CauelNfT8xvM2lXP8ky6iVu4hHaJiQOPD2UeWyTHBbobC76 GesvH3EB3ZWz+rnJbbi/JwEuK1b02ULC4diBoG2rdwyOYHz3o1+QtxXFnLlRTurx PLp2Ty5896VJsV8M0d83yrdeosir77Wt9VVJ2Ci5+kpE+coAKE79BX1VTEviUwNv P0gcM7zSwxfgSg== 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 BDB70102F0; Thu, 25 Oct 2018 11:11:21 -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: Thu, 25 Oct 2018 17:11:14 +0200 Message-Id: <20181025151117.17132-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181025151117.17132-1-thomas@monjalon.net> References: <20181024134111.26771-1-thomas@monjalon.net> <20181025151117.17132-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 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: Thu, 25 Oct 2018 15:11:23 -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 Acked-by: Bernard Iremonger --- 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 70d08d7d5..dd6e6eacd 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1614,31 +1614,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. */ @@ -2193,28 +2168,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 @@ -2259,7 +2231,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) @@ -2344,13 +2316,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"); } @@ -2396,7 +2366,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