Skip to contentSkip to conversation

net/mlx5: support software TX timestamp

PATCH Superseded Stanislav Fomichev 3 participants 7 messages May 6, 2025 – May 8, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: support software TX timestamp

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
 drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
 2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
 		return 0;
 
 	info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+				SOF_TIMESTAMPING_TX_SOFTWARE |
 				SOF_TIMESTAMPING_RX_HARDWARE |
 				SOF_TIMESTAMPING_RAW_HARDWARE;
 
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
 {
 	if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
 		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+	skb_tx_timestamp(skb);
 }
 
 static void mlx5e_tx_check_stop(struct mlx5e_txqsq *sq)
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

Only one nit as below.

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)

Quoted 22 lines
---
 drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
 drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
 2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
                return 0;
 
        info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+                               SOF_TIMESTAMPING_TX_SOFTWARE |
                                SOF_TIMESTAMPING_RX_HARDWARE |
                                SOF_TIMESTAMPING_RAW_HARDWARE;
 
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)

nit: the function name including 'hwts' doesn't reflect the following software behavior.

Thanks,
Jason

Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -1
 {
        if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
                skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+       skb_tx_timestamp(skb);
 }
 
 static void mlx5e_tx_check_stop(struct mlx5e_txqsq *sq)
--

2.49.0

#2 lore raw
In reply to Stanislav Fomichev
Quoted 28 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
  drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
  drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
  2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
  		return 0;
 
  	info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+				SOF_TIMESTAMPING_TX_SOFTWARE |
  				SOF_TIMESTAMPING_RX_HARDWARE |
  				SOF_TIMESTAMPING_RAW_HARDWARE;
 
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0 -0
index 4fd853d19e31..f6dd26ad29e5 100644

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb) · line 344

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
  {
  	if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
  		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+	skb_tx_timestamp(skb);

Doesn't this interfere with skb_tstamp_tx call in the completion flow (mlx5e_consume_skb)?

What happens if both flags (SKBTX_SW_TSTAMP / SKBTX_HW_TSTAMP) are set Is it possible?

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0 -0
  }
 
  static void mlx5e_tx_check_stop(struct mlx5e_txqsq *sq)
#3 lore raw

Hi Tariq,

Quoted 27 lines · Tariq Toukan
Quoted 23 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
  drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
  drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
  2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
              return 0;
 
      info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+                             SOF_TIMESTAMPING_TX_SOFTWARE |
                              SOF_TIMESTAMPING_RX_HARDWARE |
                              SOF_TIMESTAMPING_RAW_HARDWARE;
 
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb) · line 344

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
  {
      if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
              skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+     skb_tx_timestamp(skb);

Doesn't this interfere with skb_tstamp_tx call in the completion flow (mlx5e_consume_skb)?

skb_tstamp_tx() only takes care of hardware timestamp in this case.

Quoted 3 lines

What happens if both flags (SKBTX_SW_TSTAMP / SKBTX_HW_TSTAMP) are set Is it possible?

If only these two are set, only hardware timestamp will be passed to the userspace because of the SOF_TIMESTAMPING_OPT_TX_SWHW limit in __skb_tstamp_tx().

If users expect to see both timestamps, then
SOF_TIMESTAMPING_OPT_TX_SWHW has to be set.

Thanks,
Jason

Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0 -0
  }
 
  static void mlx5e_tx_check_stop(struct mlx5e_txqsq *sq)
#4 lore raw
Quoted 49 lines · Jason Xing

Hi Tariq,

Quoted 27 lines · Tariq Toukan
Quoted 23 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
  drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
  drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
  2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
              return 0;
 
      info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+                             SOF_TIMESTAMPING_TX_SOFTWARE |
                              SOF_TIMESTAMPING_RX_HARDWARE |
                              SOF_TIMESTAMPING_RAW_HARDWARE;
 
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb) · line 344

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
  {
      if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
              skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+     skb_tx_timestamp(skb);

Doesn't this interfere with skb_tstamp_tx call in the completion flow (mlx5e_consume_skb)?

skb_tstamp_tx() only takes care of hardware timestamp in this case.

Quoted 3 lines

What happens if both flags (SKBTX_SW_TSTAMP / SKBTX_HW_TSTAMP) are set Is it possible?

Quoted 6 lines

If only these two are set, only hardware timestamp will be passed to the userspace because of the SOF_TIMESTAMPING_OPT_TX_SWHW limit in __skb_tstamp_tx().

If users expect to see both timestamps, then
SOF_TIMESTAMPING_OPT_TX_SWHW has to be set.

Right, skb_tx_timestamp does nothing and bails out if it detects SKBTX_IN_PROGRESS. And skb_tstamp_tx in mlx5e_consume_skb handles only (and will trigger only for) HW tstamp case.

#5 lore raw
Quoted 54 lines · Stanislav Fomichev
Quoted 53 lines · Jason Xing

Hi Tariq,

Quoted 27 lines · Tariq Toukan
Quoted 23 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
   drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
   drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
   2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
               return 0;
 
       info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+                             SOF_TIMESTAMPING_TX_SOFTWARE |
                               SOF_TIMESTAMPING_RX_HARDWARE |
                               SOF_TIMESTAMPING_RAW_HARDWARE;
 
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb) · line 344

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
   {
       if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
               skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+     skb_tx_timestamp(skb);

Doesn't this interfere with skb_tstamp_tx call in the completion flow (mlx5e_consume_skb)?

skb_tstamp_tx() only takes care of hardware timestamp in this case.

Quoted 3 lines

What happens if both flags (SKBTX_SW_TSTAMP / SKBTX_HW_TSTAMP) are set Is it possible?

If only these two are set, only hardware timestamp will be passed to the userspace because of the SOF_TIMESTAMPING_OPT_TX_SWHW limit in __skb_tstamp_tx().

Quoted 6 lines
Quoted 2 lines

If users expect to see both timestamps, then
SOF_TIMESTAMPING_OPT_TX_SWHW has to be set.

Right, skb_tx_timestamp does nothing and bails out if it detects SKBTX_IN_PROGRESS. And skb_tstamp_tx in mlx5e_consume_skb handles only (and will trigger only for) HW tstamp case.

I see.
Patch LGTM, except for the function name nit, pointed out in an earlier comment. We could remove the "hw" from function name mlx5e_tx_skb_update_hwts_flags.

#6 lore raw
Quoted 60 lines · Tariq Toukan
Quoted 57 lines · Stanislav Fomichev
Quoted 55 lines · Jason Xing

Hi Tariq,

Quoted 27 lines · Tariq Toukan
Quoted 23 lines · Stanislav Fomichev

Having a software timestamp (along with existing hardware one) is useful to trace how the packets flow through the stack. mlx5e_tx_skb_update_hwts_flags is called from tx paths to setup HW timestamp; extend it to add software one as well.

---
   drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 1 +
   drivers/net/ethernet/mellanox/mlx5/core/en_tx.c      | 1 +
   2 files changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
index fdf9e9bb99ac..e399d7a3d6cb 100644
@@ -1689,6 +1689,7 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
               return 0;
 
       info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+                             SOF_TIMESTAMPING_TX_SOFTWARE |
                               SOF_TIMESTAMPING_RX_HARDWARE |
                               SOF_TIMESTAMPING_RAW_HARDWARE;
 
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb) · line 344

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1 -0
index 4fd853d19e31..f6dd26ad29e5 100644
@@ -341,6 +341,7 @@ static void mlx5e_tx_skb_update_hwts_flags(struct sk_buff *skb)
   {
       if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
               skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+     skb_tx_timestamp(skb);

Doesn't this interfere with skb_tstamp_tx call in the completion flow (mlx5e_consume_skb)?

skb_tstamp_tx() only takes care of hardware timestamp in this case.

Quoted 3 lines

What happens if both flags (SKBTX_SW_TSTAMP / SKBTX_HW_TSTAMP) are set Is it possible?

If only these two are set, only hardware timestamp will be passed to the userspace because of the SOF_TIMESTAMPING_OPT_TX_SWHW limit in __skb_tstamp_tx().

If users expect to see both timestamps, then
SOF_TIMESTAMPING_OPT_TX_SWHW has to be set.

Quoted 8 lines
Quoted 3 lines

Right, skb_tx_timestamp does nothing and bails out if it detects SKBTX_IN_PROGRESS. And skb_tstamp_tx in mlx5e_consume_skb handles only (and will trigger only for) HW tstamp case.

I see.
Patch LGTM, except for the function name nit, pointed out in an earlier comment.
We could remove the "hw" from function name mlx5e_tx_skb_update_hwts_flags.

SG, will repost with a rename!