From patchwork Wed Jun 17 04:01:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarosh Arif X-Patchwork-Id: 71646 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 54B0FA04F1; Wed, 17 Jun 2020 06:02:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2AE8A1BFEB; Wed, 17 Jun 2020 06:02:26 +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 B88B01BFC0 for ; Wed, 17 Jun 2020 06:02:24 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id r7so778104wro.1 for ; Tue, 16 Jun 2020 21:02:24 -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=OJ/W+0MdL5r6f3JnSJRt+5rRzGPw4y2gGZJ1yAQ9nfc=; b=GqsDRTLpO3GDbXBk0xGDyBaMxX1P/XeDVnqf3quIrXNODiyOvOouCIdGu9K6IlHgRY rHdqlX01onRa/GG0lZoWC+1eUFneFxHxwamNlDZR8HjAIK2+XoMTbycqqj7yYSB/NFd0 ojaup3Hjt8GbU7JadhogI7B4vUDyC0s44xg1VadvocCi8hI6aaKQv+WiVL95o+wXCIU9 BljjNiUvocwvBayvnXeh55dj+5ZgSBlO4BUZbPuwCzagadkTCk0/IuRGgXiI2vAAubSt qyKzLbsqRqJCEMxQSqR+0MbgROLY9Sz6UfmuohTqNUM+wxnUCH5onQ9y3DnASjTNWBEv JjBw== 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=OJ/W+0MdL5r6f3JnSJRt+5rRzGPw4y2gGZJ1yAQ9nfc=; b=WjjwHTIdP6nwvzFGLVNNEp+kMcFZEu2DVAPDVd78BddRnKcrMFpAvnUmTxnePuSLpp 4cfwzoKUnEW28BL0AsiFJxyB5JJ1dId330XHytBrtFInQ2RZr2DyYacX/njzLVywtoP2 ccnEdy1i+ps9lBQ8tBf2AH2ILmAbmyPS3TnOdfKEAigoNyjWBBqOyB9cAdT/1W2s4iaO wWHXCRUX9WpnScn2D5T/0tFKwULZ+YsyfZxlMW3xnU6F6qs1JlA36W6R2AlykdlnCzJa 6wdNYoKw1Lu/3ciSOnoj1fWOKiF4+y3xtvBCAtCz/FBWaK5kn56kYsFYUnL1aeSqMGJc VgDg== X-Gm-Message-State: AOAM5322tUTir2KURZmsh4m14HmqzmBxo8tUs2S/L4RW1nrPo/F6R7VK 5/2dy8BKXeXLRt3mneS7qQ3wUBPgoj51CBKT X-Google-Smtp-Source: ABdhPJxCnBUlfSqEniqjeQJ6nDOR0v5Gf69nnpRwKw1Uedxh+4fIHj+4/yzD6h246y8s/mSdaREkcg== X-Received: by 2002:a5d:6809:: with SMTP id w9mr225965wru.182.1592366544240; Tue, 16 Jun 2020 21:02:24 -0700 (PDT) Received: from localhost.localdomain ([39.40.22.64]) by smtp.gmail.com with ESMTPSA id s18sm38768111wra.85.2020.06.16.21.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 21:02:23 -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:02 +0500 Message-Id: <20200617040103.28468-2-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 2/3] examples/rxtx_callbacks: 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/rxtx_callbacks/main.c | 47 ++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c index 54d124b00..b6de8c5a9 100644 --- a/examples/rxtx_callbacks/main.c +++ b/examples/rxtx_callbacks/main.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2015 Intel Corporation */ - +#include #include #include #include @@ -34,6 +34,7 @@ static struct { } latency_numbers; int hw_timestamping; +static volatile bool quit_signal; #define TICKS_PER_CYCLE_SHIFT 16 static uint64_t ticks_per_cycle_mult; @@ -215,7 +216,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) * Main thread that does the work, reading from INPUT_PORT * and writing to OUTPUT_PORT */ -static __rte_noreturn void +static void lcore_main(void) { uint16_t port; @@ -230,7 +231,7 @@ lcore_main(void) printf("\nCore %u forwarding packets. [Ctrl+C to quit]\n", rte_lcore_id()); - for (;;) { + while (!quit_signal) { RTE_ETH_FOREACH_DEV(port) { struct rte_mbuf *bufs[BURST_SIZE]; const uint16_t nb_rx = rte_eth_rx_burst(port, 0, @@ -249,18 +250,38 @@ 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 sig_num) +{ + printf("Exiting on signal %d\n", sig_num); + quit_signal = true; +} + /* Main function, does initialisation and calls the per-lcore functions */ int main(int argc, char *argv[]) { struct rte_mempool *mbuf_pool; uint16_t nb_ports; - uint16_t portid; + uint16_t portid = 0; struct option lgopts[] = { { NULL, 0, 0, 0 } }; int opt, option_index; - + quit_signal = false; + /* catch ctrl-c so we can clear resources on exit */ + signal(SIGINT, int_handler); /* init EAL */ int ret = rte_eal_init(argc, argv); @@ -278,25 +299,33 @@ main(int argc, char *argv[]) break; default: printf(usage, argv[0]); + stop_and_close_eth_dev(portid); + rte_eal_cleanup(); return -1; } optind = 1; /* reset getopt lib */ 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"); + } 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 %"PRIu8"\n", portid); + } if (rte_lcore_count() > 1) printf("\nWARNING: Too much enabled lcores - " @@ -304,5 +333,7 @@ main(int argc, char *argv[]) /* call lcore_main on master core only */ lcore_main(); + stop_and_close_eth_dev(portid); + rte_eal_cleanup(); return 0; }