From: Marat Khalili <marat.khalili@huawei.com>
To: Stephen Hemminger <stephen@networkplumber.org>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH 08/12] net/pcap: optimize calculation of receive timestamp
Date: Wed, 7 Jan 2026 10:58:53 +0000 [thread overview]
Message-ID: <7a43c70576054749920c16e8c2ae6320@huawei.com> (raw)
In-Reply-To: <20260106182823.192350-9-stephen@networkplumber.org>
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Tuesday 6 January 2026 18:27
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>
> Subject: [PATCH 08/12] net/pcap: optimize calculation of receive timestamp
>
> Avoid doing slow instructions in receive path when calculating
> timestamp. Give all packets in the same rx burst the same timestamp.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/net/pcap/pcap_ethdev.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> index 175d6998f9..e283fb3787 100644
> --- a/drivers/net/pcap/pcap_ethdev.c
> +++ b/drivers/net/pcap/pcap_ethdev.c
> @@ -20,6 +20,7 @@
> #include <bus_vdev_driver.h>
> #include <rte_os_shim.h>
> #include <rte_time.h>
> +#include <rte_reciprocal.h>
>
> #include "pcap_osdep.h"
>
> @@ -41,7 +42,7 @@
>
> static struct timespec start_time;
> static uint64_t start_cycles;
> -static uint64_t hz;
> +static struct rte_reciprocal_u64 hz_inv;
>
> static uint64_t timestamp_rx_dynflag;
> static int timestamp_dynfield_offset = -1;
> @@ -362,8 +363,6 @@ eth_null_rx(void *queue __rte_unused,
> return 0;
> }
>
> -#define NSEC_PER_SEC 1000000000L
> -
> /*
> * This function stores nanoseconds in `tv_usec` field of `struct timeval`,
> * because `ts` goes directly to nanosecond-precision dump.
> @@ -374,8 +373,10 @@ calculate_timestamp(struct timeval *ts) {
> struct timespec cur_time;
>
> cycles = rte_get_timer_cycles() - start_cycles;
> - cur_time.tv_sec = cycles / hz;
> - cur_time.tv_nsec = (cycles % hz) * NSEC_PER_SEC / hz;
> + cur_time.tv_sec = rte_reciprocal_divide_u64(cycles, &hz_inv);
> + /* compute remainder */
> + cycles -= cur_time.tv_sec * rte_get_timer_hz();
Can be made faster and safer by caching rte_get_timer_hz() result in current translation unit.
> + cur_time.tv_nsec = rte_reciprocal_divide_u64(cycles * NS_PER_S, &hz_inv);
>
> ts->tv_sec = start_time.tv_sec + cur_time.tv_sec;
> ts->tv_usec = start_time.tv_nsec + cur_time.tv_nsec;
> @@ -394,6 +395,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> unsigned int i;
> struct pmd_process_private *pp;
> struct pcap_tx_queue *dumper_q = queue;
> + struct pcap_pkthdr header;
> uint16_t num_tx = 0;
> uint32_t tx_bytes = 0;
> pcap_dumper_t *dumper;
> @@ -406,13 +408,14 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> if (unlikely(dumper == NULL || nb_pkts == 0))
> return 0;
>
> - /* writes the nb_pkts packets to the previously opened pcap file
> - * dumper */
> + /* all packets in burst have same timestamp */
> + calculate_timestamp(&header.ts);
> +
> + /* writes the nb_pkts packets to the previously opened pcap file dumper */
> for (i = 0; i < nb_pkts; i++) {
> struct rte_mbuf *mbuf = bufs[i];
> size_t len = rte_pktmbuf_pkt_len(mbuf);
> uint8_t temp_data[RTE_ETH_PCAP_SNAPLEN];
> - struct pcap_pkthdr header;
>
> if (unlikely(len > mtu))
> continue;
> @@ -420,7 +423,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> if ((mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) && rte_vlan_insert(&mbuf))
> continue;
>
> - calculate_timestamp(&header.ts);
> header.len = len;
> header.caplen = len;
>
> @@ -1530,7 +1532,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
>
> timespec_get(&start_time, TIME_UTC);
> start_cycles = rte_get_timer_cycles();
> - hz = rte_get_timer_hz();
> +
> + hz_inv = rte_reciprocal_value_u64(rte_get_timer_hz());
>
> if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
> eth_dev = rte_eth_dev_attach_secondary(name);
> --
> 2.51.0
Apart from one minor optimization suggestion above,
Acked-by: Marat Khalili <marat.khalili@huawei.com>
next prev parent reply other threads:[~2026-01-07 10:58 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 18:26 [PATCH 00/12] net/pcap: cleanups and test Stephen Hemminger
2026-01-06 18:26 ` [PATCH 01/12] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-06 18:26 ` [PATCH 02/12] net/pcap: support MTU set Stephen Hemminger
2026-01-06 18:26 ` [PATCH 03/12] net/pcap: use bool for flags Stephen Hemminger
2026-01-07 10:28 ` Marat Khalili
2026-01-09 0:23 ` Stephen Hemminger
2026-01-06 18:26 ` [PATCH 04/12] net/pcap: support Tx offloads Stephen Hemminger
2026-01-06 18:26 ` [PATCH 05/12] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-06 18:26 ` [PATCH 06/12] net/pcap: remove global variables Stephen Hemminger
2026-01-07 9:48 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 07/12] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-07 10:31 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 08/12] net/pcap: optimize calculation of receive timestamp Stephen Hemminger
2026-01-07 10:58 ` Marat Khalili [this message]
2026-01-06 18:26 ` [PATCH 09/12] net/pcap: report receive clock Stephen Hemminger
2026-01-06 18:26 ` [PATCH 10/12] net/pcap: cleanup MAC address handling Stephen Hemminger
2026-01-06 18:26 ` [PATCH 11/12] net/pcap: support MAC address set Stephen Hemminger
2026-01-06 18:26 ` [PATCH 12/12] test: add test for pcap PMD Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 0/9] pcap: cleanup pcap PMD and add test Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 1/9] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 2/9] net/pcap: support MTU set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 3/9] net/pcap: use bool for flags Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 4/9] net/pcap: support Tx offloads Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 5/9] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 6/9] net/pcap: remove global variables Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 7/9] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 8/9] net/pcap: support MAC address set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 9/9] test: add test for pcap PMD Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7a43c70576054749920c16e8c2ae6320@huawei.com \
--to=marat.khalili@huawei.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).