]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: fix timestamp issues
authorVictor Julien <vjulien@oisf.net>
Wed, 19 Oct 2022 12:18:20 +0000 (12:18 +0000)
committerVictor Julien <vjulien@oisf.net>
Wed, 19 Oct 2022 21:04:53 +0000 (23:04 +0200)
Each thread had its own version of the `machine_start_time`, which
lead to slight time differences. This became apparent mostly in IPS,
where 2 threads each process a side of the flow.

This patch makes the `machine_start_time` global.

src/runmode-dpdk.c
src/source-dpdk.c
src/source-dpdk.h

index f4b3e27fe15cb4a1d783e95b92936257f084bc74..a0d1d2871d1f65a9c35b8b1af16ce6a32f590493 100644 (file)
@@ -291,6 +291,7 @@ static void InitEal()
         FatalError(
                 SC_ERR_DPDK_EAL_INIT, "DPDK EAL initialization error: %s", rte_strerror(-retval));
     }
+    DPDKSetTimevalOfMachineStart();
 }
 
 static void DPDKDerefConfig(void *conf)
index 3dc9733c1efc3cb6946b7a88556edcbff3bc29dd..644c277d2a6317d27a57cf15f3078a9ae49a3c99 100644 (file)
@@ -90,6 +90,7 @@ TmEcode NoDPDKSupportExit(ThreadVars *tv, const void *initdata, void **data)
 #include <numa.h>
 
 #define BURST_SIZE 32
+static struct timeval machine_start_time = { 0, 0 };
 
 /**
  * \brief Structure to hold thread specific variables.
@@ -122,7 +123,6 @@ typedef struct DPDKThreadVars_ {
     uint16_t queue_id;
     struct rte_mempool *pkt_mempool;
     struct rte_mbuf *received_mbufs[BURST_SIZE];
-    struct timeval machine_start_time;
 } DPDKThreadVars;
 
 static TmEcode ReceiveDPDKThreadInit(ThreadVars *, const void *, void **);
@@ -166,10 +166,10 @@ static void CyclesAddToTimeval(
     new_tv->tv_usec = (usec % 1000000);
 }
 
-static void DPDKSetTimevalOfMachineStart(struct timeval *tv)
+void DPDKSetTimevalOfMachineStart(void)
 {
-    gettimeofday(tv, NULL);
-    tv->tv_sec -= DPDKGetSeconds();
+    gettimeofday(&machine_start_time, NULL);
+    machine_start_time.tv_sec -= DPDKGetSeconds();
 }
 
 /**
@@ -374,7 +374,7 @@ static TmEcode ReceiveDPDKLoop(ThreadVars *tv, void *data, void *slot)
                 p->flags |= PKT_IGNORE_CHECKSUM;
             }
 
-            DPDKSetTimevalReal(&ptv->machine_start_time, &p->ts);
+            DPDKSetTimevalReal(&machine_start_time, &p->ts);
             p->dpdk_v.mbuf = ptv->received_mbufs[i];
             p->ReleasePacket = DPDKReleasePacket;
             p->dpdk_v.copy_mode = ptv->copy_mode;
@@ -432,7 +432,6 @@ static TmEcode ReceiveDPDKThreadInit(ThreadVars *tv, const void *initdata, void
     ptv->pkts = 0;
     ptv->bytes = 0;
     ptv->livedev = LiveGetDevice(dpdk_config->iface);
-    DPDKSetTimevalOfMachineStart(&ptv->machine_start_time);
 
     ptv->capture_dpdk_packets = StatsRegisterCounter("capture.packets", ptv->tv);
     ptv->capture_dpdk_rx_errs = StatsRegisterCounter("capture.rx_errors", ptv->tv);
index 9ee46676ce744e73effcde802f15ae7f489c41f7..ae855253136592d07a2a442ec05d38a77c544df0 100644 (file)
@@ -41,6 +41,7 @@ typedef enum { DPDK_COPY_MODE_NONE, DPDK_COPY_MODE_TAP, DPDK_COPY_MODE_IPS } Dpd
 // Offloads
 #define DPDK_RX_CHECKSUM_OFFLOAD (1 << 4) /**< Enable chsum offload */
 
+void DPDKSetTimevalOfMachineStart(void);
 typedef struct DPDKIfaceConfig_ {
 #ifdef HAVE_DPDK
     char iface[RTE_ETH_NAME_MAX_LEN];