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: [email protected]

Signed-off-by: Stephen Hemminger <[email protected]>
---
 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

Reply via email to