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 25DD2A0526; Wed, 22 Jul 2020 14:52:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 986DD1BFEB; Wed, 22 Jul 2020 14:52:00 +0200 (CEST) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by dpdk.org (Postfix) with ESMTP id 5E5561BFF9 for ; Wed, 22 Jul 2020 14:51:59 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id o2so1888600wmh.2 for ; Wed, 22 Jul 2020 05:51:59 -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=amwDWqWINvo1zdd82iW8vfrnfhw7xGOy5jIcGTH+afY=; b=0WUPJeDTL8ug3WTOmmgQxH/5+ow6JTcu3blqCvQylt5AohdgLo1K+6sDX4Alwe7XJt /I5w7b5QfSO/VD5c1J8zNI9UnoHqQ+CR0osOJ7FZkhiF10F2K17uIyDt+gj1jGdU4h6u jT3IugaEe3TUSGLcVeEzwzpeskS0VT2W5N3CqhuJq0q0qjm9bQdop/8QpmnjUf0nIdKA IIZBdVlklKxSdDWs/Cu1AQRWNJNyZ2/Z895Q3T2vkuhzOt+sdPL9nqStAgj2x+ubFFAV KKKepCkwQyD4E+aIPOXPfdJtt4OGOd/OX2PPux1PuAtxRW3AR5DEVeObomzyt4ZZLTkM ZkNQ== 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=amwDWqWINvo1zdd82iW8vfrnfhw7xGOy5jIcGTH+afY=; b=n+gDn3ObDpfEeDcBWH7S7fTemt9NOyh27FjtxYS6oQjk9zAlBuh7EcLO5vtvis8t4e M089hA36dYzRnj+q517/h/EyCCLTeU9zMi7OlbAH7VD/UBnb8sg18dEO2+yBxFgjGRp6 47d3d9gvT4OtVwAzXD0/JedXY/kVJS7YzJpZsFtXzLI/xLb0c/muRGMOLSM7sFNmtWZV Lhw7p93g0tWzezaTPYtGLFR3jLVbZtE81K1wKDbhzogftsplRgtBK3w4g04q5VbD9SKD deVSIbdCetzFF8EK2cHulrMe2xP1Zw7alyCEeAfCU3brfWcttof45OSp23LTmWstzp+r OpLg== X-Gm-Message-State: AOAM5322+XPgThmpESi4mY6UjeitjVt56gz0dkF97S+cG4es2C5oJHNE diQvbdMuF9ICXKDc5o2g/U7u1A== X-Google-Smtp-Source: ABdhPJzIwvncXSPWoPVFVcU9jnwthG8zAehzZ2vCV4LbUxdWWgMAkR+BJhmKNpYH6I+4kPiUrxb/pA== X-Received: by 2002:a1c:4408:: with SMTP id r8mr8494781wma.100.1595422318765; Wed, 22 Jul 2020 05:51:58 -0700 (PDT) Received: from localhost.localdomain ([39.33.200.211]) by smtp.gmail.com with ESMTPSA id 26sm6983074wmj.25.2020.07.22.05.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:51:58 -0700 (PDT) From: Ibtisam Tariq To: declan.doherty@intel.com Cc: dev@dpdk.org, Ibtisam Tariq Date: Wed, 22 Jul 2020 12:50:26 +0000 Message-Id: <20200722125026.2595-2-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125026.2595-1-ibtisam.tariq@emumba.com> References: <20200722125026.2595-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: 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" When exiting the application, resources should be cleared. Signed-off-by: Ibtisam Tariq --- examples/l2fwd-crypto/main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 827da9b3e..5b00e2ade 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,8 @@ #include #endif +static volatile bool force_quit; + enum cdev_type { CDEV_TYPE_ANY, CDEV_TYPE_HW, @@ -838,7 +841,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options) * so user can see the crypto information. */ prev_tsc = rte_rdtsc(); - while (1) { + while (!force_quit) { cur_tsc = rte_rdtsc(); @@ -1738,8 +1741,12 @@ check_all_ports_link_status(uint32_t port_mask) printf("\nChecking link status"); fflush(stdout); for (count = 0; count <= MAX_CHECK_TIME; count++) { + if (force_quit) + return; all_ports_up = 1; RTE_ETH_FOREACH_DEV(portid) { + if (force_quit) + return; if ((port_mask & (1 << portid)) == 0) continue; memset(&link, 0, sizeof(link)); @@ -2662,6 +2669,16 @@ reserve_key_memory(struct l2fwd_crypto_options *options) options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data); } +static void +signal_handler(int signum) +{ + if (signum == SIGINT || signum == SIGTERM) { + printf("\n\nSignal %d received, preparing to exit...\n", + signum); + force_quit = true; + } +} + int main(int argc, char **argv) { @@ -2681,6 +2698,10 @@ main(int argc, char **argv) argc -= ret; argv += ret; + force_quit = false; + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + /* reserve memory for Cipher/Auth key and IV */ reserve_key_memory(&options); @@ -2807,6 +2828,14 @@ main(int argc, char **argv) if (rte_eal_wait_lcore(lcore_id) < 0) return -1; } + 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(); + printf("Bye...\n"); return 0; } -- 2.17.1