From: "Minggang Li(Gavin)" <gavinl@nvidia.com>
To: <matan@nvidia.com>, <viacheslavo@nvidia.com>, <orika@nvidia.com>,
<thomas@monjalon.net>, Dariusz Sosnowski <dsosnowski@nvidia.com>,
Bing Zhao <bingz@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>
Subject: [PATCH 6/7] mlx5: use RDMA Netlink to update port information
Date: Mon, 23 Dec 2024 12:11:00 +0200 [thread overview]
Message-ID: <20241223101101.677449-7-gavinl@nvidia.com> (raw)
In-Reply-To: <20241223101101.677449-1-gavinl@nvidia.com>
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.
Signed-off-by: Minggang Li(Gavin) <gavinl@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
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(-)
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 3bc8495e7a..af521c5d9b 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -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.
diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c
index e03db4f918..ce1c2a8e75 100644
--- a/drivers/common/mlx5/linux/mlx5_nl.c
+++ b/drivers/common/mlx5/linux/mlx5_nl.c
@@ -101,6 +101,7 @@
#ifndef HAVE_RDMA_NL_GROUP_NOTIFY
#define RDMA_NL_GROUP_NOTIFY 4
#endif
+#define RDMA_NL_GROUP_NOTIFICATION (1 << (RDMA_NL_GROUP_NOTIFY - 1))
/* These are normally found in linux/if_link.h. */
#ifndef HAVE_IFLA_NUM_VF
@@ -176,22 +177,6 @@ struct mlx5_nl_mac_addr {
int mac_n; /**< Number of addresses in the array. */
};
-#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)
-
-/** 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). */
-};
-
RTE_ATOMIC(uint32_t) atomic_sn;
/* Generate Netlink sequence number. */
@@ -2110,3 +2095,60 @@ mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id, const char *pci_ad
*enable ? "en" : "dis", pci_addr);
return ret;
}
+
+int
+mlx5_nl_rdma_monitor_init(void)
+{
+ return mlx5_nl_init(NETLINK_RDMA, RDMA_NL_GROUP_NOTIFICATION);
+}
+
+void
+mlx5_nl_rdma_monitor_info_get(struct nlmsghdr *hdr, struct mlx5_nl_port_info *data)
+{
+ size_t off = NLMSG_HDRLEN;
+ uint8_t event_type = 0;
+
+ if (hdr->nlmsg_type != RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_MONITOR))
+ goto error;
+
+ while (off < hdr->nlmsg_len) {
+ struct nlattr *na = (void *)((uintptr_t)hdr + off);
+ void *payload = (void *)((uintptr_t)na + NLA_HDRLEN);
+
+ if (na->nla_len > hdr->nlmsg_len - off)
+ goto error;
+ switch (na->nla_type) {
+ case RDMA_NLDEV_ATTR_EVENT_TYPE:
+ event_type = *(uint8_t *)payload;
+ if (event_type == RDMA_NETDEV_ATTACH_EVENT) {
+ data->flags |= MLX5_NL_CMD_GET_EVENT_TYPE;
+ data->event_type = MLX5_NL_RDMA_NETDEV_ATTACH_EVENT;
+ } else if (event_type == RDMA_NETDEV_DETACH_EVENT) {
+ data->flags |= MLX5_NL_CMD_GET_EVENT_TYPE;
+ data->event_type = MLX5_NL_RDMA_NETDEV_DETACH_EVENT;
+ }
+ break;
+ case RDMA_NLDEV_ATTR_DEV_INDEX:
+ data->ibindex = *(uint32_t *)payload;
+ data->flags |= MLX5_NL_CMD_GET_IB_INDEX;
+ break;
+ case RDMA_NLDEV_ATTR_PORT_INDEX:
+ data->portnum = *(uint32_t *)payload;
+ data->flags |= MLX5_NL_CMD_GET_PORT_INDEX;
+ break;
+ case RDMA_NLDEV_ATTR_NDEV_INDEX:
+ data->ifindex = *(uint32_t *)payload;
+ data->flags |= MLX5_NL_CMD_GET_NET_INDEX;
+ break;
+ default:
+ DRV_LOG(DEBUG, "Unknown attribute[%d] found", na->nla_type);
+ break;
+ }
+ off += NLA_ALIGN(na->nla_len);
+ }
+
+ return;
+
+error:
+ rte_errno = EINVAL;
+}
diff --git a/drivers/common/mlx5/linux/mlx5_nl.h b/drivers/common/mlx5/linux/mlx5_nl.h
index 396ffc98ce..e32080fa63 100644
--- a/drivers/common/mlx5/linux/mlx5_nl.h
+++ b/drivers/common/mlx5/linux/mlx5_nl.h
@@ -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_ */
diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map
index a2f72ef46a..5230576006 100644
--- a/drivers/common/mlx5/version.map
+++ b/drivers/common/mlx5/version.map
@@ -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;
diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 88d3c57c6e..5156d96b3a 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -894,6 +894,85 @@ mlx5_dev_interrupt_handler_devx(void *cb_arg)
#endif /* HAVE_IBV_DEVX_ASYNC */
}
+static void
+mlx5_dev_interrupt_ib_cb(struct nlmsghdr *hdr, void *cb_arg)
+{
+ mlx5_nl_rdma_monitor_info_get(hdr, (struct mlx5_nl_port_info *)cb_arg);
+}
+
+void
+mlx5_dev_interrupt_handler_ib(void *arg)
+{
+ struct mlx5_dev_ctx_shared *sh = arg;
+ struct mlx5_nl_port_info data = {
+ .flags = 0,
+ .name = "",
+ .ifindex = 0,
+ .ibindex = 0,
+ .portnum = 0,
+ };
+ int nlsk_fd = rte_intr_fd_get(sh->intr_handle_ib);
+ struct mlx5_dev_info *dev_info;
+ uint32_t i;
+
+ dev_info = &sh->cdev->dev_info;
+ DRV_LOG(DEBUG, "IB device %s received RDMA monitor netlink event", dev_info->ibname);
+ if (dev_info->port_num <= 1 || dev_info->port_info == NULL)
+ return;
+
+ if (nlsk_fd < 0)
+ return;
+
+ if (mlx5_nl_read_events(nlsk_fd, mlx5_dev_interrupt_ib_cb, &data) < 0)
+ DRV_LOG(ERR, "Failed to process Netlink events: %s",
+ rte_strerror(rte_errno));
+
+ if (!(data.flags & MLX5_NL_CMD_GET_EVENT_TYPE) ||
+ !(data.flags & MLX5_NL_CMD_GET_PORT_INDEX) ||
+ !(data.flags & MLX5_NL_CMD_GET_IB_INDEX))
+ return;
+
+ if (data.ibindex != dev_info->ibindex)
+ return;
+
+ if (data.event_type != MLX5_NL_RDMA_NETDEV_ATTACH_EVENT &&
+ data.event_type != MLX5_NL_RDMA_NETDEV_DETACH_EVENT)
+ return;
+
+ if (data.event_type == MLX5_NL_RDMA_NETDEV_ATTACH_EVENT &&
+ !(data.flags & MLX5_NL_CMD_GET_NET_INDEX))
+ return;
+
+ DRV_LOG(DEBUG, "Event info: type %d, ibindex %d, ifindex %d, portnum %d,",
+ data.event_type, data.ibindex, data.ifindex, data.portnum);
+
+ /* Changes found in number of SF/VF ports. All information is likely unreliable. */
+ if (data.portnum > dev_info->port_num) {
+ DRV_LOG(ERR, "Port[%d] exceeds maximum[%d]", data.portnum, dev_info->port_num);
+ goto flush_all;
+ }
+ if (data.event_type == MLX5_NL_RDMA_NETDEV_ATTACH_EVENT) {
+ if (!dev_info->port_info[data.portnum].ifindex) {
+ dev_info->port_info[data.portnum].ifindex = data.ifindex;
+ dev_info->port_info[data.portnum].valid = 1;
+ } else {
+ DRV_LOG(WARNING, "Duplicate RDMA event for port[%d] ifindex[%d]",
+ data.portnum, data.ifindex);
+ if (data.ifindex != dev_info->port_info[data.portnum].ifindex)
+ goto flush_all;
+ }
+ } else if (data.event_type == MLX5_NL_RDMA_NETDEV_DETACH_EVENT) {
+ memset(dev_info->port_info + data.portnum, 0, sizeof(struct mlx5_port_nl_info));
+ }
+ return;
+
+flush_all:
+ for (i = 1; i <= dev_info->port_num; i++) {
+ dev_info->port_info[i].ifindex = 0;
+ dev_info->port_info[i].valid = 0;
+ }
+}
+
/**
* DPDK callback to bring the link DOWN.
*
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 4537ca0466..16b275c71e 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -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);
}
/**
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 89d277b523..688a7270ca 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -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);
--
2.34.1
next prev parent reply other threads:[~2024-12-23 10:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-23 10:10 [PATCH V1 0/7] port probe time optimization Minggang Li(Gavin)
2024-12-23 10:10 ` [PATCH 1/7] mailmap: update user name Minggang Li(Gavin)
2024-12-23 10:10 ` [PATCH 2/7] net/mlx5: optimize device probing Minggang Li(Gavin)
2024-12-23 10:10 ` [PATCH 3/7] net/mlx5: add new devargs to control probe optimization Minggang Li(Gavin)
2024-12-23 10:10 ` [PATCH 4/7] common/mlx5: fix Netlink socket leak Minggang Li(Gavin)
2024-12-23 10:10 ` [PATCH 5/7] common/mlx5: add RDMA monitor event awareness Minggang Li(Gavin)
2024-12-23 10:11 ` Minggang Li(Gavin) [this message]
2024-12-23 10:11 ` [PATCH 7/7] mlx5: add backward compatibility for RDMA monitor Minggang Li(Gavin)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241223101101.677449-7-gavinl@nvidia.com \
--to=gavinl@nvidia.com \
--cc=bingz@nvidia.com \
--cc=dev@dpdk.org \
--cc=dsosnowski@nvidia.com \
--cc=matan@nvidia.com \
--cc=orika@nvidia.com \
--cc=rasland@nvidia.com \
--cc=suanmingm@nvidia.com \
--cc=thomas@monjalon.net \
--cc=viacheslavo@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).