From patchwork Thu Jun 11 15:16:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Keroulas X-Patchwork-Id: 71280 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E67F8A0093; Thu, 11 Jun 2020 17:16:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B88042BF7; Thu, 11 Jun 2020 17:16:43 +0200 (CEST) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by dpdk.org (Postfix) with ESMTP id 5F4C32A5D for ; Thu, 11 Jun 2020 17:16:42 +0200 (CEST) Received: by mail-qt1-f196.google.com with SMTP id w9so4814076qtv.3 for ; Thu, 11 Jun 2020 08:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=radio-canada-ca.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VbwQ9zgLJg84bEvioUX37HglishNU+ztxQDFz+3wF4I=; b=XvZ5nDglQ5IPBS5hJVq54KK+2Z+2kXB02OXfUSML638uY42vxJEpG2Xo/lu86e6Dh8 6ZemvmC5mZsG7mPP36ZiFyLI/32VtjuTeav37dwKk5IJn/VSTRqWyeF48bJcbsCWG5w0 yXUyr9CEKf/XJbKWk8xzsDQl64ia3fkP73ib+NuBL1ApfuaGhzyadnBZtgMoGie8EOiV 7phK4yIX4tz120lw7vKmWJNVgloQZKVqIa/nogRLvuqCByUqK3/7tXeoyoZE0+uNFQS4 BuvUxaVg5EsI3pv5j63UE8hnTUmLGlk6Y1XDKyX4POtxQiMOb6XCLTL74sbHPSg9vu8P lMww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VbwQ9zgLJg84bEvioUX37HglishNU+ztxQDFz+3wF4I=; b=WRpOvq0xn1RjwSqkOVZhDN6ELBNRKi38N73xAQnfhymvfOhMXHCOrC4JbNIEYkv0ia vlAft34vNAx/NRlqnBMt0MgITc6+cOtzxTzr4RVV6N+tidXGlvSO4HZ/DmjxISm1MvSd uX6RvQgewLc+Vrq/OjV0zNsU+FhdNspD9YYubcXRwSTg1q9R6kyhpy6mGsz1l2HQnNVr S/b/vQ8CSR7GO/KTyVaRdf96ZSvNaYBLOOcvmm8ajrydg/6cCTGlu2IL/d1L32U4CEvG 2xShIKVWi80IqAF05/RaKB1GvbT/cggPhOS3kvwl7sEFy7wpwMk4vrfN4UdRdTtNzdoI SoXg== X-Gm-Message-State: AOAM5336lQbp9cO+y3FtWyF8cFFVcqJ6fBHthSiwrnsXzNaj1JSKS+vJ ktSIHQlQOiJBhwWzgZsjBMoLyRIwCuN8iw== X-Google-Smtp-Source: ABdhPJxTZukZYwxZvQRfCEoQiGjMdJYjie8hakv3ftubuJAgFUrHSkml0enbQ9/Jswl0gtbwmgRzIw== X-Received: by 2002:ac8:4e86:: with SMTP id 6mr9003371qtp.390.1591888601574; Thu, 11 Jun 2020 08:16:41 -0700 (PDT) Received: from localhost.localdomain (modemcable246.10-73-45.static.videotron.ca. [45.73.10.246]) by smtp.gmail.com with ESMTPSA id h77sm2524379qke.37.2020.06.11.08.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 08:16:41 -0700 (PDT) From: Patrick Keroulas To: dev@dpdk.org Cc: Patrick Keroulas , Vivien Didelot Date: Thu, 11 Jun 2020 11:16:10 -0400 Message-Id: <20200611151610.32409-4-patrick.keroulas@radio-canada.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200611151610.32409-1-patrick.keroulas@radio-canada.ca> References: <20200611151610.32409-1-patrick.keroulas@radio-canada.ca> Subject: [dpdk-dev] [RFC][PATCH v2 3/3] net/pcap: dump hardware timestamps X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Signed-off-by: Vivien Didelot --- drivers/net/pcap/rte_eth_pcap.c | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 13a3d0ac7..6a4ffae7b 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; @@ -287,22 +289,23 @@ eth_null_rx(void *queue __rte_unused, return 0; } -#define NSEC_PER_SEC 1000000000L - 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) * 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; +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; + } } } @@ -339,7 +342,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