DPDK-dev Archive on lore.kernel.org
 help / color / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Vivien Didelot <vivien.didelot@gmail.com>
Cc: dev@dpdk.org, patrick.keroulas@radio-canada.ca, thomas@monjalon.net
Subject: Re: [dpdk-dev] [PATCH 1/2] net/pcap: support software Tx nanosecond timestamp
Date: Sat, 23 May 2020 18:39:50 -0700
Message-ID: <20200523183950.562eb25d@hermes.lan> (raw)
In-Reply-To: <20200523172130.2285380-1-vivien.didelot@gmail.com>

On Sat, 23 May 2020 13:21:29 -0400
Vivien Didelot <vivien.didelot@gmail.com> wrote:

> When capturing packets into a PCAP file, DPDK currently uses
> microseconds for the timestamp. But libpcap supports interpreting
> tv_usec as nanoseconds depending on the file timestamp precision.
> 
> 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).
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
> ---
>  drivers/net/pcap/rte_eth_pcap.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
> index b4c79d174..68588c3d7 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	1e9
> +
>  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;
> +	}

Please no floating point math in the fast path of capturing packets!

      parent reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-23 17:21 Vivien Didelot
2020-05-23 17:21 ` [dpdk-dev] [PATCH 2/2] net/pcap: add TODO for writing Tx HW timestamp Vivien Didelot
2020-05-24  1:38   ` Stephen Hemminger
2020-05-24  1:39 ` Stephen Hemminger [this message]

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=20200523183950.562eb25d@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=patrick.keroulas@radio-canada.ca \
    --cc=thomas@monjalon.net \
    --cc=vivien.didelot@gmail.com \
    /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

DPDK-dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dpdk-dev/0 dpdk-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dpdk-dev dpdk-dev/ https://lore.kernel.org/dpdk-dev \
		dev@dpdk.org
	public-inbox-index dpdk-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git