From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 1B5275B32 for ; Thu, 18 Oct 2018 12:40:07 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Oct 2018 03:40:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,396,1534834800"; d="scan'208";a="82439502" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga008.jf.intel.com with ESMTP; 18 Oct 2018 03:40:05 -0700 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by IRSMSX102.ger.corp.intel.com (163.33.3.155) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 18 Oct 2018 11:40:04 +0100 Received: from irsmsx107.ger.corp.intel.com ([169.254.10.56]) by IRSMSX156.ger.corp.intel.com ([169.254.3.178]) with mapi id 14.03.0319.002; Thu, 18 Oct 2018 11:40:04 +0100 From: "Iremonger, Bernard" To: Thomas Monjalon , "Yigit, Ferruh" , "arybchenko@solarflare.com" CC: "dev@dpdk.org" , "ophirmu@mellanox.com" , "rahul.lakkireddy@chelsio.com" , Wisam Jaddo Thread-Topic: [PATCH v5 1/6] app/testpmd: fix ports list after removing several at once Thread-Index: AQHUZoFIrvqYSgZKkECV9iUkxJ1NeaUky2UA Date: Thu, 18 Oct 2018 10:40:03 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C260D12CD2@IRSMSX107.ger.corp.intel.com> References: <20180907233929.21950-1-thomas@monjalon.net> <20181018012402.1240-1-thomas@monjalon.net> <20181018012402.1240-2-thomas@monjalon.net> In-Reply-To: <20181018012402.1240-2-thomas@monjalon.net> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjY2YjYwYTQtZmY5NC00NDdmLTliOTMtYTJhMGQ2ZjQ1ZWUyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSElFWVlGT2NGankxOXBIOVFjTnByU1prcEpiUGZCME5MOUxyTXE1UENERG80cThFcjlacXV0RGdOR0FuK0ZPUCJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v5 1/6] app/testpmd: fix ports list after removing several at once 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: , X-List-Received-Date: Thu, 18 Oct 2018 10:40:08 -0000 Hi Wisam, > -----Original Message----- > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Thursday, October 18, 2018 2:24 AM > To: Yigit, Ferruh ; arybchenko@solarflare.com > Cc: dev@dpdk.org; ophirmu@mellanox.com; Iremonger, Bernard > ; rahul.lakkireddy@chelsio.com; Wisam Jaddo > > Subject: [PATCH v5 1/6] app/testpmd: fix ports list after removing severa= l at > once >=20 > From: Wisam Jaddo >=20 > When detaching a port, the full rte_device is removed. > If the rte_device was hosting several ports, the testpmd list of ports mu= st be > updated for multiple removals. ./devtools/check-git-log.sh -1 Missing 'Fixes' tag: app/testpmd: fix ports list after removing several at once =20 > Signed-off-by: Wisam Jaddo > --- > app/test-pmd/testpmd.c | 36 +++++++++++++++++++++++++----------- > 1 file changed, 25 insertions(+), 11 deletions(-) >=20 > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index > 5dbbf783f..c4109417a 100644 > --- a/app/test-pmd/testpmd.c > +++ b/app/test-pmd/testpmd.c > @@ -2186,6 +2186,30 @@ stop_port(portid_t pid) > printf("Done\n"); > } >=20 > +static void > +remove_unused_fwd_ports(void) > +{ > + int i; > + int last_port_idx =3D nb_ports - 1; > + > + for (i =3D 0; i < last_port_idx + 1; i++) { /* iterate in ports_ids */ Why not use " i <=3D last_port_index" instead of adding back 1 > + if (rte_eth_devices[ports_ids[i]].state =3D=3D > RTE_ETH_DEV_UNUSED) { > + /* skip unused ports at the end */ > + while (rte_eth_devices[ports_ids[last_port_idx]].state > + =3D=3D RTE_ETH_DEV_UNUSED && i <=3D > last_port_idx) WARNING:LONG_LINE: line over 80 characters #48: FILE: app/test-pmd/testpmd.c:2199: + =3D=3D RTE_ETH_DEV_UNUSED && i <=3D= last_port_idx) > + last_port_idx--; > + if (last_port_idx < i) > + break; > + /* overwrite unused port with last valid port */ > + ports_ids[i] =3D ports_ids[last_port_idx]; > + /* decrease ports count */ > + last_port_idx--; > + } > + } > + nb_ports =3D rte_eth_dev_count_avail(); > + update_fwd_ports(RTE_MAX_ETHPORTS); > +} > + > void > close_port(portid_t pid) > { > @@ -2315,7 +2339,6 @@ void > detach_port(portid_t port_id) > { > char name[RTE_ETH_NAME_MAX_LEN]; > - uint16_t i; >=20 > printf("Detaching a port...\n"); >=20 > @@ -2332,16 +2355,7 @@ detach_port(portid_t port_id) > return; > } >=20 > - for (i =3D 0; i < nb_ports; i++) { > - if (ports_ids[i] =3D=3D port_id) { > - ports_ids[i] =3D ports_ids[nb_ports-1]; > - ports_ids[nb_ports-1] =3D 0; > - break; > - } > - } > - nb_ports =3D rte_eth_dev_count_avail(); > - > - update_fwd_ports(RTE_MAX_ETHPORTS); > + remove_unused_fwd_ports(); >=20 > printf("Port %u is detached. Now total ports is %d\n", > port_id, nb_ports); > -- > 2.19.0 Regards, Bernard.