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 84092A0517; Wed, 10 Jun 2020 12:21:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2258A29D6; Wed, 10 Jun 2020 12:21:29 +0200 (CEST) Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by dpdk.org (Postfix) with ESMTP id 17F42B62 for ; Tue, 9 Jun 2020 21:07:54 +0200 (CEST) Received: by mail-qv1-f65.google.com with SMTP id p15so10634779qvr.9 for ; Tue, 09 Jun 2020 12:07:54 -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=/aUAREE5qmSyMcExxhtF1BphYNK7EX65x392aJ2umHc=; b=hhz3cH4Y3g+5Ig/ut0Hf1DkflJJrsEilNoDX54FvlrDzoju7uYqNSy/dJKtBTyLixc UJ3J7tZ1fGjGAeL/+dWHRMljGxD3tKwI3TnhM9XiXEl4FxGfXNMRdGON1yEcMfSIMvKS M/mgvsAgTjFugObO5JuWpUM15oeN/jsRDNMlAVPSFB9nAS4GiVCS7MUluSgLj0fzSVVE u83+7zCFggIMItcc4jGhex01TO0E1XUirmJYa57iqfLvEgzl+6s6mO1kN6YChAo03VbR /Fns6OfxeLTvJ+zlDQB6DsRs/im7DH3MFYVCGE9p2RMAZ9NYJ5+QUOKygS9RSiydJDDR x45g== 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=/aUAREE5qmSyMcExxhtF1BphYNK7EX65x392aJ2umHc=; b=YZ4E/zuMzurbwBjPJDL9BVJjY/ywBnkfp5FgQhUN+vKdI83p7mVKyMsmKx+sKwFpZ6 JUvNnCVcZrHbdPBqly0eYeXrY0H/4xz3MTr4NU40J0X790pS63tJnH3XHSQCq0BEVBc5 ttCJszPy/Hspr1j2aoVST0z8ZCILTZcRZt346CR8IJjsN70/Zl0zKCdpU+SfyVEYiWb0 cToMuOnKtUdX/f0HMrjEyLR6IS2JuKmANX8Bci1nDJw92obgebxyDJNa7WRji9mSsvyN pkg4SLtCTt26bCunrcqON2VOjlqmxBPhlGBv43psbb48qkYcP5VWowdXTSawitOXoduX 8dmA== X-Gm-Message-State: AOAM533XBTrx3B+KBDnVWMAR0LnwM4mGlaSmgKp3zSGm5oJHTUH6YWfx Zheq5RzrHWcUBeftGw08r5UxRdzX X-Google-Smtp-Source: ABdhPJxGlrAEMAkqXxOgLXlifbDNkzchFQmyUC3EN2lfccGXwTTeFGKKOcg3eICBnGyBHtnWKdbw6g== X-Received: by 2002:a0c:b35a:: with SMTP id a26mr5411031qvf.114.1591729669827; Tue, 09 Jun 2020 12:07:49 -0700 (PDT) Received: from localhost (modemcable249.105-163-184.mc.videotron.ca. [184.163.105.249]) by smtp.gmail.com with ESMTPSA id k10sm10104263qkh.47.2020.06.09.12.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 12:07:48 -0700 (PDT) From: Vivien Didelot To: dev@dpdk.org Cc: Stephen Hemminger , Ferruh Yigit , patrick.keroulas@radio-canada.ca, thomas@monjalon.net, Vivien Didelot Date: Tue, 9 Jun 2020 15:07:19 -0400 Message-Id: <20200609190719.105323-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: Wed, 10 Jun 2020 12:21:28 +0200 Subject: [dpdk-dev] [PATCH v2] net/pcap: support software Tx nanosecond 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 capturing packets into a PCAP file, DPDK currently uses microseconds for the timestamps. But libpcap supports interpreting tv_usec as nanoseconds depending on the file timestamp precision, as of commit ba89e4a18e8b ("Make timestamps precision configurable"). To support this, use PCAP_TSTAMP_PRECISION_NANO when creating the empty PCAP file as specified by PCAP_OPEN_DEAD(3PCAP) and implement nanosecond timeval addition. This also ensures that the precision reported by capinfos is nanoseconds (9). Note that NSEC_PER_SEC is defined as 1000000000L instead of 1e9 since the latter might be interpreted as floating point. Signed-off-by: Vivien Didelot --- doc/guides/rel_notes/release_20_08.rst | 6 ++++++ drivers/net/pcap/rte_eth_pcap.c | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/guides/rel_notes/release_20_08.rst b/doc/guides/rel_notes/release_20_08.rst index dee4ccbb5..7a67c960c 100644 --- a/doc/guides/rel_notes/release_20_08.rst +++ b/doc/guides/rel_notes/release_20_08.rst @@ -56,6 +56,12 @@ New Features Also, make sure to start the actual text at the margin. ========================================================= +* **Updated PCAP driver.** + + Updated PCAP driver with new features and improvements, including: + + * Support software Tx nanosecond timestamps precision. + * **Updated Mellanox mlx5 driver.** Updated Mellanox mlx5 driver with new features and improvements, including: diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index b4c79d174..13a3d0ac7 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -287,6 +287,8 @@ 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; @@ -294,8 +296,14 @@ calculate_timestamp(struct timeval *ts) { 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); + 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; + } } /* @@ -475,7 +483,8 @@ 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; -- 2.27.0