From 16bbcb3f3624d625666055570601c5e4203da8d5 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Mon, 6 Mar 2017 11:09:41 -0700 Subject: [PATCH] env: register PMDs on associated first probe This avoids registering PMDs that are not used by a given application. For example, an app may wish to *not* use ioat - in this case, ioat PMD would not be registered with DPDK, and we would not waste time probing these devices when probing other devices like NVMe. Signed-off-by: Jim Harris Change-Id: If378e40bde9057c7808603aa1918bcfe80fa0e9d --- lib/env_dpdk/env_internal.h | 1 + lib/env_dpdk/pci.c | 10 ++++++++++ lib/env_dpdk/pci_ioat.c | 25 ++----------------------- lib/env_dpdk/pci_nvme.c | 25 ++----------------------- 4 files changed, 15 insertions(+), 46 deletions(-) diff --git a/lib/env_dpdk/env_internal.h b/lib/env_dpdk/env_internal.h index 70156e643..7b1383526 100644 --- a/lib/env_dpdk/env_internal.h +++ b/lib/env_dpdk/env_internal.h @@ -61,6 +61,7 @@ struct spdk_pci_enum_ctx { spdk_pci_enum_cb cb_fn; void *cb_arg; pthread_mutex_t mtx; + bool is_registered; }; int spdk_pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device); diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 7b32938f1..c99a5be2a 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -108,6 +108,11 @@ spdk_pci_device_attach(struct spdk_pci_enum_ctx *ctx, pthread_mutex_lock(&ctx->mtx); + if (!ctx->is_registered) { + ctx->is_registered = true; + rte_eal_pci_register(&ctx->driver); + } + ctx->cb_fn = enum_cb; ctx->cb_arg = enum_ctx; @@ -136,6 +141,11 @@ spdk_pci_enumerate(struct spdk_pci_enum_ctx *ctx, { pthread_mutex_lock(&ctx->mtx); + if (!ctx->is_registered) { + ctx->is_registered = true; + rte_eal_pci_register(&ctx->driver); + } + ctx->cb_fn = enum_cb; ctx->cb_arg = enum_ctx; diff --git a/lib/env_dpdk/pci_ioat.c b/lib/env_dpdk/pci_ioat.c index dde3c4281..b96402830 100644 --- a/lib/env_dpdk/pci_ioat.c +++ b/lib/env_dpdk/pci_ioat.c @@ -95,6 +95,7 @@ static struct spdk_pci_enum_ctx g_ioat_pci_drv = { #if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) .probe = spdk_pci_device_init, .remove = spdk_pci_device_fini, + .driver.name = "spdk_ioat", #else .devinit = spdk_pci_device_init, .devuninit = spdk_pci_device_fini, @@ -105,31 +106,9 @@ static struct spdk_pci_enum_ctx g_ioat_pci_drv = { .cb_fn = NULL, .cb_arg = NULL, .mtx = PTHREAD_MUTEX_INITIALIZER, + .is_registered = false, }; -#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) -RTE_PMD_REGISTER_PCI(spdk_ioat, g_ioat_pci_drv.driver); -#else -static int -spdk_ioat_drv_register(const char *name __rte_unused, const char *params __rte_unused) -{ - rte_eal_pci_register(&g_ioat_pci_drv.driver); - - return 0; -} - -static struct rte_driver g_ioat_drv = { - .type = PMD_PDEV, - .init = spdk_ioat_drv_register, -}; - -#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0) -PMD_REGISTER_DRIVER(g_ioat_drv, spdk_ioat); -#else -PMD_REGISTER_DRIVER(g_ioat_drv); -#endif -#endif - int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, struct spdk_pci_addr *pci_address) diff --git a/lib/env_dpdk/pci_nvme.c b/lib/env_dpdk/pci_nvme.c index 242546417..93a341eda 100644 --- a/lib/env_dpdk/pci_nvme.c +++ b/lib/env_dpdk/pci_nvme.c @@ -57,6 +57,7 @@ static struct spdk_pci_enum_ctx g_nvme_pci_drv = { #if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) .probe = spdk_pci_device_init, .remove = spdk_pci_device_fini, + .driver.name = "spdk_nvme", #else .devinit = spdk_pci_device_init, .devuninit = spdk_pci_device_fini, @@ -67,31 +68,9 @@ static struct spdk_pci_enum_ctx g_nvme_pci_drv = { .cb_fn = NULL, .cb_arg = NULL, .mtx = PTHREAD_MUTEX_INITIALIZER, + .is_registered = false, }; -#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) -RTE_PMD_REGISTER_PCI(spdk_nvme, g_nvme_pci_drv.driver); -#else -static int -spdk_nvme_drv_register(const char *name __rte_unused, const char *params __rte_unused) -{ - rte_eal_pci_register(&g_nvme_pci_drv.driver); - - return 0; -} - -static struct rte_driver g_nvme_drv = { - .type = PMD_PDEV, - .init = spdk_nvme_drv_register, -}; - -#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0) -PMD_REGISTER_DRIVER(g_nvme_drv, spdk_nvme); -#else -PMD_REGISTER_DRIVER(g_nvme_drv); -#endif -#endif - int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, struct spdk_pci_addr *pci_address)