From: Thomas Monjalon <thomas@monjalon.net>
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
Subject: [dpdk-dev] [PATCH 2/5] app/testpmd: merge ports list update functions
Date: Wed, 24 Oct 2018 15:41:08 +0200 [thread overview]
Message-ID: <20181024134111.26771-3-thomas@monjalon.net> (raw)
In-Reply-To: <20181024134111.26771-1-thomas@monjalon.net>
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 <thomas@monjalon.net>
---
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
next prev parent reply other threads:[~2018-10-24 13:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 13:41 [dpdk-dev] [PATCH 0/5] app/testpmd: improve attach/detach support Thomas Monjalon
2018-10-24 13:41 ` [dpdk-dev] [PATCH 1/5] app/testpmd: check not detaching device twice Thomas Monjalon
2018-10-24 15:38 ` Iremonger, Bernard
2018-10-24 13:41 ` Thomas Monjalon [this message]
2018-10-24 15:45 ` [dpdk-dev] [PATCH 2/5] app/testpmd: merge ports list update functions Iremonger, Bernard
2018-10-24 13:41 ` [dpdk-dev] [PATCH 3/5] app/testpmd: check not configuring port twice Thomas Monjalon
2018-10-24 15:50 ` Iremonger, Bernard
2018-10-24 13:41 ` [dpdk-dev] [PATCH 4/5] app/testpmd: move ethdev events registration Thomas Monjalon
2018-10-24 15:55 ` Iremonger, Bernard
2018-10-24 19:55 ` Thomas Monjalon
2018-10-25 8:54 ` Iremonger, Bernard
2018-10-25 8:58 ` Thomas Monjalon
2018-10-24 13:41 ` [dpdk-dev] [PATCH 5/5] app/testpmd: setup attached ports on probe event Thomas Monjalon
2018-10-24 16:13 ` Iremonger, Bernard
2018-10-24 19:57 ` Thomas Monjalon
2018-10-25 8:58 ` Iremonger, Bernard
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 0/5] app/testpmd: improve attach/detach support Thomas Monjalon
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 1/5] app/testpmd: check not detaching device twice Thomas Monjalon
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 2/5] app/testpmd: merge ports list update functions Thomas Monjalon
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 3/5] app/testpmd: check not configuring port twice Thomas Monjalon
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 4/5] app/testpmd: move ethdev events registration Thomas Monjalon
2018-10-25 16:05 ` Iremonger, Bernard
2018-10-25 15:11 ` [dpdk-dev] [PATCH v2 5/5] app/testpmd: setup attached ports on probe event Thomas Monjalon
2018-10-25 16:07 ` Iremonger, Bernard
2018-10-26 12:46 ` [dpdk-dev] [PATCH v2 0/5] app/testpmd: improve attach/detach support Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181024134111.26771-3-thomas@monjalon.net \
--to=thomas@monjalon.net \
--cc=arybchenko@solarflare.com \
--cc=bernard.iremonger@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=jingjing.wu@intel.com \
--cc=ophirmu@mellanox.com \
--cc=wenzhuo.lu@intel.com \
--cc=wisamm@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).