From patchwork Tue Jan 30 06:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lihuisong (C)" X-Patchwork-Id: 136215 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 926A543A06; Tue, 30 Jan 2024 07:38:10 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 86246410E4; Tue, 30 Jan 2024 07:37:44 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 8949440DFD for ; Tue, 30 Jan 2024 07:37:38 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4TPFnK2QR4zNlrd; Tue, 30 Jan 2024 14:36:37 +0800 (CST) Received: from kwepemm600004.china.huawei.com (unknown [7.193.23.242]) by mail.maildlp.com (Postfix) with ESMTPS id 72D7014040F; Tue, 30 Jan 2024 14:37:36 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 14:37:35 +0800 From: Huisong Li To: , Aman Singh , Yuying Zhang , Chas Williams , "Min Hu (Connor)" CC: , , , , , , Subject: [PATCH v7 4/5] app/testpmd: add attach and detach port for multiple process Date: Tue, 30 Jan 2024 14:36:47 +0800 Message-ID: <20240130063648.32131-5-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240130063648.32131-1-lihuisong@huawei.com> References: <20220825024425.10534-1-lihuisong@huawei.com> <20240130063648.32131-1-lihuisong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600004.china.huawei.com (7.193.23.242) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Signed-off-by: Dongdong Liu Acked-by: Chengwen Feng --- 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(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 859d4aad7d..db985d33a3 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -3625,15 +3625,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) { @@ -3664,7 +3661,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); @@ -3698,10 +3694,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; } @@ -3768,11 +3762,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); } @@ -3936,11 +3928,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, @@ -3965,8 +3968,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, @@ -3977,6 +3980,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 9b10a9ea1c..0e860c2e67 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -326,7 +326,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 8fcd6cadd0..f4845206ad 100644 --- a/drivers/net/bonding/bonding_testpmd.c +++ b/drivers/net/bonding/bonding_testpmd.c @@ -493,7 +493,6 @@ static void cmd_create_bonding_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; }