From patchwork Tue May 19 08:54:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Bilal X-Patchwork-Id: 70416 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8B52BA0093; Tue, 19 May 2020 10:55:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7A6841D14E; Tue, 19 May 2020 10:55:15 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 9A6E81C1EB for ; Tue, 19 May 2020 10:55:13 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id v12so14879375wrp.12 for ; Tue, 19 May 2020 01:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=zYeLUhIw2vLuEfR0Z1cgrneZsaE5ZayGK5rrzhcN+xI=; b=mmCAxRv5/YLsXbzxKJzj0j0LumLs5ZaQDaktiCuust63jPSB2Lf16t6UNYK/eaqePB +e38Qunvkmf21lud8fLy0R8bZZ+Du5Ifs0HP1LqiwIdBaA2nsqwAMMw1WKRJNAVKUF40 C28vMNM6udp0KLMjLWTu1HMKBai0BTU2CYzXvrPEHPjOV8phNQYN4eEHaM+V+M34CtV3 p3hE4tw5v3l3kDBmYerivinTPAnB9bNOu4t+bmFJ/NbVyGdsyCUVk0i9MEawINkIISb+ 5aAnHM2DpHIiZ2WN6j7OmiOKZNexnsG6WXwiO9XVGYpd6LxBxjd8NRZ+R2E3sw2Ot7PW OqDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zYeLUhIw2vLuEfR0Z1cgrneZsaE5ZayGK5rrzhcN+xI=; b=EcNWf0d7NhBf1ijJqs23CX95ortLO+245cGTo/JvhHjgg6YLL07fkfjWHD3FVK6MWl BkEicIWYJh/sQ1PkvDcKpZ23eZq8kC8eNX9q4VCdjesbbw1LFUnFgrEtwiIWprBRyR8D MQ4weOcnOadGc/PM3w3NjlLCQeyJZl3+uMiDkLZwt6xdSczm7i0tld8XP82O+jYYzfoc t7a/uDC47otp/Jd0U8iAalItcGdegMA2GwB0wY5oojkdioHSs2nXRoxTz8NetJRpQ0sa pdhquUfovXT1Fu4trNNvtRlT8k6ILrqLsiGSy7vtlnP4XOtX1Q+3D3X8HZ6Fx213R+T7 2W6g== X-Gm-Message-State: AOAM533PTKWVlYWYu/Q/KVMSrv2oFXYbK50ioZcV0/NG7HCrT/IDjsux 4RSXoQU085iKxHZpWtEAkx3Eaw== X-Google-Smtp-Source: ABdhPJxdWj7AOP2zegfuVzaJiwFZjT+0vaS2x8/JBTLb2RZmVO8IuJS8Cm+SRY/gbAgc4M4wkFe4cg== X-Received: by 2002:adf:efd0:: with SMTP id i16mr23959598wrp.315.1589878513307; Tue, 19 May 2020 01:55:13 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:12 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:40 +0500 Message-Id: <20200519085444.4562-1-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH 1/5] examples/l2fwd-event: free resources in case of error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- examples/l2fwd-event/main.c | 43 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c index 9593ef11e..442a664e9 100644 --- a/examples/l2fwd-event/main.c +++ b/examples/l2fwd-event/main.c @@ -556,13 +556,26 @@ signal_handler(int signum) } } +static void +stop_and_close_eth_dev(uint16_t portid) +{ + RTE_ETH_FOREACH_DEV(portid) { + printf("Closing port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + rte_eal_cleanup(); +} + int main(int argc, char **argv) { struct l2fwd_resources *rsrc; uint16_t nb_ports_available = 0; uint32_t nb_ports_in_mask = 0; - uint16_t port_id, last_port; + uint16_t port_id = 0; + uint16_t last_port; uint32_t nb_mbufs; uint16_t nb_ports; int i, ret; @@ -581,20 +594,26 @@ main(int argc, char **argv) /* parse application arguments (after the EAL ones) */ ret = l2fwd_event_parse_args(argc, argv, rsrc); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(port_id); rte_panic("Invalid L2FWD arguments\n"); + } printf("MAC updating %s\n", rsrc->mac_updating ? "enabled" : "disabled"); nb_ports = rte_eth_dev_count_avail(); - if (nb_ports == 0) + if (nb_ports == 0) { + stop_and_close_eth_dev(port_id); rte_panic("No Ethernet ports - bye\n"); + } /* check port mask to possible port mask */ - if (rsrc->enabled_port_mask & ~((1 << nb_ports) - 1)) + if (rsrc->enabled_port_mask & ~((1 << nb_ports) - 1)) { + stop_and_close_eth_dev(port_id); rte_panic("Invalid portmask; possible (0x%x)\n", (1 << nb_ports) - 1); + } if (!rsrc->port_pairs) { last_port = 0; @@ -621,8 +640,10 @@ main(int argc, char **argv) rsrc->dst_ports[last_port] = last_port; } } else { - if (check_port_pair_config(rsrc) < 0) + if (check_port_pair_config(rsrc) < 0) { + stop_and_close_eth_dev(port_id); rte_panic("Invalid port pair config\n"); + } } nb_mbufs = RTE_MAX(nb_ports * (RTE_TEST_RX_DESC_DEFAULT + @@ -634,12 +655,16 @@ main(int argc, char **argv) rsrc->pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs, MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (rsrc->pktmbuf_pool == NULL) + if (rsrc->pktmbuf_pool == NULL) { + stop_and_close_eth_dev(port_id); rte_panic("Cannot init mbuf pool\n"); + } nb_ports_available = l2fwd_event_init_ports(rsrc); - if (!nb_ports_available) + if (!nb_ports_available) { + stop_and_close_eth_dev(port_id); rte_panic("All available ports are disabled. Please set portmask.\n"); + } /* Configure eventdev parameters if required */ if (rsrc->event_mode) @@ -659,9 +684,11 @@ main(int argc, char **argv) continue; ret = rte_eth_dev_start(port_id); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(port_id); rte_panic("rte_eth_dev_start:err=%d, port=%u\n", ret, port_id); + } } if (rsrc->event_mode) From patchwork Tue May 19 08:54:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Bilal X-Patchwork-Id: 70417 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 56A72A0093; Tue, 19 May 2020 10:55:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0A7241D55C; Tue, 19 May 2020 10:55:23 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id B7BAB1D446 for ; Tue, 19 May 2020 10:55:21 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id u1so1411569wmn.3 for ; Tue, 19 May 2020 01:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AI6ElnkvTx0XJj11vu6BqxWSCma9q3PEJzuUxj0W8bc=; b=wmeEmTK8OOFr9e68rqPWUmiYzklqscQL5dX+n0HCSEkwKjiDVvTJC6AMCzx9kKIWcw l9DFvx6I4u737FsTpQRDlFfHpQ6qeXhOYNzKXeY61tMgmFWPDuP0O6JqffXEmHkVFuFt Laotn0rVa/iQseE8mqXAOGbGwy4O3JIhp81X1p9W/sFzdjqguhq2odR7403j5u/ApzOa HYLMlQ49QUX4DNF4aciV65K/aSdGauFtA05rqi4H5BWvBDKYAnZP2Y9ViIU/7SmNxNKX 3QO+ntfW8xjSeUOt4HdIKolaidUwG3pJ7+ACORZzXrTtYI+mWMzWw52xEHkmFHr4UWsp enqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AI6ElnkvTx0XJj11vu6BqxWSCma9q3PEJzuUxj0W8bc=; b=N6D6MCLm/eq1HXxl90/cpM7tzNe6fm1n+1ooDf1Csei2hCOx2OlIojpWZP/SjzS0Qr e0vYmZzwNlLPbkHs8VjmrCZ3G9U5Z/37gIiYWNIdAzt+/c2JRp31mEPsOfauihVxEqQH wbxWrBBf2cwtwCvPLpKZlZVqTJg5dS2uhF45aPYeHGO8/lTb1+OnM/3IiUa1bhZSNTLm ZHbMOQ0foklA/2HZFZixgMpBDJIGOdtEAdGKEsqfvDhpafhNbuKik01L/X5Luw7iFNar FQxe86fsJHG+eD6GfuRTrye2LdX3LUcNxluPz7AZKQEjyEw3tAiPUwixmdxTFrPBmEpx 0yuA== X-Gm-Message-State: AOAM533AKaLIW37PgWOP3IBcPpFqU0xh/Da5oSbOeN6jaoh6UdFPigyh jvgeVuZy6iXLGWnLKhkgt9NCvA== X-Google-Smtp-Source: ABdhPJxo7qvwxbt1THtaOGv59J7PmGnKXZVUKbn7Qtw8O5vwtAOufS0SvVOPm20GVxN7+R/5Kzf+nQ== X-Received: by 2002:a1c:a74a:: with SMTP id q71mr4133667wme.23.1589878521422; Tue, 19 May 2020 01:55:21 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:20 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:41 +0500 Message-Id: <20200519085444.4562-2-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 2/5] examples/l2fwd-jobstats: free resources in case of error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- examples/l2fwd-jobstats/main.c | 75 +++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/examples/l2fwd-jobstats/main.c b/examples/l2fwd-jobstats/main.c index 396fd89db..e74e16113 100644 --- a/examples/l2fwd-jobstats/main.c +++ b/examples/l2fwd-jobstats/main.c @@ -739,6 +739,18 @@ check_all_ports_link_status(uint32_t port_mask) } } +static void +stop_and_close_eth_dev(uint16_t portid) +{ + RTE_ETH_FOREACH_DEV(portid) { + printf("Closing port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + rte_eal_cleanup(); +} + int main(int argc, char **argv) { @@ -749,7 +761,8 @@ main(int argc, char **argv) char name[RTE_JOBSTATS_NAMESIZE]; uint16_t nb_ports; uint16_t nb_ports_available = 0; - uint16_t portid, last_port; + uint16_t portid = 0; + uint16_t last_port; uint8_t i; /* init EAL */ @@ -761,8 +774,10 @@ main(int argc, char **argv) /* parse application arguments (after the EAL ones) */ ret = l2fwd_parse_args(argc, argv); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n"); + } rte_timer_subsystem_init(); @@ -773,12 +788,16 @@ main(int argc, char **argv) l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (l2fwd_pktmbuf_pool == NULL) + if (l2fwd_pktmbuf_pool == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n"); + } nb_ports = rte_eth_dev_count_avail(); - if (nb_ports == 0) + if (nb_ports == 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); + } /* reset l2fwd_dst_ports */ for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) @@ -820,8 +839,10 @@ main(int argc, char **argv) lcore_queue_conf[rx_lcore_id].n_rx_port == l2fwd_rx_queue_per_lcore) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } if (qconf != &lcore_queue_conf[rx_lcore_id]) @@ -852,32 +873,40 @@ main(int argc, char **argv) fflush(stdout); ret = rte_eth_dev_info_get(portid, &dev_info); - if (ret != 0) + if (ret != 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Error during getting device (port %u) info: %s\n", portid, strerror(-ret)); + } if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) local_port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", ret, portid); + } ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot adjust number of descriptors: err=%d, port=%u\n", ret, portid); + } ret = rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot get MAC address: err=%d, port=%u\n", ret, portid); + } /* init one RX queue */ fflush(stdout); @@ -887,9 +916,11 @@ main(int argc, char **argv) rte_eth_dev_socket_id(portid), &rxq_conf, l2fwd_pktmbuf_pool); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n", ret, portid); + } /* init one TX queue on each port */ txq_conf = dev_info.default_txconf; @@ -898,39 +929,48 @@ main(int argc, char **argv) ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), &txq_conf); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n", ret, portid); + } /* Initialize TX buffers */ tx_buffer[portid] = rte_zmalloc_socket("tx_buffer", RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0, rte_eth_dev_socket_id(portid)); - if (tx_buffer[portid] == NULL) + if (tx_buffer[portid] == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n", portid); + } rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST); ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid], rte_eth_tx_buffer_count_callback, &port_statistics[portid].dropped); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot set error callback for tx buffer on port %u\n", portid); + } /* Start device */ ret = rte_eth_dev_start(portid); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n", ret, portid); + } printf("done:\n"); ret = rte_eth_promiscuous_enable(portid); if (ret != 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_promiscuous_enable:err=%s, port=%u\n", rte_strerror(-ret), portid); @@ -952,6 +992,7 @@ main(int argc, char **argv) } if (!nb_ports_available) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "All available ports are disabled. Please set portmask.\n"); } @@ -965,8 +1006,10 @@ main(int argc, char **argv) rte_spinlock_init(&qconf->lock); - if (rte_jobstats_context_init(&qconf->jobs_context) != 0) + if (rte_jobstats_context_init(&qconf->jobs_context) != 0) { + stop_and_close_eth_dev(portid); rte_panic("Jobs stats context for core %u init failed\n", lcore_id); + } if (qconf->n_rx_port == 0) { RTE_LOG(INFO, L2FWD, @@ -985,6 +1028,7 @@ main(int argc, char **argv) lcore_id, &l2fwd_flush_job, NULL); if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(1, "Failed to reset flush job timer for lcore %u: %s", lcore_id, rte_strerror(-ret)); } @@ -1007,6 +1051,7 @@ main(int argc, char **argv) &l2fwd_fwd_job, (void *)(uintptr_t)i); if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(1, "Failed to reset lcore %u port %u job timer: %s", lcore_id, qconf->rx_port_list[i], rte_strerror(-ret)); } From patchwork Tue May 19 08:54:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Bilal X-Patchwork-Id: 70418 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 976BBA0093; Tue, 19 May 2020 10:55:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D92791D5C7; Tue, 19 May 2020 10:55:28 +0200 (CEST) Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by dpdk.org (Postfix) with ESMTP id B6EBB1D5C6 for ; Tue, 19 May 2020 10:55:26 +0200 (CEST) Received: by mail-wm1-f66.google.com with SMTP id z4so2195012wmi.2 for ; Tue, 19 May 2020 01:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GIZsNI1UFeNZdhLExs1RMHkvrAHxjtWL5j1i1vKXGo8=; b=zcQHjmglbldsCu4U+1bjJuByw2PfIZHgyFN2YIcpbJ+ddJn5uo58wX6mjxM4tYkYw4 trxEBRHNHZX7HcsOQcEi3jZMhvKRT+SbtoVmgwl9gZEnWMtJpgDzvIyfMszZpzpuN38R arVd/oBWIqzWa6SJdYxNSMeiStqM4dI1DqMGDHEIiD+f9nKr9WWWPrUtLBNogR/bmpJ9 Sm5n5h/5hpEK3gwXyjZYNc51o+3SEZVPq6a7JU7edOqLw2cJq5Z/ukDJ7Af2024GQMGi +UMw0uTquwvbrIVwJ/Cc/eO588AYMolSvhxQm+JCxkix5tOehDWPgtwmeOsFryBcWres aEoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GIZsNI1UFeNZdhLExs1RMHkvrAHxjtWL5j1i1vKXGo8=; b=fa3u5DQj4ILFOVHq9qLcHQ0RuCthA+BSgJI22r0lOxRdDPU68cz71i3rbQZfiCt9ve FLSeODl3iSv4QREhq9axvmViOzgyTaQtHRwFGPKPjQsv+tz2sl1yysEKgveS6JojhdUu YooUH+1v3L641HG8qwJwVcRahrX6NwqyjH3lbOKljqGWIRFLbuZAws3hjzuLIlN3OXyL 96PZdO3EM1CRLL9Oaz0tMJ1pJTL5i7zVbB92KDJqHZMf/uMX8NTihpKtgLz5is4GJ4/a P1mEYGk/9jVfDW0XCSj2VOA/moe91Yfj5m2rw1K6Biq7pFrR4iIcSqw+FWyykG1kRLaj kIpQ== X-Gm-Message-State: AOAM531ZVtkQ/vv61FBBTD8L2sGhZvcBKCjvBMeOHK6x2OkxxIJ/fqAp Fd2AE04uirYCJ+xz+hnNNLzHF2NGnuk= X-Google-Smtp-Source: ABdhPJzHAfIjF+rByLK6+OHoTo+WF4bu+ebIBqmX7sW6pKEBtbN+W/mSL3K6Ytmull1fVSxs37ES1g== X-Received: by 2002:a7b:cd84:: with SMTP id y4mr4129086wmj.2.1589878526471; Tue, 19 May 2020 01:55:26 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:25 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:42 +0500 Message-Id: <20200519085444.4562-3-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 3/5] examples/l2fwd-keepalive: free resources in case of error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- examples/l2fwd-keepalive/main.c | 97 +++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 23 deletions(-) diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c index b7585d55e..04038711f 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -526,6 +526,18 @@ relay_core_state(void *ptr_data, const int id_core, id_core, core_state, last_alive); } +static void +stop_and_close_eth_dev(uint16_t portid) +{ + RTE_ETH_FOREACH_DEV(portid) { + printf("Closing port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + rte_eal_cleanup(); +} + int main(int argc, char **argv) { @@ -533,7 +545,8 @@ main(int argc, char **argv) int ret; uint16_t nb_ports; uint16_t nb_ports_available = 0; - uint16_t portid, last_port; + uint16_t portid = 0; + uint16_t last_port; unsigned lcore_id, rx_lcore_id; unsigned nb_ports_in_mask = 0; unsigned int total_nb_mbufs; @@ -559,21 +572,28 @@ main(int argc, char **argv) /* parse application arguments (after the EAL ones) */ ret = l2fwd_parse_args(argc, argv); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n"); + } nb_ports = rte_eth_dev_count_avail(); if (nb_ports == 0) rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); /* create the mbuf pool */ - total_nb_mbufs = NB_MBUF_PER_PORT * nb_ports; - - l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", - total_nb_mbufs, 32, 0, RTE_MBUF_DEFAULT_BUF_SIZE, - rte_socket_id()); - if (l2fwd_pktmbuf_pool == NULL) + l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, + 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (l2fwd_pktmbuf_pool == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n"); + } + + nb_ports = rte_eth_dev_count_avail(); + if (nb_ports == 0) { + stop_and_close_eth_dev(portid); + rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); + } /* reset l2fwd_dst_ports */ for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) @@ -615,8 +635,10 @@ main(int argc, char **argv) lcore_queue_conf[rx_lcore_id].n_rx_port == l2fwd_rx_queue_per_lcore) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } if (qconf != &lcore_queue_conf[rx_lcore_id]) @@ -648,33 +670,41 @@ main(int argc, char **argv) fflush(stdout); ret = rte_eth_dev_info_get(portid, &dev_info); - if (ret != 0) + if (ret != 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Error during getting device (port %u) info: %s\n", portid, strerror(-ret)); + } if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) local_port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", ret, portid); + } ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot adjust number of descriptors: err=%d, port=%u\n", ret, portid); + } ret = rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot mac address: err=%d, port=%u\n", ret, portid); + } /* init one RX queue */ fflush(stdout); @@ -684,10 +714,12 @@ main(int argc, char **argv) rte_eth_dev_socket_id(portid), &rxq_conf, l2fwd_pktmbuf_pool); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n", ret, portid); + } /* init one TX queue on each port */ fflush(stdout); @@ -696,41 +728,51 @@ main(int argc, char **argv) ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), &txq_conf); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n", ret, portid); + } /* Initialize TX buffers */ tx_buffer[portid] = rte_zmalloc_socket("tx_buffer", RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0, rte_eth_dev_socket_id(portid)); - if (tx_buffer[portid] == NULL) + if (tx_buffer[portid] == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n", portid); + } rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST); ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid], rte_eth_tx_buffer_count_callback, &port_statistics[portid].dropped); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot set error callback for tx buffer on port %u\n", portid); + } /* Start device */ ret = rte_eth_dev_start(portid); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n", ret, portid); + } ret = rte_eth_promiscuous_enable(portid); - if (ret != 0) + if (ret != 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_eth_promiscuous_enable:err=%s, port=%u\n", rte_strerror(-ret), portid); + } printf("Port %u, MAC address: " "%02X:%02X:%02X:%02X:%02X:%02X\n\n", @@ -747,6 +789,7 @@ main(int argc, char **argv) } if (!nb_ports_available) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "All available ports are disabled. Please set portmask.\n"); } @@ -761,13 +804,17 @@ main(int argc, char **argv) ka_shm = NULL; if (check_period > 0) { ka_shm = rte_keepalive_shm_create(); - if (ka_shm == NULL) + if (ka_shm == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "rte_keepalive_shm_create() failed"); + } rte_global_keepalive_info = rte_keepalive_create(&dead_core, ka_shm); - if (rte_global_keepalive_info == NULL) + if (rte_global_keepalive_info == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "init_keep_alive() failed"); + } rte_keepalive_register_relay_callback(rte_global_keepalive_info, relay_core_state, ka_shm); rte_timer_init(&hb_timer); @@ -778,8 +825,10 @@ main(int argc, char **argv) (void(*)(struct rte_timer*, void*)) &rte_keepalive_dispatch_pings, rte_global_keepalive_info - ) != 0 ) + ) != 0 ) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Keepalive setup failure.\n"); + } } if (timer_period > 0) { if (rte_timer_reset(&stats_timer, @@ -787,8 +836,10 @@ main(int argc, char **argv) PERIODICAL, rte_lcore_id(), &print_stats, NULL - ) != 0 ) + ) != 0 ) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Stats setup failure.\n"); + } } /* launch per-lcore init on every slave lcore */ RTE_LCORE_FOREACH_SLAVE(lcore_id) { From patchwork Tue May 19 08:54:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Bilal X-Patchwork-Id: 70419 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3824EA0093; Tue, 19 May 2020 10:55:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 62F781D5DA; Tue, 19 May 2020 10:55:35 +0200 (CEST) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id EC62E1D5D8 for ; Tue, 19 May 2020 10:55:32 +0200 (CEST) Received: by mail-wm1-f68.google.com with SMTP id n18so2515979wmj.5 for ; Tue, 19 May 2020 01:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z6A1A6TDLHKnvHPlWFTMsJIBwCeFb8WRShYXw6xTz/M=; b=jzCZni7zhUVfRSUQW8bcsieuIBggtQZEm/7Ikt8zethmv6L1tMiI8MRXhiSUI4UcyG aK6dKD7dwEvmH8mQgDr8A7XgewB5V/bOI6upJMTo/qZ9VvUrMAtgnvPXt6o0uEijrdmQ 39BLIcFYYWigWuDNmYVLJVxgaVXnVHxLqVgu0tRRMZAh/YzL3hNmWe3TTDWDfThR42IF gAgcdR6LvZF5ibiNQ0OohR1ers0AKaOXIVpZN+iywhP5vKs7jrV/NZ7cb/CipKdl5wyz XzJJ3hmiynbt56N4vqlAj8P6tZcY+f61sI1sS23L3qaeJrc4UOWTfK6QLP+6rGaldgdn cbzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z6A1A6TDLHKnvHPlWFTMsJIBwCeFb8WRShYXw6xTz/M=; b=hoZSiNs7695CpLV4jOOIWZ+EeYVakZT0dSuiyObZE7pMlihLOcAXE21mQXN18LO4vr VggYzrQWO84Zt8RcgPWeV1k8aOypJUM8EJCSAMoDMyv/rZHzmWAMR7rU7CkG+EhkWkVq 53bBQ0jXvCdDkkEMXX3BI5JM8xKcICQ43wTZ4+CMwwd7+NCEunXXV5XyXOS5DghrmE3+ IGY8pzA63ct+JLr2zD0tuQOnBbSFLshwL14z/R29rKAZYjec8w1Es76uzJHEMXS4l2em WLm4n0kC+m+D+1vA3RA4a5Wz4sjKzuYnFfQmMtBMGMlRcg1cC+klDN+sZHlYrteFtag1 w1kg== X-Gm-Message-State: AOAM531UYGYYx17pytFcKGbnrJlPCJQerkQnPhl5K2+nuXzah4UckOdw 7V5tmk7jGbOAOzhemYEm89EjkA== X-Google-Smtp-Source: ABdhPJztgheHlkeKyCYv0TYoyZvhQ5//cg9lHVod2xPeIAfqsBsEBq/24ht/qF9kaLPOmkOQmVMPRw== X-Received: by 2002:a1c:3585:: with SMTP id c127mr4182584wma.34.1589878532650; Tue, 19 May 2020 01:55:32 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:32 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:43 +0500 Message-Id: <20200519085444.4562-4-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 4/5] examples/l2fwd-cat: free resources in case of error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- examples/l2fwd-cat/l2fwd-cat.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/l2fwd-cat/l2fwd-cat.c b/examples/l2fwd-cat/l2fwd-cat.c index 45a497c08..06eeae9ae 100644 --- a/examples/l2fwd-cat/l2fwd-cat.c +++ b/examples/l2fwd-cat/l2fwd-cat.c @@ -147,6 +147,18 @@ lcore_main(void) } } +static void +stop_and_close_eth_dev(uint16_t portid) +{ + RTE_ETH_FOREACH_DEV(portid) { + printf("Closing port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + rte_eal_cleanup(); +} + /* * The main function, which does initialization and calls the per-lcore * functions. @@ -156,7 +168,7 @@ main(int argc, char *argv[]) { struct rte_mempool *mbuf_pool; unsigned nb_ports; - uint16_t portid; + uint16_t portid = 0; /* Initialize the Environment Abstraction Layer (EAL). */ int ret = rte_eal_init(argc, argv); @@ -171,30 +183,38 @@ main(int argc, char *argv[]) * Please see l2fwd-cat documentation for more info. */ ret = cat_init(argc, argv); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "PQOS: L3CA init failed!\n"); + } argc -= ret; argv += ret; /* Check that there is an even number of ports to send/receive on. */ nb_ports = rte_eth_dev_count_avail(); - if (nb_ports < 2 || (nb_ports & 1)) + if (nb_ports < 2 || (nb_ports & 1)) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n"); + } /* Creates a new mempool in memory to hold the mbufs. */ mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (mbuf_pool == NULL) + if (mbuf_pool == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n"); + } /* Initialize all ports. */ RTE_ETH_FOREACH_DEV(portid) - if (port_init(portid, mbuf_pool) != 0) + if (port_init(portid, mbuf_pool) != 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu16 "\n", portid); - + } + if (rte_lcore_count() > 1) printf("\nWARNING: Too many lcores enabled. Only 1 used.\n"); From patchwork Tue May 19 08:54:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Bilal X-Patchwork-Id: 70420 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9B3FAA0093; Tue, 19 May 2020 10:55:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C19431D5D8; Tue, 19 May 2020 10:55:40 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 9DD0B1D5D7 for ; Tue, 19 May 2020 10:55:39 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id f13so2180497wmc.5 for ; Tue, 19 May 2020 01:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1bJ8C63K9QfAiP6OGLhqjOW2OeIWzB2peTJe2RgkVfw=; b=KXHnZbmEZia9Rj9USgCoxKs9XnOb8WNOJy88fYXy7BiEGr8D8LiD18W0gNx2DQZin8 FatKfWHFA1NBCgnetSRdU5ERh/Rh64DmPX59RzgPqT9G0oO4U/rcD+3DSAtGCr4mxrUa K6ayeRaP9m8XWF82Uz34GTYh95dmxQV4K67uM3CrU03YN4fI+ZfzSRYdFscdbIz+j7H8 LjaDVEmRTiU8eB+re45WpY58Ow4DPML5CWavXLDVMlep8mTpGIoE5XtksF6LkRGawdC2 ZT+Y9/87zkURX9KOB20X8LOlP3Mc2t0K653OB4zj5AL/pdGLf/ESrj0Uo3jKCqMnf774 85xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1bJ8C63K9QfAiP6OGLhqjOW2OeIWzB2peTJe2RgkVfw=; b=nmTT2XWoQ29uxmkBusQqY1EwdfJNgFaV2WfsPMNrYt7k8XaXbgqfpZKeeII/TVRg7w GScvihqEBGLqPvsd8qJ/VIPBH3AanMjjpq0EkYNdFRmRUk4cW5o32s1tcakjzc2LFbg4 1ddnrUkNdCsIPquqBMerVPHzw0+z5pKIxDz6xCCxCkSIjRVX4RbsmrKi8IN6enj1byGg 5KBi3VsQCALx5Wcdb9bYKS8+pBM9+asLD13yKAtsZlhH0bXFGCAZMfLIV/de6XQ7cKsF uAxcruhIZ/fnlvmOT+P2bXveYHmuBOoESdSMTHe8+R5yqIqpqwZuLr65PyZzlubsSpNE G50w== X-Gm-Message-State: AOAM531z/99wPrp5rI1fB0NDuUdh6fYabBNb12aBwajIeA3JJdhjykLV mL+zxTjSjX71sE+j0JO/DKgzEA== X-Google-Smtp-Source: ABdhPJzICpoRmDTxoFWylNcrwWuooj8Z6ozEIBnxptQA7WTqOdycFvhzrfu3pf5uvQyfixePFE7YAQ== X-Received: by 2002:a7b:cc06:: with SMTP id f6mr4129263wmh.119.1589878539333; Tue, 19 May 2020 01:55:39 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:38 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:44 +0500 Message-Id: <20200519085444.4562-5-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 5/5] examples/l2fwd-crypto: free resources in case of error 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- examples/l2fwd-crypto/main.c | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index fcb55c370..169f011f8 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -2660,6 +2660,18 @@ reserve_key_memory(struct l2fwd_crypto_options *options) options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data); } +static void +stop_and_close_eth_dev(uint16_t portid) +{ + RTE_ETH_FOREACH_DEV(portid) { + printf("Closing port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + rte_eal_cleanup(); +} + int main(int argc, char **argv) { @@ -2667,7 +2679,7 @@ main(int argc, char **argv) struct l2fwd_crypto_options options; uint8_t nb_cryptodevs, cdev_id; - uint16_t portid; + uint16_t portid = 0; unsigned lcore_id, rx_lcore_id = 0; int ret, enabled_cdevcount, enabled_portcount; uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = {0}; @@ -2684,8 +2696,10 @@ main(int argc, char **argv) /* parse application arguments (after the EAL ones) */ ret = l2fwd_crypto_parse_args(&options, argc, argv); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Invalid L2FWD-CRYPTO arguments\n"); + } printf("MAC updating %s\n", options.mac_updating ? "enabled" : "disabled"); @@ -2694,20 +2708,26 @@ main(int argc, char **argv) l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 512, sizeof(struct rte_crypto_op), RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (l2fwd_pktmbuf_pool == NULL) + if (l2fwd_pktmbuf_pool == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n"); + } /* create crypto op pool */ l2fwd_crypto_op_pool = rte_crypto_op_pool_create("crypto_op_pool", RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MBUF, 128, MAXIMUM_IV_LENGTH, rte_socket_id()); - if (l2fwd_crypto_op_pool == NULL) + if (l2fwd_crypto_op_pool == NULL) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n"); + } /* Enable Ethernet ports */ enabled_portcount = initialize_ports(&options); - if (enabled_portcount < 1) + if (enabled_portcount < 1) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Failed to initial Ethernet ports\n"); + } /* Initialize the port/queue configuration of each logical core */ RTE_ETH_FOREACH_DEV(portid) { @@ -2719,9 +2739,11 @@ main(int argc, char **argv) if (options.single_lcore && qconf == NULL) { while (rte_lcore_is_enabled(rx_lcore_id) == 0) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } } else if (!options.single_lcore) { /* get the lcore_id for this port */ @@ -2729,9 +2751,11 @@ main(int argc, char **argv) lcore_queue_conf[rx_lcore_id].nb_rx_ports == options.nb_ports_per_lcore) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } } @@ -2748,13 +2772,17 @@ main(int argc, char **argv) /* Enable Crypto devices */ enabled_cdevcount = initialize_cryptodevs(&options, enabled_portcount, enabled_cdevs); - if (enabled_cdevcount < 0) + if (enabled_cdevcount < 0) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Failed to initialize crypto devices\n"); + } - if (enabled_cdevcount < enabled_portcount) + if (enabled_cdevcount < enabled_portcount) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Number of capable crypto devices (%d) " "has to be more or equal to number of ports (%d)\n", enabled_cdevcount, enabled_portcount); + } nb_cryptodevs = rte_cryptodev_count(); @@ -2769,9 +2797,11 @@ main(int argc, char **argv) if (options.single_lcore && qconf == NULL) { while (rte_lcore_is_enabled(rx_lcore_id) == 0) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } } else if (!options.single_lcore) { /* get the lcore_id for this port */ @@ -2779,9 +2809,11 @@ main(int argc, char **argv) lcore_queue_conf[rx_lcore_id].nb_crypto_devs == options.nb_ports_per_lcore) { rx_lcore_id++; - if (rx_lcore_id >= RTE_MAX_LCORE) + if (rx_lcore_id >= RTE_MAX_LCORE) { + stop_and_close_eth_dev(portid); rte_exit(EXIT_FAILURE, "Not enough cores\n"); + } } }