[[PATCH,v3,3/4] pdump: convert timestamp to nanoseconds on Rx path

Message ID 20200724202315.19533-4-patrick.keroulas@radio-canada.ca (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series pdump HW Rx timestamps for mlx5 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Patrick Keroulas July 24, 2020, 8:23 p.m. UTC
  Use start time and device frequency to translate raw Rx hardware
timestamps into nanoseconds.

Signed-off-by: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
---
 lib/librte_pdump/rte_pdump.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
  

Comments

Pattan, Reshma Sept. 2, 2020, 3:41 p.m. UTC | #1
> -----Original Message-----
> +			rte_eth_read_clock(port, &start_cycles);
> +			rte_eth_get_clock_freq(port, &hz);

Do you need to check return value of these calls to  handle -ENOTSUP? And avoid timestamping marking.
If -ENOTSUP, then hz value is 0 and using hz in function pdump_ts_to_ns() might be illegal.


> +			gettimeofday(&now, NULL);

Same here, need to handle return value carefully?

Thanks,
Reshma
  

Patch

diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c
index b3c8d5ce43..8fd7e13af5 100644
--- a/lib/librte_pdump/rte_pdump.c
+++ b/lib/librte_pdump/rte_pdump.c
@@ -2,6 +2,8 @@ 
  * Copyright(c) 2016-2018 Intel Corporation
  */
 
+#include <sys/time.h>
+
 #include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
@@ -69,6 +71,21 @@  static struct pdump_rxtx_cbs {
 } rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT],
 tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT];
 
+static uint64_t hz;
+static uint64_t start_time;
+static uint64_t start_cycles;
+
+static inline void
+pdump_ts_to_ns(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	unsigned int i;
+
+	for (i = 0; i < nb_pkts; i++) {
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) && hz)
+			pkts[i]->timestamp = start_time +
+				 (pkts[i]->timestamp - start_cycles) * NS_PER_S / hz;
+	}
+}
 
 static inline void
 pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
@@ -107,6 +124,7 @@  pdump_rx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
 	uint16_t max_pkts __rte_unused,
 	void *user_params)
 {
+	pdump_ts_to_ns(pkts, nb_pkts);
 	pdump_copy(pkts, nb_pkts, user_params);
 	return nb_pkts;
 }
@@ -131,6 +149,13 @@  pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 	for (; qid < end_q; qid++) {
 		cbs = &rx_cbs[port][qid];
 		if (cbs && operation == ENABLE) {
+			struct timeval now;
+
+			rte_eth_read_clock(port, &start_cycles);
+			rte_eth_get_clock_freq(port, &hz);
+			gettimeofday(&now, NULL);
+			start_time = now.tv_sec * NS_PER_S + now.tv_usec * 1000;
+
 			if (cbs->cb) {
 				PDUMP_LOG(ERR,
 					"failed to add rx callback for port=%d "