From: Sarosh Arif <sarosh.arif@emumba.com>
To: dev@dpdk.org, bruce.richardson@intel.com,
john.mcnamara@intel.com, reshma.pattan@intel.com,
vipin.varghese@intel.com
Cc: Sarosh Arif <sarosh.arif@emumba.com>
Subject: [dpdk-dev] [PATCH v2 3/3] examples/skeleton: free resources on exit
Date: Wed, 17 Jun 2020 09:01:03 +0500 [thread overview]
Message-ID: <20200617040103.28468-3-sarosh.arif@emumba.com> (raw)
In-Reply-To: <20200617040103.28468-1-sarosh.arif@emumba.com>
Resources should be cleared while exiting the application.
Bugzilla ID: 437
Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
---
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 <rte_cycles.h>
#include <rte_lcore.h>
#include <rte_mbuf.h>
+#include <signal.h>
#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
next prev parent reply other threads:[~2020-06-17 4:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-15 8:41 [dpdk-dev] [PATCH 1/3] examples/packet_ordering: " Sarosh Arif
2020-06-15 8:41 ` [dpdk-dev] [PATCH 2/3] examples/rxtx_callbacks: " Sarosh Arif
2020-06-15 8:41 ` [dpdk-dev] [PATCH 3/3] examples/skeleton: " Sarosh Arif
2020-06-17 4:01 ` [dpdk-dev] [PATCH v2 1/3] examples/packet_ordering: " Sarosh Arif
2020-06-17 4:01 ` [dpdk-dev] [PATCH v2 2/3] examples/rxtx_callbacks: " Sarosh Arif
2020-06-17 4:01 ` Sarosh Arif [this message]
2020-06-23 10:48 ` [dpdk-dev] [PATCH v2 1/3] examples/packet_ordering: " Pattan, Reshma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200617040103.28468-3-sarosh.arif@emumba.com \
--to=sarosh.arif@emumba.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=john.mcnamara@intel.com \
--cc=reshma.pattan@intel.com \
--cc=vipin.varghese@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).