Skip to contentSkip to conversation

port probe time optimization

PATCH In review Minggang Li(Gavin) 2 participants 9 messages Dec 23, 2024 – Feb 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover port probe time optimization

This patch series introduced a feature that the time to probe a VF/SF will be reduced greatly in large scale, eg hundreds of VF/SFs. This feature is controlled through the "probe_opt_en" device argument. Setting it to a non-zero value indicates the application will enable this functionality when probing a device. This feature relies on a feature of RDMA driver to be release in incoming upstream kernel 6.12 or the equivalent in OFED 24.10, ie. RDMA monitor. For further information on the devargs limitation, see "doc/guides/nics/mlx5.rst".

Minggang Li(Gavin) (5):
mailmap: update user name
common/mlx5: fix Netlink socket leak common/mlx5: add RDMA monitor event awareness
mlx5: use RDMA Netlink to update port information
mlx5: add backward compatibility for RDMA monitor

Rongwei Liu (2):
net/mlx5: optimize device probing
net/mlx5: add new devargs to control probe optimization

 .mailmap                                     |   2 +-
 doc/guides/nics/mlx5.rst                     |  13 +
 doc/guides/rel_notes/release_24_11.rst       |  14 +
 drivers/common/mlx5/linux/meson.build        |  10 +
 drivers/common/mlx5/linux/mlx5_common_os.h   |   6 +
 drivers/common/mlx5/linux/mlx5_nl.c          | 262 ++++++++++++++++---
 drivers/common/mlx5/linux/mlx5_nl.h          |  36 ++-
 drivers/common/mlx5/mlx5_common.c            |  20 ++
 drivers/common/mlx5/mlx5_common.h            |  15 ++
 drivers/common/mlx5/version.map              |   3 +
 drivers/common/mlx5/windows/mlx5_common_os.h |   5 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c      | 136 ++++++++++
 drivers/net/mlx5/linux/mlx5_os.c             | 144 ++++++++--
 drivers/net/mlx5/linux/mlx5_os.h             |   6 -
 drivers/net/mlx5/mlx5.h                      |   3 +
 drivers/net/mlx5/windows/mlx5_os.h           |   5 -
 16 files changed, 605 insertions(+), 75 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/7 mailmap: update user name

---
 .mailmap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.mailmap +1 -1
index 818798273f..69afc5b6b2 100644
@@ -464,7 +464,6 @@ Gary Mussar <[email protected]>
 Gaurav Singh <[email protected]>
 Gautam Dawar <[email protected]>
 Gavin Hu <[email protected]> <[email protected]>
-Gavin Li <[email protected]>
 Geoffrey Le Gourriérec <[email protected]>
 Geoffrey Lv <[email protected]>
 Geoff Thorpe <[email protected]>
@@ -1031,6 +1030,7 @@ Mike Ximing Chen <[email protected]>
 Milena Olech <[email protected]>
 Min Cao <[email protected]>
 Minghuan Lian <[email protected]>
+Minggang Li(Gavin) <[email protected]>
 Mingjin Ye <[email protected]>
 Mingshan Zhang <[email protected]>
 Mingxia Liu <[email protected]>
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/7 net/mlx5: optimize device probing

In reply to Minggang Li(Gavin)

From: Rongwei Liu <[email protected]>

Current DPDK probing logic is:
1. Query IB device index and total port number.
2. Query each port information by traversing the port index and get the port's ifindex, name and state information etc.
3. Compare the information with devargs until getting matched.
4. For each probing device, repeat steps 2 and 3.

Step 2 will communicate with kernel via netlink and it's time-consuming. There is no need to repeat netlink communication for each probing device, PMD can traverse all ports once and save the information into a caching structure.

Introduce the device information caching in the mlx5 common device handle and cache the port number, ibindex, port ifindex.

For dynamic interface changing:
1. New VF by toggling switchdev mode should restart dpdk as sriov configuration changed.
2. Changing VF number w/o toggling switchdev mode will trigger RTM_DELLINK and RTM_NEWLINK events. All the caching information is cleared.
3. New SF triggers RTM_NEWLINK event and no port index information in the message. All free entries (ifindex = 0) in the cache are invalidated.
4. Delete SF triggers RTM_DELLINK event. Traverse the cache entries and invalidate the one with the same ifindex.

Didn't consider race-condition between probing thread and interrupt thread.

---
 drivers/common/mlx5/linux/mlx5_common_os.h   |   6 ++
 drivers/common/mlx5/linux/mlx5_nl.c          |  94 +++++++++++++----
 drivers/common/mlx5/linux/mlx5_nl.h          |   8 +-
 drivers/common/mlx5/mlx5_common.c            |   5 +
 drivers/common/mlx5/mlx5_common.h            |  13 +++
 drivers/common/mlx5/windows/mlx5_common_os.h |   5 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c      |  54 ++++++++++
 drivers/net/mlx5/linux/mlx5_os.c             | 104 ++++++++++++++-----
 drivers/net/mlx5/linux/mlx5_os.h             |   6 --
 drivers/net/mlx5/windows/mlx5_os.h           |   5 -
 10 files changed, 242 insertions(+), 58 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.h +6 -0
index e8aa1d46ec..2e2c54f1fa 100644
@@ -22,6 +22,12 @@
 #include "mlx5_glue.h"
 #include "mlx5_malloc.h"
 
+/* verb enumerations translations to local enums. */
+enum {
+	MLX5_FS_NAME_MAX = IBV_SYSFS_NAME_MAX + 1,
+	MLX5_FS_PATH_MAX = IBV_SYSFS_PATH_MAX + 1
+};
+
 /**
  * Get device name. Given an ibv_device pointer - return a
  * pointer to the corresponding device name.
drivers/common/mlx5/linux/mlx5_nl.c +75 -19

165 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_nl.h +5 -3
index 580de3b769..396ffc98ce 100644
@@ -11,6 +11,7 @@
 #include <rte_ether.h>
 
 #include "mlx5_common.h"
+#include "mlx5_common_utils.h"
 
 typedef void (mlx5_nl_event_cb)(struct nlmsghdr *hdr, void *user_data);
 
@@ -52,11 +53,12 @@ int mlx5_nl_promisc(int nlsk_fd, unsigned int iface_idx, int enable);
 __rte_internal
 int mlx5_nl_allmulti(int nlsk_fd, unsigned int iface_idx, int enable);
 __rte_internal
-unsigned int mlx5_nl_portnum(int nl, const char *name);
+unsigned int mlx5_nl_portnum(int nl, const char *name, struct mlx5_dev_info *dev_info);
 __rte_internal
-unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
+unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex,
+			     struct mlx5_dev_info *info);
 __rte_internal
-int mlx5_nl_port_state(int nl, const char *name, uint32_t pindex);
+int mlx5_nl_port_state(int nl, const char *name, uint32_t pindex, struct mlx5_dev_info *dev_info);
 __rte_internal
 int mlx5_nl_vf_mac_addr_modify(int nlsk_fd, unsigned int iface_idx,
 			       struct rte_ether_addr *mac, int vf_index);
drivers/common/mlx5/mlx5_common.c +5 -0
index ca8543e36e..0aaae91c31 100644
@@ -735,6 +735,11 @@ mlx5_common_dev_release(struct mlx5_common_device *cdev)
 		if (TAILQ_EMPTY(&devices_list))
 			rte_mem_event_callback_unregister("MLX5_MEM_EVENT_CB",
 							  NULL);
+		if (cdev->dev_info.port_info != NULL) {
+			mlx5_free(cdev->dev_info.port_info);
+			cdev->dev_info.port_info = NULL;
+		}
+		cdev->dev_info.port_num = 0;
 		mlx5_dev_mempool_unsubscribe(cdev);
 		mlx5_mr_release_cache(&cdev->mr_scache);
 		mlx5_dev_hw_global_release(cdev);
drivers/common/mlx5/mlx5_common.h +13 -0
index 1abd1e8239..6cb40f54dd 100644
@@ -174,6 +174,18 @@ enum mlx5_nl_phys_port_name_type {
 	MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
 };
 
+struct mlx5_port_nl_info {
+	uint32_t ifindex;
+	uint8_t valid;
+};
+
+struct mlx5_dev_info {
+	uint32_t port_num;
+	uint32_t ibindex;
+	char ibname[MLX5_FS_NAME_MAX];
+	struct mlx5_port_nl_info *port_info;
+};
+
 /** Switch information returned by mlx5_nl_switch_info(). */
 struct mlx5_switch_info {
 	uint32_t master:1; /**< Master device. */
@@ -525,6 +537,7 @@ struct mlx5_common_device {
 	uint32_t classes_loaded;
 	void *ctx; /* Verbs/DV/DevX context. */
 	void *pd; /* Protection Domain. */
+	struct mlx5_dev_info dev_info; /* Device port info queried via netlink. */
 	uint32_t pdn; /* Protection Domain Number. */
 	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 	struct mlx5_common_dev_config config; /* Device configuration. */
drivers/common/mlx5/windows/mlx5_common_os.h +5 -0
index acee0c987f..65394035de 100644
@@ -20,6 +20,11 @@
 
 #define MLX5_BF_OFFSET 0x800
 
+enum {
+	MLX5_FS_NAME_MAX = MLX5_DEVX_DEVICE_NAME_SIZE + 1,
+	MLX5_FS_PATH_MAX = MLX5_DEVX_DEVICE_PNP_SIZE + 1
+};
+
 /**
  * This API allocates aligned or non-aligned memory.  The free can be on either
  * aligned or nonaligned memory.  To be protected - even though there may be no
drivers/net/mlx5/linux/mlx5_ethdev_os.c +54 -0

72 lines not on this page · raw message

drivers/net/mlx5/linux/mlx5_os.c +79 -25

278 lines not on this page · raw message

drivers/net/mlx5/linux/mlx5_os.h +0 -6
index 80c70d713a..4ef0916173 100644
@@ -8,12 +8,6 @@
 
 #include <net/if.h>
 
-/* verb enumerations translations to local enums. */
-enum {
-	MLX5_FS_NAME_MAX = IBV_SYSFS_NAME_MAX + 1,
-	MLX5_FS_PATH_MAX = IBV_SYSFS_PATH_MAX + 1
-};
-
 /* Maximal data of sendmsg message(in bytes). */
 #define MLX5_SENDMSG_MAX 64
 
drivers/net/mlx5/windows/mlx5_os.h +0 -5
index 8b58265687..fb7198c244 100644
@@ -7,11 +7,6 @@
 
 #include "mlx5_win_ext.h"
 
-enum {
-	MLX5_FS_NAME_MAX = MLX5_DEVX_DEVICE_NAME_SIZE + 1,
-	MLX5_FS_PATH_MAX = MLX5_DEVX_DEVICE_PNP_SIZE + 1
-};
-
 #define PCI_DRV_FLAGS 0
 
 #define MLX5_NAMESIZE MLX5_FS_NAME_MAX
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/7 net/mlx5: add new devargs to control probe optimization

In reply to Minggang Li(Gavin)

From: Rongwei Liu <[email protected]>

Add a new devarg probe_opt_en to control probe optimization in PMD.

By default, the value is 0 and no behavior changed.

---
 doc/guides/nics/mlx5.rst                |  7 +++++++
 drivers/common/mlx5/linux/mlx5_nl.c     | 12 ++++++++----
 drivers/common/mlx5/mlx5_common.c       | 15 +++++++++++++++
 drivers/common/mlx5/mlx5_common.h       |  2 ++
 drivers/net/mlx5/linux/mlx5_ethdev_os.c |  5 ++++-
 drivers/net/mlx5/linux/mlx5_os.c        |  2 +-
 6 files changed, 37 insertions(+), 6 deletions(-)
doc/guides/nics/mlx5.rst +7 -0
index 30c40f767b..3bc8495e7a 100644
@@ -1517,6 +1517,13 @@ for an additional list of options shared with other mlx5 drivers.
 
   By default, the PMD will set this value to 1.
 
+- ``probe_opt_en`` parameter [int]
+
+  A non-zero value optimizes the probe process, especially for large scale.
+  PMD will hold the IB device information internally and reuse it.
+
+  By default, the PMD will set this value to 0.
+
 - ``lacp_by_user`` parameter [int]
 
   A nonzero value enables the control of LACP traffic by the user application.
drivers/common/mlx5/linux/mlx5_nl.c +8 -4
index e98073aafe..745e443f8f 100644
@@ -1148,7 +1148,7 @@ mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex, struct mlx5_dev_info
 			.flags = 0,
 	};
 
-	if (!strcmp(name, dev_info->ibname)) {
+	if (dev_info->probe_opt && !strcmp(name, dev_info->ibname)) {
 		if (dev_info->port_info && pindex <= dev_info->port_num &&
 		    dev_info->port_info[pindex].valid) {
 			if (!dev_info->port_info[pindex].ifindex)
@@ -1161,7 +1161,7 @@ mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex, struct mlx5_dev_info
 
 	ret = mlx5_nl_port_info(nl, pindex, &data);
 
-	if (!strcmp(dev_info->ibname, name)) {
+	if (dev_info->probe_opt && !strcmp(dev_info->ibname, name)) {
 		if ((!ret || ret == -ENODEV) && dev_info->port_info &&
 		    pindex <= dev_info->port_num) {
 			if (!ret)
@@ -1201,7 +1201,8 @@ mlx5_nl_port_state(int nl, const char *name, uint32_t pindex, struct mlx5_dev_in
 			.ibindex = UINT32_MAX,
 	};
 
-	if (dev_info && !strcmp(name, dev_info->ibname) && dev_info->port_num)
+	if (dev_info && dev_info->probe_opt &&
+	    !strcmp(name, dev_info->ibname) && dev_info->port_num)
 		data.ibindex = dev_info->ibindex;
 	if (mlx5_nl_port_info(nl, pindex, &data) < 0)
 		return -rte_errno;
@@ -1244,7 +1245,8 @@ mlx5_nl_portnum(int nl, const char *name, struct mlx5_dev_info *dev_info)
 	uint32_t sn = MLX5_NL_SN_GENERATE;
 	int ret, size;
 
-	if (dev_info->port_num && !strcmp(name, dev_info->ibname))
+	if (dev_info->probe_opt && dev_info->port_num &&
+	    !strcmp(name, dev_info->ibname))
 		return dev_info->port_num;
 
 	ret = mlx5_nl_send(nl, &req, sn);
@@ -1263,6 +1265,8 @@ mlx5_nl_portnum(int nl, const char *name, struct mlx5_dev_info *dev_info)
 		rte_errno = EINVAL;
 		return 0;
 	}
+	if (!dev_info->probe_opt)
+		return data.portnum;
 	MLX5_ASSERT(!strlen(dev_info->ibname));
 	dev_info->port_num = data.portnum;
 	dev_info->ibindex = data.ibindex;
drivers/common/mlx5/mlx5_common.c +15 -0
index 0aaae91c31..9abae4a374 100644
@@ -40,6 +40,9 @@ uint8_t haswell_broadwell_cpu;
 /* The default memory allocator used in PMD. */
 #define MLX5_SYS_MEM_EN "sys_mem_en"
 
+/* Probe optimization in PMD. */
+#define MLX5_PROBE_OPT "probe_opt_en"
+
 /*
  * Device parameter to force doorbell register mapping
  * to non-cached region eliminating the extra write memory barrier.
@@ -295,6 +298,8 @@ mlx5_common_args_check_handler(const char *key, const char *val, void *opaque)
 		config->device_fd = tmp;
 	} else if (strcmp(key, MLX5_PD_HANDLE) == 0) {
 		config->pd_handle = tmp;
+	} else if (strcmp(key, MLX5_PROBE_OPT) == 0) {
+		config->probe_opt = !!tmp;
 	}
 	return 0;
 }
@@ -324,6 +329,7 @@ mlx5_common_config_get(struct mlx5_kvargs_ctrl *mkvlist,
 		MLX5_MR_MEMPOOL_REG_EN,
 		MLX5_DEVICE_FD,
 		MLX5_PD_HANDLE,
+		MLX5_PROBE_OPT,
 		NULL,
 	};
 	int ret = 0;
@@ -332,6 +338,7 @@ mlx5_common_config_get(struct mlx5_kvargs_ctrl *mkvlist,
 	config->mr_ext_memseg_en = 1;
 	config->mr_mempool_reg_en = 1;
 	config->sys_mem_en = 0;
+	config->probe_opt = 0;
 	config->dbnc = MLX5_ARG_UNSET;
 	config->device_fd = MLX5_ARG_UNSET;
 	config->pd_handle = MLX5_ARG_UNSET;
@@ -351,6 +358,7 @@ mlx5_common_config_get(struct mlx5_kvargs_ctrl *mkvlist,
 	DRV_LOG(DEBUG, "mr_ext_memseg_en is %u.", config->mr_ext_memseg_en);
 	DRV_LOG(DEBUG, "mr_mempool_reg_en is %u.", config->mr_mempool_reg_en);
 	DRV_LOG(DEBUG, "sys_mem_en is %u.", config->sys_mem_en);
+	DRV_LOG(DEBUG, "probe_opt_en is %u.", config->probe_opt);
 	DRV_LOG(DEBUG, "Send Queue doorbell mapping parameter is %d.",
 		config->dbnc);
 	return ret;
@@ -791,6 +799,7 @@ mlx5_common_dev_create(struct rte_device *eal_dev, uint32_t classes,
 	if (TAILQ_EMPTY(&devices_list))
 		rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
 						mlx5_mr_mem_event_cb, NULL);
+	cdev->dev_info.probe_opt = cdev->config.probe_opt;
 exit:
 	pthread_mutex_lock(&devices_list_lock);
 	TAILQ_INSERT_HEAD(&devices_list, cdev, next);
@@ -880,6 +889,12 @@ mlx5_common_probe_again_args_validate(struct mlx5_common_device *cdev,
 			cdev->dev->name);
 		goto error;
 	}
+	if (cdev->config.probe_opt != config->probe_opt) {
+		DRV_LOG(ERR, "\"" MLX5_PROBE_OPT"\" "
+			"configuration mismatch for device %s.",
+			cdev->dev->name);
+		goto error;
+	}
 	if (cdev->config.dbnc != config->dbnc) {
 		DRV_LOG(ERR, "\"" MLX5_SQ_DB_NC "\" "
 			"configuration mismatch for device %s.",
drivers/common/mlx5/mlx5_common.h +2 -0
index 6cb40f54dd..f1b59d6f07 100644
@@ -183,6 +183,7 @@ struct mlx5_dev_info {
 	uint32_t port_num;
 	uint32_t ibindex;
 	char ibname[MLX5_FS_NAME_MAX];
+	uint8_t probe_opt;
 	struct mlx5_port_nl_info *port_info;
 };
 
@@ -525,6 +526,7 @@ struct mlx5_common_dev_config {
 	int pd_handle; /* Protection Domain handle for importation.  */
 	unsigned int devx:1; /* Whether devx interface is available or not. */
 	unsigned int sys_mem_en:1; /* The default memory allocator. */
+	unsigned int probe_opt:1; /* Optimize probing . */
 	unsigned int mr_mempool_reg_en:1;
 	/* Allow/prevent implicit mempool memory registration. */
 	unsigned int mr_ext_memseg_en:1;
drivers/net/mlx5/linux/mlx5_ethdev_os.c +4 -1
index 08ac6dd939..88d3c57c6e 100644
@@ -691,6 +691,8 @@ mlx5_handle_port_info_update(struct mlx5_dev_info *dev_info, uint32_t if_index,
 	if (dev_info->port_num <= 1 || dev_info->port_info == NULL)
 		return;
 
+	DRV_LOG(DEBUG, "IB device %s ifindex %u received netlink event %u",
+			dev_info->ibname, if_index, msg_type);
 	for (i = 1; i <= dev_info->port_num; i++) {
 		if (!dev_info->port_info[i].valid)
 			continue;
@@ -734,7 +736,8 @@ mlx5_dev_interrupt_nl_cb(struct nlmsghdr *hdr, void *cb_arg)
 
 	if (mlx5_nl_parse_link_status_update(hdr, &if_index) < 0)
 		return;
-	mlx5_handle_port_info_update(&sh->cdev->dev_info, if_index, hdr->nlmsg_type);
+	if (sh->cdev->config.probe_opt && sh->cdev->dev_info.port_num > 1)
+		mlx5_handle_port_info_update(&sh->cdev->dev_info, if_index, hdr->nlmsg_type);
 
 	for (i = 0; i < sh->max_port; i++) {
 		struct mlx5_dev_shared_port *port = &sh->port[i];
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index 8f6e584154..695936f634 100644
@@ -2340,7 +2340,7 @@ mlx5_os_pci_probe_pf(struct mlx5_common_device *cdev,
 	while (ret-- > 0) {
 		struct rte_pci_addr pci_addr;
 
-		if (cdev->dev_info.port_num) {
+		if (cdev->config.probe_opt && cdev->dev_info.port_num) {
 			if (strcmp(ibv_list[ret]->name, cdev->dev_info.ibname)) {
 				DRV_LOG(INFO, "Unmatched caching device \"%s\" \"%s\"",
 					cdev->dev_info.ibname, ibv_list[ret]->name);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/7 common/mlx5: fix Netlink socket leak

In reply to Minggang Li(Gavin)
Fixes 72d7efe464b1 ("common/mlx5: share interrupt management")
---
 drivers/net/mlx5/linux/mlx5_os.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +5 -0
index 695936f634..4537ca0466 100644
@@ -3071,10 +3071,15 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
 void
 mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)
 {
+	int fd;
+
 	mlx5_os_interrupt_handler_destroy(sh->intr_handle,
 					  mlx5_dev_interrupt_handler, sh);
+	fd = rte_intr_fd_get(sh->intr_handle_nl);
 	mlx5_os_interrupt_handler_destroy(sh->intr_handle_nl,
 					  mlx5_dev_interrupt_handler_nl, sh);
+	if (fd >= 0)
+		close(fd);
 #ifdef HAVE_IBV_DEVX_ASYNC
 	mlx5_os_interrupt_handler_destroy(sh->intr_handle_devx,
 					  mlx5_dev_interrupt_handler_devx, sh);
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/7 common/mlx5: add RDMA monitor event awareness

In reply to Minggang Li(Gavin)

RDMA monitor is a new feature introduced by kernel driver. This commit adds backward compatibility for the kernels do not support it.

---
 drivers/common/mlx5/linux/meson.build | 10 ++++++++++
 drivers/common/mlx5/linux/mlx5_nl.c   | 17 +++++++++++++++++
 2 files changed, 27 insertions(+)
drivers/common/mlx5/linux/meson.build +10 -0
index 82e8046e0c..58d0328c6d 100644
@@ -170,6 +170,16 @@ has_sym_args = [
             'RDMA_NLDEV_ATTR_PORT_STATE' ],
         [ 'HAVE_RDMA_NLDEV_ATTR_NDEV_INDEX', 'rdma/rdma_netlink.h',
             'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
+        [ 'HAVE_RDMA_NL_GROUP_NOTIFY', 'rdma/rdma_netlink.h',
+            'RDMA_NL_GROUP_NOTIFY' ],
+        [ 'HAVE_RDMA_NLDEV_CMD_SYS_GET', 'rdma/rdma_netlink.h',
+            'RDMA_NLDEV_CMD_SYS_GET' ],
+        [ 'HAVE_RDMA_NLDEV_SYS_ATTR_MONITOR_MODE', 'rdma/rdma_netlink.h',
+            'RDMA_NLDEV_SYS_ATTR_MONITOR_MODE' ],
+        [ 'HAVE_RDMA_NLDEV_ATTR_EVENT_TYPE', 'rdma/rdma_netlink.h',
+            'RDMA_NLDEV_ATTR_EVENT_TYPE' ],
+        [ 'HAVE_RDMA_NLDEV_CMD_MONITOR', 'rdma/rdma_netlink.h',
+            'RDMA_NLDEV_CMD_MONITOR' ],
         [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
             'mlx5dv_dump_dr_domain'],
         [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/mlx5_nl.c +17 -0
index 745e443f8f..e03db4f918 100644
@@ -84,6 +84,23 @@
 #ifndef HAVE_RDMA_NLDEV_ATTR_NDEV_INDEX
 #define RDMA_NLDEV_ATTR_NDEV_INDEX 50
 #endif
+#ifndef HAVE_RDMA_NLDEV_ATTR_EVENT_TYPE
+#define RDMA_NLDEV_ATTR_EVENT_TYPE 102
+#define RDMA_NETDEV_ATTACH_EVENT 2
+#define RDMA_NETDEV_DETACH_EVENT 3
+#endif
+#ifndef HAVE_RDMA_NLDEV_SYS_ATTR_MONITOR_MODE
+#define RDMA_NLDEV_SYS_ATTR_MONITOR_MODE 103
+#endif
+#ifndef HAVE_RDMA_NLDEV_CMD_MONITOR
+#define RDMA_NLDEV_CMD_MONITOR 28
+#endif
+#ifndef HAVE_RDMA_NLDEV_CMD_SYS_GET
+#define RDMA_NLDEV_CMD_SYS_GET 6
+#endif
+#ifndef HAVE_RDMA_NL_GROUP_NOTIFY
+#define RDMA_NL_GROUP_NOTIFY 4
+#endif
 
 /* These are normally found in linux/if_link.h. */
 #ifndef HAVE_IFLA_NUM_VF
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/7 mlx5: use RDMA Netlink to update port information

In reply to Minggang Li(Gavin)

Previously, port information, such as adding and deleting, is updated via route netlink. And the events used are link up/down, not the exact event for port adding or deleting, which does not performance well.

To improve the performance, use RDMA monitor events to track port adding and deleting events and update corresponding port information.

---
 doc/guides/nics/mlx5.rst                |  6 ++
 drivers/common/mlx5/linux/mlx5_nl.c     | 74 ++++++++++++++++++-----
 drivers/common/mlx5/linux/mlx5_nl.h     | 28 +++++++++
 drivers/common/mlx5/version.map         |  2 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 79 +++++++++++++++++++++++++
 drivers/net/mlx5/linux/mlx5_os.c        | 20 +++++++
 drivers/net/mlx5/mlx5.h                 |  2 +
 7 files changed, 195 insertions(+), 16 deletions(-)
doc/guides/nics/mlx5.rst +6 -0
index 3bc8495e7a..af521c5d9b 100644
@@ -1524,6 +1524,12 @@ for an additional list of options shared with other mlx5 drivers.
 
   By default, the PMD will set this value to 0.
 
+  .. note::
+
+    There is a race condition in probing port if probe_opt_en is set to 1.
+    Port probe may fail with wrong ifindex in cache while the interrupt
+    thread is updating the cache. Please try again if port probe failed.
+
 - ``lacp_by_user`` parameter [int]
 
   A nonzero value enables the control of LACP traffic by the user application.
drivers/common/mlx5/linux/mlx5_nl.c +58 -16

89 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_nl.h +28 -0
index 396ffc98ce..e32080fa63 100644
@@ -32,6 +32,27 @@ struct mlx5_nl_vlan_vmwa_context {
 	struct mlx5_nl_vlan_dev vlan_dev[4096];
 };
 
+#define MLX5_NL_CMD_GET_IB_NAME (1 << 0)
+#define MLX5_NL_CMD_GET_IB_INDEX (1 << 1)
+#define MLX5_NL_CMD_GET_NET_INDEX (1 << 2)
+#define MLX5_NL_CMD_GET_PORT_INDEX (1 << 3)
+#define MLX5_NL_CMD_GET_PORT_STATE (1 << 4)
+#define MLX5_NL_CMD_GET_EVENT_TYPE (1 << 5)
+
+/** Data structure used by mlx5_nl_cmdget_cb(). */
+struct mlx5_nl_port_info {
+	const char *name; /**< IB device name (in). */
+	uint32_t flags; /**< found attribute flags (out). */
+	uint32_t ibindex; /**< IB device index (out). */
+	uint32_t ifindex; /**< Network interface index (out). */
+	uint32_t portnum; /**< IB device max port number (out). */
+	uint16_t state; /**< IB device port state (out). */
+	uint8_t event_type; /**< IB RDMA event type (out). */
+};
+
+#define MLX5_NL_RDMA_NETDEV_ATTACH_EVENT (1)
+#define MLX5_NL_RDMA_NETDEV_DETACH_EVENT (2)
+
 __rte_internal
 int mlx5_nl_init(int protocol, int groups);
 __rte_internal
@@ -89,4 +110,11 @@ __rte_internal
 int mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id,
 				      const char *pci_addr, int *enable);
 
+__rte_internal
+int mlx5_nl_rdma_monitor_init(void);
+__rte_internal
+void mlx5_nl_rdma_monitor_info_get(struct nlmsghdr *hdr, struct mlx5_nl_port_info *data);
+__rte_internal
+int mlx5_nl_rdma_monitor_cap_get(int nl, uint8_t *cap);
+
 #endif /* RTE_PMD_MLX5_NL_H_ */
drivers/common/mlx5/version.map +2 -0
index a2f72ef46a..5230576006 100644
@@ -146,6 +146,8 @@ INTERNAL {
 	mlx5_nl_vf_mac_addr_modify; # WINDOWS_NO_EXPORT
 	mlx5_nl_vlan_vmwa_create; # WINDOWS_NO_EXPORT
 	mlx5_nl_vlan_vmwa_delete; # WINDOWS_NO_EXPORT
+	mlx5_nl_rdma_monitor_init; # WINDOWS_NO_EXPORT
+	mlx5_nl_rdma_monitor_info_get; # WINDOWS_NO_EXPORT
 
 	mlx5_os_umem_dereg;
 	mlx5_os_umem_reg;
drivers/net/mlx5/linux/mlx5_ethdev_os.c +79 -0

85 lines not on this page · raw message

drivers/net/mlx5/linux/mlx5_os.c +20 -0
index 4537ca0466..16b275c71e 100644
@@ -3025,6 +3025,21 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
 		DRV_LOG(ERR, "Failed to allocate intr_handle.");
 		return;
 	}
+	if (sh->cdev->config.probe_opt && sh->cdev->dev_info.port_num > 1) {
+		nlsk_fd = mlx5_nl_rdma_monitor_init();
+		if (nlsk_fd < 0) {
+			DRV_LOG(ERR, "Failed to create a socket for RDMA Netlink events: %s",
+				rte_strerror(rte_errno));
+			return;
+		}
+		sh->intr_handle_ib = mlx5_os_interrupt_handler_create
+			(RTE_INTR_INSTANCE_F_SHARED, true,
+			 nlsk_fd, mlx5_dev_interrupt_handler_ib, sh);
+		if (sh->intr_handle_ib == NULL) {
+			DRV_LOG(ERR, "Fail to allocate intr_handle");
+			return;
+		}
+	}
 	nlsk_fd = mlx5_nl_init(NETLINK_ROUTE, RTMGRP_LINK);
 	if (nlsk_fd < 0) {
 		DRV_LOG(ERR, "Failed to create a socket for Netlink events: %s",
@@ -3086,6 +3101,11 @@ mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)
 	if (sh->devx_comp)
 		mlx5_glue->devx_destroy_cmd_comp(sh->devx_comp);
 #endif
+	fd = rte_intr_fd_get(sh->intr_handle_ib);
+	mlx5_os_interrupt_handler_destroy(sh->intr_handle_ib,
+				  mlx5_dev_interrupt_handler_ib, sh);
+	if (fd >= 0)
+		close(fd);
 }
 
 /**
drivers/net/mlx5/mlx5.h +2 -0
index 89d277b523..688a7270ca 100644
@@ -1602,6 +1602,7 @@ struct mlx5_dev_ctx_shared {
 	struct rte_intr_handle *intr_handle; /* Interrupt handler for device. */
 	struct rte_intr_handle *intr_handle_devx; /* DEVX interrupt handler. */
 	struct rte_intr_handle *intr_handle_nl; /* Netlink interrupt handler. */
+	struct rte_intr_handle *intr_handle_ib; /* Interrupt handler for IB device. */
 	void *devx_comp; /* DEVX async comp obj. */
 	struct mlx5_devx_obj *tis[16]; /* TIS object. */
 	struct mlx5_devx_obj *td; /* Transport domain. */
@@ -2302,6 +2303,7 @@ int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
 void mlx5_dev_interrupt_handler(void *arg);
 void mlx5_dev_interrupt_handler_devx(void *arg);
 void mlx5_dev_interrupt_handler_nl(void *arg);
+void mlx5_dev_interrupt_handler_ib(void *arg);
 int mlx5_set_link_down(struct rte_eth_dev *dev);
 int mlx5_set_link_up(struct rte_eth_dev *dev);
 int mlx5_is_removed(struct rte_eth_dev *dev);
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/7 mlx5: add backward compatibility for RDMA monitor

In reply to Minggang Li(Gavin)

Fallback to the old way to update port information if the kernel driver does not support RDMA monitor.

---
 doc/guides/rel_notes/release_24_11.rst  | 14 +++++
 drivers/common/mlx5/linux/mlx5_nl.c     | 73 +++++++++++++++++++++++++
 drivers/common/mlx5/version.map         |  1 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c |  2 +-
 drivers/net/mlx5/linux/mlx5_os.c        | 27 +++++++--
 drivers/net/mlx5/mlx5.h                 |  1 +
 6 files changed, 111 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_24_11.rst +14 -0
index 8486cd986f..567ac42663 100644
@@ -288,6 +288,20 @@ New Features
   Added ability for a node to advertise and update multiple xstat counters,
   that can be retrieved using ``rte_graph_cluster_stats_get``.
 
+* **Updated NVIDIA mlx5 driver.**
+
+  Optimized port probe in large scale.
+  This feature enhances the efficiency of probing VF/SFs on a large scale
+  by significantly reducing the probing time. To activate this feature,
+  set ``probe_opt_en`` to a non-zero value during device probing. It
+  leverages a capability from the RDMA driver, expected to be released in
+  the upcoming kernel version 6.12 or its equivalent in OFED 24.10,
+  specifically the RDMA monitor. For additional details on the limitations
+  of devargs, refer to "doc/guides/nics/mlx5.rst".
+
+  If there are lots of VFs/SFs to be probed by the application, eg, 300
+  VFs/SFs, the option should be enabled to save probing time.
+
 
 Removed Items
 -------------
drivers/common/mlx5/linux/mlx5_nl.c +73 -0

76 lines not on this page · raw message

drivers/common/mlx5/version.map +1 -0
index 5230576006..8301485839 100644
@@ -148,6 +148,7 @@ INTERNAL {
 	mlx5_nl_vlan_vmwa_delete; # WINDOWS_NO_EXPORT
 	mlx5_nl_rdma_monitor_init; # WINDOWS_NO_EXPORT
 	mlx5_nl_rdma_monitor_info_get; # WINDOWS_NO_EXPORT
+	mlx5_nl_rdma_monitor_cap_get; # WINDOWS_NO_EXPORT
 
 	mlx5_os_umem_dereg;
 	mlx5_os_umem_reg;
drivers/net/mlx5/linux/mlx5_ethdev_os.c +1 -1
index 5156d96b3a..6b2c25a7c2 100644
@@ -736,7 +736,7 @@ mlx5_dev_interrupt_nl_cb(struct nlmsghdr *hdr, void *cb_arg)
 
 	if (mlx5_nl_parse_link_status_update(hdr, &if_index) < 0)
 		return;
-	if (sh->cdev->config.probe_opt && sh->cdev->dev_info.port_num > 1)
+	if (sh->cdev->config.probe_opt && sh->cdev->dev_info.port_num > 1 && !sh->rdma_monitor_supp)
 		mlx5_handle_port_info_update(&sh->cdev->dev_info, if_index, hdr->nlmsg_type);
 
 	for (i = 0; i < sh->max_port; i++) {
drivers/net/mlx5/linux/mlx5_os.c +21 -6
index 16b275c71e..d3fd77af58 100644
@@ -3017,6 +3017,7 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
 {
 	struct ibv_context *ctx = sh->cdev->ctx;
 	int nlsk_fd;
+	uint8_t rdma_monitor_supp = 0;
 
 	sh->intr_handle = mlx5_os_interrupt_handler_create
 		(RTE_INTR_INSTANCE_F_SHARED, true,
@@ -3025,20 +3026,34 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
 		DRV_LOG(ERR, "Failed to allocate intr_handle.");
 		return;
 	}
-	if (sh->cdev->config.probe_opt && sh->cdev->dev_info.port_num > 1) {
+	if (sh->cdev->config.probe_opt &&
+	    sh->cdev->dev_info.port_num > 1 &&
+	    !sh->rdma_monitor_supp) {
 		nlsk_fd = mlx5_nl_rdma_monitor_init();
 		if (nlsk_fd < 0) {
 			DRV_LOG(ERR, "Failed to create a socket for RDMA Netlink events: %s",
 				rte_strerror(rte_errno));
 			return;
 		}
-		sh->intr_handle_ib = mlx5_os_interrupt_handler_create
-			(RTE_INTR_INSTANCE_F_SHARED, true,
-			 nlsk_fd, mlx5_dev_interrupt_handler_ib, sh);
-		if (sh->intr_handle_ib == NULL) {
-			DRV_LOG(ERR, "Fail to allocate intr_handle");
+		if (mlx5_nl_rdma_monitor_cap_get(nlsk_fd, &rdma_monitor_supp)) {
+			DRV_LOG(ERR, "Failed to query RDMA monitor support: %s",
+				rte_strerror(rte_errno));
+			close(nlsk_fd);
 			return;
 		}
+		sh->rdma_monitor_supp = rdma_monitor_supp;
+		if (sh->rdma_monitor_supp) {
+			sh->intr_handle_ib = mlx5_os_interrupt_handler_create
+				(RTE_INTR_INSTANCE_F_SHARED, true,
+				 nlsk_fd, mlx5_dev_interrupt_handler_ib, sh);
+			if (sh->intr_handle_ib == NULL) {
+				DRV_LOG(ERR, "Fail to allocate intr_handle");
+				close(nlsk_fd);
+				return;
+			}
+		} else {
+			close(nlsk_fd);
+		}
 	}
 	nlsk_fd = mlx5_nl_init(NETLINK_ROUTE, RTMGRP_LINK);
 	if (nlsk_fd < 0) {
drivers/net/mlx5/mlx5.h +1 -0
index 688a7270ca..ab604042b9 100644
@@ -1545,6 +1545,7 @@ struct mlx5_dev_ctx_shared {
 	uint32_t lag_rx_port_affinity_en:1;
 	/* lag_rx_port_affinity is supported. */
 	uint32_t hws_max_log_bulk_sz:5;
+	uint32_t rdma_monitor_supp:1;
 	/* Log of minimal HWS counters created hard coded. */
 	uint32_t hws_max_nb_counters; /* Maximal number for HWS counters. */
 	uint32_t max_port; /* Maximal IB device port index. */
Signature · 1 line
2.34.1
#8 lore raw
In reply to Minggang Li(Gavin)

Hi,

From: Minggang(Gavin) Li <[email protected]>
Sent: Monday, December 23, 2024 12:10 PM
To: Matan Azrad; Slava Ovsiienko; Ori Kam; NBU-Contact-Thomas Monjalon (EXTERNAL)
Cc: [email protected]; Raslan Darawsheh
Subject: [PATCH V1 0/7] port probe time optimization

This patch series introduced a feature that the time to probe a VF/SF will be reduced greatly in large scale, eg hundreds of VF/SFs. This feature is controlled through the "probe_opt_en" device argument. Setting it to a non-zero value indicates the application will enable this functionality when probing a device. This feature relies on a feature of RDMA driver to be release in incoming upstream kernel 6.12 or the equivalent in OFED 24.10, ie. RDMA monitor. For further information on the devargs limitation, see "doc/guides/nics/mlx5.rst".

Minggang Li(Gavin) (5):
mailmap: update user name
common/mlx5: fix Netlink socket leak common/mlx5: add RDMA monitor event awareness
mlx5: use RDMA Netlink to update port information
mlx5: add backward compatibility for RDMA monitor

Rongwei Liu (2):
net/mlx5: optimize device probing
net/mlx5: add new devargs to control probe optimization

 .mailmap                                     |   2 +-
 doc/guides/nics/mlx5.rst                     |  13 +
 doc/guides/rel_notes/release_24_11.rst       |  14 +
 drivers/common/mlx5/linux/meson.build        |  10 +
 drivers/common/mlx5/linux/mlx5_common_os.h   |   6 +
 drivers/common/mlx5/linux/mlx5_nl.c          | 262 ++++++++++++++++---
 drivers/common/mlx5/linux/mlx5_nl.h          |  36 ++-
 drivers/common/mlx5/mlx5_common.c            |  20 ++
 drivers/common/mlx5/mlx5_common.h            |  15 ++
 drivers/common/mlx5/version.map              |   3 +
 drivers/common/mlx5/windows/mlx5_common_os.h |   5 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c      | 136 ++++++++++
 drivers/net/mlx5/linux/mlx5_os.c             | 144 ++++++++--
 drivers/net/mlx5/linux/mlx5_os.h             |   6 -
 drivers/net/mlx5/mlx5.h                      |   3 +
 drivers/net/mlx5/windows/mlx5_os.h           |   5 -
 16 files changed, 605 insertions(+), 75 deletions(-)

--
2.34.1

series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh