All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
To: dev@dpdk.org
Cc: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
Subject: [dpdk-dev] [[PATCH v3 3/4] pdump: convert timestamp to nanoseconds on Rx path
Date: Fri, 24 Jul 2020 16:23:14 -0400	[thread overview]
Message-ID: <20200724202315.19533-4-patrick.keroulas@radio-canada.ca> (raw)
In-Reply-To: <20200724202315.19533-1-patrick.keroulas@radio-canada.ca>

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(+)

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 "
-- 
2.17.1


  parent reply	other threads:[~2020-07-24 20:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 20:23 [dpdk-dev] [[PATCH v3 0/4] pdump HW Rx timestamps for mlx5 Patrick Keroulas
2020-07-24 20:23 ` [dpdk-dev] [[PATCH v3 1/4] net/mlx5: query device frequency Patrick Keroulas
2020-07-24 20:23 ` [dpdk-dev] [[PATCH v3 2/4] ethdev: add API to " Patrick Keroulas
2020-07-24 20:23 ` Patrick Keroulas [this message]
2020-09-02 15:41   ` [dpdk-dev] [[PATCH v3 3/4] pdump: convert timestamp to nanoseconds on Rx path Pattan, Reshma
2020-07-24 20:23 ` [dpdk-dev] [[PATCH v3 4/4] net/pcap: support hardware Tx timestamps Patrick Keroulas
2020-07-25  8:35   ` Tom Barbette
2020-07-25 11:51     ` Stephen Hemminger
2020-07-26 22:17   ` Stephen Hemminger
2020-10-06 16:25 ` [dpdk-dev] [[PATCH v3 0/4] pdump HW Rx timestamps for mlx5 Ferruh Yigit
2020-10-07  6:59   ` Morten Brørup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200724202315.19533-4-patrick.keroulas@radio-canada.ca \
    --to=patrick.keroulas@radio-canada.ca \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.