From: Huisong Li <lihuisong@huawei.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <ferruh.yigit@xilinx.com>,
<andrew.rybchenko@oktetlabs.ru>, <huangdaode@huawei.com>,
<lihuisong@huawei.com>
Subject: [PATCH 5/6] app/testpmd: support attach and detach port for MP
Date: Thu, 25 Aug 2022 10:57:18 +0800 [thread overview]
Message-ID: <20220825025719.14281-6-lihuisong@huawei.com> (raw)
In-Reply-To: <20220825025719.14281-1-lihuisong@huawei.com>
This patch supports attach and detach port in primary and secondary
process.
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
app/test-pmd/testpmd.c | 76 +++++++++++++++++----------
app/test-pmd/testpmd.h | 1 -
drivers/net/bonding/bonding_testpmd.c | 1 -
3 files changed, 47 insertions(+), 31 deletions(-)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index c743d65cf2..e4f17f40b6 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3356,9 +3356,6 @@ reset_port(portid_t pid)
void
attach_port(char *identifier)
{
- portid_t pi;
- struct rte_dev_iterator iterator;
-
printf("Attaching a new port...\n");
if (identifier == NULL) {
@@ -3370,24 +3367,6 @@ attach_port(char *identifier)
TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier);
return;
}
-
- /* first attach mode: event */
- if (setup_on_probe_event) {
- /* new ports are detected on RTE_ETH_EVENT_NEW event */
- for (pi = 0; pi < RTE_MAX_ETHPORTS; pi++)
- if (ports[pi].port_status == RTE_PORT_HANDLING &&
- ports[pi].need_setup != 0)
- setup_attached_port(pi);
- return;
- }
-
- /* second attach mode: iterator */
- RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) {
- /* setup ports matching the devargs used for probing */
- if (port_is_forwarding(pi))
- continue; /* port was already attached before */
- setup_attached_port(pi);
- }
}
static void
@@ -3410,7 +3389,6 @@ setup_attached_port(portid_t pi)
ports_ids[nb_ports++] = pi;
fwd_ports_ids[nb_fwd_ports++] = pi;
nb_cfg_ports = nb_fwd_ports;
- ports[pi].need_setup = 0;
ports[pi].port_status = RTE_PORT_STOPPED;
printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
@@ -3444,11 +3422,10 @@ detach_device(struct rte_device *dev)
TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
return;
}
- remove_invalid_ports();
printf("Device is detached\n");
- printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
+
return;
}
@@ -3514,11 +3491,9 @@ detach_devargs(char *identifier)
return;
}
- remove_invalid_ports();
-
printf("Device %s is detached\n", identifier);
- printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
+
rte_devargs_reset(&da);
}
@@ -3682,11 +3657,52 @@ rmv_port_callback(void *arg)
struct rte_device *device = dev_info.device;
close_port(port_id);
detach_device(device); /* might be already removed or have more ports */
+ remove_invalid_ports();
+ printf("Now total ports is %d\n", nb_ports);
}
if (need_to_start)
start_packet_forwarding(0);
}
+static void config_attached_port(portid_t port_id)
+{
+ struct rte_dev_iterator iterator;
+ struct rte_eth_dev_info dev_info;
+ portid_t pi;
+ int ret;
+
+ /* first attach mode: event */
+ if (setup_on_probe_event) {
+ /* new ports are detected on RTE_ETH_EVENT_NEW event */
+ setup_attached_port(port_id);
+ return;
+ }
+
+ ret = eth_dev_info_get_print_err(port_id, &dev_info);
+ if (ret != 0) {
+ TESTPMD_LOG(ERR,
+ "Failed to get device info for port %d, not detaching\n",
+ port_id);
+ return;
+ }
+ /* second attach mode: iterator */
+ RTE_ETH_FOREACH_MATCHING_DEV(pi, dev_info.device->name, &iterator) {
+ /* setup ports matching the devargs used for probing */
+ if (port_is_forwarding(port_id))
+ continue; /* port was already attached before */
+ setup_attached_port(port_id);
+ }
+}
+
+static void
+remove_invalid_ports_callback(void *arg)
+{
+ RTE_SET_USED(arg);
+
+ remove_invalid_ports();
+ printf("Now total ports is %d\n", nb_ports);
+}
+
/* This function is used by the interrupt thread */
static int
eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
@@ -3711,8 +3727,7 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
switch (type) {
case RTE_ETH_EVENT_NEW:
- ports[port_id].need_setup = 1;
- ports[port_id].port_status = RTE_PORT_HANDLING;
+ config_attached_port(port_id);
break;
case RTE_ETH_EVENT_INTR_RMV:
if (rte_eal_alarm_set(100000,
@@ -3723,6 +3738,9 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
case RTE_ETH_EVENT_DESTROY:
ports[port_id].port_status = RTE_PORT_CLOSED;
printf("Port %u is closed\n", port_id);
+ if (rte_eal_alarm_set(100000, remove_invalid_ports_callback,
+ (void *)(intptr_t)port_id))
+ fprintf(stderr, "Could not set up deferred device released\n");
break;
case RTE_ETH_EVENT_RX_AVAIL_THRESH: {
uint16_t rxq_id;
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index fb2f5195d3..ddfa911bd9 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -278,7 +278,6 @@ struct rte_port {
uint16_t tx_vlan_id;/**< The tag ID */
uint16_t tx_vlan_id_outer;/**< The outer tag ID */
volatile uint16_t port_status; /**< port started or not */
- uint8_t need_setup; /**< port just attached */
uint8_t need_reconfig; /**< need reconfiguring port or not */
uint8_t need_reconfig_queues; /**< need reconfiguring queues or not */
uint8_t rss_flag; /**< enable rss or not */
diff --git a/drivers/net/bonding/bonding_testpmd.c b/drivers/net/bonding/bonding_testpmd.c
index 3941f4cf23..ed1a278a44 100644
--- a/drivers/net/bonding/bonding_testpmd.c
+++ b/drivers/net/bonding/bonding_testpmd.c
@@ -763,7 +763,6 @@ static void cmd_create_bonded_device_parsed(void *parsed_result,
port_id, rte_strerror(-ret));
ports[port_id].bond_flag = 1;
- ports[port_id].need_setup = 0;
ports[port_id].port_status = RTE_PORT_STOPPED;
}
--
2.22.0
next prev parent reply other threads:[~2022-08-25 2:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 2:57 [PATCH 0/6] " Huisong Li
2022-08-25 2:57 ` [PATCH 1/6] bus/pci: fix a segfault when call callback Huisong Li
2022-08-25 2:57 ` [PATCH 2/6] bus/vdev: " Huisong Li
2022-08-25 2:57 ` [PATCH 3/6] ethdev: fix push new event Huisong Li
2022-08-25 2:57 ` [PATCH 4/6] app/testpmd: check the validity of the port Huisong Li
2022-08-25 2:57 ` Huisong Li [this message]
2022-08-25 2:57 ` [PATCH 6/6] app/testpmd: stop packet forwarding in new and destroy event Huisong Li
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=20220825025719.14281-6-lihuisong@huawei.com \
--to=lihuisong@huawei.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@xilinx.com \
--cc=huangdaode@huawei.com \
--cc=thomas@monjalon.net \
/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).