DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
	stable@dpdk.org, "Reshma Pattan" <reshma.pattan@intel.com>,
	"Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH 2/4] app/dumpcap: fix capture duration
Date: Tue, 17 Nov 2026 08:06:20 -0800	[thread overview]
Message-ID: <20261117160727.388470-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20261117160727.388470-1-stephen@networkplumber.org>

The capture duration was measured using time() which has
one second resolution and was compared with greater than,
so the capture could run up to a second longer than requested.
Also, since the duration was converted to whole seconds,
fractional durations were lost; a duration of less than one
second would be treated as no limit.

Use the TSC to measure the capture interval, as is done
in the rest of DPDK, and keep the fractional part of the
duration.

Fixes: 166591931b72 ("pcapng: modify timestamp calculation")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index c4790988e5..2808f77add 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -69,13 +69,13 @@ static bool print_stats;
 
 /* capture limit options */
 static struct {
-	time_t  duration;	/* seconds */
+	double  duration;	/* seconds */
 	unsigned long packets;  /* number of packets in file */
 	size_t size;		/* file size (bytes) */
 } stop;
 
 /* Running state */
-static time_t start_time;
+static uint64_t stop_tsc;	/* TSC when duration expires, 0 if none */
 static uint64_t packets_received;
 static size_t file_size;
 
@@ -1036,7 +1036,9 @@ int main(int argc, char **argv)
 	mp = create_mempool();
 	out = create_output();
 
-	start_time = time(NULL);
+	if (stop.duration > 0)
+		stop_tsc = rte_get_tsc_cycles() +
+			(uint64_t)(stop.duration * rte_get_tsc_hz());
 	enable_pdump(r, mp);
 
 	if (!quiet) {
@@ -1057,8 +1059,7 @@ int main(int argc, char **argv)
 		if (stop.packets && packets_received >= stop.packets)
 			break;
 
-		if (stop.duration != 0 &&
-		    time(NULL) - start_time > stop.duration)
+		if (stop_tsc != 0 && rte_get_tsc_cycles() >= stop_tsc)
 			break;
 	}
 
-- 
2.53.0


  parent reply	other threads:[~2026-11-17 16:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 16:06 [PATCH 0/4] app/dumpcap: assorted fixes Stephen Hemminger
2026-11-17 16:06 ` [PATCH 1/4] app/dumpcap: fix packet count overshoot Stephen Hemminger
2026-11-17 16:06 ` Stephen Hemminger [this message]
2026-11-17 16:06 ` [PATCH 3/4] app/dumpcap: fix pcap timestamps Stephen Hemminger
2026-11-17 16:06 ` [PATCH 4/4] app/dumpcap: do not use rte_exit before EAL init 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=20261117160727.388470-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    --cc=reshma.pattan@intel.com \
    --cc=stable@dpdk.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