From: Sunil Kumar Kori <skori@marvell.com>
To: Muhammad Bilal <m.bilal@emumba.com>,
"declan.doherty@intel.com" <declan.doherty@intel.com>,
"tomasz.kantecki@intel.com" <tomasz.kantecki@intel.com>,
Pavan Nikhilesh Bhagavatula <pbhagavatula@marvell.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case of error
Date: Tue, 19 May 2020 09:34:58 +0000 [thread overview]
Message-ID: <BY5PR18MB3105DA2A2C084E4D488E1ABAB4B90@BY5PR18MB3105.namprd18.prod.outlook.com> (raw)
In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com>
>-----Original Message-----
>From: Muhammad Bilal <m.bilal@emumba.com>
>Sent: Tuesday, May 19, 2020 2:25 PM
>To: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh
>Bhagavatula <pbhagavatula@marvell.com>; Sunil Kumar Kori
><skori@marvell.com>
>Cc: dev@dpdk.org; Muhammad Bilal <m.bilal@emumba.com>
>Subject: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case of
>error
>
>External Email
>
>----------------------------------------------------------------------
>Freeing the resources and call rte_eal_cleanup in case of error exit.
>Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
>---
> examples/l2fwd-event/main.c | 43 ++++++++++++++++++++++++++++++-------
> 1 file changed, 35 insertions(+), 8 deletions(-)
>
>diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c
>index 9593ef11e..442a664e9 100644
>--- a/examples/l2fwd-event/main.c
>+++ b/examples/l2fwd-event/main.c
>@@ -556,13 +556,26 @@ signal_handler(int signum)
> }
> }
>
>+static void
>+stop_and_close_eth_dev(uint16_t portid) {
>+ 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();
>+}
>+
> int
> main(int argc, char **argv)
> {
> struct l2fwd_resources *rsrc;
> uint16_t nb_ports_available = 0;
> uint32_t nb_ports_in_mask = 0;
>- uint16_t port_id, last_port;
>+ uint16_t port_id = 0;
>+ uint16_t last_port;
> uint32_t nb_mbufs;
> uint16_t nb_ports;
> int i, ret;
>@@ -581,20 +594,26 @@ main(int argc, char **argv)
>
> /* parse application arguments (after the EAL ones) */
> ret = l2fwd_event_parse_args(argc, argv, rsrc);
>- if (ret < 0)
>+ if (ret < 0) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("Invalid L2FWD arguments\n");
>+ }
>
IMO, up to this point only eal_init is done so rte_eal_cleanup will be sufficient for this.
Also another way to handle this, use rte_exit instead rte_panic. rte_exit internally calls
rte_eal_cleanup. Refer l2fwd.
Also I think, it is better to release the relevant resources on error.
> printf("MAC updating %s\n", rsrc->mac_updating ? "enabled" :
> "disabled");
>
> nb_ports = rte_eth_dev_count_avail();
>- if (nb_ports == 0)
>+ if (nb_ports == 0) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("No Ethernet ports - bye\n");
>+ }
>
Same as above.
> /* check port mask to possible port mask */
>- if (rsrc->enabled_port_mask & ~((1 << nb_ports) - 1))
>+ if (rsrc->enabled_port_mask & ~((1 << nb_ports) - 1)) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("Invalid portmask; possible (0x%x)\n",
> (1 << nb_ports) - 1);
>+ }
>
Same as above.
> if (!rsrc->port_pairs) {
> last_port = 0;
>@@ -621,8 +640,10 @@ main(int argc, char **argv)
> rsrc->dst_ports[last_port] = last_port;
> }
> } else {
>- if (check_port_pair_config(rsrc) < 0)
>+ if (check_port_pair_config(rsrc) < 0) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("Invalid port pair config\n");
>+ }
> }
>
> nb_mbufs = RTE_MAX(nb_ports * (RTE_TEST_RX_DESC_DEFAULT +
>@@ -634,12 +655,16 @@ main(int argc, char **argv)
> rsrc->pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
> nb_mbufs, MEMPOOL_CACHE_SIZE, 0,
> RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
>- if (rsrc->pktmbuf_pool == NULL)
>+ if (rsrc->pktmbuf_pool == NULL) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("Cannot init mbuf pool\n");
>+ }
>
> nb_ports_available = l2fwd_event_init_ports(rsrc);
>- if (!nb_ports_available)
>+ if (!nb_ports_available) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("All available ports are disabled. Please set
>portmask.\n");
>+ }
>
> /* Configure eventdev parameters if required */
> if (rsrc->event_mode)
>@@ -659,9 +684,11 @@ main(int argc, char **argv)
> continue;
>
> ret = rte_eth_dev_start(port_id);
>- if (ret < 0)
>+ if (ret < 0) {
>+ stop_and_close_eth_dev(port_id);
> rte_panic("rte_eth_dev_start:err=%d, port=%u\n",
>ret,
> port_id);
>+ }
> }
>
> if (rsrc->event_mode)
>--
>2.17.1
next prev parent reply other threads:[~2020-05-19 9:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 8:54 [dpdk-dev] " Muhammad Bilal
2020-05-19 8:54 ` [dpdk-dev] [PATCH 2/5] examples/l2fwd-jobstats: " Muhammad Bilal
2020-05-19 8:54 ` [dpdk-dev] [PATCH 3/5] examples/l2fwd-keepalive: " Muhammad Bilal
2020-05-19 8:54 ` [dpdk-dev] [PATCH 4/5] examples/l2fwd-cat: " Muhammad Bilal
2020-05-19 8:54 ` [dpdk-dev] [PATCH 5/5] examples/l2fwd-crypto: " Muhammad Bilal
2020-05-19 9:34 ` Sunil Kumar Kori [this message]
2020-06-02 12:27 ` [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: " Muhammad Bilal
2020-06-10 10:01 ` Sunil Kumar Kori
2020-06-15 12:00 ` Muhammad Bilal
2020-06-16 5:53 ` Sunil Kumar Kori
2020-06-16 10:14 ` Muhammad Bilal
2020-06-16 10:38 ` Sunil Kumar Kori
2023-06-12 16:56 ` Stephen Hemminger
2023-06-12 17:17 ` Sunil Kumar Kori
2020-06-16 11:47 ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
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=BY5PR18MB3105DA2A2C084E4D488E1ABAB4B90@BY5PR18MB3105.namprd18.prod.outlook.com \
--to=skori@marvell.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
--cc=m.bilal@emumba.com \
--cc=pbhagavatula@marvell.com \
--cc=tomasz.kantecki@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).