Skip to contentSkip to conversation

remove mbuf timestamp

PATCH Superseded Thomas Monjalon 17 participants 170 messages Oct 29, 2020 – Nov 5, 2020 Network drivers Page 2 of 2

lore
Share & tools
lore
#142 lore raw

PATCH v4 15/16 mbuf: add Tx timestamp registration helper

In reply to Thomas Monjalon

The function rte_mbuf_dyn_tx_timestamp_register() can be used to register the required field and flag.

---
 lib/librte_mbuf/rte_mbuf_dyn.c |  7 +++++++
 lib/librte_mbuf/rte_mbuf_dyn.h | 22 ++++++++++++++++++++++
 lib/librte_mbuf/version.map    |  1 +
 3 files changed, 30 insertions(+)
lib/librte_mbuf/rte_mbuf_dyn.c +7 -0
index 4f50da09f3..101b5bd95f 100644
@@ -613,3 +613,10 @@ rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag)
 	return rte_mbuf_dyn_timestamp_register(field_offset, rx_flag,
 			"Rx", RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME);
 }
+
+int
+rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag)
+{
+	return rte_mbuf_dyn_timestamp_register(field_offset, tx_flag,
+			"Tx", RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME);
+}
lib/librte_mbuf/rte_mbuf_dyn.h +22 -0
index 2e729ddaca..d88e7bacc5 100644
@@ -304,4 +304,26 @@ int rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag);
  */
 #define RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME "rte_dynflag_tx_timestamp"
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Register dynamic mbuf field and flag for Tx timestamp.
+ *
+ * @param field_offset
+ *   Pointer to the offset of the registered mbuf field, can be NULL.
+ *   The same field is shared for Rx and Tx timestamp.
+ * @param tx_flag
+ *   Pointer to the mask of the registered offload flag, can be NULL.
+ * @return
+ *   0 on success, -1 otherwise.
+ *   Possible values for rte_errno:
+ *   - EEXIST: already registered with different parameters.
+ *   - EPERM: called from a secondary process.
+ *   - ENOENT: no more field or flag available.
+ *   - ENOMEM: allocation failure.
+ */
+__rte_experimental
+int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);
+
 #endif
lib/librte_mbuf/version.map +1 -0
index 0b66668bff..b7d98e7eb1 100644
@@ -43,6 +43,7 @@ EXPERIMENTAL {
 	rte_mbuf_dynflag_register_bitnum;
 	rte_mbuf_dyn_dump;
 	rte_mbuf_dyn_rx_timestamp_register;
+	rte_mbuf_dyn_tx_timestamp_register;
 	rte_pktmbuf_copy;
 	rte_pktmbuf_free_bulk;
 	rte_pktmbuf_pool_create_extbuf;
Signature · 1 line
2.28.0
#144 lore raw

PATCH v4 16/16 ethdev: include mbuf registration in Tx timestamp API

In reply to Thomas Monjalon

Previously, the Tx timestamp field and flag were registered in testpmd, as described in mlx5 guide.
For consistency between Rx and Tx timestamps,
managing mbuf registrations inside the driver, as properly documented, is a simpler expectation.

The only driver to support this feature (mlx5) is updated as well as the testpmd application.

---
 app/test-pmd/config.c          | 38 ----------------------------------
 doc/guides/nics/mlx5.rst       |  5 ++---
 drivers/net/mlx5/mlx5_ethdev.c |  8 ++++++-
 lib/librte_ethdev/rte_ethdev.h |  6 +++++-
 4 files changed, 14 insertions(+), 43 deletions(-)
app/test-pmd/config.c +0 -38
index 1668ae3238..9a2baf16fe 100644
@@ -3955,44 +3955,6 @@ show_tx_pkt_times(void)
 void
 set_tx_pkt_times(unsigned int *tx_times)
 {
-	uint16_t port_id;
-	int offload_found = 0;
-	int offset;
-	int flag;
-
-	static const struct rte_mbuf_dynfield desc_offs = {
-		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
-		.size = sizeof(uint64_t),
-		.align = __alignof__(uint64_t),
-	};
-	static const struct rte_mbuf_dynflag desc_flag = {
-		.name = RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME,
-	};
-
-	RTE_ETH_FOREACH_DEV(port_id) {
-		struct rte_eth_dev_info dev_info = { 0 };
-		int ret;
-
-		ret = rte_eth_dev_info_get(port_id, &dev_info);
-		if (ret == 0 && dev_info.tx_offload_capa &
-				DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
-			offload_found = 1;
-			break;
-		}
-	}
-	if (!offload_found) {
-		printf("No device supporting Tx timestamp scheduling found, "
-		       "dynamic flag and field not registered\n");
-		return;
-	}
-	offset = rte_mbuf_dynfield_register(&desc_offs);
-	if (offset < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp field registration error: %d",
-		       rte_errno);
-	flag = rte_mbuf_dynflag_register(&desc_flag);
-	if (flag < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp flag registration error: %d",
-		       rte_errno);
 	tx_pkt_times_inter = tx_times[0];
 	tx_pkt_times_intra = tx_times[1];
 }
doc/guides/nics/mlx5.rst +2 -3
index afa65a1379..fa8b13dd1b 100644
@@ -237,9 +237,8 @@ Limitations
   ``txq_inline_max`` and ``txq_inline_mpw`` devargs keys.
 
 - To provide the packet send scheduling on mbuf timestamps the ``tx_pp``
-  parameter should be specified, RTE_MBUF_DYNFIELD_TIMESTAMP_NAME and
-  RTE_MBUF_DYNFLAG_TIMESTAMP_NAME should be registered by application.
-  When PMD sees the RTE_MBUF_DYNFLAG_TIMESTAMP_NAME set on the packet
+  parameter should be specified.
+  When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME set on the packet
   being sent it tries to synchronize the time of packet appearing on
   the wire with the specified packet timestamp. It the specified one
   is in the past it should be ignored, if one is in the distant future
drivers/net/mlx5/mlx5_ethdev.c +7 -1
index 7631f644b2..76ef02664f 100644
@@ -88,7 +88,13 @@ mlx5_dev_configure(struct rte_eth_dev *dev)
 
 	if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
 		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
-
+	if ((dev->data->dev_conf.txmode.offloads &
+			DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) &&
+			rte_mbuf_dyn_tx_timestamp_register(NULL, NULL) != 0) {
+		DRV_LOG(ERR, "port %u cannot register Tx timestamp field/flag",
+			dev->data->port_id);
+		return -rte_errno;
+	}
 	memcpy(priv->rss_conf.rss_key,
 	       use_app_rss_key ?
 	       dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key :
lib/librte_ethdev/rte_ethdev.h +5 -1
index 1fc5f662fa..619cbe521e 100644
@@ -1413,7 +1413,11 @@ struct rte_eth_conf {
 #define DEV_TX_OFFLOAD_IP_TNL_TSO       0x00080000
 /** Device supports outer UDP checksum */
 #define DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  0x00100000
-/** Device supports send on timestamp */
+/**
+ * Device sends on time read from RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+ * if RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME is set in ol_flags.
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP 0x00200000
 /*
  * If new Tx offload capabilities are defined, they also must be
Signature · 1 line
2.28.0
Acked-by on v4 16/16
#145 lore raw

Re: [dpdk-dev] [PATCH v4 16/16] ethdev: include mbuf registration in Tx timestamp API

Quoted 6 lines · Thomas Monjalon

Previously, the Tx timestamp field and flag were registered in testpmd, as described in mlx5 guide.
For consistency between Rx and Tx timestamps,
managing mbuf registrations inside the driver, as properly documented, is a simpler expectation.

Quoted 6 lines

The only driver to support this feature (mlx5) is updated as well as the testpmd application.

#146 lore raw

v5 cover remove mbuf timestamp

In reply to Thomas Monjalon

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

As a consequence, 8 bytes can be re-allocated to dynamic fields in the first half of mbuf structure.
It is still open to change more the mbuf layout.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year,
and can allow performance improvements with new usages in the first half.

v5:
- add a blank line between different kind of ARK variables
- move registration after octeontx2 VF config
- register also in otx2_nix_timesync_enable

v4:
- use local variable in nfb
- fix flag initialization
- remove useless blank line

v3:
- move ark variables declaration in a .h file
- improve cache locality for octeontx2
- add comments about cache locality in commit logs
- add comment for unused flag offset 17
- add timestamp register functions
- replace lookup with register in drivers and apps
- remove register in ethdev

v2:
- remove optimization to register only once in ethdev
- fix error message in latencystats
- convert rxtx_callbacks macro to inline function
- increase dynamic fields space
- do not move pool field

Thomas Monjalon (16):
eventdev: remove software Rx timestamp
mbuf: add Rx timestamp flag and helpers
latency: switch Rx timestamp to dynamic mbuf field net/ark: switch Rx timestamp to dynamic mbuf field net/dpaa2: switch Rx timestamp to dynamic mbuf field net/mlx5: fix dynamic mbuf offset lookup check net/mlx5: switch Rx timestamp to dynamic mbuf field net/nfb: switch Rx timestamp to dynamic mbuf field net/octeontx2: switch Rx timestamp to dynamic mbuf field net/pcap: switch Rx timestamp to dynamic mbuf field app/testpmd: switch Rx timestamp to dynamic mbuf field examples/rxtx_callbacks: switch timestamp to dynamic field
ethdev: add doxygen comment for Rx timestamp API
mbuf: remove deprecated timestamp field
mbuf: add Tx timestamp registration helper
ethdev: include mbuf registration in Tx timestamp API

 app/test-pmd/config.c                         | 38 -------------
 app/test-pmd/util.c                           | 38 ++++++++++++-
 app/test/test_mbuf.c                          |  1 -
 doc/guides/nics/mlx5.rst                      |  5 +-
 .../prog_guide/event_ethernet_rx_adapter.rst  |  6 +-
 doc/guides/rel_notes/deprecation.rst          |  4 --
 doc/guides/rel_notes/release_20_11.rst        |  4 ++
 drivers/net/ark/ark_ethdev.c                  | 17 ++++++
 drivers/net/ark/ark_ethdev_rx.c               |  7 ++-
 drivers/net/ark/ark_ethdev_rx.h               |  2 +
 drivers/net/dpaa2/dpaa2_ethdev.c              | 11 ++++
 drivers/net/dpaa2/dpaa2_ethdev.h              |  2 +
 drivers/net/dpaa2/dpaa2_rxtx.c                | 25 ++++++---
 drivers/net/mlx5/mlx5_ethdev.c                |  8 ++-
 drivers/net/mlx5/mlx5_rxq.c                   |  8 +++
 drivers/net/mlx5/mlx5_rxtx.c                  |  8 +--
 drivers/net/mlx5/mlx5_rxtx.h                  | 19 +++++++
 drivers/net/mlx5/mlx5_rxtx_vec_altivec.h      | 41 +++++++-------
 drivers/net/mlx5/mlx5_rxtx_vec_neon.h         | 43 ++++++++-------
 drivers/net/mlx5/mlx5_rxtx_vec_sse.h          | 35 ++++++------
 drivers/net/mlx5/mlx5_trigger.c               |  2 +-
 drivers/net/mlx5/mlx5_txq.c                   |  2 +-
 drivers/net/nfb/nfb_rx.c                      | 15 ++++-
 drivers/net/nfb/nfb_rx.h                      | 21 +++++--
 drivers/net/octeontx2/otx2_ethdev.c           | 10 ++++
 drivers/net/octeontx2/otx2_ptp.c              |  8 +++
 drivers/net/octeontx2/otx2_rx.h               | 19 ++++++-
 drivers/net/pcap/rte_eth_pcap.c               | 20 ++++++-
 examples/rxtx_callbacks/main.c                | 16 +++++-
 lib/librte_ethdev/rte_ethdev.h                | 14 ++++-
 .../rte_event_eth_rx_adapter.c                | 11 ----
 .../rte_event_eth_rx_adapter.h                |  6 +-
 lib/librte_latencystats/rte_latencystats.c    | 30 ++++++++--
 lib/librte_mbuf/rte_mbuf.c                    |  2 -
 lib/librte_mbuf/rte_mbuf.h                    |  2 +-
 lib/librte_mbuf/rte_mbuf_core.h               | 12 +---
 lib/librte_mbuf/rte_mbuf_dyn.c                | 51 +++++++++++++++++
 lib/librte_mbuf/rte_mbuf_dyn.h                | 55 +++++++++++++++++--
 lib/librte_mbuf/version.map                   |  2 +
 39 files changed, 440 insertions(+), 180 deletions(-)
Signature · 1 line
2.28.0
#147 lore raw

PATCH v5 1/16 eventdev: remove software Rx timestamp

This a revert of the commit 569758758dcd ("eventdev: add Rx timestamp"). If the Rx timestamp is not configured on the ethdev port, there is no reason to set one.
Also the accuracy of the timestamp was bad because set at a late stage. Anyway there is no trace of the usage of this timestamp.

---
 doc/guides/prog_guide/event_ethernet_rx_adapter.rst |  6 +-----
 lib/librte_eventdev/rte_event_eth_rx_adapter.c      | 11 -----------
 lib/librte_eventdev/rte_event_eth_rx_adapter.h      |  6 +-----
 3 files changed, 2 insertions(+), 21 deletions(-)
doc/guides/prog_guide/event_ethernet_rx_adapter.rst +1 -5
index 236f43f455..cb44ce0e47 100644
@@ -12,11 +12,7 @@ be supported in hardware or require a software thread to receive packets from
 the ethdev port using ethdev poll mode APIs and enqueue these as events to the
 event device using the eventdev API. Both transfer mechanisms may be present on
 the same platform depending on the particular combination of the ethdev and
-the event device. For SW based packet transfer, if the mbuf does not have a
-timestamp set, the adapter adds a timestamp to the mbuf using
-rte_get_tsc_cycles(), this provides a more accurate timestamp as compared to
-if the application were to set the timestamp since it avoids event device
-schedule latency.
+the event device.
 
 The Event Ethernet Rx Adapter library is intended for the application code to
 configure both transfer mechanisms using a common API. A capability API allows
lib/librte_eventdev/rte_event_eth_rx_adapter.c +0 -11
index f0000d1ede..3c73046551 100644
@@ -763,7 +763,6 @@ rxa_buffer_mbufs(struct rte_event_eth_rx_adapter *rx_adapter,
 	uint32_t rss_mask;
 	uint32_t rss;
 	int do_rss;
-	uint64_t ts;
 	uint16_t nb_cb;
 	uint16_t dropped;
 
@@ -771,16 +770,6 @@ rxa_buffer_mbufs(struct rte_event_eth_rx_adapter *rx_adapter,
 	rss_mask = ~(((m->ol_flags & PKT_RX_RSS_HASH) != 0) - 1);
 	do_rss = !rss_mask && !eth_rx_queue_info->flow_id_mask;
 
-	if ((m->ol_flags & PKT_RX_TIMESTAMP) == 0) {
-		ts = rte_get_tsc_cycles();
-		for (i = 0; i < num; i++) {
-			m = mbufs[i];
-
-			m->timestamp = ts;
-			m->ol_flags |= PKT_RX_TIMESTAMP;
-		}
-	}
-
 	for (i = 0; i < num; i++) {
 		m = mbufs[i];
 
lib/librte_eventdev/rte_event_eth_rx_adapter.h +1 -5
index 2dd259c279..21bb1e54c8 100644
@@ -21,11 +21,7 @@
  *
  * The adapter uses a EAL service core function for SW based packet transfer
  * and uses the eventdev PMD functions to configure HW based packet transfer
- * between the ethernet device and the event device. For SW based packet
- * transfer, if the mbuf does not have a timestamp set, the adapter adds a
- * timestamp to the mbuf using rte_get_tsc_cycles(), this provides a more
- * accurate timestamp as compared to if the application were to set the time
- * stamp since it avoids event device schedule latency.
+ * between the ethernet device and the event device.
  *
  * The ethernet Rx event adapter's functions are:
  *  - rte_event_eth_rx_adapter_create_ext()
Signature · 1 line
2.28.0
#148 lore raw

PATCH v5 2/16 mbuf: add Rx timestamp flag and helpers

In reply to Thomas Monjalon

There is already a dynamic field for timestamp,
used only for Tx scheduling with the dedicated Tx offload flag. The same field can be used for Rx timestamp filled by drivers.

A new dynamic flag is defined for Rx usage.
A new function wraps the registration of both field and Rx flag. The type rte_mbuf_timestamp_t is defined for the API users.

After migrating all Rx timestamp usages, it will be possible to remove the deprecated timestamp field.

---
 lib/librte_mbuf/rte_mbuf_dyn.c | 43 ++++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_dyn.h | 33 ++++++++++++++++++++++----
 lib/librte_mbuf/version.map    |  1 +
 3 files changed, 72 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +43 -0
index 538a43f695..5b608a27d7 100644
@@ -13,6 +13,7 @@
 #include <rte_errno.h>
 #include <rte_malloc.h>
 #include <rte_string_fns.h>
+#include <rte_bitops.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 
@@ -569,3 +570,45 @@ void rte_mbuf_dyn_dump(FILE *out)
 
 	rte_mcfg_tailq_write_unlock();
 }
+
+static int
+rte_mbuf_dyn_timestamp_register(int *field_offset, uint64_t *flag,
+		const char *direction, const char *flag_name)
+{
+	static const struct rte_mbuf_dynfield field_desc = {
+		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
+		.size = sizeof(rte_mbuf_timestamp_t),
+		.align = __alignof__(rte_mbuf_timestamp_t),
+	};
+	struct rte_mbuf_dynflag flag_desc = { 0 };
+	int offset;
+
+	offset = rte_mbuf_dynfield_register(&field_desc);
+	if (offset < 0) {
+		RTE_LOG(ERR, MBUF,
+			"Failed to register mbuf field for timestamp\n");
+		return -1;
+	}
+	if (field_offset != NULL)
+		*field_offset = offset;
+
+	strlcpy(flag_desc.name, flag_name, sizeof(flag_desc.name));
+	offset = rte_mbuf_dynflag_register(&flag_desc);
+	if (offset < 0) {
+		RTE_LOG(ERR, MBUF,
+			"Failed to register mbuf flag for %s timestamp\n",
+			direction);
+		return -1;
+	}
+	if (flag != NULL)
+		*flag = RTE_BIT64(offset);
+
+	return 0;
+}
+
+int
+rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag)
+{
+	return rte_mbuf_dyn_timestamp_register(field_offset, rx_flag,
+			"Rx", RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME);
+}
lib/librte_mbuf/rte_mbuf_dyn.h +28 -5
index 0ebac88b83..2e729ddaca 100644
@@ -258,13 +258,36 @@ void rte_mbuf_dyn_dump(FILE *out);
  * timestamp. The dynamic Tx timestamp flag tells whether the field contains
  * actual timestamp value for the packets being sent, this value can be
  * used by PMD to schedule packet sending.
- *
- * After PKT_RX_TIMESTAMP flag and fixed timestamp field deprecation
- * and obsoleting, the dedicated Rx timestamp flag is supposed to be
- * introduced and the shared dynamic timestamp field will be used
- * to handle the timestamps on receiving datapath as well.
  */
 #define RTE_MBUF_DYNFIELD_TIMESTAMP_NAME "rte_dynfield_timestamp"
+typedef uint64_t rte_mbuf_timestamp_t;
+
+/**
+ * Indicate that the timestamp field in the mbuf was filled by the driver.
+ */
+#define RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME "rte_dynflag_rx_timestamp"
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Register dynamic mbuf field and flag for Rx timestamp.
+ *
+ * @param field_offset
+ *   Pointer to the offset of the registered mbuf field, can be NULL.
+ *   The same field is shared for Rx and Tx timestamp.
+ * @param rx_flag
+ *   Pointer to the mask of the registered offload flag, can be NULL.
+ * @return
+ *   0 on success, -1 otherwise.
+ *   Possible values for rte_errno:
+ *   - EEXIST: already registered with different parameters.
+ *   - EPERM: called from a secondary process.
+ *   - ENOENT: no more field or flag available.
+ *   - ENOMEM: allocation failure.
+ */
+__rte_experimental
+int rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag);
 
 /**
  * When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME flag set on the
lib/librte_mbuf/version.map +1 -0
index a011aaead3..0b66668bff 100644
@@ -42,6 +42,7 @@ EXPERIMENTAL {
 	rte_mbuf_dynflag_register;
 	rte_mbuf_dynflag_register_bitnum;
 	rte_mbuf_dyn_dump;
+	rte_mbuf_dyn_rx_timestamp_register;
 	rte_pktmbuf_copy;
 	rte_pktmbuf_free_bulk;
 	rte_pktmbuf_pool_create_extbuf;
Signature · 1 line
2.28.0
#149 lore raw

PATCH v5 3/16 latency: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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 with the dynamic one.

---
 lib/librte_latencystats/rte_latencystats.c | 30 ++++++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)
lib/librte_latencystats/rte_latencystats.c +25 -5
index ba2fff3bcb..ab8db7a139 100644
@@ -9,6 +9,7 @@
 
 #include <rte_string_fns.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_log.h>
 #include <rte_cycles.h>
 #include <rte_ethdev.h>
@@ -31,6 +32,16 @@ latencystat_cycles_per_ns(void)
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_LATENCY_STATS RTE_LOGTYPE_USER1
 
+static uint64_t timestamp_dynflag;
+static int timestamp_dynfield_offset = -1;
+
+static inline rte_mbuf_timestamp_t *
+timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+			timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 static const char *MZ_RTE_LATENCY_STATS = "rte_latencystats";
 static int latency_stats_index;
 static uint64_t samp_intvl;
@@ -128,10 +139,10 @@ add_time_stamps(uint16_t pid __rte_unused,
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
 
-		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+		if ((pkts[i]->ol_flags & timestamp_dynflag) == 0
 				&& (timer_tsc >= samp_intvl)) {
-			pkts[i]->timestamp = now;
-			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
+			*timestamp_dynfield(pkts[i]) = now;
+			pkts[i]->ol_flags |= timestamp_dynflag;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -161,8 +172,8 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
-			latency[cnt++] = now - pkts[i]->timestamp;
+		if (pkts[i]->ol_flags & timestamp_dynflag)
+			latency[cnt++] = now - *timestamp_dynfield(pkts[i]);
 	}
 
 	rte_spinlock_lock(&glob_stats->lock);
@@ -241,6 +252,15 @@ rte_latencystats_init(uint64_t app_samp_intvl,
 		return -1;
 	}
 
+	/* Register mbuf field and flag for Rx timestamp */
+	ret = rte_mbuf_dyn_rx_timestamp_register(&timestamp_dynfield_offset,
+			&timestamp_dynflag);
+	if (ret != 0) {
+		RTE_LOG(ERR, LATENCY_STATS,
+			"Cannot register mbuf field/flag for timestamp\n");
+		return -rte_errno;
+	}
+
 	/** Register Rx/Tx callbacks */
 	RTE_ETH_FOREACH_DEV(pid) {
 		struct rte_eth_dev_info dev_info;
Signature · 1 line
2.28.0
#150 lore raw

PATCH v5 4/16 net/ark: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field. The related dynamic mbuf flag is set, although was missing previously.

The timestamp is set if configured for at least one device.

---
 drivers/net/ark/ark_ethdev.c    | 17 +++++++++++++++++
 drivers/net/ark/ark_ethdev_rx.c |  7 ++++++-
 drivers/net/ark/ark_ethdev_rx.h |  2 ++
 3 files changed, 25 insertions(+), 1 deletion(-)
drivers/net/ark/ark_ethdev.c +17 -0
index fa343999a1..a658993512 100644
@@ -79,6 +79,9 @@ static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
 #define ARK_TX_MAX_QUEUE (4096 * 4)
 #define ARK_TX_MIN_QUEUE (256)
 
+uint64_t ark_timestamp_rx_dynflag;
+int ark_timestamp_dynfield_offset = -1;
+
 int rte_pmd_ark_rx_userdata_dynfield_offset = -1;
 int rte_pmd_ark_tx_userdata_dynfield_offset = -1;
 
@@ -552,6 +555,18 @@ static int
 eth_ark_dev_configure(struct rte_eth_dev *dev)
 {
 	struct ark_adapter *ark = dev->data->dev_private;
+	int ret;
+
+	if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_TIMESTAMP) {
+		ret = rte_mbuf_dyn_rx_timestamp_register(
+				&ark_timestamp_dynfield_offset,
+				&ark_timestamp_rx_dynflag);
+		if (ret != 0) {
+			ARK_PMD_LOG(ERR,
+				"Failed to register Rx timestamp field/flag\n");
+			return -rte_errno;
+		}
+	}
 
 	eth_ark_dev_set_link_up(dev);
 	if (ark->user_ext.dev_configure)
@@ -782,6 +797,8 @@ eth_ark_dev_info_get(struct rte_eth_dev *dev,
 				ETH_LINK_SPEED_50G |
 				ETH_LINK_SPEED_100G);
 
+	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_TIMESTAMP;
+
 	return 0;
 }
 
drivers/net/ark/ark_ethdev_rx.c +6 -1
index c24cc00e2f..d29d3db783 100644
@@ -272,7 +272,12 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->port = meta->port;
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
-		mbuf->timestamp = meta->timestamp;
+		/* set timestamp if enabled at least on one device */
+		if (ark_timestamp_rx_dynflag > 0) {
+			*RTE_MBUF_DYNFIELD(mbuf, ark_timestamp_dynfield_offset,
+				rte_mbuf_timestamp_t *) = meta->timestamp;
+			mbuf->ol_flags |= ark_timestamp_rx_dynflag;
+		}
 		rte_pmd_ark_mbuf_rx_userdata_set(mbuf, meta->user_data);
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
drivers/net/ark/ark_ethdev_rx.h +2 -0
index 0fdd29b1ab..001fa9bdfa 100644
@@ -11,6 +11,8 @@
 #include <rte_mempool.h>
 #include <rte_ethdev_driver.h>
 
+extern uint64_t ark_timestamp_rx_dynflag;
+extern int ark_timestamp_dynfield_offset;
 
 int eth_ark_dev_rx_queue_setup(struct rte_eth_dev *dev,
 			       uint16_t queue_idx,
Signature · 1 line
2.28.0
#151 lore raw

PATCH v5 5/16 net/dpaa2: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

---
 drivers/net/dpaa2/dpaa2_ethdev.c | 11 +++++++++++
 drivers/net/dpaa2/dpaa2_ethdev.h |  2 ++
 drivers/net/dpaa2/dpaa2_rxtx.c   | 25 ++++++++++++++++++-------
 3 files changed, 31 insertions(+), 7 deletions(-)
drivers/net/dpaa2/dpaa2_ethdev.c +11 -0
index 04e60c56f2..3b0c7717b6 100644
@@ -65,6 +65,8 @@ static uint64_t dev_tx_offloads_nodis =
 
 /* enable timestamp in mbuf */
 bool dpaa2_enable_ts[RTE_MAX_ETHPORTS];
+uint64_t dpaa2_timestamp_rx_dynflag;
+int dpaa2_timestamp_dynfield_offset = -1;
 
 struct rte_dpaa2_xstats_name_off {
 	char name[RTE_ETH_XSTATS_NAME_SIZE];
@@ -587,7 +589,16 @@ dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
 #if !defined(RTE_LIBRTE_IEEE1588)
 	if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
 #endif
+	{
+		ret = rte_mbuf_dyn_rx_timestamp_register(
+				&dpaa2_timestamp_dynfield_offset,
+				&dpaa2_timestamp_rx_dynflag);
+		if (ret != 0) {
+			DPAA2_PMD_ERR("Error to register timestamp field/flag");
+			return -rte_errno;
+		}
 		dpaa2_enable_ts[dev->data->port_id] = true;
+	}
 
 	if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
 		tx_l3_csum_offload = true;
drivers/net/dpaa2/dpaa2_ethdev.h +2 -0
index 94cf253827..8d82f74684 100644
@@ -92,6 +92,8 @@
 
 /* enable timestamp in mbuf*/
 extern bool dpaa2_enable_ts[];
+extern uint64_t dpaa2_timestamp_rx_dynflag;
+extern int dpaa2_timestamp_dynfield_offset;
 
 #define DPAA2_QOS_TABLE_RECONFIGURE	1
 #define DPAA2_FS_TABLE_RECONFIGURE	2
drivers/net/dpaa2/dpaa2_rxtx.c +18 -7
index 6201de4606..9cca6d16c3 100644
@@ -31,6 +31,13 @@ dpaa2_dev_rx_parse_slow(struct rte_mbuf *mbuf,
 
 static void enable_tx_tstamp(struct qbman_fd *fd) __rte_unused;
 
+static inline rte_mbuf_timestamp_t *
+dpaa2_timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		dpaa2_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 #define DPAA2_MBUF_TO_CONTIG_FD(_mbuf, _fd, _bpid)  do { \
 	DPAA2_SET_FD_ADDR(_fd, DPAA2_MBUF_VADDR_TO_IOVA(_mbuf)); \
 	DPAA2_SET_FD_LEN(_fd, _mbuf->data_len); \
@@ -109,9 +116,10 @@ dpaa2_dev_rx_parse_new(struct rte_mbuf *m, const struct qbman_fd *fd,
 	m->ol_flags |= PKT_RX_RSS_HASH;
 
 	if (dpaa2_enable_ts[m->port]) {
-		m->timestamp = annotation->word2;
-		m->ol_flags |= PKT_RX_TIMESTAMP;
-		DPAA2_PMD_DP_DEBUG("pkt timestamp:0x%" PRIx64 "", m->timestamp);
+		*dpaa2_timestamp_dynfield(m) = annotation->word2;
+		m->ol_flags |= dpaa2_timestamp_rx_dynflag;
+		DPAA2_PMD_DP_DEBUG("pkt timestamp:0x%" PRIx64 "",
+				*dpaa2_timestamp_dynfield(m));
 	}
 
 	DPAA2_PMD_DP_DEBUG("HW frc = 0x%x\t packet type =0x%x "
@@ -223,9 +231,12 @@ dpaa2_dev_rx_parse(struct rte_mbuf *mbuf, void *hw_annot_addr)
 	else if (BIT_ISSET_AT_POS(annotation->word8, DPAA2_ETH_FAS_L4CE))
 		mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD;
 
-	mbuf->ol_flags |= PKT_RX_TIMESTAMP;
-	mbuf->timestamp = annotation->word2;
-	DPAA2_PMD_DP_DEBUG("pkt timestamp: 0x%" PRIx64 "", mbuf->timestamp);
+	if (dpaa2_enable_ts[mbuf->port]) {
+		*dpaa2_timestamp_dynfield(mbuf) = annotation->word2;
+		mbuf->ol_flags |= dpaa2_timestamp_rx_dynflag;
+		DPAA2_PMD_DP_DEBUG("pkt timestamp: 0x%" PRIx64 "",
+				*dpaa2_timestamp_dynfield(mbuf));
+	}
 
 	/* Check detailed parsing requirement */
 	if (annotation->word3 & 0x7FFFFC3FFFF)
@@ -629,7 +640,7 @@ dpaa2_dev_prefetch_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		else
 			bufs[num_rx] = eth_fd_to_mbuf(fd, eth_data->port_id);
 #if defined(RTE_LIBRTE_IEEE1588)
-		priv->rx_timestamp = bufs[num_rx]->timestamp;
+		priv->rx_timestamp = *dpaa2_timestamp_dynfield(bufs[num_rx]);
 #endif
 
 		if (eth_data->dev_conf.rxmode.offloads &
Signature · 1 line
2.28.0
#152 lore raw

PATCH v5 6/16 net/mlx5: fix dynamic mbuf offset lookup check

In reply to Thomas Monjalon

The functions rte_mbuf_dynfield_lookup() and rte_mbuf_dynflag_lookup() can return an offset starting with 0 or a negative error code.

In reality the first offsets are probably reserved forever, but for the sake of strict API compliance,
the checks which considered 0 as an error are fixed.

Fixes efa79e68c8cd ("net/mlx5: support fine grain dynamic flag")
Fixes 3172c471b86f ("net/mlx5: prepare Tx queue structures to support timestamp")
Fixes 0febfcce3693 ("net/mlx5: prepare Tx to support scheduling")
---
 drivers/net/mlx5/mlx5_rxtx.c    | 4 ++--
 drivers/net/mlx5/mlx5_trigger.c | 2 +-
 drivers/net/mlx5/mlx5_txq.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5_rxtx.c +2 -2
index b530ff421f..e86468b67a 100644
@@ -5661,9 +5661,9 @@ mlx5_select_tx_function(struct rte_eth_dev *dev)
 	}
 	if (tx_offloads & DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP &&
 	    rte_mbuf_dynflag_lookup
-			(RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL) > 0 &&
+			(RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL) >= 0 &&
 	    rte_mbuf_dynfield_lookup
-			(RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL) > 0) {
+			(RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL) >= 0) {
 		/* Offload configured, dynamic entities registered. */
 		olx |= MLX5_TXOFF_CONFIG_TXPP;
 	}
drivers/net/mlx5/mlx5_trigger.c +1 -1
index 7735f022a3..917b433c4a 100644
@@ -302,7 +302,7 @@ mlx5_dev_start(struct rte_eth_dev *dev)
 	DRV_LOG(DEBUG, "port %u starting device", dev->data->port_id);
 	fine_inline = rte_mbuf_dynflag_lookup
 		(RTE_PMD_MLX5_FINE_GRANULARITY_INLINE, NULL);
-	if (fine_inline > 0)
+	if (fine_inline >= 0)
 		rte_net_mlx5_dynf_inline_mask = 1UL << fine_inline;
 	else
 		rte_net_mlx5_dynf_inline_mask = 0;
drivers/net/mlx5/mlx5_txq.c +1 -1
index af84f5f72b..8ed2bcff7b 100644
@@ -1305,7 +1305,7 @@ mlx5_txq_dynf_timestamp_set(struct rte_eth_dev *dev)
 				(RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL);
 	off = rte_mbuf_dynfield_lookup
 				(RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
-	if (nbit > 0 && off >= 0 && sh->txpp.refcnt)
+	if (nbit >= 0 && off >= 0 && sh->txpp.refcnt)
 		mask = 1ULL << nbit;
 	for (i = 0; i != priv->txqs_n; ++i) {
 		data = (*priv->txqs)[i];
Signature · 1 line
2.28.0
#153 lore raw

PATCH v5 7/16 net/mlx5: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

The dynamic offset and flag are stored in struct mlx5_rxq_data to favor cache locality.

---
 drivers/net/mlx5/mlx5_rxq.c              |  8 +++++
 drivers/net/mlx5/mlx5_rxtx.c             |  4 +--
 drivers/net/mlx5/mlx5_rxtx.h             | 19 +++++++++++
 drivers/net/mlx5/mlx5_rxtx_vec_altivec.h | 41 +++++++++++-----------
 drivers/net/mlx5/mlx5_rxtx_vec_neon.h    | 43 ++++++++++++------------
 drivers/net/mlx5/mlx5_rxtx_vec_sse.h     | 35 +++++++++----------
 6 files changed, 90 insertions(+), 60 deletions(-)
drivers/net/mlx5/mlx5_rxq.c +8 -0
index f1d8373079..52519910ee 100644
@@ -1492,7 +1492,15 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
 	mlx5_max_lro_msg_size_adjust(dev, idx, max_lro_size);
 	/* Toggle RX checksum offload if hardware supports it. */
 	tmpl->rxq.csum = !!(offloads & DEV_RX_OFFLOAD_CHECKSUM);
+	/* Configure Rx timestamp. */
 	tmpl->rxq.hw_timestamp = !!(offloads & DEV_RX_OFFLOAD_TIMESTAMP);
+	tmpl->rxq.timestamp_rx_flag = 0;
+	if (tmpl->rxq.hw_timestamp && rte_mbuf_dyn_rx_timestamp_register(
+			&tmpl->rxq.timestamp_offset,
+			&tmpl->rxq.timestamp_rx_flag) != 0) {
+		DRV_LOG(ERR, "Cannot register Rx timestamp field/flag");
+		goto error;
+	}
 	/* Configure VLAN stripping. */
 	tmpl->rxq.vlan_strip = !!(offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
 	/* By default, FCS (CRC) is stripped by hardware. */
drivers/net/mlx5/mlx5_rxtx.c +2 -2
index e86468b67a..b577aab00b 100644
@@ -1287,8 +1287,8 @@ rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
 
 		if (rxq->rt_timestamp)
 			ts = mlx5_txpp_convert_rx_ts(rxq->sh, ts);
-		pkt->timestamp = ts;
-		pkt->ol_flags |= PKT_RX_TIMESTAMP;
+		mlx5_timestamp_set(pkt, rxq->timestamp_offset, ts);
+		pkt->ol_flags |= rxq->timestamp_rx_flag;
 	}
 }
 
drivers/net/mlx5/mlx5_rxtx.h +19 -0
index 674296ee98..e9eca36b40 100644
@@ -151,6 +151,8 @@ struct mlx5_rxq_data {
 	/* CQ (UAR) access lock required for 32bit implementations */
 #endif
 	uint32_t tunnel; /* Tunnel information. */
+	int timestamp_offset; /* Dynamic mbuf field for timestamp. */
+	uint64_t timestamp_rx_flag; /* Dynamic mbuf flag for timestamp. */
 	uint64_t flow_meta_mask;
 	int32_t flow_meta_offset;
 } __rte_cache_aligned;
@@ -681,4 +683,21 @@ mlx5_txpp_convert_tx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t mts)
 	return ci;
 }
 
+/**
+ * Set timestamp in mbuf dynamic field.
+ *
+ * @param mbuf
+ *   Structure to write into.
+ * @param offset
+ *   Dynamic field offset in mbuf structure.
+ * @param timestamp
+ *   Value to write.
+ */
+static __rte_always_inline void
+mlx5_timestamp_set(struct rte_mbuf *mbuf, int offset,
+		rte_mbuf_timestamp_t timestamp)
+{
+	*RTE_MBUF_DYNFIELD(mbuf, offset, rte_mbuf_timestamp_t *) = timestamp;
+}
+
 #endif /* RTE_PMD_MLX5_RXTX_H_ */
drivers/net/mlx5/mlx5_rxtx_vec_altivec.h +21 -20

65 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx_vec_neon.h +22 -21

71 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx_vec_sse.h +18 -17
index 0bbcbeefff..ae4439efc7 100644
@@ -251,7 +251,7 @@ rxq_cq_to_ptype_oflags_v(struct mlx5_rxq_data *rxq, __m128i cqes[4],
 	__m128i pinfo0, pinfo1;
 	__m128i pinfo, ptype;
 	__m128i ol_flags = _mm_set1_epi32(rxq->rss_hash * PKT_RX_RSS_HASH |
-					  rxq->hw_timestamp * PKT_RX_TIMESTAMP);
+					  rxq->hw_timestamp * rxq->timestamp_rx_flag);
 	__m128i cv_flags;
 	const __m128i zero = _mm_setzero_si128();
 	const __m128i ptype_mask =
@@ -656,31 +656,32 @@ rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t pkts_n,
 		/* D.5 fill in mbuf - rearm_data and packet_type. */
 		rxq_cq_to_ptype_oflags_v(rxq, cqes, opcode, &pkts[pos]);
 		if (rxq->hw_timestamp) {
+			int offset = rxq->timestamp_offset;
 			if (rxq->rt_timestamp) {
 				struct mlx5_dev_ctx_shared *sh = rxq->sh;
 				uint64_t ts;
 
 				ts = rte_be_to_cpu_64(cq[pos].timestamp);
-				pkts[pos]->timestamp =
-					mlx5_txpp_convert_rx_ts(sh, ts);
+				mlx5_timestamp_set(pkts[pos], offset,
+					mlx5_txpp_convert_rx_ts(sh, ts));
 				ts = rte_be_to_cpu_64(cq[pos + p1].timestamp);
-				pkts[pos + 1]->timestamp =
-					mlx5_txpp_convert_rx_ts(sh, ts);
+				mlx5_timestamp_set(pkts[pos + 1], offset,
+					mlx5_txpp_convert_rx_ts(sh, ts));
 				ts = rte_be_to_cpu_64(cq[pos + p2].timestamp);
-				pkts[pos + 2]->timestamp =
-					mlx5_txpp_convert_rx_ts(sh, ts);
+				mlx5_timestamp_set(pkts[pos + 2], offset,
+					mlx5_txpp_convert_rx_ts(sh, ts));
 				ts = rte_be_to_cpu_64(cq[pos + p3].timestamp);
-				pkts[pos + 3]->timestamp =
-					mlx5_txpp_convert_rx_ts(sh, ts);
+				mlx5_timestamp_set(pkts[pos + 3], offset,
+					mlx5_txpp_convert_rx_ts(sh, ts));
 			} else {
-				pkts[pos]->timestamp = rte_be_to_cpu_64
-						(cq[pos].timestamp);
-				pkts[pos + 1]->timestamp = rte_be_to_cpu_64
-						(cq[pos + p1].timestamp);
-				pkts[pos + 2]->timestamp = rte_be_to_cpu_64
-						(cq[pos + p2].timestamp);
-				pkts[pos + 3]->timestamp = rte_be_to_cpu_64
-						(cq[pos + p3].timestamp);
+				mlx5_timestamp_set(pkts[pos], offset,
+					rte_be_to_cpu_64(cq[pos].timestamp));
+				mlx5_timestamp_set(pkts[pos + 1], offset,
+					rte_be_to_cpu_64(cq[pos + p1].timestamp));
+				mlx5_timestamp_set(pkts[pos + 2], offset,
+					rte_be_to_cpu_64(cq[pos + p2].timestamp));
+				mlx5_timestamp_set(pkts[pos + 3], offset,
+					rte_be_to_cpu_64(cq[pos + p3].timestamp));
 			}
 		}
 		if (rxq->dynf_meta) {
Signature · 1 line
2.28.0
#154 lore raw

PATCH v5 8/16 net/nfb: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

---
 drivers/net/nfb/nfb_rx.c | 15 ++++++++++++++-
 drivers/net/nfb/nfb_rx.h | 21 +++++++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)
drivers/net/nfb/nfb_rx.c +14 -1
index d97179f818..d6d4ba9663 100644
@@ -9,6 +9,9 @@
 #include "nfb_rx.h"
 #include "nfb.h"
 
+uint64_t nfb_timestamp_rx_dynflag;
+int nfb_timestamp_dynfield_offset = -1;
+
 static int
 timestamp_check_handler(__rte_unused const char *key,
 	const char *value, __rte_unused void *opaque)
@@ -24,6 +27,7 @@ static int
 nfb_check_timestamp(struct rte_devargs *devargs)
 {
 	struct rte_kvargs *kvlist;
+	int ret;
 
 	if (devargs == NULL)
 		return 0;
@@ -38,6 +42,7 @@ nfb_check_timestamp(struct rte_devargs *devargs)
 	}
 	/* Timestamps are enabled when there is
 	 * key-value pair: enable_timestamp=1
+	 * TODO: timestamp should be enabled with DEV_RX_OFFLOAD_TIMESTAMP
 	 */
 	if (rte_kvargs_process(kvlist, TIMESTAMP_ARG,
 		timestamp_check_handler, NULL) < 0) {
@@ -46,6 +51,14 @@ nfb_check_timestamp(struct rte_devargs *devargs)
 	}
 	rte_kvargs_free(kvlist);
 
+	ret = rte_mbuf_dyn_rx_timestamp_register(
+			&nfb_timestamp_dynfield_offset,
+			&nfb_timestamp_rx_dynflag);
+	if (ret != 0) {
+		RTE_LOG(ERR, PMD, "Cannot register Rx timestamp field/flag\n");
+		return -rte_errno;
+	}
+
 	return 1;
 }
 
@@ -125,7 +138,7 @@ nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
 	else
 		rte_free(rxq);
 
-	if (nfb_check_timestamp(dev->device->devargs))
+	if (nfb_check_timestamp(dev->device->devargs) > 0)
 		rxq->flags |= NFB_TIMESTAMP_FLAG;
 
 	return ret;
drivers/net/nfb/nfb_rx.h +17 -4
index cf3899b2fb..27a2888a75 100644
@@ -15,6 +15,16 @@
 
 #define NFB_TIMESTAMP_FLAG (1 << 0)
 
+extern uint64_t nfb_timestamp_rx_dynflag;
+extern int nfb_timestamp_dynfield_offset;
+
+static inline rte_mbuf_timestamp_t *
+nfb_timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		nfb_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 struct ndp_rx_queue {
 	struct nfb_device *nfb;	     /* nfb dev structure */
 	struct ndp_queue *queue;     /* rx queue */
@@ -190,16 +200,19 @@ nfb_eth_ndp_rx(void *queue,
 			mbuf->ol_flags = 0;
 
 			if (timestamping_enabled) {
+				rte_mbuf_timestamp_t timestamp;
+
 				/* nanoseconds */
-				mbuf->timestamp =
+				timestamp =
 					rte_le_to_cpu_32(*((uint32_t *)
 					(packets[i].header + 4)));
-				mbuf->timestamp <<= 32;
+				timestamp <<= 32;
 				/* seconds */
-				mbuf->timestamp |=
+				timestamp |=
 					rte_le_to_cpu_32(*((uint32_t *)
 					(packets[i].header + 8)));
-				mbuf->ol_flags |= PKT_RX_TIMESTAMP;
+				*nfb_timestamp_dynfield(mbuf) = timestamp;
+				mbuf->ol_flags |= nfb_timestamp_rx_dynflag;
 			}
 
 			bufs[num_rx++] = mbuf;
Signature · 1 line
2.28.0
#155 lore raw

PATCH v5 9/16 net/octeontx2: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

The registration of field and flag is done in both otx2_nix_dev_start() and otx2_nix_timesync_enable().

The dynamic offset and flag are stored in struct otx2_timesync_info to favor cache locality.

---
 drivers/net/octeontx2/otx2_ethdev.c | 10 ++++++++++
 drivers/net/octeontx2/otx2_ptp.c    |  8 ++++++++
 drivers/net/octeontx2/otx2_rx.h     | 19 ++++++++++++++++---
 3 files changed, 34 insertions(+), 3 deletions(-)
drivers/net/octeontx2/otx2_ethdev.c +10 -0
index cfb733a4b5..6cebbe677d 100644
@@ -2225,6 +2225,16 @@ otx2_nix_dev_start(struct rte_eth_dev *eth_dev)
 	if (otx2_ethdev_is_ptp_en(dev) && otx2_dev_is_vf(dev))
 		otx2_nix_ptp_enable_vf(eth_dev);
 
+	if (dev->rx_offload_flags & NIX_RX_OFFLOAD_TSTAMP_F) {
+		rc = rte_mbuf_dyn_rx_timestamp_register(
+				&dev->tstamp.tstamp_dynfield_offset,
+				&dev->tstamp.rx_tstamp_dynflag);
+		if (rc != 0) {
+			otx2_err("Failed to register Rx timestamp field/flag");
+			return -rte_errno;
+		}
+	}
+
 	rc = npc_rx_enable(dev);
 	if (rc) {
 		otx2_err("Failed to enable NPC rx %d", rc);
drivers/net/octeontx2/otx2_ptp.c +8 -0
index ae5a2b7cd1..b8ef4c181d 100644
@@ -239,6 +239,14 @@ otx2_nix_timesync_enable(struct rte_eth_dev *eth_dev)
 	dev->tstamp.tx_tstamp_iova = ts->iova;
 	dev->tstamp.tx_tstamp = ts->addr;
 
+	rc = rte_mbuf_dyn_rx_timestamp_register(
+			&dev->tstamp.tstamp_dynfield_offset,
+			&dev->tstamp.rx_tstamp_dynflag);
+	if (rc != 0) {
+		otx2_err("Failed to register Rx timestamp field/flag");
+		return -rte_errno;
+	}
+
 	/* System time should be already on by default */
 	nix_start_timecounters(eth_dev);
 
drivers/net/octeontx2/otx2_rx.h +16 -3
index 61a5c436dd..926f614a4e 100644
@@ -49,6 +49,8 @@ struct otx2_timesync_info {
 	uint64_t	rx_tstamp;
 	rte_iova_t	tx_tstamp_iova;
 	uint64_t	*tx_tstamp;
+	uint64_t	rx_tstamp_dynflag;
+	int		tstamp_dynfield_offset;
 	uint8_t		tx_ready;
 	uint8_t		rx_ready;
 } __rte_cache_aligned;
@@ -63,6 +65,14 @@ union mbuf_initializer {
 	uint64_t value;
 };
 
+static inline rte_mbuf_timestamp_t *
+otx2_timestamp_dynfield(struct rte_mbuf *mbuf,
+		struct otx2_timesync_info *info)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		info->tstamp_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 +87,18 @@ 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, tstamp) =
+				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);
 			tstamp->rx_ready = 1;
 			mbuf->ol_flags |= PKT_RX_IEEE1588_PTP |
-				PKT_RX_IEEE1588_TMST | PKT_RX_TIMESTAMP;
+				PKT_RX_IEEE1588_TMST |
+				tstamp->rx_tstamp_dynflag;
 		}
 	}
 }
Signature · 1 line
2.28.0
#156 lore raw

PATCH v5 10/16 net/pcap: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

---
 drivers/net/pcap/rte_eth_pcap.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/net/pcap/rte_eth_pcap.c +17 -3
index 34e82317b1..4e6d49370e 100644
@@ -51,6 +51,9 @@ static uint64_t start_cycles;
 static uint64_t hz;
 static uint8_t iface_idx;
 
+static uint64_t timestamp_rx_dynflag;
+static int timestamp_dynfield_offset = -1;
+
 struct queue_stat {
 	volatile unsigned long pkts;
 	volatile unsigned long bytes;
@@ -265,9 +268,11 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 
 		mbuf->pkt_len = (uint16_t)header.caplen;
-		mbuf->timestamp = (uint64_t)header.ts.tv_sec * 1000000
-							+ header.ts.tv_usec;
-		mbuf->ol_flags |= PKT_RX_TIMESTAMP;
+		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset,
+			rte_mbuf_timestamp_t *) =
+				(uint64_t)header.ts.tv_sec * 1000000 +
+				header.ts.tv_usec;
+		mbuf->ol_flags |= timestamp_rx_dynflag;
 		mbuf->port = pcap_q->port_id;
 		bufs[num_rx] = mbuf;
 		num_rx++;
@@ -656,6 +661,15 @@ eth_dev_stop(struct rte_eth_dev *dev)
 static int
 eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
 {
+	int ret;
+
+	ret = rte_mbuf_dyn_rx_timestamp_register(&timestamp_dynfield_offset,
+			&timestamp_rx_dynflag);
+	if (ret != 0) {
+		PMD_LOG(ERR, "Failed to register Rx timestamp field/flag");
+		return -rte_errno;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.28.0
#157 lore raw

PATCH v5 11/16 app/testpmd: switch Rx timestamp to dynamic mbuf field

In reply to Thomas Monjalon

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.

---
 app/test-pmd/util.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
app/test-pmd/util.c +36 -2
index 781a813759..649bf8f53a 100644
@@ -5,6 +5,7 @@
 
 #include <stdio.h>
 
+#include <rte_bitops.h>
 #include <rte_net.h>
 #include <rte_mbuf.h>
 #include <rte_ether.h>
@@ -22,6 +23,39 @@ print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
 	printf("%s%s", what, buf);
 }
 
+static inline bool
+is_timestamp_enabled(const struct rte_mbuf *mbuf)
+{
+	static uint64_t timestamp_rx_dynflag;
+	int timestamp_rx_dynflag_offset;
+
+	if (timestamp_rx_dynflag == 0) {
+		timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
+				RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
+		if (timestamp_rx_dynflag_offset < 0)
+			return false;
+		timestamp_rx_dynflag = RTE_BIT64(timestamp_rx_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & timestamp_rx_dynflag) != 0;
+}
+
+static inline rte_mbuf_timestamp_t
+get_timestamp(const struct rte_mbuf *mbuf)
+{
+	static int timestamp_dynfield_offset = -1;
+
+	if (timestamp_dynfield_offset < 0) {
+		timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+		if (timestamp_dynfield_offset < 0)
+			return 0;
+	}
+
+	return *RTE_MBUF_DYNFIELD(mbuf,
+			timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 static inline void
 dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	      uint16_t nb_pkts, int is_rx)
@@ -107,8 +141,8 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 				printf("hash=0x%x ID=0x%x ",
 				       mb->hash.fdir.hash, mb->hash.fdir.id);
 		}
-		if (ol_flags & PKT_RX_TIMESTAMP)
-			printf(" - timestamp %"PRIu64" ", mb->timestamp);
+		if (is_timestamp_enabled(mb))
+			printf(" - timestamp %"PRIu64" ", get_timestamp(mb));
 		if (ol_flags & PKT_RX_QINQ)
 			printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
 			       mb->vlan_tci, mb->vlan_tci_outer);
Signature · 1 line
2.28.0
#158 lore raw

PATCH v5 12/16 examples/rxtx_callbacks: switch timestamp to dynamic field

In reply to Thomas Monjalon

The mbuf timestamp is moved to a dynamic field in order to allow removal of the deprecated static field.

---
 examples/rxtx_callbacks/main.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
examples/rxtx_callbacks/main.c +15 -1
index 1a8e7d47d9..35c6c39807 100644
@@ -19,6 +19,15 @@
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+static int hwts_dynfield_offset = -1;
+
+static inline rte_mbuf_timestamp_t *
+hwts_field(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+			hwts_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 typedef uint64_t tsc_t;
 static int tsc_dynfield_offset = -1;
 
@@ -77,7 +86,7 @@ calc_latency(uint16_t port, uint16_t qidx __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		cycles += now - *tsc_field(pkts[i]);
 		if (hw_timestamping)
-			queue_ticks += ticks - pkts[i]->timestamp;
+			queue_ticks += ticks - *hwts_field(pkts[i]);
 	}
 
 	latency_numbers.total_cycles += cycles;
@@ -141,6 +150,11 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
 			return -1;
 		}
 		port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
+		rte_mbuf_dyn_rx_timestamp_register(&hwts_dynfield_offset, NULL);
+		if (hwts_dynfield_offset < 0) {
+			printf("ERROR: Failed to register timestamp field\n");
+			return -rte_errno;
+		}
 	}
 
 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
Signature · 1 line
2.28.0
#159 lore raw

PATCH v5 13/16 ethdev: add doxygen comment for Rx timestamp API

In reply to Thomas Monjalon

The offload flag DEV_RX_OFFLOAD_TIMESTAMP had no documentation. After switching to dynamic mbuf flag and field,
it becomes even more important to explicit the feature behaviour.

A doxygen comment for the timesync API was mentioning the deprecated timestamp field, so it is also updated.

---
 lib/librte_ethdev/rte_ethdev.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_ethdev/rte_ethdev.h +6 -1
index e341a08817..4988054cb2 100644
@@ -1344,6 +1344,11 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
+/**
+ * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+ * and RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME is set in ol_flags.
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_RX_OFFLOAD_TIMESTAMP	0x00004000
 #define DEV_RX_OFFLOAD_SECURITY         0x00008000
 #define DEV_RX_OFFLOAD_KEEP_CRC		0x00010000
@@ -4646,7 +4651,7 @@ int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *time);
  * rte_eth_read_clock(port, base_clock);
  *
  * Then, convert the raw mbuf timestamp with:
- * base_time_sec + (double)(mbuf->timestamp - base_clock) / freq;
+ * base_time_sec + (double)(*timestamp_dynfield(mbuf) - base_clock) / freq;
  *
  * This simple example will not provide a very good accuracy. One must
  * at least measure multiple times the frequency and do a regression.
Signature · 1 line
2.28.0
Acked-by on v5 13/16
#160 lore raw

Re: [dpdk-dev] [PATCH v5 13/16] ethdev: add doxygen comment for Rx timestamp API

Quoted 11 lines · Thomas Monjalon

The offload flag DEV_RX_OFFLOAD_TIMESTAMP had no documentation. After switching to dynamic mbuf flag and field,
it becomes even more important to explicit the feature behaviour.

A doxygen comment for the timesync API was mentioning the deprecated timestamp field, so it is also updated.

Quoted 32 lines
---
 lib/librte_ethdev/rte_ethdev.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_ethdev/rte_ethdev.h +6 -2
index e341a08817..4988054cb2 100644
@@ -1344,6 +1344,11 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_EXTEND     0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME     0x00000800
 #define DEV_RX_OFFLOAD_SCATTER         0x00002000
+/**
+ * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+ * and RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME is set in ol_flags.
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_RX_OFFLOAD_TIMESTAMP       0x00004000
 #define DEV_RX_OFFLOAD_SECURITY         0x00008000
 #define DEV_RX_OFFLOAD_KEEP_CRC                0x00010000
@@ -4646,7 +4651,7 @@ int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *time);
  * rte_eth_read_clock(port, base_clock);
  *
  * Then, convert the raw mbuf timestamp with:
- * base_time_sec + (double)(mbuf->timestamp - base_clock) / freq;
+ * base_time_sec + (double)(*timestamp_dynfield(mbuf) - base_clock) / freq;
  *
  * This simple example will not provide a very good accuracy. One must
  * at least measure multiple times the frequency and do a regression.
--

2.28.0

#161 lore raw

PATCH v5 14/16 mbuf: remove deprecated timestamp field

In reply to Thomas Monjalon

As announced in the deprecation note, the field timestamp is removed to give more space to the dynamic fields. The related offload flag PKT_RX_TIMESTAMP is also removed.

This is how the mbuf layout looks like (pahole-style):

word  type                              name                byte  size
 0    void *                            buf_addr;         /*   0 +  8 */
 1    rte_iova_t                        buf_iova          /*   8 +  8 */
      /* --- RTE_MARKER64               rearm_data;                   */
 2    uint16_t                          data_off;         /*  16 +  2 */
      uint16_t                          refcnt;           /*  18 +  2 */
      uint16_t                          nb_segs;          /*  20 +  2 */
      uint16_t                          port;             /*  22 +  2 */
 3    uint64_t                          ol_flags;         /*  24 +  8 */
      /* --- RTE_MARKER                 rx_descriptor_fields1;        */
 4    uint32_t             union        packet_type;      /*  32 +  4 */
      uint32_t                          pkt_len;          /*  36 +  4 */
 5    uint16_t                          data_len;         /*  40 +  2 */
      uint16_t                          vlan_tci;         /*  42 +  2 */
 5.5  uint64_t             union        hash;             /*  44 +  8 */
 6.5  uint16_t                          vlan_tci_outer;   /*  52 +  2 */
      uint16_t                          buf_len;          /*  54 +  2 */
 7    uint64_t                          dynfield0[1];     /*  56 +  8 */
      /* --- RTE_MARKER                 cacheline1;                   */
 8    struct rte_mempool *              pool;             /*  64 +  8 */
 9    struct rte_mbuf *                 next;             /*  72 +  8 */
10    uint64_t             union        tx_offload;       /*  80 +  8 */
11    struct rte_mbuf_ext_shared_info * shinfo;           /*  88 +  8 */
12    uint16_t                          priv_size;        /*  96 +  2 */
      uint16_t                          timesync;         /*  98 +  2 */
12.5  uint32_t                          dynfield1[7];     /* 100 + 28 */

16 /* --- END 128 */

---
 app/test/test_mbuf.c                   |  1 -
 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_20_11.rst |  4 ++++
 lib/librte_mbuf/rte_mbuf.c             |  2 --
 lib/librte_mbuf/rte_mbuf.h             |  2 +-
 lib/librte_mbuf/rte_mbuf_core.h        | 12 ++----------
 lib/librte_mbuf/rte_mbuf_dyn.c         |  1 +
 7 files changed, 8 insertions(+), 18 deletions(-)
app/test/test_mbuf.c +0 -1
index 3a13cf4e1f..a40f7d4883 100644
@@ -1621,7 +1621,6 @@ test_get_rx_ol_flag_name(void)
 		VAL_NAME(PKT_RX_FDIR_FLX),
 		VAL_NAME(PKT_RX_QINQ_STRIPPED),
 		VAL_NAME(PKT_RX_LRO),
-		VAL_NAME(PKT_RX_TIMESTAMP),
 		VAL_NAME(PKT_RX_SEC_OFFLOAD),
 		VAL_NAME(PKT_RX_SEC_OFFLOAD_FAILED),
 		VAL_NAME(PKT_RX_OUTER_L4_CKSUM_BAD),
doc/guides/rel_notes/deprecation.rst +0 -4
index fe3fd3956c..22aecf0bab 100644
@@ -84,10 +84,6 @@ Deprecation Notices
 * mbuf: Some fields will be converted to dynamic API in DPDK 20.11
   in order to reserve more space for the dynamic fields, as explained in
   `this presentation <https://www.youtube.com/watch?v=Ttl6MlhmzWY>`_.
-  The following static fields will be moved as dynamic:
-
-  - ``timestamp``
-
   As a consequence, the layout of the ``struct rte_mbuf`` will be re-arranged,
   avoiding impact on vectorized implementation of the driver datapaths,
   while evaluating performance gains of a better use of the first cache line.
doc/guides/rel_notes/release_20_11.rst +4 -0
index f1a6925678..7c8246d1b3 100644
@@ -458,6 +458,10 @@ API Changes
 * mbuf: Removed the field ``seqn`` from the structure ``rte_mbuf``.
   It is replaced with dynamic fields.
 
+* mbuf: Removed the field ``timestamp`` from the structure ``rte_mbuf``.
+  It is replaced with the dynamic field RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+  which was previously used only for Tx.
+
 * pci: Removed the ``rte_kernel_driver`` enum defined in rte_dev.h and
   replaced with a private enum in the PCI subsystem.
 
lib/librte_mbuf/rte_mbuf.c +0 -2
index 8a456e5e64..09d93e6899 100644
@@ -764,7 +764,6 @@ const char *rte_get_rx_ol_flag_name(uint64_t mask)
 	case PKT_RX_QINQ_STRIPPED: return "PKT_RX_QINQ_STRIPPED";
 	case PKT_RX_QINQ: return "PKT_RX_QINQ";
 	case PKT_RX_LRO: return "PKT_RX_LRO";
-	case PKT_RX_TIMESTAMP: return "PKT_RX_TIMESTAMP";
 	case PKT_RX_SEC_OFFLOAD: return "PKT_RX_SEC_OFFLOAD";
 	case PKT_RX_SEC_OFFLOAD_FAILED: return "PKT_RX_SEC_OFFLOAD_FAILED";
 	case PKT_RX_OUTER_L4_CKSUM_BAD: return "PKT_RX_OUTER_L4_CKSUM_BAD";
@@ -808,7 +807,6 @@ rte_get_rx_ol_flag_list(uint64_t mask, char *buf, size_t buflen)
 		{ PKT_RX_FDIR_FLX, PKT_RX_FDIR_FLX, NULL },
 		{ PKT_RX_QINQ_STRIPPED, PKT_RX_QINQ_STRIPPED, NULL },
 		{ PKT_RX_LRO, PKT_RX_LRO, NULL },
-		{ PKT_RX_TIMESTAMP, PKT_RX_TIMESTAMP, NULL },
 		{ PKT_RX_SEC_OFFLOAD, PKT_RX_SEC_OFFLOAD, NULL },
 		{ PKT_RX_SEC_OFFLOAD_FAILED, PKT_RX_SEC_OFFLOAD_FAILED, NULL },
 		{ PKT_RX_QINQ, PKT_RX_QINQ, NULL },
lib/librte_mbuf/rte_mbuf.h +1 -1
index a1414ed7cd..17e0b205c0 100644
@@ -1095,6 +1095,7 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
 static inline void
 rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
 {
+	memcpy(&mdst->dynfield0, msrc->dynfield0, sizeof(mdst->dynfield0));
 	memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst->dynfield1));
 }
 
@@ -1108,7 +1109,6 @@ __rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
 	mdst->tx_offload = msrc->tx_offload;
 	mdst->hash = msrc->hash;
 	mdst->packet_type = msrc->packet_type;
-	mdst->timestamp = msrc->timestamp;
 	rte_mbuf_dynfield_copy(mdst, msrc);
 }
 
lib/librte_mbuf/rte_mbuf_core.h +2 -10
index 3fb5abda3c..38e24a580d 100644
@@ -149,10 +149,7 @@ extern "C" {
  */
 #define PKT_RX_LRO           (1ULL << 16)
 
-/**
- * Indicate that the timestamp field in the mbuf is valid.
- */
-#define PKT_RX_TIMESTAMP     (1ULL << 17)
+/* There is no flag defined at offset 17. It is free for any future use. */
 
 /**
  * Indicate that security offload processing was applied on the RX packet.
@@ -589,12 +586,7 @@ struct rte_mbuf {
 
 	uint16_t buf_len;         /**< Length of segment buffer. */
 
-	/** Valid if PKT_RX_TIMESTAMP is set. The unit and time reference
-	 * are not normalized but are always the same for a given port.
-	 * Some devices allow to query rte_eth_read_clock that will return the
-	 * current device timestamp.
-	 */
-	uint64_t timestamp;
+	uint64_t dynfield0[1]; /**< Reserved for dynamic fields. */
 
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
lib/librte_mbuf/rte_mbuf_dyn.c +1 -0
index 5b608a27d7..4f50da09f3 100644
@@ -125,6 +125,7 @@ init_shared_mem(void)
 		 * rte_mbuf_dynfield_copy().
 		 */
 		memset(shm, 0, sizeof(*shm));
+		mark_free(dynfield0);
 		mark_free(dynfield1);
 
 		/* init free_flags */
Signature · 1 line
2.28.0
#162 lore raw

PATCH v5 15/16 mbuf: add Tx timestamp registration helper

In reply to Thomas Monjalon

The function rte_mbuf_dyn_tx_timestamp_register() can be used to register the required field and flag.

---
 lib/librte_mbuf/rte_mbuf_dyn.c |  7 +++++++
 lib/librte_mbuf/rte_mbuf_dyn.h | 22 ++++++++++++++++++++++
 lib/librte_mbuf/version.map    |  1 +
 3 files changed, 30 insertions(+)
lib/librte_mbuf/rte_mbuf_dyn.c +7 -0
index 4f50da09f3..101b5bd95f 100644
@@ -613,3 +613,10 @@ rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag)
 	return rte_mbuf_dyn_timestamp_register(field_offset, rx_flag,
 			"Rx", RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME);
 }
+
+int
+rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag)
+{
+	return rte_mbuf_dyn_timestamp_register(field_offset, tx_flag,
+			"Tx", RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME);
+}
lib/librte_mbuf/rte_mbuf_dyn.h +22 -0
index 2e729ddaca..d88e7bacc5 100644
@@ -304,4 +304,26 @@ int rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag);
  */
 #define RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME "rte_dynflag_tx_timestamp"
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Register dynamic mbuf field and flag for Tx timestamp.
+ *
+ * @param field_offset
+ *   Pointer to the offset of the registered mbuf field, can be NULL.
+ *   The same field is shared for Rx and Tx timestamp.
+ * @param tx_flag
+ *   Pointer to the mask of the registered offload flag, can be NULL.
+ * @return
+ *   0 on success, -1 otherwise.
+ *   Possible values for rte_errno:
+ *   - EEXIST: already registered with different parameters.
+ *   - EPERM: called from a secondary process.
+ *   - ENOENT: no more field or flag available.
+ *   - ENOMEM: allocation failure.
+ */
+__rte_experimental
+int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);
+
 #endif
lib/librte_mbuf/version.map +1 -0
index 0b66668bff..b7d98e7eb1 100644
@@ -43,6 +43,7 @@ EXPERIMENTAL {
 	rte_mbuf_dynflag_register_bitnum;
 	rte_mbuf_dyn_dump;
 	rte_mbuf_dyn_rx_timestamp_register;
+	rte_mbuf_dyn_tx_timestamp_register;
 	rte_pktmbuf_copy;
 	rte_pktmbuf_free_bulk;
 	rte_pktmbuf_pool_create_extbuf;
Signature · 1 line
2.28.0
#163 lore raw

PATCH v5 16/16 ethdev: include mbuf registration in Tx timestamp API

In reply to Thomas Monjalon

Previously, the Tx timestamp field and flag were registered in testpmd, as described in mlx5 guide.
For consistency between Rx and Tx timestamps,
managing mbuf registrations inside the driver, as properly documented, is a simpler expectation.

The only driver to support this feature (mlx5) is updated as well as the testpmd application.

---
 app/test-pmd/config.c          | 38 ----------------------------------
 doc/guides/nics/mlx5.rst       |  5 ++---
 drivers/net/mlx5/mlx5_ethdev.c |  8 ++++++-
 lib/librte_ethdev/rte_ethdev.h |  7 +++++--
 4 files changed, 14 insertions(+), 44 deletions(-)
app/test-pmd/config.c +0 -38
index 1668ae3238..9a2baf16fe 100644
@@ -3955,44 +3955,6 @@ show_tx_pkt_times(void)
 void
 set_tx_pkt_times(unsigned int *tx_times)
 {
-	uint16_t port_id;
-	int offload_found = 0;
-	int offset;
-	int flag;
-
-	static const struct rte_mbuf_dynfield desc_offs = {
-		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
-		.size = sizeof(uint64_t),
-		.align = __alignof__(uint64_t),
-	};
-	static const struct rte_mbuf_dynflag desc_flag = {
-		.name = RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME,
-	};
-
-	RTE_ETH_FOREACH_DEV(port_id) {
-		struct rte_eth_dev_info dev_info = { 0 };
-		int ret;
-
-		ret = rte_eth_dev_info_get(port_id, &dev_info);
-		if (ret == 0 && dev_info.tx_offload_capa &
-				DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
-			offload_found = 1;
-			break;
-		}
-	}
-	if (!offload_found) {
-		printf("No device supporting Tx timestamp scheduling found, "
-		       "dynamic flag and field not registered\n");
-		return;
-	}
-	offset = rte_mbuf_dynfield_register(&desc_offs);
-	if (offset < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp field registration error: %d",
-		       rte_errno);
-	flag = rte_mbuf_dynflag_register(&desc_flag);
-	if (flag < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp flag registration error: %d",
-		       rte_errno);
 	tx_pkt_times_inter = tx_times[0];
 	tx_pkt_times_intra = tx_times[1];
 }
doc/guides/nics/mlx5.rst +2 -3
index afa65a1379..fa8b13dd1b 100644
@@ -237,9 +237,8 @@ Limitations
   ``txq_inline_max`` and ``txq_inline_mpw`` devargs keys.
 
 - To provide the packet send scheduling on mbuf timestamps the ``tx_pp``
-  parameter should be specified, RTE_MBUF_DYNFIELD_TIMESTAMP_NAME and
-  RTE_MBUF_DYNFLAG_TIMESTAMP_NAME should be registered by application.
-  When PMD sees the RTE_MBUF_DYNFLAG_TIMESTAMP_NAME set on the packet
+  parameter should be specified.
+  When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME set on the packet
   being sent it tries to synchronize the time of packet appearing on
   the wire with the specified packet timestamp. It the specified one
   is in the past it should be ignored, if one is in the distant future
drivers/net/mlx5/mlx5_ethdev.c +7 -1
index 7631f644b2..76ef02664f 100644
@@ -88,7 +88,13 @@ mlx5_dev_configure(struct rte_eth_dev *dev)
 
 	if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
 		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
-
+	if ((dev->data->dev_conf.txmode.offloads &
+			DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) &&
+			rte_mbuf_dyn_tx_timestamp_register(NULL, NULL) != 0) {
+		DRV_LOG(ERR, "port %u cannot register Tx timestamp field/flag",
+			dev->data->port_id);
+		return -rte_errno;
+	}
 	memcpy(priv->rss_conf.rss_key,
 	       use_app_rss_key ?
 	       dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key :
lib/librte_ethdev/rte_ethdev.h +5 -2
index 4988054cb2..f689550745 100644
@@ -1413,8 +1413,11 @@ struct rte_eth_conf {
 #define DEV_TX_OFFLOAD_IP_TNL_TSO       0x00080000
 /** Device supports outer UDP checksum */
 #define DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  0x00100000
-
-/** Device supports send on timestamp */
+/**
+ * Device sends on time read from RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+ * if RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME is set in ol_flags.
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP 0x00200000
 
 
Signature · 1 line
2.28.0
Acked-by on the v5 series
#164 lore raw
In reply to Thomas Monjalon
Quoted 95 lines · Thomas Monjalon

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

As a consequence, 8 bytes can be re-allocated to dynamic fields in the first half of mbuf structure.
It is still open to change more the mbuf layout.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year,
and can allow performance improvements with new usages in the first half.

v5:
- add a blank line between different kind of ARK variables
- move registration after octeontx2 VF config
- register also in otx2_nix_timesync_enable

v4:
- use local variable in nfb
- fix flag initialization
- remove useless blank line

v3:
- move ark variables declaration in a .h file
- improve cache locality for octeontx2
- add comments about cache locality in commit logs
- add comment for unused flag offset 17
- add timestamp register functions
- replace lookup with register in drivers and apps
- remove register in ethdev

v2:
- remove optimization to register only once in ethdev
- fix error message in latencystats
- convert rxtx_callbacks macro to inline function
- increase dynamic fields space
- do not move pool field

Thomas Monjalon (16):
eventdev: remove software Rx timestamp
mbuf: add Rx timestamp flag and helpers
latency: switch Rx timestamp to dynamic mbuf field net/ark: switch Rx timestamp to dynamic mbuf field net/dpaa2: switch Rx timestamp to dynamic mbuf field net/mlx5: fix dynamic mbuf offset lookup check net/mlx5: switch Rx timestamp to dynamic mbuf field net/nfb: switch Rx timestamp to dynamic mbuf field net/octeontx2: switch Rx timestamp to dynamic mbuf field net/pcap: switch Rx timestamp to dynamic mbuf field app/testpmd: switch Rx timestamp to dynamic mbuf field examples/rxtx_callbacks: switch timestamp to dynamic field
ethdev: add doxygen comment for Rx timestamp API
mbuf: remove deprecated timestamp field
mbuf: add Tx timestamp registration helper
ethdev: include mbuf registration in Tx timestamp API

 app/test-pmd/config.c                         | 38 -------------
 app/test-pmd/util.c                           | 38 ++++++++++++-
 app/test/test_mbuf.c                          |  1 -
 doc/guides/nics/mlx5.rst                      |  5 +-
 .../prog_guide/event_ethernet_rx_adapter.rst  |  6 +-
 doc/guides/rel_notes/deprecation.rst          |  4 --
 doc/guides/rel_notes/release_20_11.rst        |  4 ++
 drivers/net/ark/ark_ethdev.c                  | 17 ++++++
 drivers/net/ark/ark_ethdev_rx.c               |  7 ++-
 drivers/net/ark/ark_ethdev_rx.h               |  2 +
 drivers/net/dpaa2/dpaa2_ethdev.c              | 11 ++++
 drivers/net/dpaa2/dpaa2_ethdev.h              |  2 +
 drivers/net/dpaa2/dpaa2_rxtx.c                | 25 ++++++---
 drivers/net/mlx5/mlx5_ethdev.c                |  8 ++-
 drivers/net/mlx5/mlx5_rxq.c                   |  8 +++
 drivers/net/mlx5/mlx5_rxtx.c                  |  8 +--
 drivers/net/mlx5/mlx5_rxtx.h                  | 19 +++++++
 drivers/net/mlx5/mlx5_rxtx_vec_altivec.h      | 41 +++++++-------
 drivers/net/mlx5/mlx5_rxtx_vec_neon.h         | 43 ++++++++-------
 drivers/net/mlx5/mlx5_rxtx_vec_sse.h          | 35 ++++++------
 drivers/net/mlx5/mlx5_trigger.c               |  2 +-
 drivers/net/mlx5/mlx5_txq.c                   |  2 +-
 drivers/net/nfb/nfb_rx.c                      | 15 ++++-
 drivers/net/nfb/nfb_rx.h                      | 21 +++++--
 drivers/net/octeontx2/otx2_ethdev.c           | 10 ++++
 drivers/net/octeontx2/otx2_ptp.c              |  8 +++
 drivers/net/octeontx2/otx2_rx.h               | 19 ++++++-
 drivers/net/pcap/rte_eth_pcap.c               | 20 ++++++-
 examples/rxtx_callbacks/main.c                | 16 +++++-
 lib/librte_ethdev/rte_ethdev.h                | 14 ++++-
 .../rte_event_eth_rx_adapter.c                | 11 ----
 .../rte_event_eth_rx_adapter.h                |  6 +-
Quoted 12 lines
 lib/librte_latencystats/rte_latencystats.c    | 30 ++++++++--
 lib/librte_mbuf/rte_mbuf.c                    |  2 -
 lib/librte_mbuf/rte_mbuf.h                    |  2 +-
 lib/librte_mbuf/rte_mbuf_core.h               | 12 +---
 lib/librte_mbuf/rte_mbuf_dyn.c                | 51 +++++++++++++++++
 lib/librte_mbuf/rte_mbuf_dyn.h                | 55 +++++++++++++++++--
 lib/librte_mbuf/version.map                   |  2 +
 39 files changed, 440 insertions(+), 180 deletions(-)
Signature · 1 line
2.28.0

For the series:

author Applied
#165 lore raw

03/11/2020 15:17, Olivier Matz:

Quoted 17 lines · Thomas Monjalon
Quoted 16 lines

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

As a consequence, 8 bytes can be re-allocated to dynamic fields in the first half of mbuf structure.
It is still open to change more the mbuf layout.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year,
and can allow performance improvements with new usages in the first half.

[...]

Quoted 4 lines
Quoted 1 line
 39 files changed, 440 insertions(+), 180 deletions(-)

For the series:

Applied, thanks for the help Olivier, David and Andrew.

Next step: decide whether we keep "free space" in the first half for dynamic fields or move another field from the second half.

#166 lore raw
In reply to Thomas Monjalon
Quoted 8 lines · On Tue, 3 Nov 2020 15:09:15 +0100 Thomas Monjalon <[email protected]> wrote:

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

There should be a place in documentation which describes all the dynamic fields and their meaning. For example, which drivers/features set the field and the exact meaning. Is the timestamp in HW units, UTC units, or TSC ticks?

#167 lore raw

03/11/2020 17:08, Stephen Hemminger:

Quoted 8 lines
Quoted 5 lines · On Tue, 3 Nov 2020 15:09:15 +0100 Thomas Monjalon <[email protected]> wrote:

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

Quoted 7 lines
Quoted 3 lines

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

There should be a place in documentation which describes all the dynamic fields and their meaning. For example, which drivers/features set the field and the exact meaning.

A dynamic field can be registered by anyone, including the apps. So you will never get a full list.
The meaning of each field should be defined in its context (driver, lib or app).

Quoted 1 line

Is the timestamp in HW units, UTC units, or TSC ticks?

The timestamp unit is driver-specific.
It is explained in ethdev API:
http://doc.dpdk.org/api/rte__ethdev_8h.html#a4346bf07a0d302c9ba4fe06baffd3196

#168 lore raw
Quoted 22 lines · On Tue, 03 Nov 2020 17:20:20 +0100 Thomas Monjalon <[email protected]> wrote:

03/11/2020 17:08, Stephen Hemminger:

Quoted 8 lines
Quoted 5 lines · On Tue, 3 Nov 2020 15:09:15 +0100 Thomas Monjalon <[email protected]> wrote:

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

Quoted 7 lines
Quoted 3 lines

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

There should be a place in documentation which describes all the dynamic fields and their meaning. For example, which drivers/features set the field and the exact meaning.

A dynamic field can be registered by anyone, including the apps. So you will never get a full list.
The meaning of each field should be defined in its context (driver, lib or app).

Quoted 5 lines
Quoted 1 line

Is the timestamp in HW units, UTC units, or TSC ticks?

The timestamp unit is driver-specific.
It is explained in ethdev API:
http://doc.dpdk.org/api/rte__ethdev_8h.html#a4346bf07a0d302c9ba4fe06baffd3196

Are there are any conventions we should use in this area? There could be overlapping usage between subsystems?

#169 lore raw

03/11/2020 18:42, Stephen Hemminger:

Quoted 26 lines
Quoted 24 lines · On Tue, 03 Nov 2020 17:20:20 +0100 Thomas Monjalon <[email protected]> wrote:

03/11/2020 17:08, Stephen Hemminger:

Quoted 8 lines
Quoted 5 lines · On Tue, 3 Nov 2020 15:09:15 +0100 Thomas Monjalon <[email protected]> wrote:

The mbuf field timestamp was announced to be removed for three reasons:
- a dynamic field already exist, used for Tx only
- this field always used 8 bytes even if unneeded
- this field is in the first half (cacheline) of mbuf

Quoted 7 lines
Quoted 3 lines

After this series, the dynamic field timestamp is used for both Rx and Tx with separate dynamic flags to distinguish when the value is meaningful without resetting the field during forwarding.

There should be a place in documentation which describes all the dynamic fields and their meaning. For example, which drivers/features set the field and the exact meaning.

A dynamic field can be registered by anyone, including the apps. So you will never get a full list.
The meaning of each field should be defined in its context (driver, lib or app).

Quoted 1 line

Is the timestamp in HW units, UTC units, or TSC ticks?

Quoted 7 lines
Quoted 3 lines

The timestamp unit is driver-specific.
It is explained in ethdev API:
http://doc.dpdk.org/api/rte__ethdev_8h.html#a4346bf07a0d302c9ba4fe06baffd3196

Are there are any conventions we should use in this area? There could be overlapping usage between subsystems?

The name of the field should be prefixed with the right context to avoid overlapping of different usages.
It is documented here:

	http://doc.dpdk.org/api/rte__mbuf__dyn_8h.html