Skip to contentSkip to conversation

net/mlx5e: Add support for PCIe congestion events

PATCH Superseded Tariq Toukan 5 participants 11 messages Jul 10, 2025 – Jul 15, 2025

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

v2 cover net/mlx5e: Add support for PCIe congestion events

Hi,

This is V2. Previous one submitted by Mark.
Find it here:
https://lore.kernel.org/all/[email protected]/

Find detailed feature description by Dragos below [1].

Regards,
Tariq

V2:
- Rebase on top of the IFC patches, they got pulled through mlx5-next.

[1]
PCIe congestion events are events generated by the firmware when the device side has sustained PCIe inbound or outbound traffic above certain thresholds. The high and low threshold are hysteresis thresholds to prevent flapping: once the high threshold has been reached, a low threshold event will be triggered only after the bandwidth usage went below the low threshold.

This series adds support for receiving and exposing such events as ethtool counters.

2 new pairs of counters are exposed: pci_bw_in/outbound_high/low. These should help the user understand if the device PCI is under pressure. The thresholds are configurable via sysfs when the feature is supported.

Dragos Tatulea (3):
net/mlx5e: Create/destroy PCIe Congestion Event object net/mlx5e: Add device PCIe congestion ethtool stats net/mlx5e: Make PCIe congestion event thresholds configurable

 .../ethernet/mellanox/mlx5/counters.rst       |  32 ++
 .../net/ethernet/mellanox/mlx5/core/Makefile  |   2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   2 +
 .../mellanox/mlx5/core/en/pcie_cong_event.c   | 464 ++++++++++++++++++
 .../mellanox/mlx5/core/en/pcie_cong_event.h   |  11 +
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   3 +
 .../ethernet/mellanox/mlx5/core/en_stats.c    |   1 +
 .../ethernet/mellanox/mlx5/core/en_stats.h    |   1 +
 drivers/net/ethernet/mellanox/mlx5/core/eq.c  |   4 +
 9 files changed, 519 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.h

base-commit: c65d34296b2252897e37835d6007bbd01b255742

Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v2 1/3 net/mlx5e: Create/destroy PCIe Congestion Event object

From: Dragos Tatulea <[email protected]>

Add initial infrastructure to create and destroy the PCIe Congestion Event object if the object is supported.

The verb for the object creation function is "set" instead of "create" because the function will accommodate the modify operation as well in a subsequent patch.

The next patches will hook it up to the event handler and will add actual functionality.

---
 .../net/ethernet/mellanox/mlx5/core/Makefile  |   2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   2 +
 .../mellanox/mlx5/core/en/pcie_cong_event.c   | 153 ++++++++++++++++++
 .../mellanox/mlx5/core/en/pcie_cong_event.h   |  11 ++
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   3 +
 5 files changed, 170 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
index d292e6a9e22c..650df18a9216 100644
@@ -29,7 +29,7 @@ mlx5_core-$(CONFIG_MLX5_CORE_EN) += en/rqt.o en/tir.o en/rss.o en/rx_res.o \
 		en/reporter_tx.o en/reporter_rx.o en/params.o en/xsk/pool.o \
 		en/xsk/setup.o en/xsk/rx.o en/xsk/tx.o en/devlink.o en/ptp.o \
 		en/qos.o en/htb.o en/trap.o en/fs_tt_redirect.o en/selq.o \
-		lib/crypto.o lib/sd.o
+		lib/crypto.o lib/sd.o en/pcie_cong_event.o
 
 #
 # Netdev extra
drivers/net/ethernet/mellanox/mlx5/core/en.h +2 -0
index 64e69e616b1f..b6340e9453c0 100644
@@ -920,6 +920,8 @@ struct mlx5e_priv {
 	struct notifier_block      events_nb;
 	struct notifier_block      blocking_events_nb;
 
+	struct mlx5e_pcie_cong_event *cong_event;
+
 	struct udp_tunnel_nic_info nic_info;
 #ifdef CONFIG_MLX5_CORE_EN_DCB
 	struct mlx5e_dcbx          dcbx;
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c new file +153 -0

153 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.h new file +11 -0
new file mode 100644
index 000000000000..bf1e3632d596
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. */
+
+#ifndef __MLX5_PCIE_CONG_EVENT_H__
+#define __MLX5_PCIE_CONG_EVENT_H__
+
+bool mlx5e_pcie_cong_event_supported(struct mlx5_core_dev *dev);
+int mlx5e_pcie_cong_event_init(struct mlx5e_priv *priv);
+void mlx5e_pcie_cong_event_cleanup(struct mlx5e_priv *priv);
+
+#endif /* __MLX5_PCIE_CONG_EVENT_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -0
index fee323ade522..bd481f3384d0 100644
@@ -76,6 +76,7 @@
 #include "en/trap.h"
 #include "lib/devcom.h"
 #include "lib/sd.h"
+#include "en/pcie_cong_event.h"
 
 static bool mlx5e_hw_gro_supported(struct mlx5_core_dev *mdev)
 {
@@ -5989,6 +5990,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
 	if (mlx5e_monitor_counter_supported(priv))
 		mlx5e_monitor_counter_init(priv);
 
+	mlx5e_pcie_cong_event_init(priv);
 	mlx5e_hv_vhca_stats_create(priv);
 	if (netdev->reg_state != NETREG_REGISTERED)
 		return;
@@ -6028,6 +6030,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
 
 	mlx5e_nic_set_rx_mode(priv);
 
+	mlx5e_pcie_cong_event_cleanup(priv);
 	mlx5e_hv_vhca_stats_destroy(priv);
 	if (mlx5e_monitor_counter_supported(priv))
 		mlx5e_monitor_counter_cleanup(priv);
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH v2 2/3 net/mlx5e: Add device PCIe congestion ethtool stats

In reply to Tariq Toukan

From: Dragos Tatulea <[email protected]>

Implement the PCIe Congestion Event notifier which triggers a work item to query the PCIe Congestion Event object. The result of the congestion state is reflected in the new ethtool stats:

* pci_bw_inbound_high: the device has crossed the high threshold for inbound PCIe traffic.
* pci_bw_inbound_low: the device has crossed the low threshold for inbound PCIe traffic
* pci_bw_outbound_high: the device has crossed the high threshold for outbound PCIe traffic.
* pci_bw_outbound_low: the device has crossed the low threshold for outbound PCIe traffic

The high and low thresholds are currently configured at 90% and 75%. These are hysteresis thresholds which help to check if the PCI bus on the device side is in a congested state.

If low + 1 = high then the device is in a congested state. If low == high then the device is not in a congested state.

The counters are also documented.

A follow-up patch will make the thresholds configurable.

---
 .../ethernet/mellanox/mlx5/counters.rst       |  32 ++++
 .../mellanox/mlx5/core/en/pcie_cong_event.c   | 175 ++++++++++++++++++
 .../ethernet/mellanox/mlx5/core/en_stats.c    |   1 +
 .../ethernet/mellanox/mlx5/core/en_stats.h    |   1 +
 drivers/net/ethernet/mellanox/mlx5/core/eq.c  |   4 +
 5 files changed, 213 insertions(+)
Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst +32 -0
index 43d72c8b713b..754c81436408 100644
@@ -1341,3 +1341,35 @@ Device Counters
      - The number of times the device owned queue had not enough buffers
        allocated.
      - Error
+
+   * - `pci_bw_inbound_high`
+     - The number of times the device crossed the high inbound pcie bandwidth
+       threshold. To be compared to pci_bw_inbound_low to check if the device
+       is in a congested state.
+       If pci_bw_inbound_high == pci_bw_inbound_low then the device is not congested.
+       If pci_bw_inbound_high > pci_bw_inbound_low then the device is congested.
+     - Tnformative
+
+   * - `pci_bw_inbound_low`
+     - The number of times the device crossed the low inbound PCIe bandwidth
+       threshold. To be compared to pci_bw_inbound_high to check if the device
+       is in a congested state.
+       If pci_bw_inbound_high == pci_bw_inbound_low then the device is not congested.
+       If pci_bw_inbound_high > pci_bw_inbound_low then the device is congested.
+     - Informative
+
+   * - `pci_bw_outbound_high`
+     - The number of times the device crossed the high outbound pcie bandwidth
+       threshold. To be compared to pci_bw_outbound_low to check if the device
+       is in a congested state.
+       If pci_bw_outbound_high == pci_bw_outbound_low then the device is not congested.
+       If pci_bw_outbound_high > pci_bw_outbound_low then the device is congested.
+     - Informative
+
+   * - `pci_bw_outbound_low`
+     - The number of times the device crossed the low outbound PCIe bandwidth
+       threshold. To be compared to pci_bw_outbound_high to check if the device
+       is in a congested state.
+       If pci_bw_outbound_high == pci_bw_outbound_low then the device is not congested.
+       If pci_bw_outbound_high > pci_bw_outbound_low then the device is congested.
+     - Informative
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +175 -0

225 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +1 -0
index 19664fa7f217..87536f158d07 100644
@@ -2612,6 +2612,7 @@ mlx5e_stats_grp_t mlx5e_nic_stats_grps[] = {
 #ifdef CONFIG_MLX5_MACSEC
 	&MLX5E_STATS_GRP(macsec_hw),
 #endif
+	&MLX5E_STATS_GRP(pcie_cong),
 };
 
 unsigned int mlx5e_nic_stats_grps_num(struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en_stats.h +1 -0
index def5dea1463d..72dbcc1928ef 100644
@@ -535,5 +535,6 @@ extern MLX5E_DECLARE_STATS_GRP(ipsec_hw);
 extern MLX5E_DECLARE_STATS_GRP(ipsec_sw);
 extern MLX5E_DECLARE_STATS_GRP(ptp);
 extern MLX5E_DECLARE_STATS_GRP(macsec_hw);
+extern MLX5E_DECLARE_STATS_GRP(pcie_cong);
 
 #endif /* __MLX5_EN_STATS_H__ */
drivers/net/ethernet/mellanox/mlx5/core/eq.c +4 -0
index dfb079e59d85..db54f6d26591 100644
@@ -21,6 +21,7 @@
 #include "pci_irq.h"
 #include "devlink.h"
 #include "en_accel/ipsec.h"
+#include "en/pcie_cong_event.h"
 
 enum {
 	MLX5_EQE_OWNER_INIT_VAL	= 0x1,
@@ -585,6 +586,9 @@ static void gather_async_events_mask(struct mlx5_core_dev *dev, u64 mask[4])
 		async_event_mask |=
 			(1ull << MLX5_EVENT_TYPE_OBJECT_CHANGE);
 
+	if (mlx5e_pcie_cong_event_supported(dev))
+		async_event_mask |= (1ull << MLX5_EVENT_TYPE_OBJECT_CHANGE);
+
 	mask[0] = async_event_mask;
 
 	if (MLX5_CAP_GEN(dev, event_cap))
Signature · 1 line
2.31.1
author maintainer
#9 lore raw

PATCH v2 3/3 net/mlx5e: Make PCIe congestion event thresholds configurable

In reply to Tariq Toukan

From: Dragos Tatulea <[email protected]>

Add a new sysfs entry for reading and configuring the PCIe congestion event thresholds. The format is the following:
<inbound_low> <inbound_high> <outbound_low> <outbound_high>

Units are 0.01 %. Accepted values are in range (0, 10000].

When new thresholds are configured, a object modify operation will happen. The set function is updated accordingly to act as a modify as well.

The threshold configuration is stored and queried directly in the firmware.

To prevent fat fingering the numbers, read them initially as u64.

---
 .../mellanox/mlx5/core/en/pcie_cong_event.c   | 152 +++++++++++++++++-
 1 file changed, 144 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +144 -8
index a24e5465ceeb..a74d1e15c92e 100644
@@ -39,9 +39,13 @@ struct mlx5e_pcie_cong_event {
 
 	/* For ethtool stats group. */
 	struct mlx5e_pcie_cong_stats stats;
+
+	struct device_attribute attr;
 };
 
 /* In units of 0.01 % */
+#define MLX5E_PCIE_CONG_THRESH_MAX 10000
+
 static const struct mlx5e_pcie_cong_thresh default_thresh_config = {
 	.inbound_high = 9000,
 	.inbound_low = 7500,
@@ -97,6 +101,7 @@ MLX5E_DEFINE_STATS_GRP(pcie_cong, 0);
 static int
 mlx5_cmd_pcie_cong_event_set(struct mlx5_core_dev *dev,
 			     const struct mlx5e_pcie_cong_thresh *config,
+			     bool modify,
 			     u64 *obj_id)
 {
 	u32 in[MLX5_ST_SZ_DW(pcie_cong_event_cmd_in)] = {};
@@ -108,8 +113,16 @@ mlx5_cmd_pcie_cong_event_set(struct mlx5_core_dev *dev,
 	hdr = MLX5_ADDR_OF(pcie_cong_event_cmd_in, in, hdr);
 	cong_obj = MLX5_ADDR_OF(pcie_cong_event_cmd_in, in, cong_obj);
 
-	MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
-		 MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
+	if (!modify) {
+		MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
+			 MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
+	} else {
+		MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
+			 MLX5_CMD_OP_MODIFY_GENERAL_OBJECT);
+		MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, *obj_id);
+		MLX5_SET64(pcie_cong_event_obj, cong_obj, modify_select_field,
+			   MLX5_PCIE_CONG_EVENT_MOD_THRESH);
+	}
 
 	MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
 		 MLX5_GENERAL_OBJECT_TYPES_PCIE_CONG_EVENT);
@@ -131,10 +144,12 @@ mlx5_cmd_pcie_cong_event_set(struct mlx5_core_dev *dev,
 	if (err)
 		return err;
 
-	*obj_id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
+	if (!modify)
+		*obj_id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
 
-	mlx5_core_dbg(dev, "PCIe congestion event (obj_id=%llu) created. Config: in: [%u, %u], out: [%u, %u]\n",
+	mlx5_core_dbg(dev, "PCIe congestion event (obj_id=%llu) %s. Config: in: [%u, %u], out: [%u, %u]\n",
 		      *obj_id,
+		      modify ? "modified" : "created",
 		      config->inbound_high, config->inbound_low,
 		      config->outbound_high, config->outbound_low);
 
@@ -160,13 +175,13 @@ static int mlx5_cmd_pcie_cong_event_destroy(struct mlx5_core_dev *dev,
 
 static int mlx5_cmd_pcie_cong_event_query(struct mlx5_core_dev *dev,
 					  u64 obj_id,
-					  u32 *state)
+					  u32 *state,
+					  struct mlx5e_pcie_cong_thresh *config)
 {
 	u32 in[MLX5_ST_SZ_DW(pcie_cong_event_cmd_in)] = {};
 	u32 out[MLX5_ST_SZ_DW(pcie_cong_event_cmd_out)];
 	void *obj;
 	void *hdr;
-	u8 cong;
 	int err;
 
 	hdr = MLX5_ADDR_OF(pcie_cong_event_cmd_in, in, hdr);
@@ -184,6 +199,8 @@ static int mlx5_cmd_pcie_cong_event_query(struct mlx5_core_dev *dev,
 	obj = MLX5_ADDR_OF(pcie_cong_event_cmd_out, out, cong_obj);
 
 	if (state) {
+		u8 cong;
+
 		cong = MLX5_GET(pcie_cong_event_obj, obj, inbound_cong_state);
 		if (cong == MLX5E_CONG_HIGH_STATE)
 			*state |= MLX5E_INBOUND_CONG;
@@ -193,6 +210,19 @@ static int mlx5_cmd_pcie_cong_event_query(struct mlx5_core_dev *dev,
 			*state |= MLX5E_OUTBOUND_CONG;
 	}
 
+	if (config) {
+		*config = (struct mlx5e_pcie_cong_thresh) {
+			.inbound_low = MLX5_GET(pcie_cong_event_obj, obj,
+						inbound_cong_low_threshold),
+			.inbound_high = MLX5_GET(pcie_cong_event_obj, obj,
+						inbound_cong_high_threshold),
+			.outbound_low = MLX5_GET(pcie_cong_event_obj, obj,
+						 outbound_cong_low_threshold),
+			.outbound_high = MLX5_GET(pcie_cong_event_obj, obj,
+						  outbound_cong_high_threshold),
+		};
+	}
+
 	return 0;
 }
 
@@ -210,7 +240,7 @@ static void mlx5e_pcie_cong_event_work(struct work_struct *work)
 	dev = priv->mdev;
 
 	err = mlx5_cmd_pcie_cong_event_query(dev, cong_event->obj_id,
-					     &new_cong_state);
+					     &new_cong_state, NULL);
 	if (err) {
 		mlx5_core_warn(dev, "Error %d when querying PCIe cong event object (obj_id=%llu).\n",
 			       err, cong_event->obj_id);
@@ -249,6 +279,101 @@ static int mlx5e_pcie_cong_event_handler(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
+static bool mlx5e_thresh_check_val(u64 val)
+{
+	return val > 0 && val <= MLX5E_PCIE_CONG_THRESH_MAX;
+}
+
+static bool
+mlx5e_thresh_config_check_order(const struct mlx5e_pcie_cong_thresh *config)
+{
+	if (config->inbound_high <= config->inbound_low)
+		return false;
+
+	if (config->outbound_high <= config->outbound_low)
+		return false;
+
+	return true;
+}
+
+#define MLX5E_PCIE_CONG_THRESH_SYSFS_VALUES 4
+
+static ssize_t thresh_config_store(struct device *dev,
+				   struct device_attribute *attr,
+				   const char *buf,
+				   size_t count)
+{
+	struct mlx5e_pcie_cong_thresh config = {};
+	struct mlx5e_pcie_cong_event *cong_event;
+	u64 outbound_high, outbound_low;
+	u64 inbound_high, inbound_low;
+	struct mlx5e_priv *priv;
+	int ret;
+	int err;
+
+	cong_event = container_of(attr, struct mlx5e_pcie_cong_event, attr);
+	priv = cong_event->priv;
+
+	ret = sscanf(buf, "%llu %llu %llu %llu",
+		     &inbound_low, &inbound_high,
+		     &outbound_low, &outbound_high);
+	if (ret != MLX5E_PCIE_CONG_THRESH_SYSFS_VALUES) {
+		mlx5_core_err(priv->mdev, "Invalid format for PCIe congestion threshold configuration. Expected %d, got %d.\n",
+			      MLX5E_PCIE_CONG_THRESH_SYSFS_VALUES, ret);
+		return -EINVAL;
+	}
+
+	if (!mlx5e_thresh_check_val(inbound_high) ||
+	    !mlx5e_thresh_check_val(inbound_low) ||
+	    !mlx5e_thresh_check_val(outbound_high) ||
+	    !mlx5e_thresh_check_val(outbound_low)) {
+		mlx5_core_err(priv->mdev, "Invalid values for PCIe congestion threshold configuration. Valid range [1, %d]\n",
+			      MLX5E_PCIE_CONG_THRESH_MAX);
+		return -EINVAL;
+	}
+
+	config = (struct mlx5e_pcie_cong_thresh) {
+		.inbound_low = inbound_low,
+		.inbound_high = inbound_high,
+		.outbound_low = outbound_low,
+		.outbound_high = outbound_high,
+
+	};
+
+	if (!mlx5e_thresh_config_check_order(&config)) {
+		mlx5_core_err(priv->mdev, "Invalid order of values for PCIe congestion threshold configuration.\n");
+		return -EINVAL;
+	}
+
+	err = mlx5_cmd_pcie_cong_event_set(priv->mdev, &config,
+					   true, &cong_event->obj_id);
+
+	return err ? err : count;
+}
+
+static ssize_t thresh_config_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct mlx5e_pcie_cong_event *cong_event;
+	struct mlx5e_pcie_cong_thresh config;
+	struct mlx5e_priv *priv;
+	int err;
+
+	cong_event = container_of(attr, struct mlx5e_pcie_cong_event, attr);
+	priv = cong_event->priv;
+
+	err = mlx5_cmd_pcie_cong_event_query(priv->mdev, cong_event->obj_id,
+					     NULL, &config);
+
+	if (err)
+		return err;
+
+	return sysfs_emit(buf, "%u %u %u %u\n",
+			  config.inbound_low, config.inbound_high,
+			  config.outbound_low, config.outbound_high);
+}
+
 bool mlx5e_pcie_cong_event_supported(struct mlx5_core_dev *dev)
 {
 	u64 features = MLX5_CAP_GEN_2_64(dev, general_obj_types_127_64);
@@ -283,7 +408,7 @@ int mlx5e_pcie_cong_event_init(struct mlx5e_priv *priv)
 	cong_event->priv = priv;
 
 	err = mlx5_cmd_pcie_cong_event_set(mdev, &default_thresh_config,
-					   &cong_event->obj_id);
+					   false, &cong_event->obj_id);
 	if (err) {
 		mlx5_core_warn(mdev, "Error creating a PCIe congestion event object\n");
 		goto err_free;
@@ -295,10 +420,20 @@ int mlx5e_pcie_cong_event_init(struct mlx5e_priv *priv)
 		goto err_obj_destroy;
 	}
 
+	cong_event->attr = (struct device_attribute)__ATTR_RW(thresh_config);
+	err = sysfs_create_file(&mdev->device->kobj,
+				&cong_event->attr.attr);
+	if (err) {
+		mlx5_core_warn(mdev, "Error creating a sysfs entry for pcie_cong limits.\n");
+		goto err_unregister_nb;
+	}
+
 	priv->cong_event = cong_event;
 
 	return 0;
 
+err_unregister_nb:
+	mlx5_eq_notifier_unregister(mdev, &cong_event->nb);
 err_obj_destroy:
 	mlx5_cmd_pcie_cong_event_destroy(mdev, cong_event->obj_id);
 err_free:
@@ -316,6 +451,7 @@ void mlx5e_pcie_cong_event_cleanup(struct mlx5e_priv *priv)
 		return;
 
 	priv->cong_event = NULL;
+	sysfs_remove_file(&mdev->device->kobj, &cong_event->attr.attr);
 
 	mlx5_eq_notifier_unregister(mdev, &cong_event->nb);
 	cancel_work_sync(&cong_event->work);
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

In reply to Tariq Toukan
kernel test robot noticed the following build errors:

Hi Tariq,

kernel test robot noticed the following build errors:

[auto build test ERROR on c65d34296b2252897e37835d6007bbd01b255742]

url:    https://github.com/intel-lab-lkp/linux/commits/Tariq-Toukan/net-mlx5e-Create-destroy-PCIe-Congestion-Event-object/20250710-145940
base:   c65d34296b2252897e37835d6007bbd01b255742
patch link:    https://lore.kernel.org/r/1752130292-22249-3-git-send-email-tariqt%40nvidia.com
patch subject: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats
config: powerpc-randconfig-003-20250711 (https://download.01.org/0day-ci/archive/20250711/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 01c97b4953e87ae455bd4c41e3de3f0f0f29c61c)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250711/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "mlx5e_pcie_cong_event_supported" [drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#4 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

In reply to Tariq Toukan

Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst Device Counters · line 1351

Quoted 7 lines · On Thu, 10 Jul 2025 09:51:31 +0300 Tariq Toukan wrote:
Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst +7 -0
+   * - `pci_bw_inbound_high`
+     - The number of times the device crossed the high inbound pcie bandwidth
+       threshold. To be compared to pci_bw_inbound_low to check if the device
+       is in a congested state.
+       If pci_bw_inbound_high == pci_bw_inbound_low then the device is not congested.
+       If pci_bw_inbound_high > pci_bw_inbound_low then the device is congested.
+     - Tnformative

The metrics make sense, but utilization has to be averaged over some period of time to be meaningful. Can you shad any light on what the measurement period or algorithm is?

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c static int mlx5_cmd_pcie_cong_event_destroy(struct mlx5_core_dev *dev, · line 222

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +3 -0
+	changes = cong_event->state ^ new_cong_state;
+	if (!changes)
+		return;

no risk of the high / low events coming so quickly we'll miss both? Should there be a counter for "mis-firing" of that sort? You'd be surprised how long the scheduling latency for a kernel worker can be on a busy server :(

Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +15 -0
+	cong_event->state = new_cong_state;
+
+	if (changes & MLX5E_INBOUND_CONG) {
+		if (new_cong_state & MLX5E_INBOUND_CONG)
+			cong_event->stats.pci_bw_inbound_high++;
+		else
+			cong_event->stats.pci_bw_inbound_low++;
+	}
+
+	if (changes & MLX5E_OUTBOUND_CONG) {
+		if (new_cong_state & MLX5E_OUTBOUND_CONG)
+			cong_event->stats.pci_bw_outbound_high++;
+		else
+			cong_event->stats.pci_bw_outbound_low++;
+	}
maintainer
#10 lore raw

Re: [PATCH net-next V2 3/3] net/mlx5e: Make PCIe congestion event thresholds configurable

In reply to Tariq Toukan
Quoted 6 lines · On Thu, 10 Jul 2025 09:51:32 +0300 Tariq Toukan wrote:

Add a new sysfs entry for reading and configuring the PCIe congestion event thresholds. The format is the following:
<inbound_low> <inbound_high> <outbound_low> <outbound_high>

Units are 0.01 %. Accepted values are in range (0, 10000].

Quoted 8 lines

When new thresholds are configured, a object modify operation will happen. The set function is updated accordingly to act as a modify as well.

The threshold configuration is stored and queried directly in the firmware.

To prevent fat fingering the numbers, read them initially as u64.

no sysfs, please :S Could you add these knobs to devlink?

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c static int mlx5_cmd_pcie_cong_event_query(struct mlx5_core_dev *dev, · line 216

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +4 -0
+	if (config) {
+		*config = (struct mlx5e_pcie_cong_thresh) {
+			.inbound_low = MLX5_GET(pcie_cong_event_obj, obj,
+						inbound_cong_low_threshold),

Why are you overwriting the whole struct. It'd literally save you 1 char of line length and 2 lines of LoC to pop a config-> in front of each of these assignments...

The "whole struct assignment" really only makes sense when you intentionally want to set the remaining members to 0 which is likely very much _not_ what you want here, was the config struct ever to be extended..

I know the cool new language features are cool but..

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +8 -0
+			.inbound_high = MLX5_GET(pcie_cong_event_obj, obj,
+						inbound_cong_high_threshold),
+			.outbound_low = MLX5_GET(pcie_cong_event_obj, obj,
+						 outbound_cong_low_threshold),
+			.outbound_high = MLX5_GET(pcie_cong_event_obj, obj,
+						  outbound_cong_high_threshold),
+		};
+	}
#5 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski

Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst Device Counters · line 1351

Quoted 7 lines · On Thu, 10 Jul 2025 09:51:31 +0300 Tariq Toukan wrote:
Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst +7 -0
+   * - `pci_bw_inbound_high`
+     - The number of times the device crossed the high inbound pcie bandwidth
+       threshold. To be compared to pci_bw_inbound_low to check if the device
+       is in a congested state.
+       If pci_bw_inbound_high == pci_bw_inbound_low then the device is not congested.
+       If pci_bw_inbound_high > pci_bw_inbound_low then the device is congested.
+     - Tnformative
Quoted 4 lines

The metrics make sense, but utilization has to be averaged over some period of time to be meaningful. Can you shad any light on what the measurement period or algorithm is?

The measurement period in FW is 200 ms.

Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c static int mlx5_cmd_pcie_cong_event_destroy(struct mlx5_core_dev *dev, · line 222

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +3 -0
+	changes = cong_event->state ^ new_cong_state;
+	if (!changes)
+		return;

no risk of the high / low events coming so quickly we'll miss both?

Yes it is possible and it is fine because short bursts are not counted. The counters are for sustained high PCI BW usage.

Quoted 4 lines

Should there be a counter for "mis-firing" of that sort? You'd be surprised how long the scheduling latency for a kernel worker can be on a busy server :(

The event is just a notification to read the state from FW. If the read is issued later and the state has not changed then it will not be considered.

Thanks,
Dragos

maintainer
#6 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

Quoted 5 lines · On Sat, 12 Jul 2025 07:55:27 +0000 Dragos Tatulea wrote:
Quoted 3 lines

The metrics make sense, but utilization has to be averaged over some period of time to be meaningful. Can you shad any light on what the measurement period or algorithm is?

The measurement period in FW is 200 ms.

SG, please include in the doc.

Quoted 8 lines
Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c static int mlx5_cmd_pcie_cong_event_destroy(struct mlx5_core_dev *dev, · line 222

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +3 -0
+	changes = cong_event->state ^ new_cong_state;
+	if (!changes)
+		return;  

no risk of the high / low events coming so quickly we'll miss both?

Yes it is possible and it is fine because short bursts are not counted. The counters are for sustained high PCI BW usage.

Quoted 7 lines
Quoted 4 lines

Should there be a counter for "mis-firing" of that sort? You'd be surprised how long the scheduling latency for a kernel worker can be on a busy server :(

The event is just a notification to read the state from FW. If the read is issued later and the state has not changed then it will not be considered.

200ms is within the range of normal scheduler latency on a busy server. It's not a deal breaker, but I'd personally add a counter for wakeups which did not result in any state change. Likely recent experience with constant EEVDF regressions and sched_ext is coloring my judgment.

#7 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

Quoted 21 lines · Jakub Kicinski
Quoted 5 lines · On Sat, 12 Jul 2025 07:55:27 +0000 Dragos Tatulea wrote:
Quoted 3 lines

The metrics make sense, but utilization has to be averaged over some period of time to be meaningful. Can you shad any light on what the measurement period or algorithm is?

The measurement period in FW is 200 ms.

SG, please include in the doc.

Quoted 12 lines
Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c static int mlx5_cmd_pcie_cong_event_destroy(struct mlx5_core_dev *dev, · line 222

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en/pcie_cong_event.c +3 -0
+	changes = cong_event->state ^ new_cong_state;
+	if (!changes)
+		return;

no risk of the high / low events coming so quickly we'll miss both?

Yes it is possible and it is fine because short bursts are not counted. The counters are for sustained high PCI BW usage.

Quoted 4 lines

Should there be a counter for "mis-firing" of that sort? You'd be surprised how long the scheduling latency for a kernel worker can be on a busy server :(

Quoted 9 lines
Quoted 3 lines

The event is just a notification to read the state from FW. If the read is issued later and the state has not changed then it will not be considered.

200ms is within the range of normal scheduler latency on a busy server. It's not a deal breaker, but I'd personally add a counter for wakeups which did not result in any state change. Likely recent experience with constant EEVDF regressions and sched_ext is coloring my judgment.

NP with that.
We'll add it as a followup patch, after it's implemented and properly tested.

Same applies for the requested devlink config (replacing the sysfs).

For now, I'll respin without the configuration part and the extra counter.

maintainer
#8 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5e: Add device PCIe congestion ethtool stats

Quoted 7 lines · On Tue, 15 Jul 2025 16:59:43 +0300 Tariq Toukan wrote:

NP with that.
We'll add it as a followup patch, after it's implemented and properly tested.

Same applies for the requested devlink config (replacing the sysfs).

For now, I'll respin without the configuration part and the extra counter.

SG.