Message ID | 20200519085444.4562-1-m.bilal@emumba.com (mailing list archive) |
---|---|
State | Rejected, archived |
Delegated to: | Thomas Monjalon |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8B52BA0093; Tue, 19 May 2020 10:55:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7A6841D14E; Tue, 19 May 2020 10:55:15 +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 9A6E81C1EB for <dev@dpdk.org>; Tue, 19 May 2020 10:55:13 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id v12so14879375wrp.12 for <dev@dpdk.org>; Tue, 19 May 2020 01:55:13 -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=zYeLUhIw2vLuEfR0Z1cgrneZsaE5ZayGK5rrzhcN+xI=; b=mmCAxRv5/YLsXbzxKJzj0j0LumLs5ZaQDaktiCuust63jPSB2Lf16t6UNYK/eaqePB +e38Qunvkmf21lud8fLy0R8bZZ+Du5Ifs0HP1LqiwIdBaA2nsqwAMMw1WKRJNAVKUF40 C28vMNM6udp0KLMjLWTu1HMKBai0BTU2CYzXvrPEHPjOV8phNQYN4eEHaM+V+M34CtV3 p3hE4tw5v3l3kDBmYerivinTPAnB9bNOu4t+bmFJ/NbVyGdsyCUVk0i9MEawINkIISb+ 5aAnHM2DpHIiZ2WN6j7OmiOKZNexnsG6WXwiO9XVGYpd6LxBxjd8NRZ+R2E3sw2Ot7PW OqDQ== 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=zYeLUhIw2vLuEfR0Z1cgrneZsaE5ZayGK5rrzhcN+xI=; b=EcNWf0d7NhBf1ijJqs23CX95ortLO+245cGTo/JvhHjgg6YLL07fkfjWHD3FVK6MWl BkEicIWYJh/sQ1PkvDcKpZ23eZq8kC8eNX9q4VCdjesbbw1LFUnFgrEtwiIWprBRyR8D MQ4weOcnOadGc/PM3w3NjlLCQeyJZl3+uMiDkLZwt6xdSczm7i0tld8XP82O+jYYzfoc t7a/uDC47otp/Jd0U8iAalItcGdegMA2GwB0wY5oojkdioHSs2nXRoxTz8NetJRpQ0sa pdhquUfovXT1Fu4trNNvtRlT8k6ILrqLsiGSy7vtlnP4XOtX1Q+3D3X8HZ6Fx213R+T7 2W6g== X-Gm-Message-State: AOAM533PTKWVlYWYu/Q/KVMSrv2oFXYbK50ioZcV0/NG7HCrT/IDjsux 4RSXoQU085iKxHZpWtEAkx3Eaw== X-Google-Smtp-Source: ABdhPJxdWj7AOP2zegfuVzaJiwFZjT+0vaS2x8/JBTLb2RZmVO8IuJS8Cm+SRY/gbAgc4M4wkFe4cg== X-Received: by 2002:adf:efd0:: with SMTP id i16mr23959598wrp.315.1589878513307; Tue, 19 May 2020 01:55:13 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:12 -0700 (PDT) From: Muhammad Bilal <m.bilal@emumba.com> To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal <m.bilal@emumba.com> Date: Tue, 19 May 2020 13:54:40 +0500 Message-Id: <20200519085444.4562-1-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [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 <dev.dpdk.org> List-Unsubscribe: <https://mails.dpdk.org/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://mails.dpdk.org/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <https://mails.dpdk.org/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Series |
[1/5] examples/l2fwd-event: free resources in case of error
|
|
Checks
Context | Check | Description |
---|---|---|
ci/checkpatch | success | coding style OK |
ci/Intel-compilation | fail | Compilation issues |
ci/iol-intel-Performance | success | Performance Testing PASS |
ci/iol-nxp-Performance | success | Performance Testing PASS |
ci/iol-mellanox-Performance | success | Performance Testing PASS |
Commit Message
Muhammad Bilal
May 19, 2020, 8:54 a.m. UTC
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(-)
Comments
>-----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
On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> wrote: > > >-----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"); > >+ } > > Yes you are right we should use rte_exit instead of rte_panic, as rte_exit internally calls rte_eal_cleanup function. > 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. Here I'm solving the problem reported in bugzilla id 437. The bug was that if we use --vdev=net_memif with l2fwd application (and with its other variants) then a socket is created by memif PMD, after rte_eal_init function has run successfully. And if an error occurs then the application exits without freeing the resources (socket). On running the application 2nd time we get an error of "socket already exists". As in the previous version of patch " http://patches.dpdk.org/patch/70081/ " it was recommended to clean the resources when an error occurs. Here only using rte_eal_cleanup() is not solving the problem as using memif PMD is creating a socket and it's only cleaned when rte_eth_dev_close(portid) function is called. so that's why using it along with rte_exit or rte_panic. > > > 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 >
>-----Original Message----- >From: Muhammad Bilal <m.bilal@emumba.com> >Sent: Tuesday, June 2, 2020 5:57 PM >To: Sunil Kumar Kori <skori@marvell.com> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh >Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >jgrajcia@cisco.com; vipin.varghese@intel.com >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case >of error > >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> >wrote: >> >> >-----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"); >> >+ } >> > >Yes you are right we should use rte_exit instead of rte_panic, as rte_exit >internally calls rte_eal_cleanup function. >> 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. >Here I'm solving the problem reported in bugzilla id 437. The bug was that if >we use --vdev=net_memif with l2fwd application (and with its other variants) >then a socket is created by memif PMD, after rte_eal_init function has run >successfully. And if an error occurs then the application exits without freeing >the resources (socket). On running the application 2nd time we get an error of >"socket already exists". >As in the previous version of patch " >https://urldefense.proofpoint.com/v2/url?u=http- >3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7x >tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7sMv >Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payDWc >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the resources >when an error occurs. > >Here only using rte_eal_cleanup() is not solving the problem as using memif >PMD is creating a socket and it's only cleaned when >rte_eth_dev_close(portid) function is called. so that's why using it along with >rte_exit or rte_panic. Understood but I am only thinking from user's perspective that user didn't do rte_eth_dev_configure and related APIs so closing the device using rte_eth_dev_close does not look good. May be other's (eal and memif PMD owners) can suggest something better. Please redirect this query to them for suggestions also. >> >> > 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 >>
On Wed, Jun 10, 2020 at 3:01 PM Sunil Kumar Kori <skori@marvell.com> wrote: > > >-----Original Message----- > >From: Muhammad Bilal <m.bilal@emumba.com> > >Sent: Tuesday, June 2, 2020 5:57 PM > >To: Sunil Kumar Kori <skori@marvell.com> > >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh > >Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; > >jgrajcia@cisco.com; vipin.varghese@intel.com > >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case > >of error > > > >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> > >wrote: > >> > >> >-----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"); > >> >+ } > >> > > >Yes you are right we should use rte_exit instead of rte_panic, as rte_exit > >internally calls rte_eal_cleanup function. > >> 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. > >Here I'm solving the problem reported in bugzilla id 437. The bug was that if > >we use --vdev=net_memif with l2fwd application (and with its other variants) > >then a socket is created by memif PMD, after rte_eal_init function has run > >successfully. And if an error occurs then the application exits without freeing > >the resources (socket). On running the application 2nd time we get an error of > >"socket already exists". > >As in the previous version of patch " > >https://urldefense.proofpoint.com/v2/url?u=http- > >3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7x > >tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7sMv > >Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payDWc > >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the resources > >when an error occurs. > > > >Here only using rte_eal_cleanup() is not solving the problem as using memif > >PMD is creating a socket and it's only cleaned when > >rte_eth_dev_close(portid) function is called. so that's why using it along with > >rte_exit or rte_panic. > > > Understood but I am only thinking from user's perspective that user didn't do > rte_eth_dev_configure and related APIs so closing the device using rte_eth_dev_close > does not look good. > May be other's (eal and memif PMD owners) can suggest something better. > Please redirect this query to them for suggestions also. Maintainer also recommended to call rte_eth_dev_close() for this problem in bug No. 437 Here : https://bugs.dpdk.org/show_bug.cgi?id=437#c1 > > >> > >> > 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 > >>
>-----Original Message----- >From: Muhammad Bilal <m.bilal@emumba.com> >Sent: Monday, June 15, 2020 5:30 PM >To: Sunil Kumar Kori <skori@marvell.com> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh >Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >jgrajcia@cisco.com; vipin.varghese@intel.com >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case >of error > >On Wed, Jun 10, 2020 at 3:01 PM Sunil Kumar Kori <skori@marvell.com> >wrote: >> >> >-----Original Message----- >> >From: Muhammad Bilal <m.bilal@emumba.com> >> >Sent: Tuesday, June 2, 2020 5:57 PM >> >To: Sunil Kumar Kori <skori@marvell.com> >> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan >> >Nikhilesh Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >> >jgrajcia@cisco.com; vipin.varghese@intel.com >> >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources >> >in case of error >> > >> >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> >> >wrote: >> >> >> >> >-----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"); >> >> >+ } >> >> > >> >Yes you are right we should use rte_exit instead of rte_panic, as >> >rte_exit internally calls rte_eal_cleanup function. >> >> 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. >> >Here I'm solving the problem reported in bugzilla id 437. The bug was >> >that if we use --vdev=net_memif with l2fwd application (and with its >> >other variants) then a socket is created by memif PMD, after >> >rte_eal_init function has run successfully. And if an error occurs >> >then the application exits without freeing the resources (socket). On >> >running the application 2nd time we get an error of "socket already exists". >> >As in the previous version of patch " >> >https://urldefense.proofpoint.com/v2/url?u=http- >> >>3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 >x >> >>tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7sM >v >> >>Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payDW >c >> >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the resources >> >when an error occurs. >> > >> >Here only using rte_eal_cleanup() is not solving the problem as using >> >memif PMD is creating a socket and it's only cleaned when >> >rte_eth_dev_close(portid) function is called. so that's why using it >> >along with rte_exit or rte_panic. >> >> >> Understood but I am only thinking from user's perspective that user >> didn't do rte_eth_dev_configure and related APIs so closing the device >> using rte_eth_dev_close does not look good. >> May be other's (eal and memif PMD owners) can suggest something better. >> Please redirect this query to them for suggestions also. >Maintainer also recommended to call rte_eth_dev_close() for this problem in >bug No. 437 Here : https://urldefense.proofpoint.com/v2/url?u=https- >3A__bugs.dpdk.org_show-5Fbug.cgi-3Fid-3D437- >23c1&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtfQ&r=dXeXaAMkP5COgn1zxHMy >aF1_d9IIuq6vHQO6NrIPjaE&m=C6PYaZqbOP-IfP6yK- >nkxpSLonovGalGzl9QJ03qBmU&s=SEiTU3- >EhOV5r16Kk9ZbW67E_dzuHvls4Fn41WyfCN0&e= In mentioned link, I see that Vipin has also suggested to clean this resource in memif PMD But did not found any reason to drop that idea. I am still in favor of this. Also as a query, I see that changes are only l2fwd and its variants. Is this problem not applicable to other applications where memif is used ? >> >> >> >> >> > 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 >> >>
On Tue, Jun 16, 2020 at 10:53 AM Sunil Kumar Kori <skori@marvell.com> wrote: > > >-----Original Message----- > >From: Muhammad Bilal <m.bilal@emumba.com> > >Sent: Monday, June 15, 2020 5:30 PM > >To: Sunil Kumar Kori <skori@marvell.com> > >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh > >Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; > >jgrajcia@cisco.com; vipin.varghese@intel.com > >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case > >of error > > > >On Wed, Jun 10, 2020 at 3:01 PM Sunil Kumar Kori <skori@marvell.com> > >wrote: > >> > >> >-----Original Message----- > >> >From: Muhammad Bilal <m.bilal@emumba.com> > >> >Sent: Tuesday, June 2, 2020 5:57 PM > >> >To: Sunil Kumar Kori <skori@marvell.com> > >> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan > >> >Nikhilesh Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; > >> >jgrajcia@cisco.com; vipin.varghese@intel.com > >> >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources > >> >in case of error > >> > > >> >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> > >> >wrote: > >> >> > >> >> >-----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"); > >> >> >+ } > >> >> > > >> >Yes you are right we should use rte_exit instead of rte_panic, as > >> >rte_exit internally calls rte_eal_cleanup function. > >> >> 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. > >> >Here I'm solving the problem reported in bugzilla id 437. The bug was > >> >that if we use --vdev=net_memif with l2fwd application (and with its > >> >other variants) then a socket is created by memif PMD, after > >> >rte_eal_init function has run successfully. And if an error occurs > >> >then the application exits without freeing the resources (socket). On > >> >running the application 2nd time we get an error of "socket already exists". > >> >As in the previous version of patch " > >> >https://urldefense.proofpoint.com/v2/url?u=http- > >> > >>3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 > >x > >> > >>tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7sM > >v > >> > >>Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payDW > >c > >> >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the resources > >> >when an error occurs. > >> > > >> >Here only using rte_eal_cleanup() is not solving the problem as using > >> >memif PMD is creating a socket and it's only cleaned when > >> >rte_eth_dev_close(portid) function is called. so that's why using it > >> >along with rte_exit or rte_panic. > >> > >> > >> Understood but I am only thinking from user's perspective that user > >> didn't do rte_eth_dev_configure and related APIs so closing the device > >> using rte_eth_dev_close does not look good. > >> May be other's (eal and memif PMD owners) can suggest something better. > >> Please redirect this query to them for suggestions also. > >Maintainer also recommended to call rte_eth_dev_close() for this problem in > >bug No. 437 Here : https://urldefense.proofpoint.com/v2/url?u=https- > >3A__bugs.dpdk.org_show-5Fbug.cgi-3Fid-3D437- > >23c1&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtfQ&r=dXeXaAMkP5COgn1zxHMy > >aF1_d9IIuq6vHQO6NrIPjaE&m=C6PYaZqbOP-IfP6yK- > >nkxpSLonovGalGzl9QJ03qBmU&s=SEiTU3- > >EhOV5r16Kk9ZbW67E_dzuHvls4Fn41WyfCN0&e= > > In mentioned link, I see that Vipin has also suggested to clean this resource in memif PMD > But did not found any reason to drop that idea. I am still in favor of this. You are right, Vipin initially recommended change in Memif PMD but later agreed upon cleaning the resources in applications. > Also as a query, I see that changes are only l2fwd and its variants. > Is this problem not applicable to other applications where memif is used ? This problem is applicable to other applications where memif is used. We are working on other applications as time permits, Some patches already submitted e.g: http://patches.dpdk.org/project/dpdk/list/?series=10458 > > >> > >> >> > >> >> > 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 > >> >>
>-----Original Message----- >From: Muhammad Bilal <m.bilal@emumba.com> >Sent: Tuesday, June 16, 2020 3:44 PM >To: Sunil Kumar Kori <skori@marvell.com> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh >Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >jgrajcia@cisco.com; vipin.varghese@intel.com >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case >of error > >On Tue, Jun 16, 2020 at 10:53 AM Sunil Kumar Kori <skori@marvell.com> >wrote: >> >> >-----Original Message----- >> >From: Muhammad Bilal <m.bilal@emumba.com> >> >Sent: Monday, June 15, 2020 5:30 PM >> >To: Sunil Kumar Kori <skori@marvell.com> >> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan >> >Nikhilesh Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >> >jgrajcia@cisco.com; vipin.varghese@intel.com >> >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources >> >in case of error >> > >> >On Wed, Jun 10, 2020 at 3:01 PM Sunil Kumar Kori <skori@marvell.com> >> >wrote: >> >> >> >> >-----Original Message----- >> >> >From: Muhammad Bilal <m.bilal@emumba.com> >> >> >Sent: Tuesday, June 2, 2020 5:57 PM >> >> >To: Sunil Kumar Kori <skori@marvell.com> >> >> >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan >> >> >Nikhilesh Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; >> >> >jgrajcia@cisco.com; vipin.varghese@intel.com >> >> >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free >> >> >resources in case of error >> >> > >> >> >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori >> >> ><skori@marvell.com> >> >> >wrote: >> >> >> >> >> >> >-----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"); >> >> >> >+ } >> >> >> > >> >> >Yes you are right we should use rte_exit instead of rte_panic, as >> >> >rte_exit internally calls rte_eal_cleanup function. >> >> >> 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. >> >> >Here I'm solving the problem reported in bugzilla id 437. The bug >> >> >was that if we use --vdev=net_memif with l2fwd application (and >> >> >with its other variants) then a socket is created by memif PMD, >> >> >after rte_eal_init function has run successfully. And if an error >> >> >occurs then the application exits without freeing the resources >> >> >(socket). On running the application 2nd time we get an error of "socket >already exists". >> >> >As in the previous version of patch " >> >> >https://urldefense.proofpoint.com/v2/url?u=http- >> >> >> >>>3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz >7 >> >x >> >> >> >>>tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7s >M >> >v >> >> >> >>>Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payD >W >> >c >> >> >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the >resources >> >> >when an error occurs. >> >> > >> >> >Here only using rte_eal_cleanup() is not solving the problem as >> >> >using memif PMD is creating a socket and it's only cleaned when >> >> >rte_eth_dev_close(portid) function is called. so that's why using >> >> >it along with rte_exit or rte_panic. >> >> >> >> >> >> Understood but I am only thinking from user's perspective that user >> >> didn't do rte_eth_dev_configure and related APIs so closing the >> >> device using rte_eth_dev_close does not look good. >> >> May be other's (eal and memif PMD owners) can suggest something >better. >> >> Please redirect this query to them for suggestions also. >> >Maintainer also recommended to call rte_eth_dev_close() for this >> >problem in bug No. 437 Here : >> >https://urldefense.proofpoint.com/v2/url?u=https- >> >3A__bugs.dpdk.org_show-5Fbug.cgi-3Fid-3D437- >> >>23c1&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtfQ&r=dXeXaAMkP5COgn1zxHM >y >> >aF1_d9IIuq6vHQO6NrIPjaE&m=C6PYaZqbOP-IfP6yK- >> >nkxpSLonovGalGzl9QJ03qBmU&s=SEiTU3- >> >EhOV5r16Kk9ZbW67E_dzuHvls4Fn41WyfCN0&e= >> >> In mentioned link, I see that Vipin has also suggested to clean this >> resource in memif PMD But did not found any reason to drop that idea. I am >still in favor of this. > >You are right, Vipin initially recommended change in Memif PMD but later >agreed upon cleaning the resources in applications. > Okay. >> Also as a query, I see that changes are only l2fwd and its variants. >> Is this problem not applicable to other applications where memif is used ? > >This problem is applicable to other applications where memif is used. >We are working on other applications as time permits, Some patches already >submitted e.g: >https://urldefense.proofpoint.com/v2/url?u=http- >3A__patches.dpdk.org_project_dpdk_list_-3Fseries- >3D10458&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtfQ&r=dXeXaAMkP5COgn1zx >HMyaF1_d9IIuq6vHQO6NrIPjaE&m=v5R9KG76zcLqWJF7H_FNAliRW3Peorns7b >O9tYEPZ8g&s=HjKnDn7I8abChgl_c1uoMfy8hCEb09geYL7sTHoatNY&e= > >> >> >> >> >> >> >> >> >> > 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 >> >> >>
Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
June 16, 2020, 11:47 a.m. UTC |
#8
Addressed
Unaddressed
> -----Original Message----- > From: Sunil Kumar Kori <skori@marvell.com> > Sent: Wednesday, June 10, 2020 12:01 PM > To: Muhammad Bilal <m.bilal@emumba.com> > Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan Nikhilesh > Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; Jakub Grajciar -X > (jgrajcia - PANTHEON TECH SRO at Cisco) <jgrajcia@cisco.com>; > vipin.varghese@intel.com > Subject: RE: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in case > of error > > >-----Original Message----- > >From: Muhammad Bilal <m.bilal@emumba.com> > >Sent: Tuesday, June 2, 2020 5:57 PM > >To: Sunil Kumar Kori <skori@marvell.com> > >Cc: declan.doherty@intel.com; tomasz.kantecki@intel.com; Pavan > >Nikhilesh Bhagavatula <pbhagavatula@marvell.com>; dev@dpdk.org; > >jgrajcia@cisco.com; vipin.varghese@intel.com > >Subject: Re: [EXT] [PATCH 1/5] examples/l2fwd-event: free resources in > >case of error > > > >On Tue, May 19, 2020 at 2:35 PM Sunil Kumar Kori <skori@marvell.com> > >wrote: > >> > >> >-----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"); > >> >+ } > >> > > >Yes you are right we should use rte_exit instead of rte_panic, as > >rte_exit internally calls rte_eal_cleanup function. > >> 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. > >Here I'm solving the problem reported in bugzilla id 437. The bug was > >that if we use --vdev=net_memif with l2fwd application (and with its > >other variants) then a socket is created by memif PMD, after > >rte_eal_init function has run successfully. And if an error occurs then > >the application exits without freeing the resources (socket). On > >running the application 2nd time we get an error of "socket already exists". > >As in the previous version of patch " > >https://urldefense.proofpoint.com/v2/url?u=http- > >3A__patches.dpdk.org_patch_70081_&d=DwIBaQ&c=nKjWec2b6R0mOyPa > z7x > >tfQ&r=dXeXaAMkP5COgn1zxHMyaF1_d9IIuq6vHQO6NrIPjaE&m=XKcRI2e7 > sMv > >Y0nGabnBQl_Q8meL03FXFAjeNGdCV91A&s=TKq1J0W3QbnkeuG4c63payD > Wc > >Pc4zTg4DumA95RVzwg&e= " it was recommended to clean the resources > when > >an error occurs. > > > >Here only using rte_eal_cleanup() is not solving the problem as using > >memif PMD is creating a socket and it's only cleaned when > >rte_eth_dev_close(portid) function is called. so that's why using it > >along with rte_exit or rte_panic. > > > Understood but I am only thinking from user's perspective that user didn't do > rte_eth_dev_configure and related APIs so closing the device using > rte_eth_dev_close does not look good. > May be other's (eal and memif PMD owners) can suggest something better. > Please redirect this query to them for suggestions also. > So if calling ret_eth_dev_close() makes sense after rte_eth_dev_configure() the socket initialization can be moved to the configure function. One more thought: struct rte_vdev_driver holds .probe and .remove functions. Shouldn't .remove be called before exiting if .probe was called? This would close the socket in case of memif PMD. > >> > >> > 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 > >>
On Tue, 16 Jun 2020 10:38:01 +0000 Sunil Kumar Kori <skori@marvell.com> wrote: > >> >> >> > >> >> >> Also I think, it is better to release the relevant resources on error. > >> >> >Here I'm solving the problem reported in bugzilla id 437. The bug > >> >> >was that if we use --vdev=net_memif with l2fwd application (and > >> >> >with its other variants) then a socket is created by memif PMD, > >> >> >after rte_eal_init function has run successfully. And if an error > >> >> >occurs then the application exits without freeing the resources > >> >> >(socket). On running the application 2nd time we get an error of "socket > >already exists". Bottom line: Fix memif, don't wallpaper over the bug by fixing the examples. Other user applications, can and do crash. The driver needs to be robust and handle that.
Previous mail was destined to me which I believe is not correct. Updating "To recipient". Regards Sunil Kumar Kori > -----Original Message----- > From: Stephen Hemminger <stephen@networkplumber.org> > Sent: Monday, June 12, 2023 10:27 PM > To: Sunil Kumar Kori <skori@marvell.com> > Cc: Muhammad Bilal <m.bilal@emumba.com>; declan.doherty@intel.com; > tomasz.kantecki@intel.com; Pavan Nikhilesh Bhagavatula > <pbhagavatula@marvell.com>; dev@dpdk.org; jgrajcia@cisco.com; > vipin.varghese@intel.com > Subject: Re: [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: free > resources in case of error > > On Tue, 16 Jun 2020 10:38:01 +0000 > Sunil Kumar Kori <skori@marvell.com> wrote: > > > >> >> >> > > >> >> >> Also I think, it is better to release the relevant resources on error. > > >> >> >Here I'm solving the problem reported in bugzilla id 437. The > > >> >> >bug was that if we use --vdev=net_memif with l2fwd application > > >> >> >(and with its other variants) then a socket is created by memif > > >> >> >PMD, after rte_eal_init function has run successfully. And if > > >> >> >an error occurs then the application exits without freeing the > > >> >> >resources (socket). On running the application 2nd time we get > > >> >> >an error of "socket > > >already exists". > > Bottom line: Fix memif, don't wallpaper over the bug by fixing the examples. > > Other user applications, can and do crash. The driver needs to be robust and > handle that.
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"); + } 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"); + } /* 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); + } 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)