[v7,7/7] app/testpmd: check not detaching device twice
Checks
Commit Message
The command "port detach" is removing the EAL rte_device
of the ethdev port specified as parameter.
After detaching, the pointer, which maps a port to its device,
is resetted. This way, it is possible to check whether a port
is still associated to a (not removed) device.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
Comments
Hi Thomas,
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Tuesday, October 23, 2018 9:29 AM
> To: dev@dpdk.org
> Cc: gaetan.rivet@6wind.com; ophirmu@mellanox.com;
> wisamm@mellanox.com; Yigit, Ferruh <ferruh.yigit@intel.com>;
> arybchenko@solarflare.com; Iremonger, Bernard
> <bernard.iremonger@intel.com>
> Subject: [PATCH v7 7/7] app/testpmd: check not detaching device twice
>
> The command "port detach" is removing the EAL rte_device of the ethdev
> port specified as parameter.
>
> After detaching, the pointer, which maps a port to its device, is resetted. This
Typo: "resetted" should be "reset"
> way, it is possible to check whether a port is still associated to a (not
> removed) device.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
> app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
> 14647fa19..d5998fddc 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
> detach_port(portid_t port_id) {
> + struct rte_device *dev;
> + portid_t sibling;
> +
> printf("Removing a device...\n");
The functionality of the detach_port() function has changed now to removing a device, should the function name be changed to reflect the new functionality.
How about detach_device() instead of detach detach_port().
>
> + dev = rte_eth_devices[port_id].device;
> + if (dev == NULL) {
> + printf("Device already removed\n");
> + return;
> + }
> +
> if (ports[port_id].port_status != RTE_PORT_CLOSED) {
> if (ports[port_id].port_status != RTE_PORT_STOPPED) {
> printf("Port not stopped\n");
> @@ -2365,15 +2374,24 @@ detach_port(portid_t port_id)
> port_flow_flush(port_id);
> }
>
> - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> + if (rte_dev_remove(dev) != 0) {
> TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
Should the log message be ( ERR "Failed to detach device %s\n", dev->name) ?
> return;
> }
>
> + /* reset mapping between old ports and removed device */
> + for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++)
> + if (rte_eth_devices[sibling].device == dev) {
> + rte_eth_devices[sibling].device = NULL;
> + if (ports[sibling].port_status != RTE_PORT_CLOSED) {
> + ports[sibling].port_status =
> RTE_PORT_CLOSED;
> + printf("Port %u is closed\n", sibling);
> + }
> + }
> +
> remove_unused_fwd_ports();
>
> - printf("Port %u is detached. Now total ports is %d\n",
> - port_id, nb_ports);
How about printf("Device %s is detached, Now total ports is %d\n"
dev->name, nb_ports);
> + printf("Now total ports is %d\n", nb_ports);
> printf("Done\n");
> return;
> }
> --
> 2.19.0
Regards,
Bernard.
23/10/2018 12:01, Iremonger, Bernard:
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > The command "port detach" is removing the EAL rte_device of the ethdev
> > port specified as parameter.
> >
> > After detaching, the pointer, which maps a port to its device, is resetted. This
>
> Typo: "resetted" should be "reset"
>
> > way, it is possible to check whether a port is still associated to a (not
> > removed) device.
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> > app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
> > 1 file changed, 21 insertions(+), 3 deletions(-)
> >
> > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
> > 14647fa19..d5998fddc 100644
> > --- a/app/test-pmd/testpmd.c
> > +++ b/app/test-pmd/testpmd.c
> > @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
> > detach_port(portid_t port_id) {
> > + struct rte_device *dev;
> > + portid_t sibling;
> > +
> > printf("Removing a device...\n");
>
> The functionality of the detach_port() function has changed now to
> removing a device, should the function name be changed to reflect
> the new functionality.
No it doesn't change, it has always removed the rte_device of the port.
But the naming is a bit strange, I agree.
I just changed the log to make it a bit clearer.
> How about detach_device() instead of detach detach_port().
The strange thing with testpmd is that every commands take a port id.
The rte_device is hidden in testpmd.
So the detach command is detaching the underlying device of the port,
and all its sibling ports of course.
What about detach_device_of_port() ?
[...]
> > - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> > + if (rte_dev_remove(dev) != 0) {
> > TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
>
> Should the log message be ( ERR "Failed to detach device %s\n", dev->name) ?
Yes!
[...]
> > - printf("Port %u is detached. Now total ports is %d\n",
> > - port_id, nb_ports);
>
> How about printf("Device %s is detached, Now total ports is %d\n"
> dev->name, nb_ports);
The issue is that we cannot get the device name after detach.
I can reword it differently:
Device of port %u is detached, Now total ports is %d
23/10/2018 14:03, Thomas Monjalon:
> 23/10/2018 12:01, Iremonger, Bernard:
> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > The command "port detach" is removing the EAL rte_device of the ethdev
> > > port specified as parameter.
> > >
> > > After detaching, the pointer, which maps a port to its device, is resetted. This
> >
> > Typo: "resetted" should be "reset"
> >
> > > way, it is possible to check whether a port is still associated to a (not
> > > removed) device.
> > >
> > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > ---
> > > app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
> > > 1 file changed, 21 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
> > > 14647fa19..d5998fddc 100644
> > > --- a/app/test-pmd/testpmd.c
> > > +++ b/app/test-pmd/testpmd.c
> > > @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
> > > detach_port(portid_t port_id) {
> > > + struct rte_device *dev;
> > > + portid_t sibling;
> > > +
> > > printf("Removing a device...\n");
> >
> > The functionality of the detach_port() function has changed now to
> > removing a device, should the function name be changed to reflect
> > the new functionality.
>
> No it doesn't change, it has always removed the rte_device of the port.
> But the naming is a bit strange, I agree.
> I just changed the log to make it a bit clearer.
>
> > How about detach_device() instead of detach detach_port().
>
> The strange thing with testpmd is that every commands take a port id.
> The rte_device is hidden in testpmd.
> So the detach command is detaching the underlying device of the port,
> and all its sibling ports of course.
>
> What about detach_device_of_port() ?
Or detach_port_device()?
> [...]
> > > - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> > > + if (rte_dev_remove(dev) != 0) {
> > > TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
> >
> > Should the log message be ( ERR "Failed to detach device %s\n", dev->name) ?
>
> Yes!
>
> [...]
> > > - printf("Port %u is detached. Now total ports is %d\n",
> > > - port_id, nb_ports);
> >
> > How about printf("Device %s is detached, Now total ports is %d\n"
> > dev->name, nb_ports);
>
> The issue is that we cannot get the device name after detach.
> I can reword it differently:
> Device of port %u is detached, Now total ports is %d
>
>
>
>
I want to submit two more patches to clean testpmd for attach/detach.
I propose to drop this patch from this series,
and I will submit a new series dedicated to testpmd cleanup,
including this patch.
23/10/2018 14:13, Thomas Monjalon:
> 23/10/2018 14:03, Thomas Monjalon:
> > 23/10/2018 12:01, Iremonger, Bernard:
> > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > > The command "port detach" is removing the EAL rte_device of the ethdev
> > > > port specified as parameter.
> > > >
> > > > After detaching, the pointer, which maps a port to its device, is resetted. This
> > >
> > > Typo: "resetted" should be "reset"
> > >
> > > > way, it is possible to check whether a port is still associated to a (not
> > > > removed) device.
> > > >
> > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > > ---
> > > > app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
> > > > 1 file changed, 21 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
> > > > 14647fa19..d5998fddc 100644
> > > > --- a/app/test-pmd/testpmd.c
> > > > +++ b/app/test-pmd/testpmd.c
> > > > @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
> > > > detach_port(portid_t port_id) {
> > > > + struct rte_device *dev;
> > > > + portid_t sibling;
> > > > +
> > > > printf("Removing a device...\n");
> > >
> > > The functionality of the detach_port() function has changed now to
> > > removing a device, should the function name be changed to reflect
> > > the new functionality.
> >
> > No it doesn't change, it has always removed the rte_device of the port.
> > But the naming is a bit strange, I agree.
> > I just changed the log to make it a bit clearer.
> >
> > > How about detach_device() instead of detach detach_port().
> >
> > The strange thing with testpmd is that every commands take a port id.
> > The rte_device is hidden in testpmd.
> > So the detach command is detaching the underlying device of the port,
> > and all its sibling ports of course.
> >
> > What about detach_device_of_port() ?
>
> Or detach_port_device()?
>
> > [...]
> > > > - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> > > > + if (rte_dev_remove(dev) != 0) {
> > > > TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
> > >
> > > Should the log message be ( ERR "Failed to detach device %s\n", dev->name) ?
> >
> > Yes!
> >
> > [...]
> > > > - printf("Port %u is detached. Now total ports is %d\n",
> > > > - port_id, nb_ports);
> > >
> > > How about printf("Device %s is detached, Now total ports is %d\n"
> > > dev->name, nb_ports);
> >
> > The issue is that we cannot get the device name after detach.
> > I can reword it differently:
> > Device of port %u is detached, Now total ports is %d
Hi Thomas
<snip>
> Subject: Re: [dpdk-dev] [PATCH v7 7/7] app/testpmd: check not detaching
> device twice
>
> 23/10/2018 14:03, Thomas Monjalon:
> > 23/10/2018 12:01, Iremonger, Bernard:
> > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > > The command "port detach" is removing the EAL rte_device of the
> > > > ethdev port specified as parameter.
> > > >
> > > > After detaching, the pointer, which maps a port to its device, is
> > > > resetted. This
> > >
> > > Typo: "resetted" should be "reset"
> > >
> > > > way, it is possible to check whether a port is still associated to
> > > > a (not
> > > > removed) device.
> > > >
> > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > > ---
> > > > app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
> > > > 1 file changed, 21 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
> > > > 14647fa19..d5998fddc 100644
> > > > --- a/app/test-pmd/testpmd.c
> > > > +++ b/app/test-pmd/testpmd.c
> > > > @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
> > > > detach_port(portid_t port_id) {
> > > > + struct rte_device *dev;
> > > > + portid_t sibling;
> > > > +
> > > > printf("Removing a device...\n");
> > >
> > > The functionality of the detach_port() function has changed now to
> > > removing a device, should the function name be changed to reflect
> > > the new functionality.
> >
> > No it doesn't change, it has always removed the rte_device of the port.
> > But the naming is a bit strange, I agree.
> > I just changed the log to make it a bit clearer.
> >
> > > How about detach_device() instead of detach detach_port().
> >
> > The strange thing with testpmd is that every commands take a port id.
> > The rte_device is hidden in testpmd.
> > So the detach command is detaching the underlying device of the port,
> > and all its sibling ports of course.
> >
> > What about detach_device_of_port() ?
>
> Or detach_port_device()?
detach_port_device() looks fine to me.
>
> > [...]
> > > > - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> > > > + if (rte_dev_remove(dev) != 0) {
> > > > TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
> > >
> > > Should the log message be ( ERR "Failed to detach device %s\n", dev-
> >name) ?
> >
> > Yes!
> >
> > [...]
> > > > - printf("Port %u is detached. Now total ports is %d\n",
> > > > - port_id, nb_ports);
> > >
> > > How about printf("Device %s is detached, Now total ports is %d\n"
> > > dev->name, nb_ports);
> >
> > The issue is that we cannot get the device name after detach.
> > I can reword it differently:
> > Device of port %u is detached, Now total ports is %d
Looks fine to me.
Regards,
Bernard
On 10/23/2018 1:37 PM, Thomas Monjalon wrote:
> I want to submit two more patches to clean testpmd for attach/detach.
>
> I propose to drop this patch from this series,
> and I will submit a new series dedicated to testpmd cleanup,
> including this patch.
Got the set without this patch, please sent it separately.
>
>
> 23/10/2018 14:13, Thomas Monjalon:
>> 23/10/2018 14:03, Thomas Monjalon:
>>> 23/10/2018 12:01, Iremonger, Bernard:
>>>> From: Thomas Monjalon [mailto:thomas@monjalon.net]
>>>>> The command "port detach" is removing the EAL rte_device of the ethdev
>>>>> port specified as parameter.
>>>>>
>>>>> After detaching, the pointer, which maps a port to its device, is resetted. This
>>>>
>>>> Typo: "resetted" should be "reset"
>>>>
>>>>> way, it is possible to check whether a port is still associated to a (not
>>>>> removed) device.
>>>>>
>>>>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>>>>> ---
>>>>> app/test-pmd/testpmd.c | 24 +++++++++++++++++++++---
>>>>> 1 file changed, 21 insertions(+), 3 deletions(-)
>>>>>
>>>>> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index
>>>>> 14647fa19..d5998fddc 100644
>>>>> --- a/app/test-pmd/testpmd.c
>>>>> +++ b/app/test-pmd/testpmd.c
>>>>> @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void
>>>>> detach_port(portid_t port_id) {
>>>>> + struct rte_device *dev;
>>>>> + portid_t sibling;
>>>>> +
>>>>> printf("Removing a device...\n");
>>>>
>>>> The functionality of the detach_port() function has changed now to
>>>> removing a device, should the function name be changed to reflect
>>>> the new functionality.
>>>
>>> No it doesn't change, it has always removed the rte_device of the port.
>>> But the naming is a bit strange, I agree.
>>> I just changed the log to make it a bit clearer.
>>>
>>>> How about detach_device() instead of detach detach_port().
>>>
>>> The strange thing with testpmd is that every commands take a port id.
>>> The rte_device is hidden in testpmd.
>>> So the detach command is detaching the underlying device of the port,
>>> and all its sibling ports of course.
>>>
>>> What about detach_device_of_port() ?
>>
>> Or detach_port_device()?
>>
>>> [...]
>>>>> - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
>>>>> + if (rte_dev_remove(dev) != 0) {
>>>>> TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
>>>>
>>>> Should the log message be ( ERR "Failed to detach device %s\n", dev->name) ?
>>>
>>> Yes!
>>>
>>> [...]
>>>>> - printf("Port %u is detached. Now total ports is %d\n",
>>>>> - port_id, nb_ports);
>>>>
>>>> How about printf("Device %s is detached, Now total ports is %d\n"
>>>> dev->name, nb_ports);
>>>
>>> The issue is that we cannot get the device name after detach.
>>> I can reword it differently:
>>> Device of port %u is detached, Now total ports is %d
>
>
>
>
@@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi)
void
detach_port(portid_t port_id)
{
+ struct rte_device *dev;
+ portid_t sibling;
+
printf("Removing a device...\n");
+ dev = rte_eth_devices[port_id].device;
+ if (dev == NULL) {
+ printf("Device already removed\n");
+ return;
+ }
+
if (ports[port_id].port_status != RTE_PORT_CLOSED) {
if (ports[port_id].port_status != RTE_PORT_STOPPED) {
printf("Port not stopped\n");
@@ -2365,15 +2374,24 @@ detach_port(portid_t port_id)
port_flow_flush(port_id);
}
- if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
+ if (rte_dev_remove(dev) != 0) {
TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
return;
}
+ /* reset mapping between old ports and removed device */
+ for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++)
+ if (rte_eth_devices[sibling].device == dev) {
+ rte_eth_devices[sibling].device = NULL;
+ if (ports[sibling].port_status != RTE_PORT_CLOSED) {
+ ports[sibling].port_status = RTE_PORT_CLOSED;
+ printf("Port %u is closed\n", sibling);
+ }
+ }
+
remove_unused_fwd_ports();
- printf("Port %u is detached. Now total ports is %d\n",
- port_id, nb_ports);
+ printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
return;
}