diff --git a/app/nvmf_tgt/conf.c b/app/nvmf_tgt/conf.c index a7348b71a..d3f8fbce2 100644 --- a/app/nvmf_tgt/conf.c +++ b/app/nvmf_tgt/conf.c @@ -364,9 +364,9 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, { struct spdk_nvmf_probe_ctx *ctx = cb_ctx; int rc; - char path[MAX_STRING_LEN]; int numa_node = -1; struct spdk_pci_addr pci_addr; + struct spdk_pci_device *pci_dev; spdk_pci_addr_parse(&pci_addr, trid->traddr); @@ -375,10 +375,10 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, trid->traddr, spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem)); - snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/numa_node", - trid->traddr); - - numa_node = spdk_get_numa_node_value(path); + pci_dev = spdk_pci_get_device(&pci_addr); + if (pci_dev) { + numa_node = spdk_pci_device_get_socket_id(pci_dev); + } if (numa_node >= 0) { /* Running subsystem and NVMe device is on the same socket or not */ if (rte_lcore_to_socket_id(ctx->app_subsystem->lcore) != (unsigned)numa_node) { diff --git a/include/spdk/env.h b/include/spdk/env.h index 697554e94..35b2a3ce8 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -210,6 +210,15 @@ uint16_t spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev); struct spdk_pci_id spdk_pci_device_get_id(struct spdk_pci_device *dev); +/** + * Get the NUMA socket ID of a PCI device. + * + * \param dev PCI device to get the socket ID of. + * + * \return Socket ID (>= 0), or negative if unknown. + */ +int spdk_pci_device_get_socket_id(struct spdk_pci_device *dev); + int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len); int spdk_pci_device_claim(const struct spdk_pci_addr *pci_addr); void spdk_pci_device_detach(struct spdk_pci_device *device); diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 77b9da6ed..0be2ac559 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -249,6 +249,16 @@ spdk_pci_device_get_id(struct spdk_pci_device *pci_dev) return pci_id; } +int +spdk_pci_device_get_socket_id(struct spdk_pci_device *pci_dev) +{ +#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) + return pci_dev->device.numa_node; +#else + return pci_dev->numa_node; +#endif +} + int spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset) {