net/mlx5: move to polling for LSC interrupts
Subsystems (2)
PATCH 1/1 net/mlx5: move to polling for LSC interrupts
mlx5 networking driver on Linux implemented LSC interrupts by listening on netlink events.
This method is unfortunately not reliable enough, because of linkwatch mechanism. It can delay link up/down events for up to ~1 second. This introduces unnecessary delay when mlx5 ports are used with DPDK bonding driver for examples.
This patch addresses that by migrating LSC checks
to polling on link status using ETHTOOL_GLINK command. This ethtool command, implemented by mlx5 since kernel 4.14, will always get the current link status.
As a side effect it is also flushes the pending link watch events.
--- .mailmap | 1 + drivers/common/mlx5/linux/mlx5_nl.c | 29 --- drivers/common/mlx5/linux/mlx5_nl.h | 2 - drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_ethdev_os.c | 147 ++++------- drivers/net/mlx5/linux/mlx5_lsc_intr.c | 302 +++++++++++++++++++++++ drivers/net/mlx5/linux/mlx5_os.c | 22 -- drivers/net/mlx5/mlx5.c | 7 - drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_lsc_intr.h | 15 ++ drivers/net/mlx5/mlx5_trigger.c | 19 +- drivers/net/mlx5/windows/meson.build | 1 + drivers/net/mlx5/windows/mlx5_lsc_intr.c | 24 ++ 13 files changed, 398 insertions(+), 176 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_lsc_intr.c create mode 100644 drivers/net/mlx5/mlx5_lsc_intr.h create mode 100644 drivers/net/mlx5/windows/mlx5_lsc_intr.c
.mailmap +1 -0
@@ -315,6 +315,7 @@ Congjie Zhou <[email protected]> Congwen Zhang <[email protected]> Conor Fogarty <[email protected]> Conor Walsh <[email protected]> +Cosmin Ratiu <[email protected]> Cristian Bidea <[email protected]> Cristian Dumitrescu <[email protected]> Cristian Sovaiala <[email protected]>
drivers/common/mlx5/linux/mlx5_nl.c +0 -29
@@ -1994,35 +1994,6 @@ mlx5_nl_enable_roce_set(int nlsk_fd, int family_id, const char *pci_addr,return mlx5_nl_driver_reload (nlsk_fd, family_id, pci_addr); } -/** -* Try to parse a Netlink message as a link status update. -* -* @param hdr -* Netlink message header. -* @param[out] ifindex -* Index of the updated interface. -* -* @return -* 0 on success, negative on failure. -*/ -RTE_EXPORT_INTERNAL_SYMBOL (mlx5_nl_parse_link_status_update) -int -mlx5_nl_parse_link_status_update (struct nlmsghdr *hdr,uint32_t *ifindex) -{ -struct ifinfomsg *info; - -switch (hdr->nlmsg_type) { -case RTM_NEWLINK : -case RTM_DELLINK : -case RTM_GETLINK : -case RTM_SETLINK : - info =NLMSG_DATA (hdr); - *ifindex = info->ifi_index; -return 0 ; - } -return -1 ; -} -/** * Read pending events from a Netlink socket. *
drivers/common/mlx5/linux/mlx5_nl.h +0 -2
@@ -102,8 +102,6 @@ int mlx5_nl_enable_roce_set(int nlsk_fd, int family_id, const char *pci_addr,__rte_internal int mlx5_nl_read_events(int nlsk_fd, mlx5_nl_event_cb *cb, void *cb_arg); -__rte_internal -int mlx5_nl_parse_link_status_update(struct nlmsghdr *hdr, uint32_t *ifindex); __rte_internal int mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id,
drivers/net/mlx5/linux/meson.build +1 -0
@@ -10,6 +10,7 @@ sources += files( 'mlx5_mp_os.c', 'mlx5_vlan_os.c', 'mlx5_flow_os.c', + 'mlx5_lsc_intr.c', ) cflags += no_wvla_cflag
drivers/net/mlx5/linux/mlx5_ethdev_os.c +43 -104
179 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_lsc_intr.c new file +302 -0
302 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +0 -22
@@ -1803,8 +1803,6 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, eth_dev->data->port_id);/* Read link status in case it is up and there will be no event. */ mlx5_link_update (eth_dev,0 ); -/* Watch LSC interrupts between port probe and port start. */ - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = eth_dev->data->port_id;mlx5_set_link_up (eth_dev);for (i =0 ; i <MLX5_FLOW_TYPE_MAXI ; i++) { icfg[i].release_mem_en = !!sh->config.reclaim_mode;
@@ -1956,8 +1954,6 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,return eth_dev; error:if (priv) { - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = -RTE_MAX_ETHPORTS ;rte_io_wmb ();#ifdef HAVE_MLX5_HWS_SUPPORT if (eth_dev &&
@@ -3262,19 +3258,6 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) } } } - 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" , -rte_strerror (rte_errno)); -return ; - } - sh->intr_handle_nl =mlx5_os_interrupt_handler_create - (RTE_INTR_INSTANCE_F_SHARED , true, - nlsk_fd, mlx5_dev_interrupt_handler_nl, sh); -if (sh->intr_handle_nl ==NULL ) { -DRV_LOG (ERR ,"Fail to allocate intr_handle" ); -return ; - }if (sh->cdev->config.devx) {#ifdef HAVE_IBV_DEVX_ASYNC struct mlx5dv_devx_cmd_comp *devx_comp;
@@ -3312,11 +3295,6 @@ mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)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);
drivers/net/mlx5/mlx5.c +0 -7
@@ -1930,7 +1930,6 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,for (i =0 ; i < sh->max_port; i++) { sh->port[i].ih_port_id =RTE_MAX_ETHPORTS ; sh->port[i].devx_ih_port_id =RTE_MAX_ETHPORTS ; - sh->port[i].nl_ih_port_id =RTE_MAX_ETHPORTS ; }if (sh->cdev->config.devx) { sh->td =mlx5_devx_cmd_create_td (sh->cdev->ctx);
@@ -2559,12 +2558,6 @@ mlx5_dev_close(struct rte_eth_dev *dev)mlx5_free (priv->mac); dev->data->mac_addrs =NULL ;mlx5_free (priv->mac_own); - sh->port[priv->dev_port -1 ].nl_ih_port_id =RTE_MAX_ETHPORTS ; -/* -* The interrupt handler port id must be reset before priv is reset -* since 'mlx5_dev_interrupt_nl_cb' uses priv. -*/ -rte_io_wmb ();/* * Free the shared context in last turn, because the cleanup * routines above may use some shared fields, like
drivers/net/mlx5/mlx5.h +1 -3
@@ -838,7 +838,6 @@ struct mlx5_age_info {struct mlx5_dev_shared_port {uint32_t ih_port_id;uint32_t devx_ih_port_id; -uint32_t nl_ih_port_id;/* * Interrupt handler port_id. Used by shared interrupt * handler to find the corresponding rte_eth device
@@ -1649,7 +1648,6 @@ struct mlx5_dev_ctx_shared {/* Shared interrupt handler section. */ 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. */
@@ -2382,13 +2380,13 @@ int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);int mlx5_set_mtu (struct rte_eth_dev *dev,uint16_t mtu);int mlx5_read_clock (struct rte_eth_dev *dev,uint64_t *clock);int mlx5_link_update (struct rte_eth_dev *dev,int wait_to_complete); +int mlx5_link_carrier_get (struct rte_eth_dev *dev);int mlx5_dev_get_flow_ctrl (struct rte_eth_dev *dev,struct rte_eth_fc_conf *fc_conf);int mlx5_dev_set_flow_ctrl (struct rte_eth_dev *dev,struct rte_eth_fc_conf *fc_conf);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);
drivers/net/mlx5/mlx5_lsc_intr.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2026 NVIDIA Corporation & Affiliates +*/ + +#ifndef RTE_PMD_MLX5_LSC_INTR_H_ +#define RTE_PMD_MLX5_LSC_INTR_H_ + +#include <stdbool.h> + +struct rte_eth_dev ; + +int mlx5_lsc_intr_setup (struct rte_eth_dev *dev); +void mlx5_lsc_intr_cleanup (struct rte_eth_dev *dev); + +#endif /* RTE_PMD_MLX5_LSC_INTR_H_ */
drivers/net/mlx5/mlx5_trigger.c +10 -9
@@ -18,6 +18,7 @@#include "mlx5_rx.h" #include "mlx5_tx.h" #include "mlx5_utils.h" +#include "mlx5_lsc_intr.h" #include "rte_pmd_mlx5.h" static void mlx5_traffic_disable_legacy (struct rte_eth_dev *dev);
@@ -1507,6 +1508,14 @@ mlx5_dev_start(struct rte_eth_dev *dev) dev->rx_pkt_burst =mlx5_select_rx_function (dev);/* Enable datapath on secondary process. */ mlx5_mp_os_req_start_rxtx (dev); +if (dev->data->dev_conf.intr_conf.lsc) { + ret =mlx5_lsc_intr_setup (dev); +if (ret <0 ) { +DRV_LOG (INFO ,"port %u failed configure LSC interrupts, starting without" , + dev->data->port_id); + dev->data->dev_conf.intr_conf.lsc =0 ; + } + }if (rte_intr_fd_get (priv->sh->intr_handle) >=0 ) { priv->sh->port[priv->dev_port -1 ].ih_port_id = (uint32_t )dev->data->port_id;
@@ -1515,14 +1524,6 @@ mlx5_dev_start(struct rte_eth_dev *dev) dev->data->port_id); dev->data->dev_conf.intr_conf.rmv =0 ; } -if (rte_intr_fd_get (priv->sh->intr_handle_nl) >=0 ) { - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = - (uint32_t )dev->data->port_id; - }else { -DRV_LOG (INFO ,"port %u starts without LSC interrupts." , - dev->data->port_id); - dev->data->dev_conf.intr_conf.lsc =0 ; - }if (rte_intr_fd_get (priv->sh->intr_handle_devx) >=0 ) priv->sh->port[priv->dev_port -1 ].devx_ih_port_id = (uint32_t )dev->data->port_id;
@@ -1664,7 +1665,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)mlx5_rx_intr_vec_disable (dev); priv->sh->port[priv->dev_port -1 ].ih_port_id =RTE_MAX_ETHPORTS ; priv->sh->port[priv->dev_port -1 ].devx_ih_port_id =RTE_MAX_ETHPORTS ; - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id =RTE_MAX_ETHPORTS ; +mlx5_lsc_intr_cleanup (dev);mlx5_txq_stop (dev);mlx5_rxq_stop (dev);mlx5_dev_free_consec_tx_mem (dev, true);
drivers/net/mlx5/windows/meson.build +1 -0
@@ -8,4 +8,5 @@ sources += files( 'mlx5_ethdev_os.c', 'mlx5_vlan_os.c', 'mlx5_flow_os.c', + 'mlx5_lsc_intr.c', )
drivers/net/mlx5/windows/mlx5_lsc_intr.c new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2026 NVIDIA Corporation & Affiliates +*/ + +#include <errno.h> +#include <stdbool.h> + +#include <ethdev_driver.h> +#include <rte_common.h> + +#include "mlx5_utils.h" +#include "mlx5_lsc_intr.h" + +int +mlx5_lsc_intr_setup (struct rte_eth_dev *dev) +{ +DRV_LOG (ERR ,"port %u does not support LSC interrupts" , dev->data->port_id); +return -ENOTSUP ; +} + +void +mlx5_lsc_intr_cleanup(struct rte_eth_dev *dev __rte_unused) +{ +}
Signature · 1 line
2.43.0
Quoted 16 lines · On Mon, 26 Oct 2026 17:04:00 +0100 Dariusz Sosnowski <[email protected]>…
drivers/net/mlx5/linux/mlx5_ethdev_os.c +16
-0+/** +* Retrieve the carrier state of a device. +* +* The IFF_RUNNING flag reported by SIOCGIFFLAGS reflects the RFC 2863 +* operational state, which the kernel only refreshes from its link watch +* work queue and which may therefore lag the actual carrier by up to a +* second. ETHTOOL_GLINK reports the carrier directly, and additionally +* flushes any link watch event still pending for the device. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 1 if the carrier is up, 0 otherwise. +* Negative errno value is returned on error. +*/
drivers/net/mlx5/linux/mlx5_ethdev_os.c mlx5_find_master_dev(struct rte_eth_dev *dev) · line 345
Quoted 10 lines
drivers/net/mlx5/linux/mlx5_ethdev_os.c +10
-0+int +mlx5_link_carrier_get (struct rte_eth_dev *dev) +{ +struct ethtool_value ecmd = { + .cmd =ETHTOOL_GLINK , + }; +struct ifreq ifr; +int ret; + +memset (&ifr,0 ,sizeof (ifr));
Odd, why not use structure initialization for both?
Quoted 23 lines · Stephen Hemminger
Quoted 20 lines · On Mon, 26 Oct 2026 17:04:00 +0100 Dariusz Sosnowski <[email protected]>…
drivers/net/mlx5/linux/mlx5_ethdev_os.c +20
-0+/** +* Retrieve the carrier state of a device. +* +* The IFF_RUNNING flag reported by SIOCGIFFLAGS reflects the RFC 2863 +* operational state, which the kernel only refreshes from its link watch +* work queue and which may therefore lag the actual carrier by up to a +* second. ETHTOOL_GLINK reports the carrier directly, and additionally +* flushes any link watch event still pending for the device. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 1 if the carrier is up, 0 otherwise. +* Negative errno value is returned on error. +*/ +int +mlx5_link_carrier_get (struct rte_eth_dev *dev) +{ +struct ethtool_value ecmd = {
Quoted 8 lines
drivers/net/mlx5/linux/mlx5_ethdev_os.c mlx5_find_master_dev(struct rte_eth_dev *dev) · line 345
Quoted 6 lines
drivers/net/mlx5/linux/mlx5_ethdev_os.c +6
-0+ .cmd = ETHTOOL_GLINK, + }; +struct ifreq ifr; +int ret; + +memset (&ifr,0 ,sizeof (ifr));Odd, why not use structure initialization for both?
Agreed, odd. I'll unify in v2
Quoted 13 lines · On Mon, 26 Oct 2026 17:04:00 +0100 Dariusz Sosnowski <[email protected]>…
mlx5 networking driver on Linux implemented LSC interrupts by listening on netlink events.
This method is unfortunately not reliable enough, because of linkwatch mechanism. It can delay link up/down events for up to ~1 second. This introduces unnecessary delay when mlx5 ports are used with DPDK bonding driver for examples.This patch addresses that by migrating LSC checks
to polling on link status usingETHTOOL_GLINKcommand. This ethtool command, implemented by mlx5 since kernel 4.14, will always get the current link status.
As a side effect it is also flushes the pending link watch events.
Quoted 7 lines
Fixes 17f95513adca ("net/mlx5: fix link status change detection")Signed-off-by Cosmin Ratiu <[email protected]>Signed-off-by Dariusz Sosnowski <[email protected]>---
Agree that 1s delay is bad for bonding, there are historical reasons for link watch. With some old NIC's the PHY would stream up/down on loose cables causing DoS on the machine. If you are using LSC for bonding and implementing LSC in driver, you might want to consider some rate limiting.
AI review showed some issues.
[PATCH] net/mlx5: move to polling for LSC interrupts
Applies cleanly to main (a635140). Moves Linux LSC detection from netlink RTM_NEWLINK to a 100ms EAL alarm polling ETHTOOL_GLINK.
Warning
1. Poller stores a partial, non-atomic dev_link.
lsc_intr_check_links() copies dev->data->dev_link, flips only link_status, and writes the struct back with a plain assignment. mlx5_link_update() (now using rte_eth_linkstatus_set(), an atomic exchange on val64) can run concurrently from an application thread, so the read-modify-write can lose that update. On link up, speed and duplex are left at whatever the last link-down stored. The poller also ignores IFF_UP while mlx5_link_update() reports IFF_UP && carrier, so the two paths can disagree.
Keep the cheap carrier probe, and on change refresh the full record through the existing path:
ret = mlx5_link_carrier_get(dev);
if (ret < 0 || ret == dev->data->dev_link.link_status ||
mlx5_link_update(dev, 0) <= 0) {
devs[i] = NULL;
continue;
}2. Polling cost on the host.
ETHTOOL_GLINK runs under rtnl_lock in the kernel. This is 10 Hz per started port with lsc=1, including representors in switchdev setups, per DPDK process. The adaptive period only reacts to latency seen by the DPDK interrupt thread, not to rtnl contention imposed on the rest of the system. Was this measured with a large number of representors?
The delay 17f95513adca worked around was IFF_RUNNING lagging the IB port event. With the query now done via ETHTOOL_GLINK (reads carrier and syncs linkwatch), going back to IBV_EVENT_PORT_ACTIVE/ERR on the existing shared async handler and querying carrier there would give immediate events without polling. Please explain why that was not chosen, or use it.
3. Not stable material as is.
A new 300 line polling framework using rte_bitset (24.11 only) is not a backport candidate for 23.11, and reducing a ~1s notification delay is not a regression fix. Suggest splitting:
- small fix: use ETHTOOL_GLINK in mlx5_link_update_unlocked_gs/gset
(Fixes: 17f95513adca, Cc: stable)
- the LSC mechanism change, without Fixes/Cc stable
Info
4. Windows stub logs ERR on every dev_start with lsc=1, while the PCI driver still advertises RTE_PCI_DRV_INTR_LSC. The old path logged INFO. Make the stub silent; mlx5_dev_start() already logs. Also "failed configure" -> "failed to configure" in that message.
5. Leftovers: the rte_io_wmb() in the mlx5_dev_spawn() error path ordered the removed nl_ih_port_id store and can go; <stdbool.h> in mlx5_lsc_intr.h is unused.
6. mlx5_link_update() now reports only link_status changes instead of a memcmp of the whole struct. Fine, but mention it in the commit message.
7. Commit message: "for examples" -> "for example", "it is also flushes" -> "it also flushes".
Quoted 53 lines · Stephen Hemminger
Quoted 13 lines · On Mon, 26 Oct 2026 17:04:00 +0100 Dariusz Sosnowski <[email protected]>…
mlx5 networking driver on Linux implemented LSC interrupts by listening on netlink events.
This method is unfortunately not reliable enough, because of linkwatch mechanism. It can delay link up/down events for up to ~1 second. This introduces unnecessary delay when mlx5 ports are used with DPDK bonding driver for examples.This patch addresses that by migrating LSC checks
to polling on link status usingETHTOOL_GLINKcommand. This ethtool command, implemented by mlx5 since kernel 4.14, will always get the current link status.
As a side effect it is also flushes the pending link watch events.Quoted 7 lines
Fixes 17f95513adca ("net/mlx5: fix link status change detection")Signed-off-by Cosmin Ratiu <[email protected]>Signed-off-by Dariusz Sosnowski <[email protected]>---
Agree that 1s delay is bad for bonding, there are historical reasons for link watch. With some old NIC's the PHY would stream up/down on loose cables causing DoS on the machine. If you are using LSC for bonding and implementing LSC in driver, you might want to consider some rate limiting.
AI review showed some issues.
[PATCH] net/mlx5: move to polling for LSC interrupts
Applies cleanly to main (a635140). Moves Linux LSC detection from netlink
RTM_NEWLINKto a 100ms EAL alarm pollingETHTOOL_GLINK.Warning
1. Poller stores a partial, non-atomic
dev_link.
lsc_intr_check_links()copiesdev->data->dev_link, flips onlylink_status, and writes the struct back with a plain assignment.mlx5_link_update()(now usingrte_eth_linkstatus_set(), an atomic exchange on val64) can run concurrently from an application thread, so the read-modify-write can lose that update. On link up, speed and duplex are left at whatever the last link-down stored. The poller also ignoresIFF_UPwhilemlx5_link_update()reportsIFF_UP&& carrier, so the two paths can disagree.Keep the cheap carrier probe, and on change refresh the full record through the existing path:
Quoted 6 lines
ret = mlx5_link_carrier_get(dev);
if (ret < 0 || ret == dev->data->dev_link.link_status ||
mlx5_link_update(dev, 0) <= 0) {
devs[i] = NULL;
continue;
}I'll address in v2
Quoted 8 lines
2. Polling cost on the host.
ETHTOOL_GLINKruns underrtnl_lockin the kernel. This is 10 Hz per started port with lsc=1, including representors in switchdev setups, per DPDK process. The adaptive period only reacts to latency seen by the DPDK interrupt thread, not to rtnl contention imposed on the rest of the system. Was this measured with a large number of representors?
I ran some tests on a following environment:
- Ubuntu 24.04
- Intel(R) Xeon(R) Platinum 8380 CPU
- NVIDIA ConnectX-7
- 1 PF, 127 VFs
Polling time of all 128 ports (time spent in mlx5_lsc_intr_cb()):
- only ETHTOOL_GLINK on each port:
- total: ~0.71 ms
- per port: ~5.5 us
- ETHTOOL_GLINK, followed by mlx5_link_update() on each port:
- total: ~19.72 ms
- per port: ~154 us
Quoted 7 lines
The delay
17f95513adcaworked around wasIFF_RUNNINGlagging the IB port event. With the query now done viaETHTOOL_GLINK(reads carrier and syncs linkwatch), going back to IBV_EVENT_PORT_ACTIVE/ERR on the existing shared async handler and querying carrier there would give immediate events without polling. Please explain why that was not chosen, or use it.
On mlx5 ethernet devices, IBV_EVENT_PORT_ACTIVE/ERR events are generated based on netdev carrier status [1].
As a result, these are subject to the same delay as netlink notifications.
There is also IBV_EVENT_DEVICE_SPEED_CHANGE, which is generated on port up/down events and is generated immediately, but:
- it is only available from Linux v7.0;
- it is a device-wide event; it would require a scan of all related ports to know which one is affected;
[1]: https://github.com/torvalds/linux/blob/v7.3/drivers/infiniband/hw/mlx5/main.c#L3082
Quoted 21 lines
3. Not stable material as is.
A new 300 line polling framework using
rte_bitset(24.11 only) is not a backport candidate for 23.11, and reducing a ~1s notification delay is not a regression fix. Suggest splitting:
- small fix: useETHTOOL_GLINKin mlx5_link_update_unlocked_gs/gset(Fixes: 17f95513adca, Cc: stable)- the LSC mechanism change, without Fixes/Cc stable
Info
4. Windows stub logs ERR on every
dev_startwith lsc=1, while the PCI driver still advertisesRTE_PCI_DRV_INTR_LSC. The old path logged INFO. Make the stub silent;mlx5_dev_start()already logs. Also "failed configure" -> "failed to configure" in that message.5. Leftovers: the
rte_io_wmb()in themlx5_dev_spawn()error path ordered the removednl_ih_port_idstore and can go; <stdbool.h> inmlx5_lsc_intr.his unused.
Quoted 6 lines
6.
mlx5_link_update()now reports onlylink_statuschanges instead of a memcmp of the whole struct. Fine, but mention it in the commit message.7. Commit message: "for examples" -> "for example", "it is also flushes" -> "it also flushes".
Points 3-7: I'll address in v2
v2 cover net/mlx5: improvements to link status handling
In reply to Dariusz SosnowskiThis series is a result of splitting patch:
https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Patch 1 - Fix for mlx5 link update function to query current link carrier status, bypassing the delay introduced by linkwatch in Linux kernel.
Patch 2 - Move to link status polling, in place of relying on netlink events which can be delayed by linkwatch for up to 1s.
Dariusz Sosnowski (2):
net/mlx5: fix link status query
net/mlx5: move to polling for LSC interrupts
.mailmap | 1 + drivers/common/mlx5/linux/mlx5_nl.c | 29 --- drivers/common/mlx5/linux/mlx5_nl.h | 2 - drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_ethdev_os.c | 147 ++++-------- drivers/net/mlx5/linux/mlx5_lsc_intr.c | 294 +++++++++++++++++++++++ drivers/net/mlx5/linux/mlx5_os.c | 23 -- drivers/net/mlx5/mlx5.c | 7 - drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_lsc_intr.h | 13 + drivers/net/mlx5/mlx5_trigger.c | 20 +- drivers/net/mlx5/windows/meson.build | 1 + drivers/net/mlx5/windows/mlx5_lsc_intr.c | 20 ++ 13 files changed, 385 insertions(+), 177 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_lsc_intr.c create mode 100644 drivers/net/mlx5/mlx5_lsc_intr.h create mode 100644 drivers/net/mlx5/windows/mlx5_lsc_intr.c
--
2.43.0
PATCH v2 1/2 net/mlx5: fix link status query
Querying link parameters in mlx5 driver is implemented using either ETHTOOL_GLINKSETTINGS or ETHTOOL_GSET ioctl commands. Link status reported by the above can be stale, due to a delay introduced by Linux kernel's linkwatch mechanism.
This patch fixes that by reading link carrier status through ETHTOOL_GLINK command. This ethtool command, implemented by mlx5 since kernel 4.14, will always get the current link status. It also flushes the pending link watch events, so following ETHTOOL_GLINKSETTINGS/ETHTOOL_GSET will return actual link carrier status.
--- .mailmap | 1 + drivers/net/mlx5/linux/mlx5_ethdev_os.c | 46 ++++++++++++++++++++++--- drivers/net/mlx5/mlx5.h | 1 + 3 files changed, 44 insertions(+), 4 deletions(-)
.mailmap +1 -0
@@ -316,6 +316,7 @@ Congjie Zhou <[email protected]> Congwen Zhang <[email protected]> Conor Fogarty <[email protected]> Conor Walsh <[email protected]> +Cosmin Ratiu <[email protected]> Cristian Bidea <[email protected]> Cristian Dumitrescu <[email protected]> Cristian Sovaiala <[email protected]>
drivers/net/mlx5/linux/mlx5_ethdev_os.c +42 -4
66 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +1 -0
@@ -2391,6 +2391,7 @@ int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);int mlx5_set_mtu (struct rte_eth_dev *dev,uint16_t mtu);int mlx5_read_clock (struct rte_eth_dev *dev,uint64_t *clock);int mlx5_link_update (struct rte_eth_dev *dev,int wait_to_complete); +int mlx5_link_carrier_get (struct rte_eth_dev *dev);int mlx5_dev_get_flow_ctrl (struct rte_eth_dev *dev,struct rte_eth_fc_conf *fc_conf); int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] net/mlx5: fix link status query
Patch applied to next-net-mlx.
Thanks,
Raslan Darawsheh
PATCH v2 2/2 net/mlx5: move to polling for LSC interrupts
In reply to Dariusz Sosnowskimlx5 networking driver on Linux implemented LSC interrupts by listening on netlink events.
This method is unfortunately not reliable enough, because of linkwatch mechanism. It can delay link up/down events for up to ~1 second. This introduces unnecessary delay when mlx5 ports are used with DPDK bonding driver for example.
This patch addresses that by migrating LSC handling to polling on link status using ETHTOOL_GLINK command. If link status has changed, polling loop will perform full link parameter update and execute callbacks registered for RTE_ETH_EVENT_INTR_LSC event.
---
v2:
- Add full link update after link carrier status change is detected.
- Removed redundant log for Windows.
- Removed leftover rte_io_wmb().
- Removed unneeded includes.
- Fix commit message typos.
drivers/common/mlx5/linux/mlx5_nl.c | 29 --- drivers/common/mlx5/linux/mlx5_nl.h | 2 - drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_ethdev_os.c | 101 +------- drivers/net/mlx5/linux/mlx5_lsc_intr.c | 294 +++++++++++++++++++++++ drivers/net/mlx5/linux/mlx5_os.c | 23 -- drivers/net/mlx5/mlx5.c | 7 - drivers/net/mlx5/mlx5.h | 3 - drivers/net/mlx5/mlx5_lsc_intr.h | 13 + drivers/net/mlx5/mlx5_trigger.c | 20 +- drivers/net/mlx5/windows/meson.build | 1 + drivers/net/mlx5/windows/mlx5_lsc_intr.c | 20 ++ 12 files changed, 341 insertions(+), 173 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_lsc_intr.c create mode 100644 drivers/net/mlx5/mlx5_lsc_intr.h create mode 100644 drivers/net/mlx5/windows/mlx5_lsc_intr.c
drivers/common/mlx5/linux/mlx5_nl.c +0 -29
@@ -1994,35 +1994,6 @@ mlx5_nl_enable_roce_set(int nlsk_fd, int family_id, const char *pci_addr,return mlx5_nl_driver_reload (nlsk_fd, family_id, pci_addr); } -/** -* Try to parse a Netlink message as a link status update. -* -* @param hdr -* Netlink message header. -* @param[out] ifindex -* Index of the updated interface. -* -* @return -* 0 on success, negative on failure. -*/ -RTE_EXPORT_INTERNAL_SYMBOL (mlx5_nl_parse_link_status_update) -int -mlx5_nl_parse_link_status_update (struct nlmsghdr *hdr,uint32_t *ifindex) -{ -struct ifinfomsg *info; - -switch (hdr->nlmsg_type) { -case RTM_NEWLINK : -case RTM_DELLINK : -case RTM_GETLINK : -case RTM_SETLINK : - info =NLMSG_DATA (hdr); - *ifindex = info->ifi_index; -return 0 ; - } -return -1 ; -} -/** * Read pending events from a Netlink socket. *
drivers/common/mlx5/linux/mlx5_nl.h +0 -2
@@ -102,8 +102,6 @@ int mlx5_nl_enable_roce_set(int nlsk_fd, int family_id, const char *pci_addr,__rte_internal int mlx5_nl_read_events(int nlsk_fd, mlx5_nl_event_cb *cb, void *cb_arg); -__rte_internal -int mlx5_nl_parse_link_status_update(struct nlmsghdr *hdr, uint32_t *ifindex); __rte_internal int mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id,
drivers/net/mlx5/linux/meson.build +1 -0
@@ -10,6 +10,7 @@ sources += files( 'mlx5_mp_os.c', 'mlx5_vlan_os.c', 'mlx5_flow_os.c', + 'mlx5_lsc_intr.c', ) cflags += no_wvla_cflag
drivers/net/mlx5/linux/mlx5_ethdev_os.c +1 -100
113 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_lsc_intr.c new file +294 -0
294 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +0 -23
@@ -1778,8 +1778,6 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, eth_dev->data->port_id);/* Read link status in case it is up and there will be no event. */ mlx5_link_update (eth_dev,0 ); -/* Watch LSC interrupts between port probe and port start. */ - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = eth_dev->data->port_id;mlx5_set_link_up (eth_dev);for (i =0 ; i <MLX5_FLOW_TYPE_MAXI ; i++) { icfg[i].release_mem_en = !!sh->config.reclaim_mode;
@@ -1956,9 +1954,6 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,return eth_dev; error:if (priv) { - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = -RTE_MAX_ETHPORTS ; -rte_io_wmb ();#ifdef HAVE_MLX5_HWS_SUPPORT if (eth_dev && priv->sh &&
@@ -3262,19 +3257,6 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) } } } - 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" , -rte_strerror (rte_errno)); -return ; - } - sh->intr_handle_nl =mlx5_os_interrupt_handler_create - (RTE_INTR_INSTANCE_F_SHARED , true, - nlsk_fd, mlx5_dev_interrupt_handler_nl, sh); -if (sh->intr_handle_nl ==NULL ) { -DRV_LOG (ERR ,"Fail to allocate intr_handle" ); -return ; - }if (sh->cdev->config.devx) {#ifdef HAVE_IBV_DEVX_ASYNC struct mlx5dv_devx_cmd_comp *devx_comp;
@@ -3312,11 +3294,6 @@ mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)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);
drivers/net/mlx5/mlx5.c +0 -7
@@ -1930,7 +1930,6 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,for (i =0 ; i < sh->max_port; i++) { sh->port[i].ih_port_id =RTE_MAX_ETHPORTS ; sh->port[i].devx_ih_port_id =RTE_MAX_ETHPORTS ; - sh->port[i].nl_ih_port_id =RTE_MAX_ETHPORTS ; }if (sh->cdev->config.devx) { sh->td =mlx5_devx_cmd_create_td (sh->cdev->ctx);
@@ -2559,12 +2558,6 @@ mlx5_dev_close(struct rte_eth_dev *dev)mlx5_free (priv->mac); dev->data->mac_addrs =NULL ;mlx5_free (priv->mac_own); - sh->port[priv->dev_port -1 ].nl_ih_port_id =RTE_MAX_ETHPORTS ; -/* -* The interrupt handler port id must be reset before priv is reset -* since 'mlx5_dev_interrupt_nl_cb' uses priv. -*/ -rte_io_wmb ();/* * Free the shared context in last turn, because the cleanup * routines above may use some shared fields, like
drivers/net/mlx5/mlx5.h +0 -3
@@ -838,7 +838,6 @@ struct mlx5_age_info {struct mlx5_dev_shared_port {uint32_t ih_port_id;uint32_t devx_ih_port_id; -uint32_t nl_ih_port_id;/* * Interrupt handler port_id. Used by shared interrupt * handler to find the corresponding rte_eth device
@@ -1649,7 +1648,6 @@ struct mlx5_dev_ctx_shared {/* Shared interrupt handler section. */ 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. */
@@ -2398,7 +2396,6 @@ int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf);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);
drivers/net/mlx5/mlx5_lsc_intr.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2026 NVIDIA Corporation & Affiliates +*/ + +#ifndef RTE_PMD_MLX5_LSC_INTR_H_ +#define RTE_PMD_MLX5_LSC_INTR_H_ + +struct rte_eth_dev ; + +int mlx5_lsc_intr_setup (struct rte_eth_dev *dev); +void mlx5_lsc_intr_cleanup (struct rte_eth_dev *dev); + +#endif /* RTE_PMD_MLX5_LSC_INTR_H_ */
drivers/net/mlx5/mlx5_trigger.c +11 -9
@@ -18,6 +18,7 @@#include "mlx5_rx.h" #include "mlx5_tx.h" #include "mlx5_utils.h" +#include "mlx5_lsc_intr.h" #include "rte_pmd_mlx5.h" static void mlx5_traffic_disable_legacy (struct rte_eth_dev *dev);
@@ -1507,6 +1508,15 @@ mlx5_dev_start(struct rte_eth_dev *dev) dev->rx_pkt_burst =mlx5_select_rx_function (dev);/* Enable datapath on secondary process. */ mlx5_mp_os_req_start_rxtx (dev); +if (dev->data->dev_conf.intr_conf.lsc) { + ret =mlx5_lsc_intr_setup (dev); +if (ret <0 ) { +DRV_LOG (INFO , +"port %u failed to configure LSC interrupts, starting without" , + dev->data->port_id); + dev->data->dev_conf.intr_conf.lsc =0 ; + } + }if (rte_intr_fd_get (priv->sh->intr_handle) >=0 ) { priv->sh->port[priv->dev_port -1 ].ih_port_id = (uint32_t )dev->data->port_id;
@@ -1515,14 +1525,6 @@ mlx5_dev_start(struct rte_eth_dev *dev) dev->data->port_id); dev->data->dev_conf.intr_conf.rmv =0 ; } -if (rte_intr_fd_get (priv->sh->intr_handle_nl) >=0 ) { - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id = - (uint32_t )dev->data->port_id; - }else { -DRV_LOG (INFO ,"port %u starts without LSC interrupts." , - dev->data->port_id); - dev->data->dev_conf.intr_conf.lsc =0 ; - }if (rte_intr_fd_get (priv->sh->intr_handle_devx) >=0 ) priv->sh->port[priv->dev_port -1 ].devx_ih_port_id = (uint32_t )dev->data->port_id;
@@ -1664,7 +1666,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)mlx5_rx_intr_vec_disable (dev); priv->sh->port[priv->dev_port -1 ].ih_port_id =RTE_MAX_ETHPORTS ; priv->sh->port[priv->dev_port -1 ].devx_ih_port_id =RTE_MAX_ETHPORTS ; - priv->sh->port[priv->dev_port -1 ].nl_ih_port_id =RTE_MAX_ETHPORTS ; +mlx5_lsc_intr_cleanup (dev);mlx5_txq_stop (dev);mlx5_rxq_stop (dev);mlx5_dev_free_consec_tx_mem (dev, true);
drivers/net/mlx5/windows/meson.build +1 -0
@@ -8,4 +8,5 @@ sources += files( 'mlx5_ethdev_os.c', 'mlx5_vlan_os.c', 'mlx5_flow_os.c', + 'mlx5_lsc_intr.c', )
drivers/net/mlx5/windows/mlx5_lsc_intr.c new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2026 NVIDIA Corporation & Affiliates +*/ + +#include <errno.h> + +#include <rte_common.h> + +#include "mlx5_lsc_intr.h" + +int +mlx5_lsc_intr_setup(struct rte_eth_dev *dev __rte_unused) +{ +return -ENOTSUP ; +} + +void +mlx5_lsc_intr_cleanup(struct rte_eth_dev *dev __rte_unused) +{ +}
--
2.43.0
Patch applied to next-net-mlx.
Thanks,
Raslan Darawsheh
Re: [PATCH v2 0/2] net/mlx5: improvements to link status handling
In reply to Dariusz SosnowskiQuoted 8 lines · On Fri, 30 Oct 2026 18:28:41 +0100 Dariusz Sosnowski <[email protected]>…
This series is a result of splitting patch:
https://patches.dpdk.org/project/dpdk/patch/[email protected]/Patch 1 - Fix for mlx5 link update function to query current link carrier status, bypassing the delay introduced by linkwatch in Linux kernel.
Patch 2 - Move to link status polling, in place of relying on netlink events which can be delayed by linkwatch for up to 1s.
Instead of polling is there a way to get the lsc directly from devx or ibv on mlx5? That would work around the issue and avoid the overhead.
Long term, it would be good if kernel had sysctl to set linkwatch per interface but it doesn't
RE: [PATCH v2 0/2] net/mlx5: improvements to link status handling
Quoted 20 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, November 2, 2026 9:08 AM
To: Dariusz Sosnowski <[email protected]>
Cc: Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; [email protected]
Subject: Re: [PATCH v2 0/2] net/mlx5: improvements to link status handlingQuoted 2 lines · On Fri, 30 Oct 2026 18:28:41 +0100 Dariusz Sosnowski <[email protected]>…
This series is a result of splitting patch:
https://patches.dpdk.org/project/dpdk/patch/20261026160400.1290443-1-d
Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
Patch 1 - Fix for mlx5 link update function to query current link carrier status, bypassing the delay introduced by linkwatch in Linux kernel.
Patch 2 - Move to link status polling, in place of relying on netlink events which can be delayed by linkwatch for up to 1s.
Instead of polling is there a way to get the lsc directly from devx or ibv on mlx5? That would work around the issue and avoid the overhead.
From DevX, unfortunately no.
In ibv there are 2 options:
- IBV_EVENT_PORT_ACTIVE/ERR - generated on up/down respectively;
On ethernet devices, these are generated from netdev carrier state, so they are subjected to the same linkwatch delay.
- IBV_EVENT_DEVICE_SPEED_CHANGE - generated on up and down; Is generated immediately on FW event reception. It is available from Linux kernel v7.0 and rdma-core v62.0.
IBV_EVENT_DEVICE_SPEED_CHANGE would be ideal here,
but there's no good way to discover whether currently running kernel supports it.
Theoretically, this event was added alongside ibv_query_port_speed() IB verb. Following logic could be implemented (for DPDK compiled with recent rdma-core)
- Call ibv_query_port_speed()
- If error:
- start listening on device speed change async event
- on event: query link status of DPDK ports on that device
- else if ENOTSUP:
- start link status poll loop
Quoted 3 lines
Long term, it would be good if kernel had sysctl to set linkwatch per interface but it doesn't
Re: [PATCH v2 0/2] net/mlx5: improvements to link status handling
Quoted 45 lines · On Tue, 3 Nov 2026 11:04:39 +0000 Dariusz Sosnowski <[email protected]>…
Quoted 18 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, November 2, 2026 9:08 AM
To: Dariusz Sosnowski <[email protected]>
Cc: Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; [email protected]
Subject: Re: [PATCH v2 0/2] net/mlx5: improvements to link status handlingQuoted 2 lines · On Fri, 30 Oct 2026 18:28:41 +0100 Dariusz Sosnowski <[email protected]>…
This series is a result of splitting patch:
https://patches.dpdk.org/project/dpdk/patch/20261026160400.1290443-1-d
Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
Patch 1 - Fix for mlx5 link update function to query current link carrier status, bypassing the delay introduced by linkwatch in Linux kernel.
Patch 2 - Move to link status polling, in place of relying on netlink events which can be delayed by linkwatch for up to 1s.
Instead of polling is there a way to get the lsc directly from devx or ibv on mlx5? That would work around the issue and avoid the overhead.
From DevX, unfortunately no.
In ibv there are 2 options:
- IBV_EVENT_PORT_ACTIVE/ERR - generated on up/down respectively;
On ethernet devices, these are generated from netdev carrier state, so they are subjected to the same linkwatch delay.-
IBV_EVENT_DEVICE_SPEED_CHANGE- generated on up and down; Is generated immediately on FW event reception. It is available from Linux kernel v7.0 and rdma-core v62.0.
IBV_EVENT_DEVICE_SPEED_CHANGEwould be ideal here,
but there's no good way to discover whether currently running kernel supports it.Theoretically, this event was added alongside
ibv_query_port_speed()IB verb. Following logic could be implemented (for DPDK compiled with recent rdma-core)
Quoted 10 lines
- Call
ibv_query_port_speed()
- If error:
- start listening on device speed change async event
- on event: query link status of DPDK ports on that device
- else if ENOTSUP:
- start link status poll loopQuoted 3 lines
Long term, it would be good if kernel had sysctl to set linkwatch per interface but it doesn't
I have a patch to allow link watch timeout to be set via netlink or sysfs. But needs more testing. In future, mlx5 could detect and configure that.