From fe511d03d211998cf35d0f24cf62b42910da58d8 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Fri, 21 Jun 2019 08:15:59 +0200 Subject: [PATCH] env_dpdk/pci: reduce g_pci_mutex scope The global pci tailq is no longer modified on the dpdk thread, so on the spdk thread we can access it safely without any lock. The code is slightly more readable then. This shows that cleanup_pci_devices() is always wrapped with lock/unlock. We'll put the locks inside this function in the next patch. Change-Id: Ia4d386b78a87078761df0a3b953bfc4ff44102f8 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458933 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/env_dpdk/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 0cb5fd8ab..e8aeea3fc 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -358,6 +358,8 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver, pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); + pthread_mutex_unlock(&g_pci_mutex); + TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) { break; @@ -365,6 +367,7 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver, } if (dev != NULL && dev->internal.driver == driver) { + pthread_mutex_lock(&g_pci_mutex); if (dev->internal.attached || dev->internal.pending_removal) { pthread_mutex_unlock(&g_pci_mutex); return -1; @@ -377,7 +380,6 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver, pthread_mutex_unlock(&g_pci_mutex); return rc; } - pthread_mutex_unlock(&g_pci_mutex); if (!driver->is_registered) { driver->is_registered = true;