From: Victor Julien Date: Wed, 19 Oct 2022 12:18:20 +0000 (+0000) Subject: dpdk: fix timestamp issues X-Git-Tag: suricata-7.0.0-beta1~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1068bbb08b6b3a50126cec32142d744a39ed712;p=thirdparty%2Fsuricata.git dpdk: fix timestamp issues 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. --- diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index f4b3e27fe1..a0d1d2871d 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -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) diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 3dc9733c1e..644c277d2a 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -90,6 +90,7 @@ TmEcode NoDPDKSupportExit(ThreadVars *tv, const void *initdata, void **data) #include #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); diff --git a/src/source-dpdk.h b/src/source-dpdk.h index 9ee46676ce..ae85525313 100644 --- a/src/source-dpdk.h +++ b/src/source-dpdk.h @@ -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];