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 19F23A00C5; Thu, 11 Jun 2020 09:54:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E7A7814581; Thu, 11 Jun 2020 09:54:34 +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 3D4541BEB7 for ; Wed, 10 Jun 2020 21:40:06 +0200 (CEST) Received: by mail-qt1-f196.google.com with SMTP id g62so2766067qtd.5 for ; Wed, 10 Jun 2020 12:40:06 -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:mime-version :content-transfer-encoding; bh=l2h5G9H1GgPzB7BaAdeLn1amFRtgqXlgEgAh+Z1FsrM=; b=hRFxgTtRORvuFDisDRyhLMHoApy2g170g8e8bYf1q+iv4dkonAA3GINnyua1Af3rCG 7zZ3j6vBgwy7VfF6TgF/36QX2z3dvj9CoSpNOTu1gPNKw5pAL9wY9lZ6ltdDP/dmh2Ht tqVCy2AdUF1y4MFN4VIW3492tQ8FWYoT+jBB+kEZxpdSi4hmEcga8CAJ3TyZpqlDGGEg Fve0/Pr2Suw2gRozyqIb0p1bpas4/d48Wvo/0sOUrS/ZQpHOqyC0YvAPdwwH5G4PGJts l5U5Zr1EFi1o3PhLrPMdDLiEIMe6EDaZK46s40EohA5Ff66fyEIzvfWnNK3kEO5BGvWQ yn4A== 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:mime-version :content-transfer-encoding; bh=l2h5G9H1GgPzB7BaAdeLn1amFRtgqXlgEgAh+Z1FsrM=; b=WjCsWtbBRztri//AGbWjqiOa291kDQbartU62dsHOZVhfkRZyOGP8k7XgFfzSUK7E3 wE4I1Jt0PnCNQV1BCUsLFiuG/tSHf67jRnGucL6oIIZ6HPpFPerE+R8DrtCBVjlg+XVV 83XN0KwJQk4Vo87lzSXUTJnXPAc74Rfa/wiJu+WNBfPfgxXc4/HzUTSQL9qgISJfmCtP 2TlfyBWt1mq/KDsAcRPaixQFB3WF99xQCc6wvGyjFGhXyf5us1HU7PnKC/8MmOfFdos9 vGDYHU3GrpRKMSOnw/n6EtMCyqKiik1XXwNJW6B2WuOw3TvtjiQnFZt1tWrT6jbYboBK Aqww== X-Gm-Message-State: AOAM530UA4JwlFpd2tXxxeraotkAWecnbkFIUkbih0jYKDHrtNPOYTKX Uvr2Zq4aDVGSKfl4rSITW0vz9sl3 X-Google-Smtp-Source: ABdhPJzUHa1prBlU1QaTsRwhuqddpKgSpjzh7iGPan+59GFaOs2s10ujZgsUIXhQLM58V5gO8ZNKKA== X-Received: by 2002:aed:2744:: with SMTP id n62mr4977879qtd.152.1591818005152; Wed, 10 Jun 2020 12:40:05 -0700 (PDT) Received: from localhost (modemcable249.105-163-184.mc.videotron.ca. [184.163.105.249]) by smtp.gmail.com with ESMTPSA id w3sm545822qkb.85.2020.06.10.12.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 12:40:04 -0700 (PDT) From: Vivien Didelot To: dev@dpdk.org Cc: Ferruh Yigit , patrick.keroulas@radio-canada.ca, Vivien Didelot Date: Wed, 10 Jun 2020 15:39:38 -0400 Message-Id: <20200610193938.218768-1-vivien.didelot@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 11 Jun 2020 09:54:33 +0200 Subject: [dpdk-dev] [PATCH] 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 7a67c960c..cedceaf9d 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