env/pci: cleanup spdk_detach_rte by moving code
Change-Id: I1dee015e44ecfbd7fcb1680cce0e6d527d083c99 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1728 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
9db8040738
commit
23a7e4b94f
@ -131,43 +131,44 @@ spdk_detach_rte(struct spdk_pci_device *dev)
|
|||||||
* again while we go asynchronous, so we explicitly forbid that.
|
* again while we go asynchronous, so we explicitly forbid that.
|
||||||
*/
|
*/
|
||||||
dev->internal.pending_removal = true;
|
dev->internal.pending_removal = true;
|
||||||
if (spdk_process_is_primary() && !pthread_equal(g_dpdk_tid, pthread_self())) {
|
if (!spdk_process_is_primary() || pthread_equal(g_dpdk_tid, pthread_self())) {
|
||||||
rte_eal_alarm_set(1, spdk_detach_rte_cb, rte_dev);
|
spdk_detach_rte_cb(rte_dev);
|
||||||
/* wait up to 2s for the cb to finish executing */
|
return;
|
||||||
for (i = 2000; i > 0; i--) {
|
}
|
||||||
|
|
||||||
spdk_delay_us(1000);
|
rte_eal_alarm_set(1, spdk_detach_rte_cb, rte_dev);
|
||||||
pthread_mutex_lock(&g_pci_mutex);
|
/* wait up to 2s for the cb to finish executing */
|
||||||
removed = dev->internal.removed;
|
for (i = 2000; i > 0; i--) {
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
|
||||||
|
|
||||||
if (removed) {
|
spdk_delay_us(1000);
|
||||||
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.
|
|
||||||
*/
|
|
||||||
pthread_mutex_lock(&g_pci_mutex);
|
pthread_mutex_lock(&g_pci_mutex);
|
||||||
removed = dev->internal.removed;
|
removed = dev->internal.removed;
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
pthread_mutex_unlock(&g_pci_mutex);
|
||||||
if (!removed) {
|
|
||||||
fprintf(stderr, "Timeout waiting for DPDK to remove PCI device %s.\n",
|
if (removed) {
|
||||||
rte_dev->name);
|
break;
|
||||||
/* 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 */
|
|
||||||
}
|
}
|
||||||
} 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 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user