From patchwork Wed Jun 17 04:01:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarosh Arif X-Patchwork-Id: 71645 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 D738AA04F1; Wed, 17 Jun 2020 06:02:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B8B8D1BFC6; Wed, 17 Jun 2020 06:02:15 +0200 (CEST) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id D9B341BFC0 for ; Wed, 17 Jun 2020 06:02:13 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id h5so748178wrc.7 for ; Tue, 16 Jun 2020 21:02: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:in-reply-to:references; bh=lSeriX/3gcbaPFIZVEe6CU4LkDxXO+GEQAHwdECugVU=; b=bJodNszFOQ03Og0xZtQpLAzDxrD+5aKAcpB/K7F4gl0NfTeMjqpU9zn4KiZofE02wO LMv5ym2QzbMxvKbDn5taIKVVZsdWDHOIIUsko8Ur/8VDN1MEByBuqiR5WbVmcC9TEho6 IbLbEGzbvm84Ejw9JmKmgM3hhi+uVVlgoaGD0sL5vkYdoiyykxZnzdmDysBnSdUCRims vmKu4ySxC2OgOi0hHcWOk85QWU2wwPP2/O3iArLxVKnDXyXE8Xeup6PPEmkdXQ5D4U1D qllWgFPiX+jnKJIhvTo8V96YQlE9iid324tTt2lftMGFWjsqFzxac26ryrXbZLnUx6NW OVNw== 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=lSeriX/3gcbaPFIZVEe6CU4LkDxXO+GEQAHwdECugVU=; b=lYObUHxjyUZhdY+MffghF/TUX28IscZz6odJKRbAsjBvlCD/Y7SIN2yBhZRTNR6n48 u152p/WenyBR5vw4QtEcQ0+sPhR4VdRDixGLf3tg6l+A/S1OAWDzkWfUtPdEIzlAEvAP 1uyM6873Ln5BZrMdIDdDb8utDnzwYB8fsgLgGlkpBBWClphwjNodJYf7rN+uWSpoypVI MrJ5qRodCY0l9A4aVbv9Bzq2+bGKZ/M9KsHPQfAw0MINeDy0ciXjnbcc0+pHcVgt3dby zt6KiBXIqKb6Kx17nN0Hb4hXiwSXe1i/XDfRC4AxV4Gy2XHrl8cXmw/yHTtqQK/GCSgf UHZg== X-Gm-Message-State: AOAM532S5+ChVV6tydOnQ5jw2mV8gxHw2mIuDKjKxTgOvcV9FEzkmmjl p3QdCYEEKzx99Q2VakYzbpOsLRRMeKn7ngV1 X-Google-Smtp-Source: ABdhPJxYzz5G+kBkg7sHzl6NU0JMXvKfsu2JenS6bqeSJBmCVeWxarv2FSn+tHhzwDJcra0OgEKSSw== X-Received: by 2002:adf:e387:: with SMTP id e7mr6102843wrm.70.1592366532862; Tue, 16 Jun 2020 21:02:12 -0700 (PDT) Received: from localhost.localdomain ([39.40.22.64]) by smtp.gmail.com with ESMTPSA id s18sm38768111wra.85.2020.06.16.21.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 21:02:12 -0700 (PDT) From: Sarosh Arif To: dev@dpdk.org, bruce.richardson@intel.com, john.mcnamara@intel.com, reshma.pattan@intel.com, vipin.varghese@intel.com Cc: Sarosh Arif Date: Wed, 17 Jun 2020 09:01:01 +0500 Message-Id: <20200617040103.28468-1-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200615084132.9553-3-sarosh.arif@emumba.com> References: <20200615084132.9553-3-sarosh.arif@emumba.com> Subject: [dpdk-dev] [PATCH v2 1/3] examples/packet_ordering: free resources on exit 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" Resources should be cleared while exiting the application. Bugzilla ID: 437 Signed-off-by: Sarosh Arif Acked-by: Reshma Pattan --- v2: initialize portid --- examples/packet_ordering/main.c | 57 ++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c index b397b318e..8c106e91f 100644 --- a/examples/packet_ordering/main.c +++ b/examples/packet_ordering/main.c @@ -220,6 +220,17 @@ flush_tx_error_callback(struct rte_mbuf **unsent, uint16_t count, } +static void +stop_and_close_eth_dev(uint16_t port_id) +{ + RTE_ETH_FOREACH_DEV(port_id) { + printf("Closing port %d...", port_id); + rte_eth_dev_stop(port_id); + rte_eth_dev_close(port_id); + printf(" Done\n"); + } +} + static inline int free_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) { uint16_t port_id; @@ -251,18 +262,22 @@ configure_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) tx_buffer[port_id] = rte_zmalloc_socket("tx_buffer", RTE_ETH_TX_BUFFER_SIZE(MAX_PKTS_BURST), 0, rte_eth_dev_socket_id(port_id)); - if (tx_buffer[port_id] == NULL) + if (tx_buffer[port_id] == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n", port_id); + } rte_eth_tx_buffer_init(tx_buffer[port_id], MAX_PKTS_BURST); ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[port_id], flush_tx_error_callback, NULL); - if (ret < 0) + if (ret < 0) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Cannot set error callback for tx buffer on port %u\n", port_id); + } } return 0; } @@ -662,7 +677,7 @@ main(int argc, char **argv) int ret; unsigned nb_ports; unsigned int lcore_id, last_lcore_id, master_lcore_id; - uint16_t port_id; + uint16_t port_id = 0; uint16_t nb_ports_available; struct worker_thread_args worker_args = {NULL, NULL}; struct send_thread_args send_args = {NULL, NULL}; @@ -686,25 +701,31 @@ main(int argc, char **argv) return -1; /* Check if we have enought cores */ - if (rte_lcore_count() < 3) + if (rte_lcore_count() < 3) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Error, This application needs at " "least 3 logical cores to run:\n" "1 lcore for packet RX\n" "1 lcore for packet TX\n" "and at least 1 lcore for worker threads\n"); + } nb_ports = rte_eth_dev_count_avail(); if (nb_ports == 0) rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n"); - if (nb_ports != 1 && (nb_ports & 1)) + if (nb_ports != 1 && (nb_ports & 1)) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Error: number of ports must be even, except " "when using a single port\n"); + } mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", MBUF_PER_POOL, MBUF_POOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (mbuf_pool == NULL) + if (mbuf_pool == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } nb_ports_available = nb_ports; @@ -719,12 +740,15 @@ main(int argc, char **argv) /* init port */ printf("Initializing port %u... done\n", port_id); - if (configure_eth_port(port_id) != 0) + if (configure_eth_port(port_id) != 0) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Cannot initialize port %"PRIu8"\n", port_id); + } } if (!nb_ports_available) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "All available ports are disabled. Please set portmask.\n"); } @@ -732,19 +756,25 @@ main(int argc, char **argv) /* Create rings for inter core communication */ rx_to_workers = rte_ring_create("rx_to_workers", RING_SIZE, rte_socket_id(), RING_F_SP_ENQ); - if (rx_to_workers == NULL) + if (rx_to_workers == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } workers_to_tx = rte_ring_create("workers_to_tx", RING_SIZE, rte_socket_id(), RING_F_SC_DEQ); - if (workers_to_tx == NULL) + if (workers_to_tx == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } if (!disable_reorder) { send_args.buffer = rte_reorder_create("PKT_RO", rte_socket_id(), REORDER_BUFFER_SIZE); - if (send_args.buffer == NULL) + if (send_args.buffer == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } } last_lcore_id = get_last_lcore_id(); @@ -774,10 +804,15 @@ main(int argc, char **argv) rx_thread(rx_to_workers); RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (rte_eal_wait_lcore(lcore_id) < 0) + if (rte_eal_wait_lcore(lcore_id) < 0) { + stop_and_close_eth_dev(port_id); + rte_eal_cleanup(); return -1; + } } print_stats(); + stop_and_close_eth_dev(port_id); + rte_eal_cleanup(); return 0; }