DPDK patches and discussions
 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>,
	Vivien Didelot <vivien.didelot@gmail.com>
Subject: [dpdk-dev] [RFC] [PATCH v1 3/3] net/pcap: dump hardware timestamps
Date: Tue,  9 Jun 2020 10:17:13 -0400	[thread overview]
Message-ID: <20200609141713.11614-4-patrick.keroulas@radio-canada.ca> (raw)
In-Reply-To: <20200609141713.11614-1-patrick.keroulas@radio-canada.ca>

When hardware timestamping is activated, system time should no longer be
used to timestamp dumped the packets. Instead, use value held by
forwarded and assume they were converted to nanoseconds.

Signed-off-by: Patrick Keroulas <patrick.keroulas@radio-canada.ca>
Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/pcap/rte_eth_pcap.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index b4c79d174..1303e3338 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -45,6 +45,8 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
+#define NSEC_PER_SEC	1000000000L
+
 static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timeval start_time;
 static uint64_t start_cycles;
@@ -288,14 +290,24 @@ eth_null_rx(void *queue __rte_unused,
 }
 
 static inline void
-calculate_timestamp(struct timeval *ts) {
-	uint64_t cycles;
-	struct timeval cur_time;
-
-	cycles = rte_get_timer_cycles() - start_cycles;
-	cur_time.tv_sec = cycles / hz;
-	cur_time.tv_usec = (cycles % hz) * 1e6 / hz;
-	timeradd(&start_time, &cur_time, ts);
+calculate_timestamp(const struct rte_mbuf *mbuf, struct timeval *ts) {
+	if (mbuf->ol_flags & PKT_RX_TIMESTAMP) {
+		/* timestamp unit is nanoseconds but must fit in timeval */
+		ts->tv_sec = mbuf->timestamp / NSEC_PER_SEC;
+		ts->tv_usec = mbuf->timestamp % NSEC_PER_SEC;
+	}
+	else {
+		uint64_t cycles = rte_get_timer_cycles() - start_cycles;
+		struct timeval cur_time;
+		cur_time.tv_sec = cycles / hz;
+		cur_time.tv_usec = (cycles % hz) * NSEC_PER_SEC / hz;
+		ts->tv_sec = start_time.tv_sec + cur_time.tv_sec;
+		ts->tv_usec = start_time.tv_usec + cur_time.tv_usec;
+		if (ts->tv_usec > NSEC_PER_SEC) {
+			ts->tv_usec -= NSEC_PER_SEC;
+			ts->tv_sec += 1;
+		}
+	}
 }
 
 /*
@@ -331,7 +343,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			caplen = sizeof(temp_data);
 		}
 
-		calculate_timestamp(&header.ts);
+		calculate_timestamp(mbuf, &header.ts);
 		header.len = len;
 		header.caplen = caplen;
 		/* rte_pktmbuf_read() returns a pointer to the data directly
@@ -475,7 +487,7 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 	 * with pcap_dump_open(). We create big enough an Ethernet
 	 * pcap holder.
 	 */
-	tx_pcap = pcap_open_dead(DLT_EN10MB, RTE_ETH_PCAP_SNAPSHOT_LEN);
+	tx_pcap = pcap_open_dead_with_tstamp_precision(DLT_EN10MB, RTE_ETH_PCAP_SNAPSHOT_LEN, PCAP_TSTAMP_PRECISION_NANO);
 	if (tx_pcap == NULL) {
 		PMD_LOG(ERR, "Couldn't create dead pcap");
 		return -1;
-- 
2.17.1


  parent reply	other threads:[~2020-06-09 14:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09 14:17 [dpdk-dev] [RFC] [PATCH v1 0/3] pdump HW timestamps for mlx5 Patrick Keroulas
2020-06-09 14:17 ` [dpdk-dev] [RFC] [PATCH v1 1/3] net/mlx5: add timestamp-to-ns converter from libibverbs Patrick Keroulas
2020-06-09 14:17 ` [dpdk-dev] [RFC] [PATCH v1 2/3] ethdev: add API to convert raw timestamps to nsec Patrick Keroulas
2020-06-09 14:17 ` Patrick Keroulas [this message]
2020-06-09 14:41   ` [dpdk-dev] [RFC] [PATCH v1 3/3] net/pcap: dump hardware timestamps Ferruh Yigit
2020-06-10 13:51     ` Ferruh Yigit
2020-06-23 15:07 ` [dpdk-dev] [RFC] [PATCH v1 0/3] pdump HW timestamps for mlx5 Slava Ovsiienko

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=20200609141713.11614-4-patrick.keroulas@radio-canada.ca \
    --to=patrick.keroulas@radio-canada.ca \
    --cc=dev@dpdk.org \
    --cc=vivien.didelot@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).