[11/15] net/pcap: switch timestamp to dynamic mbuf field
diff mbox series

Message ID 20201029092751.3837177-12-thomas@monjalon.net
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • remove mbuf timestamp
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Thomas Monjalon Oct. 29, 2020, 9:27 a.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/pcap/rte_eth_pcap.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 34e82317b1..b4b7a1839b 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -18,6 +18,7 @@ 
 
 #include <pcap.h>
 
+#include <rte_bitops.h>
 #include <rte_cycles.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
@@ -51,6 +52,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 +269,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 +662,23 @@  eth_dev_stop(struct rte_eth_dev *dev)
 static int
 eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
 {
+	int timestamp_rx_dynflag_offset;
+
+	timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+			RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+	if (timestamp_dynfield_offset < 0) {
+		PMD_LOG(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) {
+		PMD_LOG(ERR, "Failed lookup Rx timestamp flag");
+		return -rte_errno;
+	}
+	timestamp_rx_dynflag =
+		RTE_BIT64(timestamp_rx_dynflag_offset);
+
 	return 0;
 }