@@ -886,11 +886,44 @@ rte_eal_init(int argc, char **argv)
return fctret;
}
+static int
+bus_match_all(const struct rte_bus *bus, const void *data)
+{
+ RTE_SET_USED(bus);
+ RTE_SET_USED(data);
+ return 0;
+}
+
+static void
+remove_all_device(void)
+{
+ struct rte_bus *start = NULL, *next;
+ struct rte_dev_iterator dev_iter = {0};
+ struct rte_device *dev = NULL;
+ struct rte_device *tdev = NULL;
+ char devstr[128];
+
+ RTE_DEV_FOREACH_SAFE(dev, "bus=vdev", &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
+ start = next;
+ /* Skip buses that don't have iterate method */
+ if (!next->dev_iterate || !next->name)
+ continue;
+ snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
+ RTE_DEV_FOREACH_SAFE(dev, devstr, &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ };
+}
+
int
rte_eal_cleanup(void)
{
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ remove_all_device();
rte_service_finalize();
rte_mp_channel_cleanup();
/* after this point, any DPDK pointers will become dangling */
@@ -492,6 +492,12 @@ int
rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
size_t len);
+#define RTE_DEV_FOREACH_SAFE(dev, devstr, it, tdev) \
+ for (rte_dev_iterator_init(it, devstr), \
+ (dev) = rte_dev_iterator_next(it); \
+ (dev) && ((tdev) = rte_dev_iterator_next(it), 1); \
+ (dev) = (tdev))
+
#ifdef __cplusplus
}
#endif
@@ -1248,6 +1248,38 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
return 0;
}
+static int
+bus_match_all(const struct rte_bus *bus, const void *data)
+{
+ RTE_SET_USED(bus);
+ RTE_SET_USED(data);
+ return 0;
+}
+
+static void
+remove_all_device(void)
+{
+ struct rte_bus *start = NULL, *next;
+ struct rte_dev_iterator dev_iter = {0};
+ struct rte_device *dev = NULL;
+ struct rte_device *tdev = NULL;
+ char devstr[128];
+
+ RTE_DEV_FOREACH_SAFE(dev, "bus=vdev", &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
+ start = next;
+ /* Skip buses that don't have iterate method */
+ if (!next->dev_iterate || !next->name)
+ continue;
+ snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
+ RTE_DEV_FOREACH_SAFE(dev, devstr, &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ };
+}
+
int
rte_eal_cleanup(void)
{
@@ -1257,6 +1289,7 @@ rte_eal_cleanup(void)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ remove_all_device();
if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
internal_conf->hugepage_file.unlink_existing)
rte_memseg_walk(mark_freeable, NULL);
@@ -254,12 +254,45 @@ __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
return -ENOTSUP;
}
+static int
+bus_match_all(const struct rte_bus *bus, const void *data)
+{
+ RTE_SET_USED(bus);
+ RTE_SET_USED(data);
+ return 0;
+}
+
+static void
+remove_all_device(void)
+{
+ struct rte_bus *start = NULL, *next;
+ struct rte_dev_iterator dev_iter = {0};
+ struct rte_device *dev = NULL;
+ struct rte_device *tdev = NULL;
+ char devstr[128];
+
+ RTE_DEV_FOREACH_SAFE(dev, "bus=vdev", &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
+ start = next;
+ /* Skip buses that don't have iterate method */
+ if (!next->dev_iterate || !next->name)
+ continue;
+ snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
+ RTE_DEV_FOREACH_SAFE(dev, devstr, &dev_iter, tdev) {
+ (void)rte_dev_remove(dev);
+ }
+ };
+}
+
int
rte_eal_cleanup(void)
{
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ remove_all_device();
eal_intr_thread_cancel();
eal_mem_virt2iova_cleanup();
/* after this point, any DPDK pointers will become dangling */