[PATCH 22.11] net/mlx5: fix real time counter reading from PCI BAR
Viacheslav Ovsiienko
viacheslavo at nvidia.com
Wed Nov 20 19:38:55 CET 2024
From: Tim Martin <timothym at nvidia.com>
[ upstream commit 7271cf3a27fad171880a6085af5bd1cdb5a4a624 ]
There is the mlx5_txpp_read_clock() routine reading
the 64-bit real time counter from the device PCI BAR.
It introduced two issues:
- it checks the PCI BAR mapping into process address
space and tries to map this on demand. This might be
problematic if something goes wrong and mapping fails.
It happens on every read_clock API call, invokes kernel
taking a long time and causing application malfunction.
- the 64-bit counter should be read in single atomic
transaction
Fixes: b94d93ca7380 ("net/mlx5: support reading device clock")
Cc: stable at dpdk.org
Signed-off-by: Tim Martin <timothym at nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo at nvidia.com>
---
.mailmap | 1 +
drivers/net/mlx5/mlx5.c | 4 ++++
drivers/net/mlx5/mlx5_tx.h | 30 ++++++++++++++++++++++++++++++
drivers/net/mlx5/mlx5_txpp.c | 11 ++---------
4 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/.mailmap b/.mailmap
index 025bd2daba..457af9abc2 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1392,6 +1392,7 @@ Timmons C. Player <timmons.player at spirent.com>
Timothy McDaniel <timothy.mcdaniel at intel.com>
Timothy Miskell <timothy.miskell at intel.com>
Timothy Redaelli <tredaelli at redhat.com>
+Tim Martin <timothym at nvidia.com>
Tim Shearer <tim.shearer at overturenetworks.com>
Ting-Kai Ku <ting-kai.ku at intel.com>
Ting Xu <ting.xu at intel.com>
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index d66254740b..1076ad1721 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1961,6 +1961,7 @@ int
mlx5_proc_priv_init(struct rte_eth_dev *dev)
{
struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5_dev_ctx_shared *sh = priv->sh;
struct mlx5_proc_priv *ppriv;
size_t ppriv_size;
@@ -1981,6 +1982,9 @@ mlx5_proc_priv_init(struct rte_eth_dev *dev)
dev->process_private = ppriv;
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
priv->sh->pppriv = ppriv;
+ /* Check and try to map HCA PCI BAR to allow reading real time. */
+ if (sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device))
+ mlx5_txpp_map_hca_bar(dev);
return 0;
}
diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h
index ff23d87b8a..6b796b97e1 100644
--- a/drivers/net/mlx5/mlx5_tx.h
+++ b/drivers/net/mlx5/mlx5_tx.h
@@ -18,6 +18,7 @@
#include <mlx5_common_mr.h>
#include "mlx5.h"
+#include "mlx5_rx.h"
#include "mlx5_autoconf.h"
/* TX burst subroutines return codes. */
@@ -361,6 +362,35 @@ mlx5_txpp_convert_tx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t mts)
return ci;
}
+/**
+ * Read real time clock counter directly from the device PCI BAR area.
+ * The PCI BAR must be mapped to the process memory space at initialization.
+ *
+ * @param dev
+ * Device to read clock counter from
+ *
+ * @return
+ * 0 - if HCA BAR is not supported or not mapped.
+ * !=0 - read 64-bit value of real-time in UTC formatv (nanoseconds)
+ */
+static __rte_always_inline uint64_t mlx5_read_pcibar_clock(struct rte_eth_dev *dev)
+{
+ struct mlx5_proc_priv *ppriv = dev->process_private;
+
+ if (ppriv && ppriv->hca_bar) {
+ struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5_dev_ctx_shared *sh = priv->sh;
+ uint64_t *hca_ptr = (uint64_t *)(ppriv->hca_bar) +
+ __mlx5_64_off(initial_seg, real_time);
+ uint64_t ts = __atomic_load_n(hca_ptr, __ATOMIC_SEQ_CST);
+
+ ts = rte_be_to_cpu_64(ts);
+ ts = mlx5_txpp_convert_rx_ts(sh, ts);
+ return ts;
+ }
+ return 0;
+}
+
/**
* Set Software Parser flags and offsets in Ethernet Segment of WQE.
* Flags must be preliminary initialized to zero.
diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c
index 0e1da1d5f5..c43a5a7927 100644
--- a/drivers/net/mlx5/mlx5_txpp.c
+++ b/drivers/net/mlx5/mlx5_txpp.c
@@ -969,7 +969,6 @@ mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp)
{
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_dev_ctx_shared *sh = priv->sh;
- struct mlx5_proc_priv *ppriv;
uint64_t ts;
int ret;
@@ -995,15 +994,9 @@ mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp)
*timestamp = ts;
return 0;
}
- /* Check and try to map HCA PIC BAR to allow reading real time. */
- ppriv = dev->process_private;
- if (ppriv && !ppriv->hca_bar &&
- sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device))
- mlx5_txpp_map_hca_bar(dev);
/* Check if we can read timestamp directly from hardware. */
- if (ppriv && ppriv->hca_bar) {
- ts = MLX5_GET64(initial_seg, ppriv->hca_bar, real_time);
- ts = mlx5_txpp_convert_rx_ts(sh, ts);
+ ts = mlx5_read_pcibar_clock(dev);
+ if (ts != 0) {
*timestamp = ts;
return 0;
}
--
2.34.1
More information about the stable
mailing list