Commit d3bcd1ca authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

env_dpdk/pci: split dpdk device detach and removal



Simplify the code path a bit. VFIO notification is the only
place where detach callback is called from the dpdk intr thread.
Detach checks the current thread and behaves differently in this
case, but it could be the VFIO notification that simply calls
a different function.

So instead of carrying the VFIO notification through the generic
detach routine, carry it just through the DPDK-thread specific
subset. This lets us remove some ifs in the generic routine.

Change-Id: I5e8866e4643ef08fb3cd12621e2d262b5e827c74
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1731


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent b71ee92e
Loading
Loading
Loading
Loading
+11 −19
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@
#define DPDK_HOTPLUG_RETRY_COUNT 4

/* DPDK alarm/interrupt thread */
static pthread_t g_dpdk_tid;
static pthread_mutex_t g_pci_mutex = PTHREAD_MUTEX_INITIALIZER;
static TAILQ_HEAD(, spdk_pci_device) g_pci_devices = TAILQ_HEAD_INITIALIZER(g_pci_devices);
/* devices hotplugged on a dpdk thread */
@@ -103,10 +102,8 @@ cfg_write_rte(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t o
}

static void
detach_rte_cb(void *_dev)
remove_rte_dev(struct rte_pci_device *rte_dev)
{
	struct rte_pci_device *rte_dev = _dev;

#if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0)
	char bdf[32];
	int i = 0, rc;
@@ -120,6 +117,12 @@ detach_rte_cb(void *_dev)
#endif
}

static void
detach_rte_cb(void *_dev)
{
	remove_rte_dev(_dev);
}

static void
detach_rte(struct spdk_pci_device *dev)
{
@@ -131,8 +134,8 @@ 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())) {
		detach_rte_cb(rte_dev);
	if (!spdk_process_is_primary()) {
		remove_rte_dev(rte_dev);
		return;
	}

@@ -206,8 +209,8 @@ pci_device_rte_hotremove(const char *device_name,
	pthread_mutex_unlock(&g_pci_mutex);

	if (dev != NULL && can_detach) {
		/* if device is not attached, we can remove it right away. */
		detach_rte(dev);
		/* if device is not attached we can remove it right away. */
		remove_rte_dev(dev->dev_handle);
	}
}
#endif
@@ -238,12 +241,6 @@ cleanup_pci_devices(void)
	pthread_mutex_unlock(&g_pci_mutex);
}

static void
_get_alarm_thread_cb(void *unused)
{
	g_dpdk_tid = pthread_self();
}

void
pci_env_init(void)
{
@@ -276,11 +273,6 @@ pci_env_init(void)
		rte_dev_event_callback_register(NULL, pci_device_rte_hotremove, NULL);
	}
#endif

	rte_eal_alarm_set(1, _get_alarm_thread_cb, NULL);
	/* alarms are executed in order, so this one will be always executed
	 * before any real hotremove alarms and we don't need to wait for it.
	 */
}

void