[v2,10/14] net/octeontx2: switch timestamp to dynamic mbuf field

Message ID 20201101180626.2198868-11-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series remove mbuf timestamp |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Thomas Monjalon Nov. 1, 2020, 6:06 p.m. UTC
  The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field.
The related mbuf flag is also replaced.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/octeontx2/otx2_ethdev.c | 33 +++++++++++++++++++++++++++++
 drivers/net/octeontx2/otx2_rx.h     | 19 ++++++++++++++---
 drivers/net/octeontx2/version.map   |  7 ++++++
 3 files changed, 56 insertions(+), 3 deletions(-)
  

Comments

Jerin Jacob Nov. 1, 2020, 6:28 p.m. UTC | #1
On Sun, Nov 1, 2020 at 11:40 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The mbuf timestamp is moved to a dynamic field
> in order to allow removal of the deprecated static field.
> The related mbuf flag is also replaced.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  drivers/net/octeontx2/otx2_ethdev.c | 33 +++++++++++++++++++++++++++++
>  drivers/net/octeontx2/otx2_rx.h     | 19 ++++++++++++++---
>  drivers/net/octeontx2/version.map   |  7 ++++++
>  3 files changed, 56 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/octeontx2/otx2_ethdev.c b/drivers/net/octeontx2/otx2_ethdev.c
> index cfb733a4b5..ad95219438 100644
> --- a/drivers/net/octeontx2/otx2_ethdev.c
> +++ b/drivers/net/octeontx2/otx2_ethdev.c
> @@ -4,6 +4,7 @@
>
>  #include <inttypes.h>
>
> +#include <rte_bitops.h>
>  #include <rte_ethdev_pci.h>
>  #include <rte_io.h>
>  #include <rte_malloc.h>
> @@ -14,6 +15,35 @@
>  #include "otx2_ethdev.h"
>  #include "otx2_ethdev_sec.h"
>
> +uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
> +int rte_pmd_octeontx2_timestamp_dynfield_offset = -1;


Instead of the global variable, please move the offset to struct
otx2_timesync_info(which is used in fastpath) and accessible in slow
path.

> +
> +static int
> +otx2_rx_timestamp_setup(uint16_t flags)
> +{
> +       int timestamp_rx_dynflag_offset;
> +
> +       if ((flags & NIX_RX_OFFLOAD_TSTAMP_F) == 0)
> +               return 0;
> +
> +       rte_pmd_octeontx2_timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
> +                       RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
> +       if (rte_pmd_octeontx2_timestamp_dynfield_offset < 0) {
> +               otx2_err("Failed to lookup timestamp field");
> +               return -rte_errno;
> +       }
> +       timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
> +                       RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
> +       if (timestamp_rx_dynflag_offset < 0) {
> +               otx2_err("Failed to lookup Rx timestamp flag");
> +               return -rte_errno;
> +       }
> +       rte_pmd_octeontx2_timestamp_rx_dynflag =
> +                       RTE_BIT64(timestamp_rx_dynflag_offset);
> +
> +       return 0;
> +}
> +
>  static inline uint64_t
>  nix_get_rx_offload_capa(struct otx2_eth_dev *dev)
>  {
> @@ -1874,6 +1904,9 @@ otx2_nix_configure(struct rte_eth_dev *eth_dev)
>         dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
>         dev->rss_info.rss_grps = NIX_RSS_GRPS;
>
> +       if (otx2_rx_timestamp_setup(dev->rx_offload_flags) != 0)
> +               goto fail_offloads;
> +
>         nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
>         nb_txq = RTE_MAX(data->nb_tx_queues, 1);
>
> diff --git a/drivers/net/octeontx2/otx2_rx.h b/drivers/net/octeontx2/otx2_rx.h
> index 61a5c436dd..6981edce82 100644
> --- a/drivers/net/octeontx2/otx2_rx.h
> +++ b/drivers/net/octeontx2/otx2_rx.h
> @@ -63,6 +63,18 @@ union mbuf_initializer {
>         uint64_t value;
>  };
>
> +/* variables are exported because this file is included in other drivers */
> +extern uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
> +extern int rte_pmd_octeontx2_timestamp_dynfield_offset;
> +
> +static inline rte_mbuf_timestamp_t *
> +otx2_timestamp_dynfield(struct rte_mbuf *mbuf)

Please take the offset from struct otx2_timesync_info *tstamp. it
already available in otx2_nix_mbuf_to_tstamp(). See below.

> +{
> +       return RTE_MBUF_DYNFIELD(mbuf,
> +               rte_pmd_octeontx2_timestamp_dynfield_offset,
> +               rte_mbuf_timestamp_t *);
> +}
> +
>  static __rte_always_inline void
>  otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf,
>                         struct otx2_timesync_info *tstamp, const uint16_t flag,
> @@ -77,15 +89,16 @@ otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf,
>                 /* Reading the rx timestamp inserted by CGX, viz at
>                  * starting of the packet data.
>                  */
> -               mbuf->timestamp = rte_be_to_cpu_64(*tstamp_ptr);
> +               *otx2_timestamp_dynfield(mbuf) = rte_be_to_cpu_64(*tstamp_ptr);
>                 /* PKT_RX_IEEE1588_TMST flag needs to be set only in case
>                  * PTP packets are received.
>                  */
>                 if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) {
> -                       tstamp->rx_tstamp = mbuf->timestamp;
> +                       tstamp->rx_tstamp = *otx2_timestamp_dynfield(mbuf);
>                         tstamp->rx_ready = 1;
>                         mbuf->ol_flags |= PKT_RX_IEEE1588_PTP |
> -                               PKT_RX_IEEE1588_TMST | PKT_RX_TIMESTAMP;
> +                               PKT_RX_IEEE1588_TMST |
> +                               rte_pmd_octeontx2_timestamp_rx_dynflag;
>                 }
>         }
>  }
> diff --git a/drivers/net/octeontx2/version.map b/drivers/net/octeontx2/version.map
> index 4a76d1d52d..d4f4784bcd 100644
> --- a/drivers/net/octeontx2/version.map
> +++ b/drivers/net/octeontx2/version.map
> @@ -1,3 +1,10 @@
>  DPDK_21 {
>         local: *;
>  };
> +
> +INTERNAL {
> +       global:
> +
> +       rte_pmd_octeontx2_timestamp_dynfield_offset;
> +       rte_pmd_octeontx2_timestamp_rx_dynflag;

No need to export this function if offset is part of struct otx2_timesync_info


> +};
> --
> 2.28.0
>
  
Thomas Monjalon Nov. 2, 2020, 9:38 a.m. UTC | #2
01/11/2020 19:28, Jerin Jacob:
> On Sun, Nov 1, 2020 at 11:40 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > The mbuf timestamp is moved to a dynamic field
> > in order to allow removal of the deprecated static field.
> > The related mbuf flag is also replaced.
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
[...]
> > +uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
> > +int rte_pmd_octeontx2_timestamp_dynfield_offset = -1;
> 
> Instead of the global variable, please move the offset to struct
> otx2_timesync_info(which is used in fastpath) and accessible in slow
> path.

This structure is initialized in otx2_nix_dev_start().
otx2_rx_timestamp_setup() is called earlier in otx2_nix_configure().
One of the two has to change. Which one?

> > +static int
> > +otx2_rx_timestamp_setup(uint16_t flags)
> > +{
> > +       int timestamp_rx_dynflag_offset;
> > +
> > +       if ((flags & NIX_RX_OFFLOAD_TSTAMP_F) == 0)
> > +               return 0;
> > +
> > +       rte_pmd_octeontx2_timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
> > +                       RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
> > +       if (rte_pmd_octeontx2_timestamp_dynfield_offset < 0) {
> > +               otx2_err("Failed to lookup timestamp field");
> > +               return -rte_errno;
> > +       }
> > +       timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
> > +                       RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
> > +       if (timestamp_rx_dynflag_offset < 0) {
> > +               otx2_err("Failed to lookup Rx timestamp flag");
> > +               return -rte_errno;
> > +       }
> > +       rte_pmd_octeontx2_timestamp_rx_dynflag =
> > +                       RTE_BIT64(timestamp_rx_dynflag_offset);
> > +
> > +       return 0;
> > +}
> > @@ -1874,6 +1904,9 @@ otx2_nix_configure(struct rte_eth_dev *eth_dev)
> >         dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
> >         dev->rss_info.rss_grps = NIX_RSS_GRPS;
> >
> > +       if (otx2_rx_timestamp_setup(dev->rx_offload_flags) != 0)
> > +               goto fail_offloads;
> > +
> >         nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
> >         nb_txq = RTE_MAX(data->nb_tx_queues, 1);
  
Thomas Monjalon Nov. 2, 2020, 11:01 a.m. UTC | #3
02/11/2020 10:38, Thomas Monjalon:
> 01/11/2020 19:28, Jerin Jacob:
> > On Sun, Nov 1, 2020 at 11:40 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > >
> > > The mbuf timestamp is moved to a dynamic field
> > > in order to allow removal of the deprecated static field.
> > > The related mbuf flag is also replaced.
> > >
> > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > ---
> [...]
> > > +uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
> > > +int rte_pmd_octeontx2_timestamp_dynfield_offset = -1;
> > 
> > Instead of the global variable, please move the offset to struct
> > otx2_timesync_info(which is used in fastpath) and accessible in slow
> > path.
> 
> This structure is initialized in otx2_nix_dev_start().
> otx2_rx_timestamp_setup() is called earlier in otx2_nix_configure().
> One of the two has to change. Which one?

I see that the timestamp config can be changed in otx2_nix_dev_start()
so it looks I have no other choice than moving timestamp setup
at "start" stage anyway.

Will be done in v3, that I will send later today.
  

Patch

diff --git a/drivers/net/octeontx2/otx2_ethdev.c b/drivers/net/octeontx2/otx2_ethdev.c
index cfb733a4b5..ad95219438 100644
--- a/drivers/net/octeontx2/otx2_ethdev.c
+++ b/drivers/net/octeontx2/otx2_ethdev.c
@@ -4,6 +4,7 @@ 
 
 #include <inttypes.h>
 
+#include <rte_bitops.h>
 #include <rte_ethdev_pci.h>
 #include <rte_io.h>
 #include <rte_malloc.h>
@@ -14,6 +15,35 @@ 
 #include "otx2_ethdev.h"
 #include "otx2_ethdev_sec.h"
 
+uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
+int rte_pmd_octeontx2_timestamp_dynfield_offset = -1;
+
+static int
+otx2_rx_timestamp_setup(uint16_t flags)
+{
+	int timestamp_rx_dynflag_offset;
+
+	if ((flags & NIX_RX_OFFLOAD_TSTAMP_F) == 0)
+		return 0;
+
+	rte_pmd_octeontx2_timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+			RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+	if (rte_pmd_octeontx2_timestamp_dynfield_offset < 0) {
+		otx2_err("Failed to lookup timestamp field");
+		return -rte_errno;
+	}
+	timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
+	if (timestamp_rx_dynflag_offset < 0) {
+		otx2_err("Failed to lookup Rx timestamp flag");
+		return -rte_errno;
+	}
+	rte_pmd_octeontx2_timestamp_rx_dynflag =
+			RTE_BIT64(timestamp_rx_dynflag_offset);
+
+	return 0;
+}
+
 static inline uint64_t
 nix_get_rx_offload_capa(struct otx2_eth_dev *dev)
 {
@@ -1874,6 +1904,9 @@  otx2_nix_configure(struct rte_eth_dev *eth_dev)
 	dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
 	dev->rss_info.rss_grps = NIX_RSS_GRPS;
 
+	if (otx2_rx_timestamp_setup(dev->rx_offload_flags) != 0)
+		goto fail_offloads;
+
 	nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
 	nb_txq = RTE_MAX(data->nb_tx_queues, 1);
 
diff --git a/drivers/net/octeontx2/otx2_rx.h b/drivers/net/octeontx2/otx2_rx.h
index 61a5c436dd..6981edce82 100644
--- a/drivers/net/octeontx2/otx2_rx.h
+++ b/drivers/net/octeontx2/otx2_rx.h
@@ -63,6 +63,18 @@  union mbuf_initializer {
 	uint64_t value;
 };
 
+/* variables are exported because this file is included in other drivers */
+extern uint64_t rte_pmd_octeontx2_timestamp_rx_dynflag;
+extern int rte_pmd_octeontx2_timestamp_dynfield_offset;
+
+static inline rte_mbuf_timestamp_t *
+otx2_timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		rte_pmd_octeontx2_timestamp_dynfield_offset,
+		rte_mbuf_timestamp_t *);
+}
+
 static __rte_always_inline void
 otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf,
 			struct otx2_timesync_info *tstamp, const uint16_t flag,
@@ -77,15 +89,16 @@  otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf,
 		/* Reading the rx timestamp inserted by CGX, viz at
 		 * starting of the packet data.
 		 */
-		mbuf->timestamp = rte_be_to_cpu_64(*tstamp_ptr);
+		*otx2_timestamp_dynfield(mbuf) = rte_be_to_cpu_64(*tstamp_ptr);
 		/* PKT_RX_IEEE1588_TMST flag needs to be set only in case
 		 * PTP packets are received.
 		 */
 		if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) {
-			tstamp->rx_tstamp = mbuf->timestamp;
+			tstamp->rx_tstamp = *otx2_timestamp_dynfield(mbuf);
 			tstamp->rx_ready = 1;
 			mbuf->ol_flags |= PKT_RX_IEEE1588_PTP |
-				PKT_RX_IEEE1588_TMST | PKT_RX_TIMESTAMP;
+				PKT_RX_IEEE1588_TMST |
+				rte_pmd_octeontx2_timestamp_rx_dynflag;
 		}
 	}
 }
diff --git a/drivers/net/octeontx2/version.map b/drivers/net/octeontx2/version.map
index 4a76d1d52d..d4f4784bcd 100644
--- a/drivers/net/octeontx2/version.map
+++ b/drivers/net/octeontx2/version.map
@@ -1,3 +1,10 @@ 
 DPDK_21 {
 	local: *;
 };
+
+INTERNAL {
+	global:
+
+	rte_pmd_octeontx2_timestamp_dynfield_offset;
+	rte_pmd_octeontx2_timestamp_rx_dynflag;
+};