From 23a7e4b94fa6612ffad7916f7c80bd15f0c8370d Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Thu, 2 Apr 2020 12:42:14 +0200 Subject: [PATCH] env/pci: cleanup spdk_detach_rte by moving code Change-Id: I1dee015e44ecfbd7fcb1680cce0e6d527d083c99 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1728 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/env_dpdk/pci.c | 63 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 7cf9be9b0..1cb270251 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -131,43 +131,44 @@ spdk_detach_rte(struct spdk_pci_device *dev) * again while we go asynchronous, so we explicitly forbid that. */ dev->internal.pending_removal = true; - if (spdk_process_is_primary() && !pthread_equal(g_dpdk_tid, pthread_self())) { - rte_eal_alarm_set(1, spdk_detach_rte_cb, rte_dev); - /* wait up to 2s for the cb to finish executing */ - for (i = 2000; i > 0; i--) { + if (!spdk_process_is_primary() || pthread_equal(g_dpdk_tid, pthread_self())) { + spdk_detach_rte_cb(rte_dev); + return; + } - spdk_delay_us(1000); - pthread_mutex_lock(&g_pci_mutex); - removed = dev->internal.removed; - pthread_mutex_unlock(&g_pci_mutex); + rte_eal_alarm_set(1, spdk_detach_rte_cb, rte_dev); + /* wait up to 2s for the cb to finish executing */ + for (i = 2000; i > 0; i--) { - if (removed) { - break; - } - } - - /* besides checking the removed flag, we also need to wait - * for the dpdk detach function to unwind, as it's doing some - * operations even after calling our detach callback. Simply - * cancel the alarm - if it started executing already, this - * call will block and wait for it to finish. - */ - rte_eal_alarm_cancel(spdk_detach_rte_cb, rte_dev); - - /* the device could have been finally removed, so just check - * it again. - */ + spdk_delay_us(1000); pthread_mutex_lock(&g_pci_mutex); removed = dev->internal.removed; pthread_mutex_unlock(&g_pci_mutex); - if (!removed) { - fprintf(stderr, "Timeout waiting for DPDK to remove PCI device %s.\n", - rte_dev->name); - /* If we reach this state, then the device couldn't be removed and most likely - a subsequent hot add of a device in the same BDF will fail */ + + if (removed) { + break; } - } else { - spdk_detach_rte_cb(rte_dev); + } + + /* besides checking the removed flag, we also need to wait + * for the dpdk detach function to unwind, as it's doing some + * operations even after calling our detach callback. Simply + * cancel the alarm - if it started executing already, this + * call will block and wait for it to finish. + */ + rte_eal_alarm_cancel(spdk_detach_rte_cb, rte_dev); + + /* the device could have been finally removed, so just check + * it again. + */ + pthread_mutex_lock(&g_pci_mutex); + removed = dev->internal.removed; + pthread_mutex_unlock(&g_pci_mutex); + if (!removed) { + fprintf(stderr, "Timeout waiting for DPDK to remove PCI device %s.\n", + rte_dev->name); + /* If we reach this state, then the device couldn't be removed and most likely + a subsequent hot add of a device in the same BDF will fail */ } }