From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5F3C3A0350; Tue, 30 Jun 2020 09:33:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 21E481BEE4; Tue, 30 Jun 2020 09:32:35 +0200 (CEST) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by dpdk.org (Postfix) with ESMTP id 6FEFDF04 for ; Thu, 25 Jun 2020 21:01:32 +0200 (CEST) Received: by mail-qk1-f196.google.com with SMTP id 80so6455885qko.7 for ; Thu, 25 Jun 2020 12:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n34eLvA5LQ9ISBDVlil26EmLV5fYWq7NX82LY5DrHYY=; b=N7bNS1Ky763MlMW18p5nvW3CA50hgoZiHtlD3YVRFZKHYZkb+6G8FuAAUlfl0Iplmv 62PgFAVAAnuvzE/W1S8ynYbxmlbxnSuMJ4rxsbq9fUVkv7CbD2ZcSedF7C0Xy2YR5ZnG 2+SSdZ8IFOItB/rj7enz8SWBd9iRZyJNjM6c0dW4OBpLS1OzhJ+bxvsSiAvtkWfe+iqG Uph9CO/9Rr16xrzuRbL9qbAb9vTdCkQbXirYdsQJ2PWxeslH5NbC6jHMZbhZCjz79yZZ CALwybNj46rpVFiM3Dmgqjp1n0kd9IW6/5Rf3ZllTpdTzOU85PcDUu4sLDmjbg7/V7cv GsMg== 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:mime-version:content-transfer-encoding; bh=n34eLvA5LQ9ISBDVlil26EmLV5fYWq7NX82LY5DrHYY=; b=q910iMOkXJqX21dINtkhFC+1OekwqIVoh+4aLiugbs1PBzWDpNPkNcPhfjxnmj0Pzx 7t351YZXAKz9HeTNO9e8vXjIVvMI5arl+MJqXWZRhvl5aQ/5CL+9AMamZILdvSjBvZ0c yU6+pb6uI4/sU7i17Gk2wXgX0q418uqvZWdRVagsAPyNACzO8Zl7PBvPnrC8hJ+9V1Da NtUfRs4/0bmrxLeTIMxn3GOVwaf6xhicELTd0IW3DY0miIwhxkU+//sKkb9Jr1abeTGm gE9v3LF4poCxkB7fRUVmTVVL+derKsNsPq5oMfhqw3H5psdIkdQl6kzniE523s3Zf4Yv XLrQ== X-Gm-Message-State: AOAM533pqqcIszBFmOEW8NGQU1uTdmhOdXUKWq2KXB+gEY9i3IHL1GMd f9pglVGopvc+xEhBSDuE++QiBQDr X-Google-Smtp-Source: ABdhPJywNBq+G5612S4Ho30s4+RkNYT16xDTLPUIHTmocg1WNPSMf6qnuoHmhrRJh9tKYcVQSaYUwA== X-Received: by 2002:a37:b401:: with SMTP id d1mr32913904qkf.206.1593111691525; Thu, 25 Jun 2020 12:01:31 -0700 (PDT) Received: from localhost (modemcable249.105-163-184.mc.videotron.ca. [184.163.105.249]) by smtp.gmail.com with ESMTPSA id n63sm6556276qkn.104.2020.06.25.12.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 12:01:30 -0700 (PDT) From: Vivien Didelot To: dev@dpdk.org Cc: Vivien Didelot , Olivier Matz , Ferruh Yigit , Patrick Keroulas Date: Thu, 25 Jun 2020 15:01:19 -0400 Message-Id: <20200625190119.265739-4-vivien.didelot@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200625190119.265739-1-vivien.didelot@gmail.com> References: <20200625190119.265739-1-vivien.didelot@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 30 Jun 2020 09:32:26 +0200 Subject: [dpdk-dev] [RFC PATCH 3/3] 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" 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 | 30 +++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/doc/guides/rel_notes/release_20_08.rst b/doc/guides/rel_notes/release_20_08.rst index a67015519..cd1ca987f 100644 --- a/doc/guides/rel_notes/release_20_08.rst +++ b/doc/guides/rel_notes/release_20_08.rst @@ -61,6 +61,7 @@ New Features Updated PCAP driver with new features and improvements, including: * Support software Tx nanosecond timestamps precision. + * Support hardware Tx timestamps. * **Updated Mellanox mlx5 driver.** diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 13a3d0ac7..3d80b699b 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; +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, + }; - 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; + 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 -- 2.27.0