From patchwork Fri Jul 24 20:23:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Keroulas X-Patchwork-Id: 74793 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 465AAA0526; Fri, 24 Jul 2020 22:24:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C347D1C0B1; Fri, 24 Jul 2020 22:23:42 +0200 (CEST) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by dpdk.org (Postfix) with ESMTP id 509AA1C043 for ; Fri, 24 Jul 2020 22:23:36 +0200 (CEST) Received: by mail-qv1-f68.google.com with SMTP id ed14so4711558qvb.2 for ; Fri, 24 Jul 2020 13:23:36 -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=IMmxATRmW+DN5TwZ77KMewfw+/X9d+omoIHifKJZ80E=; b=KA7D7ebBvmC4K0j5jpO/etAZCUb85lEahue4hH1VeBbNS6tF+3NXQgkubsx1NBRIgD GwxSreuHRf88xXoZcUZNhWYLT+o6lmdcEIW+tOCW4dGujpAEQZQxp+guMGJv9xpkDAt1 WZUqw/USGhAu8Ula/vrsrQAFCsud6HGIkQnrZQ5P+RjQAKngzOrSOJO+XppbXR38qon9 T8nPfgvhm1ciUnXhDUJiLmPAWV55rR7tzT+WZSfflyyC9LU6YqY1CBtko7bl/pxTEs76 ZqVb2/cCyhy2OK0vbZtji2B9jy2JOVzS0wKWH4Qlacy8lEdq1twi3Gp15z8b1HQXKuci IIIA== 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=IMmxATRmW+DN5TwZ77KMewfw+/X9d+omoIHifKJZ80E=; b=V3awv6am9ycOR/C6vSq+a6A8bNIEktA3/N0EmD0tGQ7e1KbiWy9uVN2TM1wVH92c0J /I9JU88ggZyWY957sWTSSbE11u7hTQUkm0r1XaWtgCl+ljwirpBLF3QnJ006b0B1EwX+ axIgSHWuaQxKaSOtXW9B0BizeclYbZLYxNYzMIa9xupiibjHGo/GoFRrMDdIuNPJogEC xcCH29U+adwtoSRLPnE1Mi/Nn2D3sDMs5KloNLyZd3HuPdM5YI5O8TtMdIQPPqg+w2MX 45GjYpGPnV5ZfemExBmfo18RBBp5Tl/AvGqhfWWWxFrXkd6uAdw3jEeRXPZE9XYbbdoO RF/g== X-Gm-Message-State: AOAM533knO1TQSELgrk/S/M0GIBOVPmI9MaRS+wbYntaCcFKMZQkANGu 7Sq75kLX9sJokbSqAZH8HhsZkyJ4e0A= X-Google-Smtp-Source: ABdhPJyfEUTR59+ujbRQzigPd1pze7Ydowg34cpm/6Rzapl1QMasPpY9chLTdssQ9jCKFdYq2SrpQg== X-Received: by 2002:a0c:b2d9:: with SMTP id d25mr3617516qvf.147.1595622215314; Fri, 24 Jul 2020 13:23:35 -0700 (PDT) Received: from localhost.localdomain (modemcable246.10-73-45.static.videotron.ca. [45.73.10.246]) by smtp.gmail.com with ESMTPSA id f7sm5216089qkj.32.2020.07.24.13.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 13:23:34 -0700 (PDT) From: Patrick Keroulas To: dev@dpdk.org Cc: Vivien Didelot , Patrick Keroulas Date: Fri, 24 Jul 2020 16:23:15 -0400 Message-Id: <20200724202315.19533-5-patrick.keroulas@radio-canada.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724202315.19533-1-patrick.keroulas@radio-canada.ca> References: <20200724202315.19533-1-patrick.keroulas@radio-canada.ca> Subject: [dpdk-dev] [[PATCH v3 4/4] net/pcap: support hardware Tx 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" From: Vivien Didelot When hardware timestamping is enabled on Rx path, system time should no longer be used to calculate the timestamps when dumping packets. Instead, use the value stored by the driver in mbuf->timestamp and assume it is already converted to nanoseconds (otherwise the application may edit the packet headers itself afterwards). Signed-off-by: Vivien Didelot Signed-off-by: Patrick Keroulas --- doc/guides/rel_notes/release_20_08.rst | 1 + drivers/net/pcap/rte_eth_pcap.c | 32 +++++++++++++----------- lib/librte_pdump/rte_pdump.c | 34 ++++++++++++++------------ 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/doc/guides/rel_notes/release_20_08.rst b/doc/guides/rel_notes/release_20_08.rst index 89822bcb8d..bda2f7567a 100644 --- a/doc/guides/rel_notes/release_20_08.rst +++ b/doc/guides/rel_notes/release_20_08.rst @@ -105,6 +105,7 @@ New Features Updated PCAP driver with new features and improvements, including: * Support software Tx nanosecond timestamps precision. + * Support hardware Tx timestamps. * **Updated Broadcom bnxt driver.** diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 668cbd1fc7..45775951f7 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -290,19 +290,23 @@ eth_null_rx(void *queue __rte_unused, #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) { + 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 = { + .tv_sec = cycles / hz, + .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 +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 diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index 8fd7e13af5..e8963e9dd8 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -71,21 +71,6 @@ 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) @@ -118,6 +103,23 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params) } } +#define NSEC_PER_SEC 1000000000L +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) * NSEC_PER_SEC / hz; + } +} + static uint16_t pdump_rx(uint16_t port __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts, uint16_t nb_pkts, @@ -154,7 +156,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, 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; + start_time = now.tv_sec * NSEC_PER_SEC + now.tv_usec * 1000; if (cbs->cb) { PDUMP_LOG(ERR,