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 09F8BA0093 for ; Mon, 15 Jun 2020 10:44:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EC4032B87; Mon, 15 Jun 2020 10:44:27 +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 3F2A72B87 for ; Mon, 15 Jun 2020 10:44:26 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id r15so13918632wmh.5 for ; Mon, 15 Jun 2020 01:44:26 -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=rDIiZ/9/E+RK+q2L74vX/KqE7ibGWiWvc5dcWl5BiwI=; b=PSkFbz+meBkl7nwrIxSLEFiIc+f5jGBTBzAMs7y4mbkdzxH9HAWWEVOJOW4edmDlto aGc9B7ibcthvR7iMRibwmQY1GpYF3ZkxGDFUUrOH3d5dUnEude+k7s+ATV+n8dZOCw6W XuUJ3p7Tlg2Lv3KQXbxc4AAW8tVq/cYarTDXLTaxU7Q/CIlBccFDDCMKlkSwQUi8R6K8 XiLs0dYvn1Bj5GPf4xU6q9Y/4Zc/9qBKZ8KOtAma/RJPtBVf2iXrIKLhZUZdRCJN+zAa Iv9dAlRricvKqupTmN8yjW4YLnS0EmfXC/3vF4K8EcOAN0Cllmo4BrBqmDiRnR8fNJdv 8t8w== 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=rDIiZ/9/E+RK+q2L74vX/KqE7ibGWiWvc5dcWl5BiwI=; b=mRMnS+X7NagP00oTArK4hnp+gpvrGy2/471JK0koH/t2aCFdWWPGgwe62IUG6X8bZ3 TePXO5ujlGwLrepKJbZ2lX+PjVPQvEBsWRWTv+9t/aQhxyRywON02DitiPoVp2nUZ6BE p0AITawKcWbuo2D/Q9quAOml4FMtGKUjd/h6svwYoW5FvyHALPr+hGo5foMYhuKvIM1/ KJAkvziHH+5r8wR6k9gKyDQh/6LoVdrnYxaOZfb/x/RlF4DwyQVcEDbviOpnDCsrYoHX kIoJ74/BtFLvcEnksjiwuscZ9bDH6rNsv2gcwqh/eT8FdAczWkwHAnYCNz2sjeCO71ON jfIA== X-Gm-Message-State: AOAM533pIcKi242aPM8rzievuJ5QtxFvEJPPL+lF0nPDWVsr9HBgrFuj yXs0qUJSHqcN9TJjIGwtHpyyGA== X-Google-Smtp-Source: ABdhPJwyfs4ZQuLv7VuK0ZjHKPRhXYuM2mwcFIYjfPuQOfsU3pGa9WNRgh6eOh6nNfqlb98uNZecaQ== X-Received: by 2002:a05:600c:2259:: with SMTP id a25mr12456516wmm.32.1592210665924; Mon, 15 Jun 2020 01:44:25 -0700 (PDT) Received: from localhost.localdomain ([39.40.31.151]) by smtp.gmail.com with ESMTPSA id 67sm24266075wrk.49.2020.06.15.01.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 01:44:25 -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:30 +0500 Message-Id: <20200615084132.9553-1-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-stable] [PATCH 1/3] examples/packet_ordering: 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/packet_ordering/main.c | 51 ++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c index b5fc6c54b..49326d015 100644 --- a/examples/packet_ordering/main.c +++ b/examples/packet_ordering/main.c @@ -653,6 +653,17 @@ tx_thread(struct rte_ring *ring_in) return 0; } +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"); + } +} + int main(int argc, char **argv) { @@ -683,25 +694,31 @@ main(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid packet_ordering arguments\n"); /* Check if we have enought cores */ - if (rte_lcore_count() < 3) + if (rte_lcore_count() < 3) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Error, This application needs at " "least 3 logical cores to run:\n" "1 lcore for packet RX\n" "1 lcore for packet TX\n" "and at least 1 lcore for worker threads\n"); + } nb_ports = rte_eth_dev_count_avail(); if (nb_ports == 0) - rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n"); - if (nb_ports != 1 && (nb_ports & 1)) + rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n"); + if (nb_ports != 1 && (nb_ports & 1)) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Error: number of ports must be even, except " "when using a single port\n"); + } mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", MBUF_PER_POOL, MBUF_POOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); - if (mbuf_pool == NULL) + if (mbuf_pool == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } nb_ports_available = nb_ports; @@ -716,12 +733,15 @@ main(int argc, char **argv) /* init port */ printf("Initializing port %u... done\n", port_id); - if (configure_eth_port(port_id) != 0) + if (configure_eth_port(port_id) != 0) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "Cannot initialize port %"PRIu8"\n", port_id); + } } if (!nb_ports_available) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "All available ports are disabled. Please set portmask.\n"); } @@ -729,19 +749,25 @@ main(int argc, char **argv) /* Create rings for inter core communication */ rx_to_workers = rte_ring_create("rx_to_workers", RING_SIZE, rte_socket_id(), RING_F_SP_ENQ); - if (rx_to_workers == NULL) + if (rx_to_workers == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } workers_to_tx = rte_ring_create("workers_to_tx", RING_SIZE, rte_socket_id(), RING_F_SC_DEQ); - if (workers_to_tx == NULL) + if (workers_to_tx == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } if (!disable_reorder) { send_args.buffer = rte_reorder_create("PKT_RO", rte_socket_id(), REORDER_BUFFER_SIZE); - if (send_args.buffer == NULL) + if (send_args.buffer == NULL) { + stop_and_close_eth_dev(port_id); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } } last_lcore_id = get_last_lcore_id(); @@ -769,12 +795,17 @@ main(int argc, char **argv) /* Start rx_thread() on the master core */ rx_thread(rx_to_workers); - + RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (rte_eal_wait_lcore(lcore_id) < 0) + if (rte_eal_wait_lcore(lcore_id) < 0) { + stop_and_close_eth_dev(port_id); + rte_eal_cleanup(); return -1; + } } print_stats(); + stop_and_close_eth_dev(port_id); + rte_eal_cleanup(); return 0; } -- 2.17.1