[V6,4/5] app/testpmd: add attach and detach port for multiple process
Checks
Commit Message
The port information needs to be updated due to attaching and detaching
port. Currently, it is done in the same thread as removing or probing
device, which doesn't satisfy the operation of attaching and detaching
device in multiple process.
If this operation is performed in one process, the other process can
receive 'new' or 'destroy' event. So we can move updating port information
to event callback to support attaching and detaching port in primary and
secondary process.
The reason for adding an alarm callback in 'destroy' event is that the
ethdev state is changed from 'ATTACHED' to 'UNUSED' only after the event
callback finished. But the remove_invalid_ports() function removes invalid
port only if ethdev state is 'UNUSED'. If we don't add alarm callback, this
detached port information can not be removed.
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
app/test-pmd/testpmd.c | 38 ++++++++++++++++-----------
app/test-pmd/testpmd.h | 1 -
drivers/net/bonding/bonding_testpmd.c | 1 -
3 files changed, 22 insertions(+), 18 deletions(-)
@@ -3596,15 +3596,12 @@ attach_port(char *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);
+ /*
+ * first attach mode: event, setting up attached port is done in
+ * probing callback.
+ */
+ if (setup_on_probe_event)
return;
- }
/* second attach mode: iterator */
RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) {
@@ -3635,7 +3632,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);
@@ -3669,10 +3665,8 @@ detach_device(struct rte_device *dev)
TESTPMD_LOG(ERR, "Failed to detach device %s\n", rte_dev_name(dev));
return;
}
- remove_invalid_ports();
printf("Device is detached\n");
- printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
return;
}
@@ -3739,11 +3733,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);
}
@@ -3907,11 +3899,22 @@ 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
+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,
@@ -3936,8 +3939,8 @@ 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;
+ if (setup_on_probe_event)
+ setup_attached_port(port_id);
break;
case RTE_ETH_EVENT_INTR_RMV:
if (rte_eal_alarm_set(100000,
@@ -3948,6 +3951,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;
@@ -308,7 +308,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 */
@@ -493,7 +493,6 @@ static void cmd_create_bonded_device_parsed(void *parsed_result,
ports[port_id].update_conf = 1;
ports[port_id].bond_flag = 1;
- ports[port_id].need_setup = 0;
ports[port_id].port_status = RTE_PORT_STOPPED;
}