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 46D7EA0093 for ; Mon, 15 Jun 2020 10:44:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 314D049E0; Mon, 15 Jun 2020 10:44:54 +0200 (CEST) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id B9EA249E0 for ; Mon, 15 Jun 2020 10:44:52 +0200 (CEST) Received: by mail-wr1-f65.google.com with SMTP id x6so16133448wrm.13 for ; Mon, 15 Jun 2020 01:44:52 -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=oV/yICtqN7FzbtSIeLc2BbIi3k+hz5z1xX0T/vS27pc=; b=hlsvMuHnhbWHBy1cHHjxUpaoAYv9cbg8mwFqv71Cs46JbBiofIswD/fetIVGnyAYpi na310wy9WWT9raEKcZjvTisRasLAoJ1XCjVQgzjnj7b22DdDOn/Lbb++9u8zabjq7Kba 1CXfpJf9XMbaz4ja+yeop4UQGO0G3kYwxQbjA/3X7w3Nb05P6KW/g46wASUNg9QxuS5j D6os09aRHobUgdcQEIfzxNwO7EYGcaTnQM4szq9WLklHhn6XXm0cwLLhJFdmqu1FG8xF k9buXvcsNGCfT3/MkZcZRbfo5/mgM4FX2YuZKAxVmNpIwXP0YD7hi8wu9KsazGmk5uJX r3fA== 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=oV/yICtqN7FzbtSIeLc2BbIi3k+hz5z1xX0T/vS27pc=; b=CS3fWtW8IlYlSnW2+6YryCE/uL3K3F08zv4u4Fjqt1oZboSkXp08kPrK6P+C+23ixT 88HS5T6W4zzAZIkZ1mhmXdR0dmjO/qFhZxNPYrJ/ZcS//Png/cxJP+57oeNjFr6X1VB+ RxHnLnQbR2HIT14XNzJViuv7Y8zLZfl6rzzWt1fScWx1K96tzWbovTijixNDTI5sHGzf aY+r2BxpWUjR2InSbphwJGd2fxyHUVskkNYR6Ilz6W2a5DuoF/XvhBiQrY/FOTXTKZX6 fxnMXOmPIQ6LAsBlm6aHH0zc8e5R5x8SFEi9zkpmvmewImVrqvdVxmVrV+yMo1v/5GeJ 0qNQ== X-Gm-Message-State: AOAM531ztzUEeh71FRbDGgMcEG4tTubafmN+kLf6l8mG+JiJp2BDxmG4 obMLKzq+K3QNP2TYqJekSD9eAw== X-Google-Smtp-Source: ABdhPJwoCXV21SwkFNMcUiSSc+djN7RdVP6aYLgbtu6hkSj+tSkdhUch4s70uFr7k60sSAvbl09tLg== X-Received: by 2002:adf:f208:: with SMTP id p8mr25057656wro.388.1592210692475; Mon, 15 Jun 2020 01:44:52 -0700 (PDT) Received: from localhost.localdomain ([39.40.31.151]) by smtp.gmail.com with ESMTPSA id 67sm24266075wrk.49.2020.06.15.01.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 01:44:52 -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: stable@dpdk.org, Sarosh Arif Date: Mon, 15 Jun 2020 13:41:32 +0500 Message-Id: <20200615084132.9553-3-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200615084132.9553-1-sarosh.arif@emumba.com> References: <20200615084132.9553-1-sarosh.arif@emumba.com> Subject: [dpdk-stable] [PATCH 3/3] examples/skeleton: free resources on exit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Resources should be cleared while exiting the application. Bugzilla ID: 437 Signed-off-by: Sarosh Arif --- examples/skeleton/basicfwd.c | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c index 72ba85fa1..3b40e04d7 100644 --- a/examples/skeleton/basicfwd.c +++ b/examples/skeleton/basicfwd.c @@ -9,6 +9,7 @@ #include #include #include +#include #define RX_RING_SIZE 1024 #define TX_RING_SIZE 1024 @@ -17,6 +18,7 @@ #define MBUF_CACHE_SIZE 250 #define BURST_SIZE 32 +static volatile bool force_quit; static const struct rte_eth_conf port_conf_default = { .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN, @@ -162,6 +164,26 @@ lcore_main(void) } } +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 void +int_handler(int signum) +{ + printf("\n\nSignal %d received, preparing to exit...\n", + signum); + force_quit = true; + +} + /* * The main function, which does initialization and calls the per-lcore * functions. @@ -173,6 +195,9 @@ main(int argc, char *argv[]) unsigned nb_ports; uint16_t portid; + force_quit = false; + signal(SIGINT, int_handler); + /* Initialize the Environment Abstraction Layer (EAL). */ int ret = rte_eal_init(argc, argv); if (ret < 0) @@ -183,21 +208,27 @@ main(int argc, char *argv[]) /* 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"); @@ -205,5 +236,7 @@ main(int argc, char *argv[]) /* Call lcore_main on the master core only. */ lcore_main(); + stop_and_close_eth_dev(portid); + rte_eal_cleanup(); return 0; } -- 2.17.1