[dpdk-dev] [RFC] ethdev: complete closing to free all resources

Thomas Monjalon thomas at monjalon.net
Sat Sep 8 01:39:29 CEST 2018


After closing a port, it cannot be restarted.
So there is no reason to not free all associated resources.

The last step was done with rte_eth_dev_detach() which is deprecated.
Instead of removing the associated rte_device, the driver should check
if no more port (ethdev, cryptodev, etc) is still open for the device.
Then the device resources can be freed by the driver inside the
dev_close() driver callback operation.

The last ethdev freeing (dev_private and final release), which were done
by rte_eth_dev_detach(), are now done at the end of rte_eth_dev_close().

Signed-off-by: Thomas Monjalon <thomas at monjalon.net>
---
This patch contains only the change in the close function as RFC.

This idea was presented at Dublin during the "hotplug talk".
---
 lib/librte_ethdev/rte_ethdev.c | 5 +++++
 lib/librte_ethdev/rte_ethdev.h | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 4c3202505..071fcbd23 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -1358,6 +1358,7 @@ void
 rte_eth_dev_close(uint16_t port_id)
 {
 	struct rte_eth_dev *dev;
+	struct rte_bus *bus;
 
 	RTE_ETH_VALID_PORTID_OR_RET(port_id);
 	dev = &rte_eth_devices[port_id];
@@ -1372,6 +1373,10 @@ rte_eth_dev_close(uint16_t port_id)
 	dev->data->nb_tx_queues = 0;
 	rte_free(dev->data->tx_queues);
 	dev->data->tx_queues = NULL;
+
+	rte_free(dev->data->dev_private);
+
+	rte_eth_dev_release_port(dev);
 }
 
 int
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 7070e9ab4..37a757a7a 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -1797,8 +1797,9 @@ int rte_eth_dev_set_link_down(uint16_t port_id);
 
 /**
  * Close a stopped Ethernet device. The device cannot be restarted!
- * The function frees all resources except for needed by the
- * closed state. To free these resources, call rte_eth_dev_detach().
+ * The function frees all port resources.
+ * If there is no more port associated with the underlying device,
+ * the driver should free the device resources.
  *
  * @param port_id
  *   The port identifier of the Ethernet device.
-- 
2.18.0



More information about the dev mailing list