From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)); } -- 2.17.1