[RFC,v1,3/3] net/pcap: dump hardware timestamps

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

Checks

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

Commit Message

Patrick Keroulas June 9, 2020, 2:17 p.m. UTC
  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(-)
  

Comments

Ferruh Yigit June 9, 2020, 2:41 p.m. UTC | #1
On 6/9/2020 3:17 PM, Patrick Keroulas wrote:
> 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>

I think better to get the Vivien's patch that enables 'nanosecond timestamp',
with requested change first and later this patch can be on top of it to add
PKT_RX_TIMESTAMP support.

Or you can split the patch into two, as mentioned above, both are OK but I don't
want pcap nanosecond timestamp patch blocked from this hw timestamp patchset
discussions.
  
Ferruh Yigit June 10, 2020, 1:51 p.m. UTC | #2
On 6/9/2020 3:41 PM, Ferruh Yigit wrote:
> On 6/9/2020 3:17 PM, Patrick Keroulas wrote:
>> 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>
> 
> I think better to get the Vivien's patch that enables 'nanosecond timestamp',
> with requested change first and later this patch can be on top of it to add
> PKT_RX_TIMESTAMP support.
> 
> Or you can split the patch into two, as mentioned above, both are OK but I don't
> want pcap nanosecond timestamp patch blocked from this hw timestamp patchset
> discussions.
> 

Vivien's patch merged [1], can you please rebase this patchset on top of next-net?

[1] https://patches.dpdk.org/patch/71130/
  

Patch

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;