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 AC6CDA04F1; Wed, 17 Jun 2020 06:02:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8AFDE1BFF3; Wed, 17 Jun 2020 06:02:37 +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 C399B1BFC0 for ; Wed, 17 Jun 2020 06:02:35 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id x13so756790wrv.4 for ; Tue, 16 Jun 2020 21:02:35 -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=9qdln7t1HytrIwbovEtLp6vaDV9GDNO84fQ4wDjsm2g=; b=hjNsqjWPm1gKrNeJ27hl9g1PDxUIbgZ8VbOGdi/V3FXThG26oWPh+1WPE3wI9EyrzE MVHhQmc6m4QxvJ3WLD/TODzQwE3cxAz3ixvXq3fh7wEeJMkK1wAsUmGXtFrsmhQ2S0Cb 1aPellbdnDP2H7W2+qQ2HAegcoyJcyabBAGD2vYBdd+3sJDXvuo7vuIKYGmiPwGTUNo9 DVGJEBji4d1vEuTZorChbdBkEu5lzbqjtsJbK3P6PEkDP/CJzA7Tdhb1Lc6NPxcefNfj tDEldgNq7KtkIHP3l1TWtHqkRytzdjqI3tZHD9Gbl/ks8va0jy332y3wKjsa9azDNvsC PaVg== 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=9qdln7t1HytrIwbovEtLp6vaDV9GDNO84fQ4wDjsm2g=; b=iYsPy1QSxR83XoWC5ESThXiKbVFJuYgYZAA/ltix9n1SZxfO7LRV23aaZZlSn9n3iq jTVuOZW9LpceMYj2I7wFPRCH0JOazT7Rb65qNMtPSkApxF53l6CbNT6csALtkG8S32hD s0jzzvNJxqWzOl9bgGuk6gdAW2B9fpcr8Q1i3AXP2vTZ5wM+Bl3OtMNIHycX0ue3lrsf qq/u/kZGsxYEQvWrIsGmZqumA4RZF+RYDwmQVlaz3tnCn2X2f/Krwz1A7j/oZybW8dFg 63yYNahh2x4kTBgL0nxcmM6TGUKp00l9lonX9UOLh7XXkLrM0uVUg/nCDDoHVB80Q2Gz z66w== X-Gm-Message-State: AOAM533Ac21P8NcLxHUEDLYojqKB/latPP21pevRdAj82tH9OxQEIJBQ 0cwC2BCrd1vZzWoUWSgeXS9k1Gw+XU8ZoDQm X-Google-Smtp-Source: ABdhPJz680nkTDFOQBhKMDjyGcbDkYSl3iT2m9P+Zm94r6sHafJ9c7A1YAleLnjm5j37YWMWwz0aVQ== X-Received: by 2002:a5d:4745:: with SMTP id o5mr5938121wrs.87.1592366555268; Tue, 16 Jun 2020 21:02:35 -0700 (PDT) Received: from localhost.localdomain ([39.40.22.64]) by smtp.gmail.com with ESMTPSA id s18sm38768111wra.85.2020.06.16.21.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 21:02:34 -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:03 +0500 Message-Id: <20200617040103.28468-3-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200617040103.28468-1-sarosh.arif@emumba.com> References: <20200615084132.9553-3-sarosh.arif@emumba.com> <20200617040103.28468-1-sarosh.arif@emumba.com> Subject: [dpdk-dev] [PATCH v2 3/3] examples/skeleton: 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 --- v2: initialize portid --- examples/skeleton/basicfwd.c | 41 ++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c index 72ba85fa1..7d240bddb 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. @@ -171,7 +193,10 @@ main(int argc, char *argv[]) { struct rte_mempool *mbuf_pool; unsigned nb_ports; - uint16_t portid; + uint16_t portid = 0; + + force_quit = false; + signal(SIGINT, int_handler); /* Initialize the Environment Abstraction Layer (EAL). */ int ret = rte_eal_init(argc, argv); @@ -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