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 12D69A0093; Tue, 19 May 2020 11:35:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E38B11D16B; Tue, 19 May 2020 11:35:04 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 9BE471D167 for ; Tue, 19 May 2020 11:35:03 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04J9Unmp021010; Tue, 19 May 2020 02:35:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=n0ZBy16e0ER33W9jDfJ86HKjxgxwFed1HY5UdYuPK+E=; b=h8Qav+cvDQ4eXii6w9Rd+VcZ8dKkqnx7cXvU0IjvUBZVtcRTGzgoCZxu+LIJUAqTCg8Q Hv+8PQJtjdYHVal5oPV+rm/sUn2exbABTgkbH3cLWoCyDfDWO80PizqwEBJIaKYBaKDh eqNTGJi7k/lSepes0hH4lnEGDGBWOWPwfsgybmOUsNgFxZv3e8KwFxzHagOUsUsUPXMC zgt4mEzHm3ssfmApOQwiNTr+GEQ/n1XzaSHXyTBvd1uw2o1UujPYGYNNifbAwgKTDsLQ KOFvPYebI1xS3vitnTzmOA+CaH+uCGCn62GTGUan60sSW7rgUm+ZFR8hW4Kw1JuxxhXY RA== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 312dhqk9hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 19 May 2020 02:35:02 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 19 May 2020 02:35:01 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 19 May 2020 02:35:00 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.53) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Tue, 19 May 2020 02:35:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GJiiGYvkehFnE9p1JKqWdBhELzXEuF23g/vs0Gq9YyAe4o+0px2qfZdpMWNXw5DudKtK4yiiJe3WaZRyRPno252zg7p0zRwfd0OXIQNp6dLombSF38gVdA8TLueLErgqKaCv1chrg7EYH4bsDiZZXoPfRNKr8Gv/AP9ttCug7QxDRTqhhOih3UWO4f1/wdAjLljvCWck39tAVezH1uDChT6eK9qOENT0ng446DDfcB/hd0TEXGX8nS9JTpeUaKjphe3e+xc6Eeq/bTangtUS3kA/Ve9cagxVj29vGW6drSg6Y7nwKWObKIDM4Re4J5fobTIhmtePB/rxyWAXMh4TJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n0ZBy16e0ER33W9jDfJ86HKjxgxwFed1HY5UdYuPK+E=; b=Xm0nAKLZaKVH+5iG4WUq214/zMccja/yWpIXdNOiNjjxS5+AvjFDHeSzcQx6M0TUAr5bkMm4y9p8iVmGiTZkvuIUMZt9JjHD8ppz46RkR2IKqErNeO5cFyM0A1HH6nKxQMct6twm0sWRKKifCquah0UzZ47ACA4a4Fi8D2WgCsavQb7DRClGkJ4DM2rMG9GjGk6y9C2mrHAOzzjzSf9tt1xqgYgi63Oi6q6d+0Si5+SB/pObITLw2vp6yQbcDZ+RQxKLi0WS/l2M4LpAjBsn/DPHfENQPisZNmDH/vqUu4lBW/Q/B5eGEbGlWy08W9tj0k3aiGZ+26P0xHnppog5Kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n0ZBy16e0ER33W9jDfJ86HKjxgxwFed1HY5UdYuPK+E=; b=WVWmlCMSnsPSAfDgp+1xcKK7IHSQ27O+XMSVPV/WkXN3sJFEG8JnK+tSVfqqzTg0bIJ1b3+G4NvlkDyGErwCF+dV5w30jN8v9mDoxuUUeLZ0lRB4SOgwevL/lsnzwz619hWqDPiXked8y5AlgSVC3mRCShqkIkh9XVCl7MUjqLk= Received: from BY5PR18MB3105.namprd18.prod.outlook.com (10.255.136.94) by BY5PR18MB3379.namprd18.prod.outlook.com (10.255.136.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26; Tue, 19 May 2020 09:34:58 +0000 Received: from BY5PR18MB3105.namprd18.prod.outlook.com ([fe80::cc6:c7ae:dc40:7ddf]) by BY5PR18MB3105.namprd18.prod.outlook.com ([fe80::cc6:c7ae:dc40:7ddf%7]) with mapi id 15.20.3000.034; Tue, 19 May 2020 09:34:58 +0000 From: Sunil Kumar Kori To: Muhammad Bilal , "declan.doherty@intel.com" , "tomasz.kantecki@intel.com" , Pavan Nikhilesh Bhagavatula CC: "dev@dpdk.org" Thread-Topic: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case of error Thread-Index: AQHWLbs7IiZBopkxvk+4vFBt81nvaqivIz8A Date: Tue, 19 May 2020 09:34:58 +0000 Message-ID: References: <20200519085444.4562-1-m.bilal@emumba.com> In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: emumba.com; dkim=none (message not signed) header.d=none;emumba.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [2401:4900:1690:5c2d:a17c:e4b0:1d1b:abf] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 00ba82e2-33c7-4b2e-513e-08d7fbd7e5da x-ms-traffictypediagnostic: BY5PR18MB3379: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3383; x-forefront-prvs: 040866B734 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: A5Xu3H/v4phadBYzj+mMbYzlqDlz1PdvV/jnX0qHBhGo1X9MV4bWjKSytaEoZWspCSh4KD7Up8KxCjVm7B55LAubyIR3CbTbp4YAbxQOoGuPGQKsOSAxYCdc00C5EWPmYq78bJgq95IRM7WESslXZ77XPHMrT3FhkSrKHJ2WJbFp3oZH1rOg+F0BAOJRaKT02G7Whf1D4t68sdFHr1f1lHDaBi5B/+zuAD1Cp21qqHhnxNWlpiRbUSBF0m9NctwRYEzySLTo8ufyWe+x210UKVbwdRFvy9osEXA6OL4U0IJXSo7WO27zDkhGaQjvnCvvcEKp+85jr3RD90nvlGzDSAA593790XX1tMEjhKTZQ+V51L04A+9PIFTPklanmG/SyDoFf0D2aIv30IdtmyywCWO1km5zhoa4NZ4W8fSDkcrZaCW+T0ZpQwMsLO0XPf7f x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BY5PR18MB3105.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(376002)(346002)(396003)(366004)(136003)(186003)(52536014)(6636002)(33656002)(8676002)(66556008)(66946007)(66476007)(5660300002)(7696005)(478600001)(8936002)(316002)(71200400001)(76116006)(66446008)(110136005)(6506007)(55016002)(4326008)(2906002)(9686003)(86362001)(64756008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: Uf3i727pTaTzeOt1vbSbXNiqOmt/Qq4p5K4BhUf+Vmqw9OYjTJOFOrIkEwLBwjDjOP8v4DjBUnibpVq4DydE2zvtX4AxmDv4qgCBEcDSFWE3I9CP4zI9F+j73kJc8+PBNkDFJPW1KERZDCIUFBX/+s+fD+8vVUFMufVdEzq7NP5uyBM64XOXdVo9L9axoLPDdlw/+T81nFHobNQY65r2M918I1JBTXAwXqpIIUvSzZ9hMNgjgUyt0p6dASEykPbv15vE7m7ZOlQUhFlqNtRKK4AkF72MjeSMZ90ZJ/ZSyDXp/btH8OcILJXWVqmaLWh57lxw8X/1GS9Sdq7Xmt8AZKbskLQD7LYz+qAGtmZD/KawRzw1xIqZkhMjW95WwnJbOlxobWQfVzPxnj9SNW/rgfrP9wSimfYNglVNlnsKBJUEJ/JuXvMPs+6xOqmW4mMbclPv7i9Rvs/paPjHdRYVeT/7OZMcFaG6kmGFBKy9BcSjwONtAWJC4eLyuM6+j94LQpZzp7g4A1UReM8n5Ekpu+sQQUY4cIeZE+rEtp55WZhG+FBsqbfF+eiIMq2VRNr7 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 00ba82e2-33c7-4b2e-513e-08d7fbd7e5da X-MS-Exchange-CrossTenant-originalarrivaltime: 19 May 2020 09:34:58.8565 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: t2ZYj6jxF8F/fLPAuqeq3/psJj9BJ0keOVGfWTgzXgarfD/jk3f2alukbuFTMPFlCy/ZHtJhVL36NB+hE9VpDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3379 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-19_03:2020-05-19, 2020-05-19 signatures=0 Subject: Re: [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case of error 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" >-----Original Message----- >From: Muhammad Bilal >Sent: Tuesday, May 19, 2020 2:25 PM >To: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh >Bhagavatula ; Sunil Kumar Kori > >Cc: dev@dpdk.org; Muhammad Bilal >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 >--- > 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 =3D 0; > uint32_t nb_ports_in_mask =3D 0; >- uint16_t port_id, last_port; >+ uint16_t port_id =3D 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 =3D 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 suff= icient for this. Also another way to handle this, use rte_exit instead rte_panic. rte_exit i= nternally 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 =3D rte_eth_dev_count_avail(); >- if (nb_ports =3D=3D 0) >+ if (nb_ports =3D=3D 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 =3D 0; >@@ -621,8 +640,10 @@ main(int argc, char **argv) > rsrc->dst_ports[last_port] =3D 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 =3D RTE_MAX(nb_ports * (RTE_TEST_RX_DESC_DEFAULT + >@@ -634,12 +655,16 @@ main(int argc, char **argv) > rsrc->pktmbuf_pool =3D rte_pktmbuf_pool_create("mbuf_pool", > nb_mbufs, MEMPOOL_CACHE_SIZE, 0, > RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); >- if (rsrc->pktmbuf_pool =3D=3D NULL) >+ if (rsrc->pktmbuf_pool =3D=3D NULL) { >+ stop_and_close_eth_dev(port_id); > rte_panic("Cannot init mbuf pool\n"); >+ } > > nb_ports_available =3D 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 =3D 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=3D%d, port=3D%u\n", >ret, > port_id); >+ } > } > > if (rsrc->event_mode) >-- >2.17.1