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 87EEBA0526; Wed, 22 Jul 2020 14:51:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 939271BFD1; Wed, 22 Jul 2020 14:51:56 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id CA4501BFD1 for ; Wed, 22 Jul 2020 14:51:54 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id o11so1790795wrv.9 for ; Wed, 22 Jul 2020 05:51:54 -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; bh=CTxakhkHZvuMtozp3k7HENlR0Dxbi2DmGKpdWuDw9VI=; b=maDkdzqnMG/osWq3mmrlRcfIlbC9UymomP9murWbCCw0kshG+c7UvNoEHt2W2mCeCM Vtiimkcpc1lGpYc5o9UXn2BOhBiZtlUgmoWMHbL0fr+kXW6Vu2VTifHNoZDa8ktrDJus 6vHtiZuTzK5+pj4KgwAlVgGyy7/iEjQ3Fiqc/6mlzJ5KBVAODnLdR27xq9WAFm8mu0MG CFFAJldzuDpWpdq/nSHMAd+H6yBmMpBGAgMMh3GWfLP2D6aZ0sC54Ji++iNZTvESkS75 Vm8+WVWcHku4hvKoGdAn/8A41Xw5buITe87PMKwokxFV3Kz0i/pcIeOjS4rbpsDckelp yWBA== 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; bh=CTxakhkHZvuMtozp3k7HENlR0Dxbi2DmGKpdWuDw9VI=; b=OVeWhd89BgutDxZ5Db/JCcYskMHefqVGR6DXwJ8QDRclYE1YsEZigZE98eWxnkcDdL S4bLKI+fN3BZE3p7JmkXN04vNw0+oIvT7xddHPWDaFNhn3pJjFbPGc4JxASczqx4Do8x V7SNaYLTJ3Q+uG3kuSL9gMfK30nikK4PxNKK5FHaVdyvD9uQmCXESBpHBa0g9IsMD0e0 /JD7UgOBu4iNXZnMyqQIuC1R7xVsNYeFIlG6QR55s3kFYlhgOlbxk9yb13RxQgt8PCpg 3DM5lHY5Se4iJ4R9oS6JgCvS8tb69aiHBWpk0yV+OuhgtCNDr1HhYrJ4mnCR7hiMTVsn 9VVA== X-Gm-Message-State: AOAM530mWeeQUxrWvva1IE4U9x9k+8U1cyz5TUfXn7qApb4My8RTd0dX 7hg77DzwKVbKcx3sJQ5ICvKjtQ== X-Google-Smtp-Source: ABdhPJwskVJYKlhxfAXScdU3I8oPjdMZ54cIgmnPwGOWXwE94XsFDajRL5gV1Y4uAyIfr0Ph6PjfBA== X-Received: by 2002:a5d:6681:: with SMTP id l1mr17347081wru.47.1595422314421; Wed, 22 Jul 2020 05:51:54 -0700 (PDT) Received: from localhost.localdomain ([39.33.200.211]) by smtp.gmail.com with ESMTPSA id 26sm6983074wmj.25.2020.07.22.05.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:51:53 -0700 (PDT) From: Ibtisam Tariq To: declan.doherty@intel.com Cc: dev@dpdk.org, Ibtisam Tariq Date: Wed, 22 Jul 2020 12:50:25 +0000 Message-Id: <20200722125026.2595-1-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH 1/2] examples/l2fwd-jobstats: 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-jobstats/main.c | 49 +++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/examples/l2fwd-jobstats/main.c b/examples/l2fwd-jobstats/main.c index 47a3b0976..4f29f40ea 100644 --- a/examples/l2fwd-jobstats/main.c +++ b/examples/l2fwd-jobstats/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,8 @@ #include #include +static volatile bool force_quit; + #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1 #define NB_MBUF 8192 @@ -493,7 +496,7 @@ l2fwd_main_loop(void) rte_jobstats_init(&qconf->idle_job, "idle", 0, 0, 0, 0); - for (;;) { + while (!force_quit) { rte_spinlock_lock(&qconf->lock); do { @@ -508,6 +511,9 @@ l2fwd_main_loop(void) uint64_t repeats = 0; do { + if (force_quit) + break; + uint8_t i; uint64_t now = rte_get_timer_cycles(); @@ -523,6 +529,9 @@ l2fwd_main_loop(void) } while (!need_manage); + if (force_quit) + break; + if (likely(repeats != 1)) rte_jobstats_finish(&qconf->idle_job, qconf->idle_job.target); else @@ -693,8 +702,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)); @@ -742,6 +755,27 @@ check_all_ports_link_status(uint32_t port_mask) } } +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 +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) { @@ -762,6 +796,10 @@ main(int argc, char **argv) argc -= ret; argv += ret; + force_quit = false; + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + /* parse application arguments (after the EAL ones) */ ret = l2fwd_parse_args(argc, argv); if (ret < 0) @@ -960,6 +998,12 @@ main(int argc, char **argv) } check_all_ports_link_status(l2fwd_enabled_port_mask); + if (force_quit) { + stop_and_close_eth_dev(portid); + rte_eal_cleanup(); + printf("Bye...\n"); + return 0; + } drain_tsc = (hz + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; @@ -1028,5 +1072,8 @@ main(int argc, char **argv) return -1; } + stop_and_close_eth_dev(portid); + rte_eal_cleanup(); + printf("Bye...\n"); return 0; } -- 2.17.1